Skip to content

Commit 06584ee

Browse files
committed
feat(tsserver_plugins): Allow for path in tsserver_plugins
1 parent 35e397c commit 06584ee

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

lua/typescript-tools/config.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
---@field tsserver_logs string
55
---@field publish_diagnostic_on publish_diagnostic_mode
66
---@field tsserver_path string|nil
7-
---@field tsserver_plugins string[]
7+
---@field tsserver_plugins (string|{name: string, path: string})[]
88
---@field tsserver_format_options table|fun(filetype: string): table
99
---@field tsserver_file_preferences table|fun(filetype: string): table
1010
---@field tsserver_max_memory number|"auto"

lua/typescript-tools/process.lua

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ local is_win = uv.os_uname().version:find "Windows"
2222
---@class Process
2323
local Process = {}
2424

25-
---@param type ServerType
25+
---@param ttype ServerType
2626
---@param on_response fun(response: table)
2727
---@param on_exit fun(code: number, signal: number)
2828
---@return Process
29-
function Process.new(type, on_response, on_exit)
29+
function Process.new(ttype, on_response, on_exit)
3030
local self = setmetatable({}, { __index = Process })
3131

3232
local tsserver_provider = TsserverProvider.get_instance()
@@ -54,19 +54,38 @@ function Process.new(type, on_response, on_exit)
5454

5555
local plugins_path = tsserver_provider:get_plugins_path()
5656

57-
if plugins_path and #plugin_config.tsserver_plugins > 0 then
57+
if plugin_config.tsserver_plugins and #plugin_config.tsserver_plugins > 0 then
58+
local plugin_names = {}
59+
local probe_locations = {}
60+
local has_object_plugins = false
61+
62+
for _, plugin in ipairs(plugin_config.tsserver_plugins) do
63+
if type(plugin) == "table" then
64+
has_object_plugins = true
65+
local full_path = Path:new(plugin.path, plugin.name):absolute()
66+
table.insert(plugin_names, plugin.name)
67+
table.insert(probe_locations, full_path)
68+
else
69+
table.insert(plugin_names, plugin)
70+
end
71+
end
72+
5873
table.insert(self.args, "--pluginProbeLocations")
59-
table.insert(self.args, plugins_path:absolute())
74+
if has_object_plugins then
75+
table.insert(self.args, table.concat(probe_locations, ","))
76+
else
77+
table.insert(self.args, plugins_path:absolute())
78+
end
6079
table.insert(self.args, "--globalPlugins")
61-
table.insert(self.args, table.concat(plugin_config.tsserver_plugins, ","))
80+
table.insert(self.args, table.concat(plugin_names, ","))
6281
end
6382

6483
if plugin_config.tsserver_logs ~= "off" then
6584
local log_dir = Path:new(uv.os_tmpdir())
6685
table.insert(self.args, "--logVerbosity")
6786
table.insert(self.args, plugin_config.tsserver_logs)
6887
table.insert(self.args, "--logFile")
69-
table.insert(self.args, log_dir:joinpath("tsserver_" .. type .. ".log"):absolute())
88+
table.insert(self.args, log_dir:joinpath("tsserver_" .. ttype .. ".log"):absolute())
7089
end
7190

7291
self:start()

0 commit comments

Comments
 (0)