Skip to content

Commit

Permalink
fix: fixes LspRestart command on nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
KostkaBrukowa committed Jun 19, 2024
1 parent 3f942ec commit 08a549a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lua/typescript-tools/rpc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ local autocommands = require "typescript-tools.autocommands"
local custom_handlers = require "typescript-tools.custom_handlers"
local request_router = require "typescript-tools.request_router"
local internal_commands = require "typescript-tools.internal_commands"
local utils = require "typescript-tools.utils"

local M = {}

---@param dispatchers Dispatchers
---@return LspInterface
function M.start(dispatchers)
local tsserver_syntax = Tsserver.new("syntax", dispatchers)
local modified_dispatchers = vim.deepcopy(dispatchers)
modified_dispatchers.on_exit = utils.run_once(dispatchers.on_exit) -- INFO: multiple calls to on_exit causes errors in nvim lsp

local tsserver_syntax = Tsserver.new("syntax", modified_dispatchers)
local tsserver_semantic = nil
if plugin_config.separate_diagnostic_server then
tsserver_semantic = Tsserver.new("semantic", dispatchers)
tsserver_semantic = Tsserver.new("semantic", modified_dispatchers)
end

autocommands.setup_autocommands(dispatchers)
Expand Down
1 change: 1 addition & 0 deletions lua/typescript-tools/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
---@field notification fun(method: string, params: table)
---@field server_request fun(method: string, params: table): nil, table
---@field on_exit fun(code: number, signal: number)
---@field on_error fun(code: number, ...: unknown)

---@alias LspCallback fun(err: any, result: any)

Expand Down
12 changes: 12 additions & 0 deletions lua/typescript-tools/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,16 @@ function M.add_reverse_lookup(tbl)
end
end

-- Returns a function that only runs the given function once.
--- @param func function
function M.run_once(func)
local ran = false
return function(...)
if not ran then
ran = true
return func(...)
end
end
end

return M

0 comments on commit 08a549a

Please sign in to comment.