From 23a348548a70c2084b5fe6229d543a115f325803 Mon Sep 17 00:00:00 2001 From: Tovi Jaeschke-Rogers Date: Thu, 9 May 2024 12:36:45 +0930 Subject: [PATCH] fix: volar for vue3 --- .../nvim/lua/tovi/plugins/lsp/lspconfig.lua | 67 ++++++++++++------- .zshrc | 11 +-- 2 files changed, 48 insertions(+), 30 deletions(-) diff --git a/.config/nvim/lua/tovi/plugins/lsp/lspconfig.lua b/.config/nvim/lua/tovi/plugins/lsp/lspconfig.lua index 2d551bc..0023b0f 100644 --- a/.config/nvim/lua/tovi/plugins/lsp/lspconfig.lua +++ b/.config/nvim/lua/tovi/plugins/lsp/lspconfig.lua @@ -104,42 +104,59 @@ return { vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) end - -- configure html server - lspconfig["html"].setup({ + lspconfig.html.setup({ capabilities = capabilities, on_attach = on_attach, }) - -- configure typescript server with plugin - lspconfig["tsserver"].setup({ - capabilities = capabilities, - on_attach = on_attach, - filetypes = { "typescript", "vue" }, - init_options = { - { - name = "@vue/typescript-plugin", - location = "/usr/local/lib/node_modules/@vue/typescript-plugin", - languages = {"javascript", "typescript", "vue"}, - }, - } + lspconfig.tsserver.setup({ + init_options = { + plugins = { + { + name = "@vue/typescript-plugin", + location = "/usr/local/lib/node_modules/@vue/typescript-plugin", + languages = { "javascript", "typescript", "vue" }, + }, + }, + }, + filetypes = { + "javascript", + "typescript", + "vue", + }, + capabilities = capabilities, }) - -- configure css server - lspconfig["cssls"].setup({ - capabilities = capabilities, + local function get_typescript_server_path(root_dir) + + local global_ts = '/usr/local/lib/node_modules/typescript/lib' + local found_ts = '' + local function check_dir(path) + found_ts = util.path.join(path, 'node_modules', 'typescript', 'lib') + if util.path.exists(found_ts) then + return path + end + end + if util.search_ancestors(root_dir, check_dir) then + return found_ts + else + return global_ts + end + end + + lspconfig.volar.setup({ + -- capabilities = capabilities, on_attach = on_attach, + filetypes = { "vue" }, + on_new_config = function(new_config, new_root_dir) + new_config.init_options.typescript.tsdk = get_typescript_server_path(new_root_dir) + end, }) - -- configure emmet language server - lspconfig["volar"].setup({ + -- configure css server + lspconfig["cssls"].setup({ capabilities = capabilities, on_attach = on_attach, - filetypes = { "vue" }, - init_options = { - typescript = { - tsdk = '/usr/local/lib/node_modules/typescript/lib' - }, - }, }) -- configure php server diff --git a/.zshrc b/.zshrc index cd232bd..33ab0dc 100644 --- a/.zshrc +++ b/.zshrc @@ -11,6 +11,7 @@ export CASE_SENSITIVE="true" zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}' # Load colors +autoload -U colors && colors PROMPT="%{$fg[blue]%}%1~ %{$fg[green]%}>%{$reset_color%} " # Automatically cd into typed directory. @@ -28,11 +29,11 @@ bindkey -v export KEYTIMEOUT=1 # Use vim keys in tab complete menu: -bindkey -M menuselect 'h' vi-backward-char -bindkey -M menuselect 'k' vi-up-line-or-history -bindkey -M menuselect 'l' vi-forward-char -bindkey -M menuselect 'j' vi-down-line-or-history -bindkey -v '^?' backward-delete-char +# bindkey -M menuselect 'h' vi-backward-char +# bindkey -M menuselect 'k' vi-up-line-or-history +# bindkey -M menuselect 'l' vi-forward-char +# bindkey -M menuselect 'j' vi-down-line-or-history +# bindkey -v '^?' backward-delete-char # Edit line in vim with ctrl-e: autoload edit-command-line; zle -N edit-command-line