You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
4.6 KiB
107 lines
4.6 KiB
local M = {}
|
|
|
|
M.config = function()
|
|
-- Mapping
|
|
local opts = { noremap = true, silent = true }
|
|
local kms = vim.keymap.set
|
|
kms('n', '<leader>e', vim.diagnostic.open_float, opts)
|
|
kms('n', '[d', function() vim.diagnostic.jump({ count = 1, float = true }) end, opts)
|
|
kms('n', ']d', function() vim.diagnostic.jump({ count = -1, float = true }) end, opts)
|
|
kms('n', '<leader>q', vim.diagnostic.setloclist, opts)
|
|
|
|
vim.lsp.config('*', {
|
|
capabilities = require('cmp_nvim_lsp').default_capabilities(),
|
|
on_attach = function(_, bufnr)
|
|
-- Enable completion triggered by <c-x><c-o>
|
|
vim.api.nvim_set_option_value('omnifunc', 'v:lua.vim.lsp.omnifunc', { buf = bufnr })
|
|
|
|
-- Mappings.
|
|
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
|
local bufopts = { noremap = true, silent = true, buffer = bufnr }
|
|
local kms = vim.keymap.set
|
|
-- goto *
|
|
kms('n', 'gD', vim.lsp.buf.declaration, bufopts)
|
|
kms('n', 'gd', vim.lsp.buf.definition, bufopts)
|
|
kms('n', 'gr', vim.lsp.buf.references, bufopts)
|
|
kms('n', 'gi', vim.lsp.buf.implementation, bufopts)
|
|
--kms('n', '<leader>D', vim.lsp.buf.type_definition, bufopts)
|
|
-- show info
|
|
kms('n', 'K', vim.lsp.buf.hover, bufopts)
|
|
kms('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
|
|
-- Workspace
|
|
kms('n', '<leader>wa', vim.lsp.buf.add_workspace_folder, bufopts)
|
|
kms('n', '<leader>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
|
|
kms('n', '<leader>wl', function()
|
|
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
|
end, bufopts)
|
|
-- operation
|
|
kms('n', '<leader>rn', vim.lsp.buf.rename, bufopts)
|
|
kms('n', '<leader>ca', vim.lsp.buf.code_action, bufopts)
|
|
kms('n', '<leader>f', function() vim.lsp.buf.format { async = true } end, bufopts)
|
|
end,
|
|
})
|
|
|
|
vim.lsp.config('lua_ls', {
|
|
--cmd = { 'lua-language-server.cmd' },
|
|
on_init = function(client)
|
|
if client.workspace_folders then
|
|
local path = client.workspace_folders[1].name
|
|
if
|
|
path ~= vim.fn.stdpath('config')
|
|
and (vim.uv.fs_stat(path .. '/.luarc.json') or vim.uv.fs_stat(path .. '/.luarc.jsonc'))
|
|
then
|
|
return
|
|
end
|
|
end
|
|
|
|
client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, {
|
|
runtime = {
|
|
-- Tell the language server which version of Lua you're using (most
|
|
-- likely LuaJIT in the case of Neovim)
|
|
version = 'LuaJIT',
|
|
-- Tell the language server how to find Lua modules same way as Neovim
|
|
-- (see `:h lua-module-load`)
|
|
path = {
|
|
'lua/?.lua',
|
|
'lua/?/init.lua',
|
|
},
|
|
},
|
|
-- Make the server aware of Neovim runtime files
|
|
workspace = {
|
|
checkThirdParty = false,
|
|
library = {
|
|
vim.env.VIMRUNTIME,
|
|
-- Depending on the usage, you might want to add additional paths
|
|
-- here.
|
|
-- '${3rd}/luv/library',
|
|
-- '${3rd}/busted/library',
|
|
},
|
|
-- Or pull in all of 'runtimepath'.
|
|
-- NOTE: this is a lot slower and will cause issues when working on
|
|
-- your own configuration.
|
|
-- See https://github.com/neovim/nvim-lspconfig/issues/3189
|
|
-- library = vim.api.nvim_get_runtime_file('', true),
|
|
},
|
|
})
|
|
end,
|
|
})
|
|
vim.lsp.enable('lua_ls')
|
|
|
|
vim.lsp.enable('rust_analyzer')
|
|
|
|
vim.lsp.config('powershell_es', {
|
|
bundle_path = 'D:/DevKits/SDKs/LSP/MasonManaged/packages/powershell-editor-services',
|
|
shell = 'powershell.exe',
|
|
})
|
|
vim.lsp.enable('powershell_es')
|
|
|
|
vim.lsp.config('jsonls', {
|
|
capabilities = setmetatable({
|
|
textDocument = { completion = { completionItem = { snippetSupport = true } } }
|
|
}, {
|
|
__index = require('cmp_nvim_lsp').default_capabilities()
|
|
}),
|
|
cmd = { 'node.exe', 'D:/DevKits/SDKs/LSP/MasonManaged/packages/json-lsp/node_modules/vscode-langservers-extracted/bin/vscode-json-language-server', '--stdio' },
|
|
})
|
|
vim.lsp.enable('jsonls')
|
|
end
|
|
|