Browse Source

fix: dynamically find global node modules path depending on os

master
Tovi Jaeschke-Rogers 6 months ago
parent
commit
c9e3e225ec
1 changed files with 20 additions and 2 deletions
  1. +20
    -2
      .config/nvim/lua/tovi/plugins/lsp/lspconfig.lua

+ 20
- 2
.config/nvim/lua/tovi/plugins/lsp/lspconfig.lua View File

@ -109,12 +109,30 @@ return {
on_attach = on_attach,
})
-- Function to detect the operating system
local function get_os()
local handle = io.popen('uname')
local result = handle:read("*a")
handle:close()
return result:lower():gsub("%s+", "")
end
-- Set the base path based on the operating system
local os = get_os()
local base_path = ""
if os == "darwin" then
base_path = "/opt/homebrew/lib/node_modules"
elseif os == "linux" then
base_path = "/usr/lib/node_modules"
end
lspconfig.tsserver.setup({
init_options = {
plugins = {
{
name = "@vue/typescript-plugin",
location = "/usr/local/lib/node_modules/@vue/typescript-plugin",
location = base_path .. "/@vue/typescript-plugin",
languages = { "javascript", "typescript", "vue" },
},
},
@ -129,7 +147,7 @@ return {
local function get_typescript_server_path(root_dir)
local global_ts = '/usr/local/lib/node_modules/typescript/lib'
local global_ts = base_path .. '/typescript/lib'
local found_ts = ''
local function check_dir(path)
found_ts = util.path.join(path, 'node_modules', 'typescript', 'lib')


Loading…
Cancel
Save