Skip to content

feat(tsserver plugins): Allow for path in tsserver_plugins #322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lua/typescript-tools/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
---@field tsserver_logs string
---@field publish_diagnostic_on publish_diagnostic_mode
---@field tsserver_path string|nil
---@field tsserver_plugins string[]
---@field tsserver_plugins (string|{name: string, path: string})[]
---@field tsserver_format_options table|fun(filetype: string): table
---@field tsserver_file_preferences table|fun(filetype: string): table
---@field tsserver_max_memory number|"auto"
Expand Down
31 changes: 25 additions & 6 deletions lua/typescript-tools/process.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ local is_win = uv.os_uname().version:find "Windows"
---@class Process
local Process = {}

---@param type ServerType
---@param ttype ServerType
---@param on_response fun(response: table)
---@param on_exit fun(code: number, signal: number)
---@return Process
function Process.new(type, on_response, on_exit)
function Process.new(ttype, on_response, on_exit)
local self = setmetatable({}, { __index = Process })

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

local plugins_path = tsserver_provider:get_plugins_path()

if plugins_path and #plugin_config.tsserver_plugins > 0 then
if plugin_config.tsserver_plugins and #plugin_config.tsserver_plugins > 0 then
local plugin_names = {}
local probe_locations = {}
local has_object_plugins = false

for _, plugin in ipairs(plugin_config.tsserver_plugins) do
if type(plugin) == "table" then
has_object_plugins = true
local full_path = Path:new(plugin.path, plugin.name):absolute()
table.insert(plugin_names, plugin.name)
table.insert(probe_locations, full_path)
else
table.insert(plugin_names, plugin)
end
end

table.insert(self.args, "--pluginProbeLocations")
table.insert(self.args, plugins_path:absolute())
if has_object_plugins then
table.insert(self.args, table.concat(probe_locations, ","))
else
table.insert(self.args, plugins_path:absolute())
end
table.insert(self.args, "--globalPlugins")
table.insert(self.args, table.concat(plugin_config.tsserver_plugins, ","))
table.insert(self.args, table.concat(plugin_names, ","))
end

if plugin_config.tsserver_logs ~= "off" then
local log_dir = Path:new(uv.os_tmpdir())
table.insert(self.args, "--logVerbosity")
table.insert(self.args, plugin_config.tsserver_logs)
table.insert(self.args, "--logFile")
table.insert(self.args, log_dir:joinpath("tsserver_" .. type .. ".log"):absolute())
table.insert(self.args, log_dir:joinpath("tsserver_" .. ttype .. ".log"):absolute())
end

self:start()
Expand Down
Loading