From c9e3e225ecbde821ccc37f4a9a1c382825ee0ac6 Mon Sep 17 00:00:00 2001 From: Tovi Jaeschke-Rogers Date: Tue, 14 May 2024 11:56:21 +0930 Subject: [PATCH] fix: dynamically find global node modules path depending on os --- .../nvim/lua/tovi/plugins/lsp/lspconfig.lua | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/.config/nvim/lua/tovi/plugins/lsp/lspconfig.lua b/.config/nvim/lua/tovi/plugins/lsp/lspconfig.lua index 0023b0f..f7a575c 100644 --- a/.config/nvim/lua/tovi/plugins/lsp/lspconfig.lua +++ b/.config/nvim/lua/tovi/plugins/lsp/lspconfig.lua @@ -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')