|
@ -8,7 +8,7 @@ return { |
|
|
config = function() |
|
|
config = function() |
|
|
-- import lspconfig plugin |
|
|
-- import lspconfig plugin |
|
|
local lspconfig = require("lspconfig") |
|
|
local lspconfig = require("lspconfig") |
|
|
local util = require("lspconfig.util") |
|
|
|
|
|
|
|
|
local util = require("lspconfig.util") |
|
|
|
|
|
|
|
|
-- import cmp-nvim-lsp plugin |
|
|
-- import cmp-nvim-lsp plugin |
|
|
local cmp_nvim_lsp = require("cmp_nvim_lsp") |
|
|
local cmp_nvim_lsp = require("cmp_nvim_lsp") |
|
@ -79,13 +79,16 @@ return { |
|
|
vim.diagnostic.goto_next({ severity = vim.diagnostic.severity.ERROR }) |
|
|
vim.diagnostic.goto_next({ severity = vim.diagnostic.severity.ERROR }) |
|
|
end, opts) |
|
|
end, opts) |
|
|
|
|
|
|
|
|
|
|
|
opts.desc = "Show documentation for what is under cursor" |
|
|
|
|
|
keymap.set("n", "<leader>ld", vim.diagnostic.setqflist, opts) -- show documentation for what is under cursor |
|
|
|
|
|
|
|
|
opts.desc = "Show documentation for what is under cursor" |
|
|
opts.desc = "Show documentation for what is under cursor" |
|
|
keymap.set("n", "K", vim.lsp.buf.hover, opts) -- show documentation for what is under cursor |
|
|
keymap.set("n", "K", vim.lsp.buf.hover, opts) -- show documentation for what is under cursor |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
-- override default floating window border if not set |
|
|
-- override default floating window border if not set |
|
|
local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview |
|
|
local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview |
|
|
---@diagnostic disable-next-line: duplicate-set-field |
|
|
|
|
|
|
|
|
---@diagnostic disable-next-line: duplicate-set-field |
|
|
function vim.lsp.util.open_floating_preview(contents, syntax, options, ...) |
|
|
function vim.lsp.util.open_floating_preview(contents, syntax, options, ...) |
|
|
options = options or {} |
|
|
options = options or {} |
|
|
options.border = options.border or "rounded" |
|
|
options.border = options.border or "rounded" |
|
@ -107,72 +110,72 @@ return { |
|
|
on_attach = on_attach, |
|
|
on_attach = on_attach, |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
-- Function to detect the operating system |
|
|
|
|
|
local function get_os() |
|
|
|
|
|
local handle = io.popen('uname') |
|
|
|
|
|
if not handle then |
|
|
|
|
|
return error("Failed to detect operating system") |
|
|
|
|
|
end |
|
|
|
|
|
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/local/lib/node_modules" |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
lspconfig.tsserver.setup({ |
|
|
|
|
|
init_options = { |
|
|
|
|
|
plugins = { |
|
|
|
|
|
{ |
|
|
|
|
|
name = "@vue/typescript-plugin", |
|
|
|
|
|
location = base_path .. "/@vue/typescript-plugin", |
|
|
|
|
|
languages = { "javascript", "typescript", "vue" }, |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
filetypes = { |
|
|
|
|
|
"javascript", |
|
|
|
|
|
"typescript", |
|
|
|
|
|
"vue", |
|
|
|
|
|
}, |
|
|
|
|
|
capabilities = capabilities, |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
local function get_typescript_server_path(root_dir) |
|
|
|
|
|
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') |
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
-- Function to detect the operating system |
|
|
|
|
|
local function get_os() |
|
|
|
|
|
local handle = io.popen("uname") |
|
|
|
|
|
if not handle then |
|
|
|
|
|
return error("Failed to detect operating system") |
|
|
|
|
|
end |
|
|
|
|
|
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/local/lib/node_modules" |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
lspconfig.tsserver.setup({ |
|
|
|
|
|
init_options = { |
|
|
|
|
|
plugins = { |
|
|
|
|
|
{ |
|
|
|
|
|
name = "@vue/typescript-plugin", |
|
|
|
|
|
location = base_path .. "/@vue/typescript-plugin", |
|
|
|
|
|
languages = { "javascript", "typescript", "vue" }, |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
filetypes = { |
|
|
|
|
|
"javascript", |
|
|
|
|
|
"typescript", |
|
|
|
|
|
"vue", |
|
|
|
|
|
}, |
|
|
|
|
|
capabilities = capabilities, |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
local function get_typescript_server_path(root_dir) |
|
|
|
|
|
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") |
|
|
|
|
|
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({ |
|
|
lspconfig.volar.setup({ |
|
|
capabilities = capabilities, |
|
|
capabilities = capabilities, |
|
|
on_attach = on_attach, |
|
|
on_attach = on_attach, |
|
|
filetypes = { |
|
|
|
|
|
"javascript", |
|
|
|
|
|
"typescript", |
|
|
|
|
|
"vue", |
|
|
|
|
|
}, |
|
|
|
|
|
on_new_config = function(new_config, new_root_dir) |
|
|
|
|
|
new_config.init_options.typescript.tsdk = get_typescript_server_path(new_root_dir) |
|
|
|
|
|
end, |
|
|
|
|
|
|
|
|
filetypes = { |
|
|
|
|
|
"javascript", |
|
|
|
|
|
"typescript", |
|
|
|
|
|
"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 css server |
|
|
-- configure css server |
|
@ -183,39 +186,38 @@ return { |
|
|
|
|
|
|
|
|
-- configure php server |
|
|
-- configure php server |
|
|
lspconfig["intelephense"].setup({ |
|
|
lspconfig["intelephense"].setup({ |
|
|
root_dir = function(pattern) |
|
|
|
|
|
---@diagnostic disable-next-line: undefined-field |
|
|
|
|
|
local cwd = vim.loop.cwd() |
|
|
|
|
|
local root = util.root_pattern('composer.json')(pattern) |
|
|
|
|
|
|
|
|
|
|
|
-- prefer cwd if root is a descendant |
|
|
|
|
|
return util.path.is_descendant(cwd, root) and cwd or root |
|
|
|
|
|
end, |
|
|
|
|
|
|
|
|
root_dir = function(pattern) |
|
|
|
|
|
---@diagnostic disable-next-line: undefined-field |
|
|
|
|
|
local cwd = vim.loop.cwd() |
|
|
|
|
|
local root = util.root_pattern("composer.json")(pattern) |
|
|
|
|
|
|
|
|
|
|
|
-- prefer cwd if root is a descendant |
|
|
|
|
|
return util.path.is_descendant(cwd, root) and cwd or root |
|
|
|
|
|
end, |
|
|
capabilities = capabilities, |
|
|
capabilities = capabilities, |
|
|
on_attach = on_attach, |
|
|
on_attach = on_attach, |
|
|
init_options = { |
|
|
|
|
|
licenceKey = vim.fn.expand('$HOME/.local/share/nvim/intelephense-licence.txt') |
|
|
|
|
|
}, |
|
|
|
|
|
settings = { |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
init_options = { |
|
|
|
|
|
licenceKey = vim.fn.expand("$HOME/.local/share/nvim/intelephense-licence.txt"), |
|
|
|
|
|
}, |
|
|
|
|
|
settings = {}, |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
lspconfig.gopls.setup { |
|
|
|
|
|
on_attach = on_attach, |
|
|
|
|
|
capabilities = capabilities, |
|
|
|
|
|
cmd = {"gopls"}, |
|
|
|
|
|
filetypes = { "go", "gomod", "gowork", "gotmpl" }, |
|
|
|
|
|
root_dir = util.root_pattern("go.work", "go.mod", ".git"), |
|
|
|
|
|
settings = { |
|
|
|
|
|
gopls = { |
|
|
|
|
|
completeUnimported = true, |
|
|
|
|
|
usePlaceholders = true, |
|
|
|
|
|
analyses = { |
|
|
|
|
|
unusedparams = true, |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
lspconfig.gopls.setup({ |
|
|
|
|
|
on_attach = on_attach, |
|
|
|
|
|
capabilities = capabilities, |
|
|
|
|
|
cmd = { "gopls" }, |
|
|
|
|
|
filetypes = { "go", "gomod", "gowork", "gotmpl" }, |
|
|
|
|
|
root_dir = util.root_pattern("go.work", "go.mod", ".git"), |
|
|
|
|
|
settings = { |
|
|
|
|
|
gopls = { |
|
|
|
|
|
completeUnimported = true, |
|
|
|
|
|
usePlaceholders = true, |
|
|
|
|
|
analyses = { |
|
|
|
|
|
unusedparams = true, |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
-- configure lua server (with special settings) |
|
|
-- configure lua server (with special settings) |
|
|
lspconfig["lua_ls"].setup({ |
|
|
lspconfig["lua_ls"].setup({ |
|
|