Skip to content

Commit

Permalink
fix: on_attach called multiple times with `separate_diagnostic_serv…
Browse files Browse the repository at this point in the history
…er` (#220)

* Revert "fix: use buffer number instead of a boolean to limit on_attach calls (#218)"

This reverts commit 54224a2.

* Revert "fix: `on_attach` called multiple times with `separate_diagnostic_server` (#213)"

This reverts commit df64c37.

* fix: `on_attach` called multiple times with `separate_diagnostic_server`
  • Loading branch information
pmizio authored Jan 14, 2024
1 parent 54224a2 commit 094e4f4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 42 deletions.
3 changes: 0 additions & 3 deletions lua/typescript-tools/autocommands/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ local diagnostics = require "typescript-tools.autocommands.diagnostics"
local code_lens = require "typescript-tools.autocommands.code_lens"
local config = require "typescript-tools.config"
local jsx_close_tag = require "typescript-tools.autocommands.jsx_close_tag"
local on_attach = require "typescript-tools.autocommands.on_attach"

local M = {}

---@param dispatchers Dispatchers
function M.setup_autocommands(dispatchers)
diagnostics.setup_diagnostic_autocmds(dispatchers)

on_attach.setup_on_attach_autocmds()

if config.code_lens ~= config.code_lens_mode.off then
code_lens.setup_code_lens_autocmds()
end
Expand Down
18 changes: 0 additions & 18 deletions lua/typescript-tools/autocommands/on_attach.lua

This file was deleted.

21 changes: 0 additions & 21 deletions lua/typescript-tools/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ local configs = require "lspconfig.configs"
local util = require "lspconfig.util"
local rpc = require "typescript-tools.rpc"
local plugin_config = require "typescript-tools.config"
local on_attach_aucmd = require "typescript-tools.autocommands.on_attach"

local M = {}

Expand Down Expand Up @@ -45,26 +44,6 @@ function M.setup(config)
}
end

-- INFO: some nasty ifology but it need to be placed somewhere
-- I prefer it here than in huge file tsserver.lua
-- Rationale: `on_attach` is called based on response from `configure` request and because we
-- have two servers nvim get also two responses
local buf_map = on_attach_aucmd.buf_map
local config_on_attach = config.on_attach

local function wrapped_on_attach(client, bufnr)
local buf_key = tostring(bufnr)
if buf_map[buf_key] then
return
end
buf_map[buf_key] = true
config_on_attach(client, bufnr)
end

if config.on_attach then
config.on_attach = wrapped_on_attach
end

lspconfig[plugin_config.plugin_name].setup(config)
end

Expand Down
8 changes: 8 additions & 0 deletions lua/typescript-tools/tsserver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,16 @@ function Tsserver:handle_request(method, params, callback, notify_reply_callback
function handler_context.response(response, error)
local seq = get_seq()
local notify_reply = notify_reply_callback and vim.schedule_wrap(notify_reply_callback)
---@type function|nil
local response_callback = callback and vim.schedule_wrap(callback)

-- INFO: to prevent multiple `on_attach` calls ignore `initialize` response from semantic
-- server and respond only from syntax one
if method == c.LspMethods.Initialize and self.server_type == "semantic" then
notify_reply = nil
response_callback = nil
end

if notify_reply then
notify_reply(seq)
end
Expand Down

0 comments on commit 094e4f4

Please sign in to comment.