refactor: lint and dap
This commit is contained in:
parent
7785311043
commit
2bed6f50c0
46 changed files with 2453 additions and 0 deletions
37
nivm/lua/settings/lsp_config/bashls.lua
Normal file
37
nivm/lua/settings/lsp_config/bashls.lua
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
local util = require 'lspconfig.util'
|
||||
|
||||
local bin_name = 'bash-language-server'
|
||||
local cmd = { bin_name, 'start' }
|
||||
|
||||
if vim.fn.has 'win32' == 1 then
|
||||
cmd = { 'cmd.exe', '/C', bin_name, 'start' }
|
||||
end
|
||||
|
||||
return {
|
||||
default_config = {
|
||||
cmd = cmd,
|
||||
cmd_env = {
|
||||
-- Prevent recursive scanning which will cause issues when opening a file
|
||||
-- directly in the home directory (e.g. ~/foo.sh).
|
||||
--
|
||||
-- Default upstream pattern is "**/*@(.sh|.inc|.bash|.command)".
|
||||
GLOB_PATTERN = vim.env.GLOB_PATTERN or '*@(.sh|.inc|.bash|.command)',
|
||||
},
|
||||
filetypes = { 'sh' },
|
||||
root_dir = util.find_git_ancestor,
|
||||
single_file_support = true,
|
||||
},
|
||||
docs = {
|
||||
description = [[
|
||||
https://github.com/mads-hartmann/bash-language-server
|
||||
`bash-language-server` can be installed via `npm`:
|
||||
```sh
|
||||
npm i -g bash-language-server
|
||||
```
|
||||
Language server for bash, written using tree sitter in typescript.
|
||||
]],
|
||||
default_config = {
|
||||
root_dir = [[util.find_git_ancestor]],
|
||||
},
|
||||
},
|
||||
}
|
||||
87
nivm/lua/settings/lsp_config/clangd.lua
Normal file
87
nivm/lua/settings/lsp_config/clangd.lua
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
local util = require 'lspconfig.util'
|
||||
|
||||
-- https://clangd.llvm.org/extensions.html#switch-between-sourceheader
|
||||
local function switch_source_header(bufnr)
|
||||
bufnr = util.validate_bufnr(bufnr)
|
||||
local clangd_client = util.get_active_client_by_name(bufnr, 'clangd')
|
||||
local params = { uri = vim.uri_from_bufnr(bufnr) }
|
||||
if clangd_client then
|
||||
clangd_client.request('textDocument/switchSourceHeader', params, function(err, result)
|
||||
if err then
|
||||
error(tostring(err))
|
||||
end
|
||||
if not result then
|
||||
print 'Corresponding file cannot be determined'
|
||||
return
|
||||
end
|
||||
vim.api.nvim_command('edit ' .. vim.uri_to_fname(result))
|
||||
end, bufnr)
|
||||
else
|
||||
print 'method textDocument/switchSourceHeader is not supported by any servers active on the current buffer'
|
||||
end
|
||||
end
|
||||
|
||||
local root_files = {
|
||||
'.clangd',
|
||||
'.clang-tidy',
|
||||
'.clang-format',
|
||||
'compile_commands.json',
|
||||
'compile_flags.txt',
|
||||
'configure.ac', -- AutoTools
|
||||
}
|
||||
|
||||
local default_capabilities = {
|
||||
textDocument = {
|
||||
completion = {
|
||||
editsNearCursor = true,
|
||||
},
|
||||
},
|
||||
offsetEncoding = { 'utf-8', 'utf-16' },
|
||||
}
|
||||
|
||||
return {
|
||||
default_config = {
|
||||
cmd = { 'clangd' },
|
||||
filetypes = { 'c', 'cpp', 'objc', 'objcpp', 'cuda', 'proto' },
|
||||
root_dir = function(fname)
|
||||
return util.root_pattern(unpack(root_files))(fname) or util.find_git_ancestor(fname)
|
||||
end,
|
||||
single_file_support = true,
|
||||
capabilities = default_capabilities,
|
||||
},
|
||||
commands = {
|
||||
ClangdSwitchSourceHeader = {
|
||||
function()
|
||||
switch_source_header(0)
|
||||
end,
|
||||
description = 'Switch between source/header',
|
||||
},
|
||||
},
|
||||
docs = {
|
||||
description = [[
|
||||
https://clangd.llvm.org/installation.html
|
||||
- **NOTE:** Clang >= 11 is recommended! See [#23](https://github.com/neovim/nvim-lsp/issues/23).
|
||||
- If `compile_commands.json` lives in a build directory, you should
|
||||
symlink it to the root of your source tree.
|
||||
```
|
||||
ln -s /path/to/myproject/build/compile_commands.json /path/to/myproject/
|
||||
```
|
||||
- clangd relies on a [JSON compilation database](https://clang.llvm.org/docs/JSONCompilationDatabase.html)
|
||||
specified as compile_commands.json, see https://clangd.llvm.org/installation#compile_commandsjson
|
||||
]],
|
||||
default_config = {
|
||||
root_dir = [[
|
||||
root_pattern(
|
||||
'.clangd',
|
||||
'.clang-tidy',
|
||||
'.clang-format',
|
||||
'compile_commands.json',
|
||||
'compile_flags.txt',
|
||||
'configure.ac',
|
||||
'.git'
|
||||
)
|
||||
]],
|
||||
capabilities = [[default capabilities, with offsetEncoding utf-8]],
|
||||
},
|
||||
},
|
||||
}
|
||||
20
nivm/lua/settings/lsp_config/csharp_ls.lua
Normal file
20
nivm/lua/settings/lsp_config/csharp_ls.lua
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
local util = require 'lspconfig.util'
|
||||
|
||||
return {
|
||||
default_config = {
|
||||
cmd = { 'csharp-ls' },
|
||||
root_dir = util.root_pattern('*.sln', '*.csproj', '*.fsproj', '.git'),
|
||||
filetypes = { 'cs' },
|
||||
init_options = {
|
||||
AutomaticWorkspaceInit = true,
|
||||
},
|
||||
},
|
||||
docs = {
|
||||
description = [[
|
||||
https://github.com/razzmatazz/csharp-language-server
|
||||
Language Server for C#.
|
||||
csharp-ls requires the [dotnet-sdk](https://dotnet.microsoft.com/download) to be installed.
|
||||
The preferred way to install csharp-ls is with `dotnet tool install --global csharp-ls`.
|
||||
]],
|
||||
},
|
||||
}
|
||||
43
nivm/lua/settings/lsp_config/cssls.lua
Normal file
43
nivm/lua/settings/lsp_config/cssls.lua
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
local util = require 'lspconfig.util'
|
||||
|
||||
local bin_name = 'vscode-css-language-server'
|
||||
local cmd = { bin_name, '--stdio' }
|
||||
|
||||
if vim.fn.has 'win32' == 1 then
|
||||
cmd = { 'cmd.exe', '/C', bin_name, '--stdio' }
|
||||
end
|
||||
|
||||
return {
|
||||
default_config = {
|
||||
cmd = cmd,
|
||||
filetypes = { 'css', 'scss', 'less' },
|
||||
root_dir = util.root_pattern('package.json', '.git'),
|
||||
single_file_support = true,
|
||||
settings = {
|
||||
css = { validate = true },
|
||||
scss = { validate = true },
|
||||
less = { validate = true },
|
||||
},
|
||||
},
|
||||
docs = {
|
||||
description = [[
|
||||
https://github.com/hrsh7th/vscode-langservers-extracted
|
||||
`css-languageserver` can be installed via `npm`:
|
||||
```sh
|
||||
npm i -g vscode-langservers-extracted
|
||||
```
|
||||
Neovim does not currently include built-in snippets. `vscode-css-language-server` only provides completions when snippet support is enabled. To enable completion, install a snippet plugin and add the following override to your language client capabilities during setup.
|
||||
```lua
|
||||
--Enable (broadcasting) snippet capability for completion
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
||||
require'lspconfig'.cssls.setup {
|
||||
capabilities = capabilities,
|
||||
}
|
||||
```
|
||||
]],
|
||||
default_config = {
|
||||
root_dir = [[root_pattern("package.json", ".git") or bufdir]],
|
||||
},
|
||||
},
|
||||
}
|
||||
165
nivm/lua/settings/lsp_config/eslint.lua
Normal file
165
nivm/lua/settings/lsp_config/eslint.lua
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
local util = require 'lspconfig.util'
|
||||
local lsp = vim.lsp
|
||||
|
||||
local function fix_all(opts)
|
||||
opts = opts or {}
|
||||
|
||||
local eslint_lsp_client = util.get_active_client_by_name(opts.bufnr, 'eslint')
|
||||
if eslint_lsp_client == nil then
|
||||
return
|
||||
end
|
||||
|
||||
local request
|
||||
if opts.sync then
|
||||
request = function(bufnr, method, params)
|
||||
eslint_lsp_client.request_sync(method, params, nil, bufnr)
|
||||
end
|
||||
else
|
||||
request = function(bufnr, method, params)
|
||||
eslint_lsp_client.request(method, params, nil, bufnr)
|
||||
end
|
||||
end
|
||||
|
||||
local bufnr = util.validate_bufnr(opts.bufnr or 0)
|
||||
request(0, 'workspace/executeCommand', {
|
||||
command = 'eslint.applyAllFixes',
|
||||
arguments = {
|
||||
{
|
||||
uri = vim.uri_from_bufnr(bufnr),
|
||||
version = lsp.util.buf_versions[bufnr],
|
||||
},
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
local bin_name = 'vscode-eslint-language-server'
|
||||
local cmd = { bin_name, '--stdio' }
|
||||
|
||||
if vim.fn.has 'win32' == 1 then
|
||||
cmd = { 'cmd.exe', '/C', bin_name, '--stdio' }
|
||||
end
|
||||
|
||||
return {
|
||||
default_config = {
|
||||
cmd = cmd,
|
||||
filetypes = {
|
||||
'javascript',
|
||||
'javascriptreact',
|
||||
'javascript.jsx',
|
||||
'typescript',
|
||||
'typescriptreact',
|
||||
'typescript.tsx',
|
||||
'vue',
|
||||
},
|
||||
-- https://eslint.org/docs/user-guide/configuring/configuration-files#configuration-file-formats
|
||||
root_dir = util.root_pattern(
|
||||
'.eslintrc',
|
||||
'.eslintrc.js',
|
||||
'.eslintrc.cjs',
|
||||
'.eslintrc.yaml',
|
||||
'.eslintrc.yml',
|
||||
'.eslintrc.json',
|
||||
'package.json'
|
||||
),
|
||||
-- Refer to https://github.com/Microsoft/vscode-eslint#settings-options for documentation.
|
||||
settings = {
|
||||
validate = 'on',
|
||||
packageManager = 'npm',
|
||||
useESLintClass = false,
|
||||
codeActionOnSave = {
|
||||
enable = false,
|
||||
mode = 'all',
|
||||
},
|
||||
format = true,
|
||||
quiet = false,
|
||||
onIgnoredFiles = 'off',
|
||||
rulesCustomizations = {},
|
||||
run = 'onType',
|
||||
-- nodePath configures the directory in which the eslint server should start its node_modules resolution.
|
||||
-- This path is relative to the workspace folder (root dir) of the server instance.
|
||||
nodePath = '',
|
||||
-- use the workspace folder location or the file location (if no workspace folder is open) as the working directory
|
||||
workingDirectory = { mode = 'location' },
|
||||
codeAction = {
|
||||
disableRuleComment = {
|
||||
enable = true,
|
||||
location = 'separateLine',
|
||||
},
|
||||
showDocumentation = {
|
||||
enable = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
on_new_config = function(config, new_root_dir)
|
||||
-- The "workspaceFolder" is a VSCode concept. It limits how far the
|
||||
-- server will traverse the file system when locating the ESLint config
|
||||
-- file (e.g., .eslintrc).
|
||||
config.settings.workspaceFolder = {
|
||||
uri = new_root_dir,
|
||||
name = vim.fn.fnamemodify(new_root_dir, ':t'),
|
||||
}
|
||||
|
||||
-- Support Yarn2 (PnP) projects
|
||||
local pnp_cjs = util.path.join(new_root_dir, '.pnp.cjs')
|
||||
local pnp_js = util.path.join(new_root_dir, '.pnp.js')
|
||||
if util.path.exists(pnp_cjs) or util.path.exists(pnp_js) then
|
||||
config.cmd = vim.list_extend({ 'yarn', 'exec' }, cmd)
|
||||
end
|
||||
end,
|
||||
handlers = {
|
||||
['eslint/openDoc'] = function(_, result)
|
||||
if not result then
|
||||
return
|
||||
end
|
||||
local sysname = vim.loop.os_uname().sysname
|
||||
if sysname:match 'Windows' then
|
||||
os.execute(string.format('start %q', result.url))
|
||||
elseif sysname:match 'Linux' then
|
||||
os.execute(string.format('xdg-open %q', result.url))
|
||||
else
|
||||
os.execute(string.format('open %q', result.url))
|
||||
end
|
||||
return {}
|
||||
end,
|
||||
['eslint/confirmESLintExecution'] = function(_, result)
|
||||
if not result then
|
||||
return
|
||||
end
|
||||
return 4 -- approved
|
||||
end,
|
||||
['eslint/probeFailed'] = function()
|
||||
vim.notify('[lspconfig] ESLint probe failed.', vim.log.levels.WARN)
|
||||
return {}
|
||||
end,
|
||||
['eslint/noLibrary'] = function()
|
||||
vim.notify('[lspconfig] Unable to find ESLint library.', vim.log.levels.WARN)
|
||||
return {}
|
||||
end,
|
||||
},
|
||||
},
|
||||
commands = {
|
||||
EslintFixAll = {
|
||||
function()
|
||||
fix_all { sync = true, bufnr = 0 }
|
||||
end,
|
||||
description = 'Fix all eslint problems for this buffer',
|
||||
},
|
||||
},
|
||||
docs = {
|
||||
description = [[
|
||||
https://github.com/hrsh7th/vscode-langservers-extracted
|
||||
`vscode-eslint-language-server` is a linting engine for JavaScript / Typescript.
|
||||
It can be installed via `npm`:
|
||||
```sh
|
||||
npm i -g vscode-langservers-extracted
|
||||
```
|
||||
`vscode-eslint-language-server` provides an `EslintFixAll` command that can be used to format a document on save:
|
||||
```vim
|
||||
autocmd BufWritePre *.tsx,*.ts,*.jsx,*.js EslintFixAll
|
||||
```
|
||||
See [vscode-eslint](https://github.com/microsoft/vscode-eslint/blob/55871979d7af184bf09af491b6ea35ebd56822cf/server/src/eslintServer.ts#L216-L229) for configuration options.
|
||||
Messages handled in lspconfig: `eslint/openDoc`, `eslint/confirmESLintExecution`, `eslint/probeFailed`, `eslint/noLibrary`
|
||||
Additional messages you can handle: `eslint/noConfig`
|
||||
]],
|
||||
},
|
||||
}
|
||||
165
nivm/lua/settings/lsp_config/eslint_d.lua
Normal file
165
nivm/lua/settings/lsp_config/eslint_d.lua
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
local util = require 'lspconfig.util'
|
||||
local lsp = vim.lsp
|
||||
|
||||
local function fix_all(opts)
|
||||
opts = opts or {}
|
||||
|
||||
local eslint_lsp_client = util.get_active_client_by_name(opts.bufnr, 'eslint')
|
||||
if eslint_lsp_client == nil then
|
||||
return
|
||||
end
|
||||
|
||||
local request
|
||||
if opts.sync then
|
||||
request = function(bufnr, method, params)
|
||||
eslint_lsp_client.request_sync(method, params, nil, bufnr)
|
||||
end
|
||||
else
|
||||
request = function(bufnr, method, params)
|
||||
eslint_lsp_client.request(method, params, nil, bufnr)
|
||||
end
|
||||
end
|
||||
|
||||
local bufnr = util.validate_bufnr(opts.bufnr or 0)
|
||||
request(0, 'workspace/executeCommand', {
|
||||
command = 'eslint.applyAllFixes',
|
||||
arguments = {
|
||||
{
|
||||
uri = vim.uri_from_bufnr(bufnr),
|
||||
version = lsp.util.buf_versions[bufnr],
|
||||
},
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
local bin_name = 'vscode-eslint-language-server'
|
||||
local cmd = { bin_name, '--stdio' }
|
||||
|
||||
if vim.fn.has 'win32' == 1 then
|
||||
cmd = { 'cmd.exe', '/C', bin_name, '--stdio' }
|
||||
end
|
||||
|
||||
return {
|
||||
default_config = {
|
||||
cmd = cmd,
|
||||
filetypes = {
|
||||
'javascript',
|
||||
'javascriptreact',
|
||||
'javascript.jsx',
|
||||
'typescript',
|
||||
'typescriptreact',
|
||||
'typescript.tsx',
|
||||
'vue',
|
||||
},
|
||||
-- https://eslint.org/docs/user-guide/configuring/configuration-files#configuration-file-formats
|
||||
root_dir = util.root_pattern(
|
||||
'.eslintrc',
|
||||
'.eslintrc.js',
|
||||
'.eslintrc.cjs',
|
||||
'.eslintrc.yaml',
|
||||
'.eslintrc.yml',
|
||||
'.eslintrc.json',
|
||||
'package.json'
|
||||
),
|
||||
-- Refer to https://github.com/Microsoft/vscode-eslint#settings-options for documentation.
|
||||
settings = {
|
||||
validate = 'on',
|
||||
packageManager = 'npm',
|
||||
useESLintClass = false,
|
||||
codeActionOnSave = {
|
||||
enable = false,
|
||||
mode = 'all',
|
||||
},
|
||||
format = true,
|
||||
quiet = false,
|
||||
onIgnoredFiles = 'off',
|
||||
rulesCustomizations = {},
|
||||
run = 'onType',
|
||||
-- nodePath configures the directory in which the eslint server should start its node_modules resolution.
|
||||
-- This path is relative to the workspace folder (root dir) of the server instance.
|
||||
nodePath = '',
|
||||
-- use the workspace folder location or the file location (if no workspace folder is open) as the working directory
|
||||
workingDirectory = { mode = 'location' },
|
||||
codeAction = {
|
||||
disableRuleComment = {
|
||||
enable = true,
|
||||
location = 'separateLine',
|
||||
},
|
||||
showDocumentation = {
|
||||
enable = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
on_new_config = function(config, new_root_dir)
|
||||
-- The "workspaceFolder" is a VSCode concept. It limits how far the
|
||||
-- server will traverse the file system when locating the ESLint config
|
||||
-- file (e.g., .eslintrc).
|
||||
config.settings.workspaceFolder = {
|
||||
uri = new_root_dir,
|
||||
name = vim.fn.fnamemodify(new_root_dir, ':t'),
|
||||
}
|
||||
|
||||
-- Support Yarn2 (PnP) projects
|
||||
local pnp_cjs = util.path.join(new_root_dir, '.pnp.cjs')
|
||||
local pnp_js = util.path.join(new_root_dir, '.pnp.js')
|
||||
if util.path.exists(pnp_cjs) or util.path.exists(pnp_js) then
|
||||
config.cmd = vim.list_extend({ 'yarn', 'exec' }, cmd)
|
||||
end
|
||||
end,
|
||||
handlers = {
|
||||
['eslint/openDoc'] = function(_, result)
|
||||
if not result then
|
||||
return
|
||||
end
|
||||
local sysname = vim.loop.os_uname().sysname
|
||||
if sysname:match 'Windows' then
|
||||
os.execute(string.format('start %q', result.url))
|
||||
elseif sysname:match 'Linux' then
|
||||
os.execute(string.format('xdg-open %q', result.url))
|
||||
else
|
||||
os.execute(string.format('open %q', result.url))
|
||||
end
|
||||
return {}
|
||||
end,
|
||||
['eslint/confirmESLintExecution'] = function(_, result)
|
||||
if not result then
|
||||
return
|
||||
end
|
||||
return 4 -- approved
|
||||
end,
|
||||
['eslint/probeFailed'] = function()
|
||||
vim.notify('[lspconfig] ESLint probe failed.', vim.log.levels.WARN)
|
||||
return {}
|
||||
end,
|
||||
['eslint/noLibrary'] = function()
|
||||
vim.notify('[lspconfig] Unable to find ESLint library.', vim.log.levels.WARN)
|
||||
return {}
|
||||
end,
|
||||
},
|
||||
},
|
||||
commands = {
|
||||
EslintFixAll = {
|
||||
function()
|
||||
fix_all { sync = true, bufnr = 0 }
|
||||
end,
|
||||
description = 'Fix all eslint problems for this buffer',
|
||||
},
|
||||
},
|
||||
docs = {
|
||||
description = [[
|
||||
https://github.com/hrsh7th/vscode-langservers-extracted
|
||||
`vscode-eslint-language-server` is a linting engine for JavaScript / Typescript.
|
||||
It can be installed via `npm`:
|
||||
```sh
|
||||
npm i -g vscode-langservers-extracted
|
||||
```
|
||||
`vscode-eslint-language-server` provides an `EslintFixAll` command that can be used to format a document on save:
|
||||
```vim
|
||||
autocmd BufWritePre *.tsx,*.ts,*.jsx,*.js EslintFixAll
|
||||
```
|
||||
See [vscode-eslint](https://github.com/microsoft/vscode-eslint/blob/55871979d7af184bf09af491b6ea35ebd56822cf/server/src/eslintServer.ts#L216-L229) for configuration options.
|
||||
Messages handled in lspconfig: `eslint/openDoc`, `eslint/confirmESLintExecution`, `eslint/probeFailed`, `eslint/noLibrary`
|
||||
Additional messages you can handle: `eslint/noConfig`
|
||||
]],
|
||||
},
|
||||
}
|
||||
100
nivm/lua/settings/lsp_config/handlers.lua
Normal file
100
nivm/lua/settings/lsp_config/handlers.lua
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
local M = {}
|
||||
|
||||
-- TODO: backfill this to template
|
||||
M.setup = function()
|
||||
local signs = {
|
||||
{ name = "DiagnosticSignError", text = "" },
|
||||
{ name = "DiagnosticSignWarn", text = "" },
|
||||
{ name = "DiagnosticSignHint", text = "" },
|
||||
{ name = "DiagnosticSignInfo", text = "" },
|
||||
}
|
||||
|
||||
for _, sign in ipairs(signs) do
|
||||
vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" })
|
||||
end
|
||||
|
||||
local config = {
|
||||
-- disable virtual text
|
||||
virtual_text = false,
|
||||
-- show signs
|
||||
signs = {
|
||||
active = signs,
|
||||
},
|
||||
update_in_insert = true,
|
||||
underline = true,
|
||||
severity_sort = true,
|
||||
float = {
|
||||
focusable = false,
|
||||
style = "minimal",
|
||||
border = "rounded",
|
||||
source = "always",
|
||||
header = "",
|
||||
prefix = "",
|
||||
},
|
||||
}
|
||||
|
||||
vim.diagnostic.config(config)
|
||||
|
||||
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {
|
||||
border = "rounded",
|
||||
})
|
||||
|
||||
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {
|
||||
border = "rounded",
|
||||
})
|
||||
end
|
||||
|
||||
local function lsp_highlight_document(client)
|
||||
-- Set autocommands conditional on server_capabilities
|
||||
local status_ok, illuminate = pcall(require, "illuminate")
|
||||
if not status_ok then
|
||||
return
|
||||
end
|
||||
illuminate.on_attach(client)
|
||||
-- end
|
||||
end
|
||||
|
||||
local function lsp_keymaps(bufnr)
|
||||
local opts = { noremap = true, silent = true }
|
||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
|
||||
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts)
|
||||
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>ca", "<cmd>lua vim.lsp.buf.code_action()<CR>", opts)
|
||||
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>f", "<cmd>lua vim.diagnostic.open_float()<CR>", opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "[d", '<cmd>lua vim.diagnostic.goto_prev({ border = "rounded" })<CR>', opts)
|
||||
vim.api.nvim_buf_set_keymap(
|
||||
bufnr,
|
||||
"n",
|
||||
"gl",
|
||||
'<cmd>lua vim.diagnostic.open_float({ border = "rounded" })<CR>',
|
||||
opts
|
||||
)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "]d", '<cmd>lua vim.diagnostic.goto_next({ border = "rounded" })<CR>', opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>q", "<cmd>lua vim.diagnostic.setloclist()<CR>", opts)
|
||||
vim.cmd [[ command! Format execute 'lua vim.lsp.buf.format { async = true }' ]]
|
||||
end
|
||||
|
||||
M.on_attach = function(client, bufnr)
|
||||
-- vim.notify(client.name .. " starting...")
|
||||
-- TODO: refactor this into a method that checks if string in list
|
||||
if client.name == "tsserver" then
|
||||
client.resolved_capabilities.document_formatting = false
|
||||
end
|
||||
lsp_keymaps(bufnr)
|
||||
lsp_highlight_document(client)
|
||||
end
|
||||
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
|
||||
local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
|
||||
if not status_ok then
|
||||
return
|
||||
end
|
||||
|
||||
M.capabilities = cmp_nvim_lsp.update_capabilities(capabilities)
|
||||
|
||||
return M
|
||||
43
nivm/lua/settings/lsp_config/html.lua
Normal file
43
nivm/lua/settings/lsp_config/html.lua
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
local util = require 'lspconfig.util'
|
||||
|
||||
local bin_name = 'vscode-html-language-server'
|
||||
local cmd = { bin_name, '--stdio' }
|
||||
|
||||
if vim.fn.has 'win32' == 1 then
|
||||
cmd = { 'cmd.exe', '/C', bin_name, '--stdio' }
|
||||
end
|
||||
|
||||
return {
|
||||
default_config = {
|
||||
cmd = cmd,
|
||||
filetypes = { 'html' },
|
||||
root_dir = util.root_pattern('package.json', '.git'),
|
||||
single_file_support = true,
|
||||
settings = {},
|
||||
init_options = {
|
||||
provideFormatter = true,
|
||||
embeddedLanguages = { css = true, javascript = true },
|
||||
configurationSection = { 'html', 'css', 'javascript' },
|
||||
},
|
||||
},
|
||||
docs = {
|
||||
description = [[
|
||||
https://github.com/hrsh7th/vscode-langservers-extracted
|
||||
`vscode-html-language-server` can be installed via `npm`:
|
||||
```sh
|
||||
npm i -g vscode-langservers-extracted
|
||||
```
|
||||
Neovim does not currently include built-in snippets. `vscode-html-language-server` only provides completions when snippet support is enabled.
|
||||
To enable completion, install a snippet plugin and add the following override to your language client capabilities during setup.
|
||||
The code-formatting feature of the lsp can be controlled with the `provideFormatter` option.
|
||||
```lua
|
||||
--Enable (broadcasting) snippet capability for completion
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
||||
require'lspconfig'.html.setup {
|
||||
capabilities = capabilities,
|
||||
}
|
||||
```
|
||||
]],
|
||||
},
|
||||
}
|
||||
17
nivm/lua/settings/lsp_config/jdtls.lua
Normal file
17
nivm/lua/settings/lsp_config/jdtls.lua
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
return {
|
||||
settings = {
|
||||
|
||||
java = {
|
||||
diagnostics = {
|
||||
globals = { "vim" },
|
||||
},
|
||||
workspace = {
|
||||
library = {
|
||||
[vim.fn.expand("$VIMRUNTIME/lua")] = true,
|
||||
[vim.fn.stdpath("config") .. "/lua"] = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
55
nivm/lua/settings/lsp_config/pyright.lua
Normal file
55
nivm/lua/settings/lsp_config/pyright.lua
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
local util = require 'lspconfig.util'
|
||||
|
||||
local bin_name = 'pyright-langserver'
|
||||
local cmd = { bin_name, '--stdio' }
|
||||
|
||||
if vim.fn.has 'win32' == 1 then
|
||||
cmd = { 'cmd.exe', '/C', bin_name, '--stdio' }
|
||||
end
|
||||
|
||||
local root_files = {
|
||||
'pyproject.toml',
|
||||
'setup.py',
|
||||
'setup.cfg',
|
||||
'requirements.txt',
|
||||
'Pipfile',
|
||||
'pyrightconfig.json',
|
||||
}
|
||||
|
||||
local function organize_imports()
|
||||
local params = {
|
||||
command = 'pyright.organizeimports',
|
||||
arguments = { vim.uri_from_bufnr(0) },
|
||||
}
|
||||
vim.lsp.buf.execute_command(params)
|
||||
end
|
||||
|
||||
return {
|
||||
default_config = {
|
||||
cmd = cmd,
|
||||
filetypes = { 'python' },
|
||||
root_dir = util.root_pattern(unpack(root_files)),
|
||||
single_file_support = true,
|
||||
settings = {
|
||||
python = {
|
||||
analysis = {
|
||||
autoSearchPaths = true,
|
||||
useLibraryCodeForTypes = true,
|
||||
diagnosticMode = 'workspace',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
commands = {
|
||||
PyrightOrganizeImports = {
|
||||
organize_imports,
|
||||
description = 'Organize Imports',
|
||||
},
|
||||
},
|
||||
docs = {
|
||||
description = [[
|
||||
https://github.com/microsoft/pyright
|
||||
`pyright`, a static type checker and language server for python
|
||||
]],
|
||||
},
|
||||
}
|
||||
77
nivm/lua/settings/lsp_config/rust_analyzer.lua
Normal file
77
nivm/lua/settings/lsp_config/rust_analyzer.lua
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
local util = require 'lspconfig.util'
|
||||
|
||||
local function reload_workspace(bufnr)
|
||||
bufnr = util.validate_bufnr(bufnr)
|
||||
vim.lsp.buf_request(bufnr, 'rust-analyzer/reloadWorkspace', nil, function(err)
|
||||
if err then
|
||||
error(tostring(err))
|
||||
end
|
||||
vim.notify 'Cargo workspace reloaded'
|
||||
end)
|
||||
end
|
||||
|
||||
return {
|
||||
default_config = {
|
||||
cmd = { 'rust-analyzer' },
|
||||
filetypes = { 'rust' },
|
||||
root_dir = function(fname)
|
||||
local cargo_crate_dir = util.root_pattern 'Cargo.toml'(fname)
|
||||
local cmd = { 'cargo', 'metadata', '--no-deps', '--format-version', '1' }
|
||||
if cargo_crate_dir ~= nil then
|
||||
cmd[#cmd + 1] = '--manifest-path'
|
||||
cmd[#cmd + 1] = util.path.join(cargo_crate_dir, 'Cargo.toml')
|
||||
end
|
||||
local cargo_metadata = ''
|
||||
local cargo_metadata_err = ''
|
||||
local cm = vim.fn.jobstart(cmd, {
|
||||
on_stdout = function(_, d, _)
|
||||
cargo_metadata = table.concat(d, '\n')
|
||||
end,
|
||||
on_stderr = function(_, d, _)
|
||||
cargo_metadata_err = table.concat(d, '\n')
|
||||
end,
|
||||
stdout_buffered = true,
|
||||
stderr_buffered = true,
|
||||
})
|
||||
if cm > 0 then
|
||||
cm = vim.fn.jobwait({ cm })[1]
|
||||
else
|
||||
cm = -1
|
||||
end
|
||||
local cargo_workspace_dir = nil
|
||||
if cm == 0 then
|
||||
cargo_workspace_dir = vim.json.decode(cargo_metadata)['workspace_root']
|
||||
else
|
||||
vim.notify(
|
||||
string.format('[lspconfig] cmd (%q) failed:\n%s', table.concat(cmd, ' '), cargo_metadata_err),
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
end
|
||||
return util.path.sanitize(cargo_workspace_dir)
|
||||
or cargo_crate_dir
|
||||
or util.root_pattern 'rust-project.json'(fname)
|
||||
or util.find_git_ancestor(fname)
|
||||
end,
|
||||
settings = {
|
||||
['rust-analyzer'] = {},
|
||||
},
|
||||
},
|
||||
commands = {
|
||||
CargoReload = {
|
||||
function()
|
||||
reload_workspace(0)
|
||||
end,
|
||||
description = 'Reload current cargo workspace',
|
||||
},
|
||||
},
|
||||
docs = {
|
||||
description = [[
|
||||
https://github.com/rust-analyzer/rust-analyzer
|
||||
rust-analyzer (aka rls 2.0), a language server for Rust
|
||||
See [docs](https://github.com/rust-analyzer/rust-analyzer/tree/master/docs/user#settings) for extra settings.
|
||||
]],
|
||||
default_config = {
|
||||
root_dir = [[root_pattern("Cargo.toml", "rust-project.json")]],
|
||||
},
|
||||
},
|
||||
}
|
||||
23
nivm/lua/settings/lsp_config/sqls.lua
Normal file
23
nivm/lua/settings/lsp_config/sqls.lua
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
local util = require 'lspconfig.util'
|
||||
|
||||
return {
|
||||
default_config = {
|
||||
cmd = { 'sqls' },
|
||||
filetypes = { 'sql', 'mysql' },
|
||||
root_dir = util.root_pattern 'config.yml',
|
||||
single_file_support = true,
|
||||
settings = {},
|
||||
},
|
||||
docs = {
|
||||
description = [[
|
||||
https://github.com/lighttiger2505/sqls
|
||||
```lua
|
||||
require'lspconfig'.sqls.setup{
|
||||
cmd = {"path/to/command", "-config", "path/to/config.yml"};
|
||||
...
|
||||
}
|
||||
```
|
||||
Sqls can be installed via `go get github.com/lighttiger2505/sqls`. Instructions for compiling Sqls from the source can be found at [lighttiger2505/sqls](https://github.com/lighttiger2505/sqls).
|
||||
]],
|
||||
},
|
||||
}
|
||||
16
nivm/lua/settings/lsp_config/sumneko_lua.lua
Normal file
16
nivm/lua/settings/lsp_config/sumneko_lua.lua
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
return {
|
||||
settings = {
|
||||
|
||||
Lua = {
|
||||
diagnostics = {
|
||||
globals = { "vim" },
|
||||
},
|
||||
workspace = {
|
||||
library = {
|
||||
[vim.fn.expand("$VIMRUNTIME/lua")] = true,
|
||||
[vim.fn.stdpath("config") .. "/lua"] = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
16
nivm/lua/settings/lsp_config/texlab.lua
Normal file
16
nivm/lua/settings/lsp_config/texlab.lua
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
return {
|
||||
settings = {
|
||||
|
||||
latex = {
|
||||
diagnostics = {
|
||||
globals = { "vim" },
|
||||
},
|
||||
workspace = {
|
||||
library = {
|
||||
[vim.fn.expand("$VIMRUNTIME/lua")] = true,
|
||||
[vim.fn.stdpath("config") .. "/lua"] = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
56
nivm/lua/settings/lsp_config/tsserver.lua
Normal file
56
nivm/lua/settings/lsp_config/tsserver.lua
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
local util = require 'lspconfig.util'
|
||||
|
||||
local bin_name = 'typescript-language-server'
|
||||
local cmd = { bin_name, '--stdio' }
|
||||
|
||||
if vim.fn.has 'win32' == 1 then
|
||||
cmd = { 'cmd.exe', '/C', bin_name, '--stdio' }
|
||||
end
|
||||
|
||||
return {
|
||||
default_config = {
|
||||
init_options = { hostInfo = 'neovim' },
|
||||
cmd = cmd,
|
||||
filetypes = {
|
||||
'javascript',
|
||||
'javascriptreact',
|
||||
'javascript.jsx',
|
||||
'typescript',
|
||||
'typescriptreact',
|
||||
'typescript.tsx',
|
||||
},
|
||||
root_dir = function(fname)
|
||||
return util.root_pattern 'tsconfig.json'(fname)
|
||||
or util.root_pattern('package.json', 'jsconfig.json', '.git')(fname)
|
||||
end,
|
||||
},
|
||||
docs = {
|
||||
description = [[
|
||||
https://github.com/theia-ide/typescript-language-server
|
||||
`typescript-language-server` depends on `typescript`. Both packages can be installed via `npm`:
|
||||
```sh
|
||||
npm install -g typescript typescript-language-server
|
||||
```
|
||||
To configure typescript language server, add a
|
||||
[`tsconfig.json`](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) or
|
||||
[`jsconfig.json`](https://code.visualstudio.com/docs/languages/jsconfig) to the root of your
|
||||
project.
|
||||
Here's an example that disables type checking in JavaScript files.
|
||||
```json
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"checkJs": false
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
```
|
||||
]],
|
||||
default_config = {
|
||||
root_dir = [[root_pattern("package.json", "tsconfig.json", "jsconfig.json", ".git")]],
|
||||
},
|
||||
},
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue