Skip to content

Commit

Permalink
Revert "fix: use buffer number instead of a boolean to limit on_attac…
Browse files Browse the repository at this point in the history
…h calls (#218)"

This reverts commit 54224a2.
  • Loading branch information
pmizio committed Jan 13, 2024
1 parent 54224a2 commit fff27a9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 29 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.

15 changes: 7 additions & 8 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 @@ -49,20 +48,20 @@ function M.setup(config)
-- 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 on_attach_called = false
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
local function on_attach(...)
if on_attach_called then
return
end
buf_map[buf_key] = true
config_on_attach(client, bufnr)

on_attach_called = true
config_on_attach(...)
end

if config.on_attach then
config.on_attach = wrapped_on_attach
config.on_attach = on_attach
end

lspconfig[plugin_config.plugin_name].setup(config)
Expand Down

0 comments on commit fff27a9

Please sign in to comment.