add more lsp servers for nvim

This commit is contained in:
Fabio Lenherr / DashieTM 2022-09-22 23:23:50 +02:00
parent a54e94bbb0
commit 79c002015c
8 changed files with 470 additions and 79 deletions

View 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]],
},
},
}

View 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`.
]],
},
}

View 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]],
},
},
}

View 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")]],
},
},
}

View 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).
]],
},
}

View 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")]],
},
},
}