Skip to content

Commit

Permalink
Vue files are now working thanks to GR3YH4TT3R93
Browse files Browse the repository at this point in the history
Found a config in a Github convo here:
williamboman/mason-lspconfig.nvim#371 (comment)
  • Loading branch information
Rich107 committed Jul 31, 2024
1 parent 55e4258 commit e95e71b
Showing 1 changed file with 70 additions and 36 deletions.
106 changes: 70 additions & 36 deletions lua/plugins/lsp-config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,53 +34,87 @@ return {
capabilities = capabilities,
})
end,
["volar"] = function()
require("lspconfig").volar.setup({
-- NOTE: Uncomment to enable volar in file types other than vue.
-- (Similar to Takeover Mode)

-- filetypes = { "vue", "javascript", "typescript", "javascriptreact", "typescriptreact", "json" },

-- NOTE: Uncomment to restrict Volar to only Vue/Nuxt projects. This will enable Volar to work alongside other language servers (tsserver).

-- root_dir = require("lspconfig").util.root_pattern(
-- "vue.config.js",
-- "vue.config.ts",
-- "nuxt.config.js",
-- "nuxt.config.ts"
-- ),
init_options = {
vue = {
hybridMode = false,
},
-- NOTE: This might not be needed. Uncomment if you encounter issues.

-- typescript = {
-- tsdk = vim.fn.getcwd() .. "/node_modules/typescript/lib",
-- },
},
settings = {
typescript = {
inlayHints = {
enumMemberValues = {
enabled = true,
},
functionLikeReturnTypes = {
enabled = true,
},
propertyDeclarationTypes = {
enabled = true,
},
parameterTypes = {
enabled = true,
suppressWhenArgumentMatchesName = true,
},
variableTypes = {
enabled = true,
},
},
},
},
})
end,

["tsserver"] = function()
lspconfig.tsserver.setup({
capabilities = capabilities,
local mason_packages = vim.fn.stdpath("data") .. "/mason/packages"
local volar_path = mason_packages .. "/vue-language-server/node_modules/@vue/language-server"

require("lspconfig").tsserver.setup({
-- NOTE: To enable hybridMode, change HybrideMode to true above and uncomment the following filetypes block.

-- filetypes = { "typescript", "javascript", "javascriptreact", "typescriptreact", "vue" },
init_options = {
plugins = {
{
name = "@vue/typescript-plugin",
location = "/usr/local/lib/node_modules/@vue/typescript-plugin",
languages = { "javascript", "typescript", "vue" },
location = volar_path,
languages = { "vue" },
},
},
},
filetypes = {
"javascript",
"typescript",
"vue",
},
})
end,
["volar"] = function()
lspconfig.volar.setup({
capabilities = capabilities,
init_options = {
settings = {
typescript = {
-- Ensure this path matches your TypeScript installation
serverPath = "/Users/richardellison/PycharmProjects/pa_leaderboard_frontend/frontend_app/node_modules/typescript/lib",
inlayHints = {
includeInlayParameterNameHints = "all",
includeInlayParameterNameHintsWhenArgumentMatchesName = true,
includeInlayFunctionParameterTypeHints = true,
includeInlayVariableTypeHints = true,
includeInlayVariableTypeHintsWhenTypeMatchesName = true,
includeInlayPropertyDeclarationTypeHints = true,
includeInlayFunctionLikeReturnTypeHints = true,
includeInlayEnumMemberValueHints = true,
},
},
},
on_attach = function(client, bufnr)
-- Disable other clients that might conflict
for _, other_client in pairs(vim.lsp.get_active_clients()) do
if other_client.name ~= "volar" and other_client.name ~= "null-ls" then
vim.lsp.stop_client(other_client.id)
end
end

-- Set up keybindings and commands specific to volar
local map = function(keys, func, desc)
vim.keymap.set("n", keys, func, { buffer = bufnr, desc = "LSP: " .. desc })
end

map("gd", require("telescope.builtin").lsp_definitions, "[G]oto [D]efinition")
map("gr", require("telescope.builtin").lsp_references, "[G]oto [R]eferences")
vim.keymap.set("n", "<leader>k", vim.lsp.buf.hover, {})
vim.keymap.set("n", "<leader>gr", vim.lsp.buf.references, {})
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, {})
end,
})
end,
})
Expand Down

0 comments on commit e95e71b

Please sign in to comment.