Skip to content

Commit

Permalink
fix(volar): provide tsdk location rather than full tsserver path (#77)
Browse files Browse the repository at this point in the history
Fixes #76.
  • Loading branch information
williamboman committed Oct 11, 2022
1 parent e492f12 commit d2bcb38
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lua/mason-lspconfig/server_configurations/astro/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local typescript = require "mason-lspconfig.typescript"
return function(install_dir)
return {
on_new_config = function(new_config, workspace_dir)
new_config.init_options.typescript.serverPath = typescript.resolve_server_path(install_dir, workspace_dir)
new_config.init_options.typescript.serverPath = typescript.resolve_tsserver(install_dir, workspace_dir)
end,
}
end
2 changes: 1 addition & 1 deletion lua/mason-lspconfig/server_configurations/volar/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local typescript = require "mason-lspconfig.typescript"
return function(install_dir)
return {
on_new_config = function(new_config, workspace_dir)
local tsdk = typescript.resolve_server_path(install_dir, workspace_dir)
local tsdk = typescript.resolve_tsdk(install_dir, workspace_dir)
new_config.init_options.typescript.serverPath = tsdk
new_config.init_options.typescript.tsdk = tsdk
end,
Expand Down
35 changes: 23 additions & 12 deletions lua/mason-lspconfig/typescript.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,31 @@ function typescript.tsdk(dir)
end

---@param package_dir string The Mason package installation directory where a vendored Typescript installation can be found.
---@param workspace_dir string
---@return string
function typescript.resolve_server_path(package_dir, workspace_dir)
local local_tsserverlib = workspace_dir ~= nil
and typescript.find_typescript_module_in_lib(typescript.tsdk(workspace_dir))
if local_tsserverlib then
return local_tsserverlib
else
local vendored_tsserverlib = typescript.find_typescript_module_in_lib(typescript.tsdk(package_dir))
if not vendored_tsserverlib then
log.fmt_error("Failed to find vendored Typescript module in %s", package_dir)
---@param workspace_dir string?
---@return string?, string?
function typescript.resolve_tsdk(package_dir, workspace_dir)
if workspace_dir then
local tsdk = typescript.tsdk(workspace_dir)
local local_tsserverlib = typescript.find_typescript_module_in_lib(tsdk)
if local_tsserverlib then
return tsdk, local_tsserverlib
end
return vendored_tsserverlib
end

local tsdk = typescript.tsdk(package_dir)
local vendored_tsserverlib = typescript.find_typescript_module_in_lib(tsdk)
if not vendored_tsserverlib then
log.fmt_error("Failed to find vendored Typescript module in %s", package_dir)
return nil, nil
end
return tsdk, vendored_tsserverlib
end

---@param package_dir string The Mason package installation directory where a vendored Typescript installation can be found.
---@param workspace_dir string?
function typescript.resolve_tsserver(package_dir, workspace_dir)
local _, tsserver = typescript.resolve_tsdk(package_dir, workspace_dir)
return tsserver
end

return typescript

0 comments on commit d2bcb38

Please sign in to comment.