1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 12:50:04 +08:00

feat(nvim-lspconfig): update bundle nvim-lspconfig

close https://github.com/SpaceVim/SpaceVim/issues/4609
This commit is contained in:
wsdjeg 2022-03-20 10:22:32 +08:00
parent e9e849b16c
commit a4a7ebd88f
197 changed files with 15360 additions and 10230 deletions

View File

@ -66,12 +66,6 @@ body:
description: "You can download a minimal_init.lua via `curl -fLO https://raw.githubusercontent.com/neovim/nvim-lspconfig/master/test/minimal_init.lua`. Then edit it to include your language server and add necessary configuration and paste it here."
validations:
required: true
- type: textarea
attributes:
label: "Health check"
description: "Run `:checkhealth lspconfig` and paste the results here."
validations:
required: true
- type: input
attributes:
label: "LSP log"

View File

@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -e
REF_BRANCH="$1"
PR_BRANCH="$2"
# checks for added lines that contain search pattern and prints them
SEARCH_PATTERN="(dirname|fn\.cwd)"
if git diff --pickaxe-all -U0 -G "${SEARCH_PATTERN}" "${REF_BRANCH}" "${PR_BRANCH}" -- '*.lua' | grep -Ev '(configs|utils)\.lua$' | grep -E "^\+.*${SEARCH_PATTERN}" ; then
echo
echo 'String "dirname" found. There is a high risk that this might contradict the directive:'
echo '"Do not add vim.fn.cwd or util.path.dirname in root_dir".'
echo "see: https://github.com/neovim/nvim-lspconfig/blob/master/CONTRIBUTING.md#adding-a-server-to-lspconfig."
exit 1
fi

View File

@ -0,0 +1,21 @@
name: "Close changes to config"
on: [pull_request_target]
jobs:
close-changes:
runs-on: ubuntu-latest
permissions:
pull-requests: write
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- run: |
if ! git diff origin/$GITHUB_BASE_REF...$(git branch --show-current) --exit-code -- doc/server_configurations.md doc/server_configurations.txt; then
gh pr close $PR_NUMBER
gh pr comment $PR_NUMBER --body "This pull request has been automatically closed. Changes to server_configurations.md aren't allowed - edit the lua source file instead. Consult https://github.com/neovim/nvim-lspconfig/blob/master/CONTRIBUTING.md#generating-docs."
exit 1
fi

View File

@ -5,17 +5,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
fetch-depth: 0
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install codespell
- name: Install codespell
run: pip install codespell
- name: Use codespell
run: |
codespell --quiet-level=2 --check-hidden --skip=CONFIG.md --ignore-words=.codespellignorewords || exit
run: codespell --quiet-level=2 --check-hidden --skip=./doc/server_configurations.md,./doc/server_configurations.txt --ignore-words=.codespellignorewords

View File

@ -3,7 +3,7 @@ jobs:
lint-commits:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.1
- uses: actions/checkout@v2
with:
fetch-depth: 0
- run: npm install --save-dev @commitlint/{cli,config-conventional}

View File

@ -7,79 +7,26 @@ on:
jobs:
docgen:
runs-on: [ubuntu-latest]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v2
- run: date +%F > todays-date
- name: Restore cache for today's nightly.
uses: actions/cache@v2
- uses: rhysd/action-setup-vim@v1
with:
path: _neovim
key: ${{ runner.os }}-nightly-${{ hashFiles('todays-date') }}
- name: Setup from neovim nightly and run docgen
neovim: true
version: nightly
- name: Run docgen
run: |
curl -OL https://raw.githubusercontent.com/norcalli/bot-ci/master/scripts/github-actions-setup.sh
source github-actions-setup.sh nightly-x64
scripts/docgen.sh
- name: Commit changes
env:
COMMIT_MSG: |
[docgen] Update CONFIG.md
docs: update server_configurations.md
skip-checks: true
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git add CONFIG.md
git add doc/server_configurations.md doc/server_configurations.txt
# Only commit and push if we have changes
git diff --quiet && git diff --staged --quiet || (git commit -m "${COMMIT_MSG}"; git push)
vimdocgen:
needs: docgen
runs-on: [ubuntu-latest]
permissions:
contents: write
steps:
- uses: actions/checkout@v2
- run: date +%F > todays-date
- name: Restore cache for today's nightly.
uses: actions/cache@v2
with:
path: build
key: ${{ runner.os }}-appimage-${{ hashFiles('todays-date') }}
- name: Setup neovim nightly and install plugins
run: |
test -d build || {
mkdir -p build
wget https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage
chmod +x nvim.appimage
mv nvim.appimage ./build/nvim
}
mkdir -p ~/.local/share/nvim/site/pack/vendor/start
git clone --depth 1 https://github.com/mjlbach/babelfish.nvim ~/.local/share/nvim/site/pack/vendor/start/babelfish.nvim
git clone --depth 1 https://github.com/nvim-treesitter/nvim-treesitter ~/.local/share/nvim/site/pack/vendor/start/nvim-treesitter
ln -s $(pwd) ~/.local/share/nvim/site/pack/vendor/start
- name: Build parser
run: |
export PACKPATH=$HOME/.local/share/nvim/site
./build/nvim -u ~/.local/share/nvim/site/pack/vendor/start/babelfish.nvim/scripts/init.lua --headless -c 'TSInstallSync markdown' -c 'qa'
- name: Generating docs
run: |
export PATH="${PWD}/build/:${PATH}"
export PACKPATH=$HOME/.local/share/nvim/site
./build/nvim -u ~/.local/share/nvim/site/pack/vendor/start/babelfish.nvim/scripts/init.lua --headless -c 'luafile ./scripts/vimdocgen.lua' -c 'qa'
- name: Commit changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_MSG: |
[docgen] Update README.md
skip-checks: true
run: |
git config user.email "actions@github"
git config user.name "Github Actions"
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
git add doc/lspconfig.txt
# Only commit and push if we have changes
git diff --quiet && git diff --staged --quiet || (git commit -m "${COMMIT_MSG}"; git push origin HEAD:${GITHUB_REF})

View File

@ -0,0 +1,28 @@
name: Close Non-Feature Branches
on:
pull_request_target:
branches:
- master
jobs:
close-master-branch:
runs-on: ubuntu-latest
permissions:
pull-requests: write
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Close if master branch
if: ${{ github.head_ref == 'master' }}
run: |
gh pr close $PR_NUMBER
gh pr comment $PR_NUMBER --body "This pull request has been automatically closed. Please develop on a feature branch. Thank you."
exit 1

View File

@ -7,26 +7,48 @@ on:
jobs:
lint:
runs-on: [ubuntu-latest]
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Setup luacheck
run: |
sudo apt update &&
sudo apt install -y lua5.1 luarocks &&
sudo luarocks install luacheck
- name: Run luacheck
run: |
sudo make lint
- name: Checkout sources
uses: actions/checkout@v2
- name: Setup luacheck
run: |
sudo apt update
sudo apt install -y lua5.1 luarocks
sudo luarocks install luacheck
- name: Setup selene
run: |
wget "https://github.com/Kampfkarren/selene/releases/download/$VERSION/selene-$VERSION-linux.zip"
echo "$SHA256_CHECKSUM selene-$VERSION-linux.zip" > "selene-$VERSION-linux.zip.checksum"
sha256sum --check "selene-$VERSION-linux.zip.checksum"
unzip "selene-$VERSION-linux.zip"
install -Dp selene "$HOME/.local/bin/selene"
echo "::add-matcher::.github/workflows/problem_matchers/selene.json"
env:
VERSION: "0.15.0"
SHA256_CHECKSUM: "8ff9272170158fbd9c1af38206ecadc894dc456665dc9bd9f0d43a26e5e8f1af"
- name: Add $HOME/.local/bin to $PATH
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Run luacheck
run: luacheck lua/* test/*
- name: Run selene
run: selene --display-style=quiet .
style-lint:
runs-on: [ubuntu-latest]
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Lint with stylua
uses: JohnnyMorganz/stylua-action@1.0.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
# CLI arguments
args: --check .
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Lint with stylua
uses: JohnnyMorganz/stylua-action@1.0.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
# CLI arguments
args: --check .

View File

@ -0,0 +1,30 @@
{
"problemMatcher": [
{
"owner": "selene-error",
"severity": "error",
"pattern": [
{
"regexp": "^([^:]+):(\\d+):(\\d+):\\serror(.*)$",
"file": 1,
"line": 2,
"column": 3,
"message": 4
}
]
},
{
"owner": "selene-warning",
"severity": "warning",
"pattern": [
{
"regexp": "^([^:]+):(\\d+):(\\d+):\\swarning(.*)$",
"file": 1,
"line": 2,
"column": 3,
"message": 4
}
]
}
]
}

View File

@ -0,0 +1,15 @@
name: "Dirname Checker"
on: [pull_request]
jobs:
disallowed-root-checker:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- run: |
if ! bash .github/ci/run_sanitizer.sh ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}; then
exit 1
fi

View File

@ -7,7 +7,7 @@ on:
jobs:
ubuntu:
runs-on: [ubuntu-latest]
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
@ -39,13 +39,12 @@ jobs:
run: |
make test
macos:
runs-on: [macos-latest]
runs-on: macos-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Setup build dependencies
run: |
rm -f /usr/local/bin/2to3
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" &&
brew install ninja libtool automake pkg-config gettext
- name: Run test with building Nvim

View File

@ -1,2 +1,3 @@
.luacheckcache
neovim
doc/tags

View File

@ -1,8 +0,0 @@
pull_request_rules:
- name: disallow changing a file
conditions:
- files=CONFIG.md
actions:
close:
comment:
message: "CONFIG.md is auto-generated: edit the lua source file instead (and re-read the PR template)."

View File

@ -1,164 +0,0 @@
## Advanced usage
**All provided examples are in Lua,** see `:help :lua-heredoc` to use Lua from your init.vim,
or the quickstart above for an example of a lua heredoc.
Each config provides a `setup()` function to initialize the server with reasonable default
initialization options and settings, as well as some server-specific commands. This is
invoked in the following form, where `<server>` corresponds to the language server name
in [CONFIG.md](CONFIG.md).
`setup()` takes optional arguments <config>, each of which overrides the respective
part of the default configuration. The allowed arguments are detailed [below](#setup-function).
```lua
require'lspconfig'.<server>.setup{<config>}
```
### Example: using the defaults
To use the defaults, just call `setup()` with an empty `config` parameter.
For the `gopls` config, that would be:
```lua
require'lspconfig'.gopls.setup{}
```
### Example: override some defaults
To set some config properties at `setup()`, specify their keys. For example to
change how the "project root" is found, set the `root_dir` key:
```lua
local lspconfig = require'lspconfig'
lspconfig.gopls.setup{
root_dir = lspconfig.util.root_pattern('.git');
}
```
The [documentation](CONFIG.md) for each config lists default values and
additional optional properties. For a more complicated example overriding
the `name`, `log_level`, `message_level`, and `settings` of texlab:
```lua
local lspconfig = require'lspconfig'
lspconfig.texlab.setup{
name = 'texlab_fancy';
settings = {
latex = {
build = {
onSave = true;
}
}
}
}
```
### Example: custom config
To configure a custom/private server, just
1. load the lspconfig module: `local lspconfig = require('lspconfig')`,
2. Define the config: `lspconfig.configs.foo_lsp = { … }`
3. Call `setup()`: `lspconfig.foo_lsp.setup{}`
```lua
local lspconfig = require'lspconfig'
local configs = require'lspconfig/configs'
-- Check if it's already defined for when reloading this file.
if not lspconfig.foo_lsp then
configs.foo_lsp = {
default_config = {
cmd = {'/home/ashkan/works/3rd/lua-language-server/run.sh'};
filetypes = {'lua'};
root_dir = function(fname)
return lspconfig.util.find_git_ancestor(fname) or vim.loop.os_homedir()
end;
settings = {};
};
}
end
lspconfig.foo_lsp.setup{}
```
### Example: override default config for all servers
If you want to change default configs for all servers, you can override default_config like this. In this example, we additionally add a check for log_level and message_level which can be passed to the server to control the verbosity of "window/logMessage".
```lua
local lspconfig = require'lspconfig'
lspconfig.util.default_config = vim.tbl_extend(
"force",
lspconfig.util.default_config,
{
autostart = false,
handlers = {
["window/logMessage"] = function(err, method, params, client_id)
if params and params.type <= vim.lsp.protocol.MessageType.Log then
vim.lsp.handlers["window/logMessage"](err, method, params, client_id)
end
end;
["window/showMessage"] = function(err, method, params, client_id)
if params and params.type <= vim.lsp.protocol.MessageType.Warning.Error then
vim.lsp.handlers["window/showMessage"](err, method, params, client_id)
end
end;
}
}
)
```
## setup() function
setup() extends the arguments listed in `:help vim.lsp.start_client()`. **In addition to all of the arguments defined for start_client**, the following key/value pairs can be passed to the setup function:
```
lspconfig.SERVER.setup{config}
The `config` parameter has the same shape as that of
|vim.lsp.start_client()|, with these additions:
{root_dir}
Required for some servers, optional for others.
Function of the form `function(filename, bufnr)`.
Called on new candidate buffers being attached-to.
Returns either a root_dir or nil.
If a root_dir is returned, then this file will also be attached. You
can optionally use {filetype} to help pre-filter by filetype.
If a root_dir is returned which is unique from any previously returned
root_dir, a new server will be spawned with that root_dir.
If nil is returned, the buffer is skipped.
See |lspconfig.util.search_ancestors()| and the functions which use it:
- |lspconfig.util.root_pattern(pattern1, pattern2...)| is a variadic function which
takes string patterns as arguments, and finds an ancestor
which contains one of the files matching the pattern.
Each pattern can be a specific filename, such as ".git", or a glob.
See `:help glob` for allowed patterns. This is equivalent to
coc.nvim's "rootPatterns"
- Related utilities for common tools:
- |lspconfig.util.find_git_root()|
- |lspconfig.util.find_node_modules_root()|
- |lspconfig.util.find_package_json_root()|
{name}
Defaults to the server's name.
{filetypes}
Set of filetypes to filter for consideration by {root_dir}.
May be empty.
Server may specify a default value.
{autostart}
Whether to automatically start a language server when a matching filetype is detected.
Defaults to true.
{on_new_config}
`function(new_config, new_root_dir)` will be executed after a new configuration has been
created as a result of {root_dir} returning a unique value. You can use this
as an opportunity to further modify the new_config or use it before it is
sent to |vim.lsp.start_client()|. If you set a custom `on_new_config`, ensure that
`new_config.cmd = cmd` is present within the function body.
```

File diff suppressed because it is too large Load Diff

View File

@ -1,73 +1,106 @@
## Requirements
- [Neovim](https://neovim.io/) 0.5 or later
- [Neovim](https://neovim.io/) 0.6 or later
- Lint task requires [luacheck](https://github.com/luarocks/luacheck#installation) and [stylua](https://github.com/JohnnyMorganz/StyLua). If using nix, you can use `nix develop` to install these to a local nix shell.
- Documentation is generated by `scripts/docgen.lua`.
- Only works on unix, you can ignore it on Windows.
- Lint task requires [luacheck](https://github.com/luarocks/luacheck#installation) and [stylua](https://github.com/JohnnyMorganz/StyLua).
- Only works on linux and macOS
## Scope of lspconfig
The point of lspconfig is to provide the minimal configuration necessary for a server to act in compliance with the language server protocol. In general, if a server requires custom client-side commands or off-spec handlers, then the server configuration should be added *without* those in lspconfig and receive a dedicated plugin such as nvim-jdtls, nvim-metals, etc.
## Pull requests (PRs)
- To avoid duplicate work, create a draft pull request.
- Avoid cosmetic changes to unrelated files in the same commit.
- Use a [feature branch](https://www.atlassian.com/git/tutorials/comparing-workflows) instead of the master branch.
- Use a **rebase workflow** for small PRs.
- After addressing review comments, it's fine to rebase and force-push.
## Adding a server to lspconfig
The general form of adding a new language server is to start with a minimal skeleton. This includes populated the `config` table with a `default_config` and `docs` table.
When choosing a server name, convert all dashes (`-`) to underscores (`_`) If the name of the server is a unique name (`pyright`, `clangd`) or a commonly used abbreviation (`zls`), prefer this as the server name. If the server instead follows the pattern x-language-server, prefer the convention `x_ls` (`jsonnet_ls`).
`default_config` should include, at minimum the following:
* `cmd`: a list which includes the executable name as the first entry, with arguments constituting subsequent list elements (`--stdio` is common).
Note that Windows has a limitation when it comes to directly invoking a server that's installed by `npm` or `gem`, so it requires additional handling.
```lua
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
```
* `filetypes`: a list for filetypes a
* `root_dir`: a function (or function handle) which returns the root of the project used to determine if lspconfig should launch a new language server, or attach a previously launched server when you open a new buffer matching the filetype of the server. Note, lspconfig does not offer a dedicated single file mode (this is not codified in the spec). Do not add `vim.fn.cwd` or `util.path.dirname` in `root_dir`. A future version of lspconfig will provide emulation of a single file mode until this is formally codified in the specification. A good fallback is `util.find_git_ancestor`, see other configurations for examples.
Additionally, the following options are often added:
* `init_options`: a table sent during initialization, corresponding to initializationOptions sent in [initializeParams](https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#initializeParams) as part of the first request sent from client to server during startup.
* `settings`: a table sent during [`workspace/didChangeConfiguration`](https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#didChangeConfigurationParams) shortly after server initialization. This is an undocumented convention for most language servers. There is often some duplication with initOptions.
A minimal example for adding a new language server is shown below for `pyright`, a python language server included in lspconfig:
```lua
-- Only `configs` must be required, util is optional if you are using the root resolver functions, which is usually the case.
local configs = require 'lspconfig.configs'
local util = require 'lspconfig.util'
-- Having server name defined here is the convention, this is often times also the first entry in the `cmd` table.
local server_name = 'pyright'
configs[server_name] = {
default_config = {
-- This should be executable on the command line, arguments (such as `--stdio`) are additional entries in the list.
cmd = { 'pyright-langserver' },
-- These are the filetypes that the server will either attach or start in response to opening. The user must have a filetype plugin matching the filetype, either via the built-in runtime files or installed via plugin.
filetypes = { 'python' },
-- The root directory that lspconfig uses to determine if it should start a new language server, or attach the current buffer to a previously running language server.
root_dir = util.find_git_ancestor
end,
},
docs = {
-- The description should include at minimum the link to the github project, and ideally the steps to install the language server.
description = [[
https://github.com/microsoft/pyright
`pyright`, a static type checker and language server for python
`pyright` can be installed via `npm`
`npm install -g pyright`
]],
},
}
```
## Commit style
lspconfig, like neovim core, follows the [conventional commit style](https://www.conventionalcommits.org/en/v1.0.0-beta.2/) please submit your commits accordingly. Generally commits will be of the form:
```
feat: add lua-language-server support
fix(lua-language-server): update root directory pattern
docs: update README.md
```
with the commit body containing additional details.
## Lint
PRs are checked with Luacheck and stylua. To run the linter locally:
PRs are checked with [luacheck](https://github.com/mpeterv/luacheck), [StyLua](https://github.com/JohnnyMorganz/StyLua) and [selene](https://github.com/Kampfkarren/selene). Please run the linter locally before submitting a PR:
make lint
stylua .
## Generating docs
> Note: Github Actions automatically generates the docs, so only modify
> `README_template.md` or the `docs` object on the server config.
> Don't modify `README.md` directly.
Github Actions automatically generates `server_configurations.md`. Only modify `scripts/README_template.md` or the `docs` table in the server config (the lua file). Do not modify `server_configurations.md` directly.
To preview the generated `README.md` locally, run `scripts/docgen.lua` from
To preview the generated `server_configurations.md` locally, run `scripts/docgen.lua` from
`nvim` (from the project root):
nvim -R -Es +'set rtp+=$PWD' +'luafile scripts/docgen.lua'
## Configs
The `configs` module is a singleton where configs are defined. In `vim.validate`
parlance here is the "spec":
configs.SERVER_NAME = {
default_config = {'t'};
on_new_config = {'f', true};
on_attach = {'f', true};
commands = {'t', true};
docs = {'t', true};
}
docs = {
description = {'s', true};
default_config = {'t', true};
}
- Keys in `docs.default_config` match those of
`configs.SERVER_NAME.default_config`, and can be used to specify custom
documentation. This is useful for functions, whose docs cannot be easily
auto-generated.
- `commands` is a map of `name:definition` key:value pairs, where `definition`
is a list whose first value is a function implementing the command and the
rest are either array values which will be formed into flags for the command
or special keys like `description`. Example:
```
commands = {
TexlabBuild = {
function()
buf_build(0)
end;
"-range";
description = "Build the current buffer";
};
};
```
The `configs.__newindex` metamethod consumes the config definition and returns
an object with a `setup()` method, to be invoked by users:
require'lspconfig'.SERVER_NAME.setup{}
After you set `configs.SERVER_NAME` you can add arbitrary language-specific
functions to it if necessary.
Example:
configs.texlab.buf_build = buf_build

View File

@ -1,10 +1,12 @@
test:
sh ./scripts/run_test.sh
lint:
luacheck lua/* test/*
style-lint:
lint:
@printf "\nRunning luacheck\n"
luacheck lua/* test/*
@printf "\nRunning selene\n"
selene --display-style=quiet .
@printf "\nRunning stylua\n"
stylua --check .
.PHONY: test lint style-lint
.PHONY: test lint

View File

@ -1,8 +1,11 @@
# nvim-lspconfig
# lspconfig
A [collection of common configurations](https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md) for Neovim's built-in [language server client](https://neovim.io/doc/user/lsp.html).
A [collection of common configurations](doc/server_configurations.md) for Neovim's built-in [language server client](https://neovim.io/doc/user/lsp.html).
This repo handles automatically launching and initializing language servers that are installed on your system.
This plugin allows for declaratively configuring, launching, and initializing language servers you have installed on your system.
**Disclaimer: Language server configurations are provided on a best-effort basis and are community-maintained. See [contributions](#contributions).**
`lspconfig` has extensive help documentation, see `:help lspconfig`.
# LSP overview
@ -18,149 +21,124 @@ Neovim supports the Language Server Protocol (LSP), which means it acts as a cli
Neovim provides an interface for all of these features, and the language server client is designed to be highly extensible to allow plugins to integrate language server features which are not yet present in Neovim core such as [**auto**-completion](https://github.com/neovim/nvim-lspconfig/wiki/Autocompletion) (as opposed to manual completion with omnifunc) and [snippet integration](https://github.com/neovim/nvim-lspconfig/wiki/Snippets).
These features are not implemented in this repo, but in Neovim core. See `:help lsp` for more details.
**These features are not implemented in this repo**, but in Neovim core. See `:help lsp` for more details.
## Install
* Requires [Neovim v0.5.0](https://github.com/neovim/neovim/releases/tag/v0.5.0) or [Nightly](https://github.com/neovim/neovim/releases/tag/nightly). Update Neovim and nvim-lspconfig before reporting an issue.
* Requires [Neovim v0.6.1](https://github.com/neovim/neovim/releases/tag/v0.6.1) or [Nightly](https://github.com/neovim/neovim/releases/tag/nightly). Update Neovim and 'lspconfig' before reporting an issue.
* Install nvim-lspconfig like any other Vim plugin, e.g. with [vim-plug](https://github.com/junegunn/vim-plug):
* Install 'lspconfig' like any other Vim plugin, e.g. with [packer.nvim](https://github.com/wbthomason/packer.nvim):
```vim
Plug 'neovim/nvim-lspconfig'
```lua
local use = require('packer').use
require('packer').startup(function()
use 'wbthomason/packer.nvim' -- Package manager
use 'neovim/nvim-lspconfig' -- Collection of configurations for the built-in LSP client
end)
```
## Quickstart
1. Install a language server, e.g. [pyright](CONFIG.md#pyright)
1. Install a language server, e.g. [pyright](doc/server_configurations.md#pyright)
```bash
npm i -g pyright
```
2. Add the language server setup to your init.vim. The server name must match those found in the table of contents in [CONFIG.md](CONFIG.md)
2. Add the language server setup to your init.lua.
```lua
lua << EOF
require'lspconfig'.pyright.setup{}
EOF
```
3. Create a project, this project must contain a file matching the root directory trigger. See [Automatically launching language servers](#Automatically-launching-language-servers) for additional info.
```bash
mkdir test_python_project
cd test_python_project
git init
touch main.py
```
4. Launch neovim, the language server will now be attached and providing diagnostics (see `:LspInfo`)
3. Launch neovim, the language server will now be attached and providing diagnostics (see `:LspInfo`)
```
nvim main.py
```
5. See [Keybindings and completion](#Keybindings-and-completion) for mapping useful functions and enabling omnifunc completion
4. See [Keybindings and completion](#Keybindings-and-completion) for mapping useful functions and enabling omnifunc completion
## Automatically launching language servers
For a full list of servers, see [server_configurations.md](doc/server_configurations.md) or `:help lspconfig-server-configurations`. This document contains installation instructions and additional, optional, customization suggestions for each language server. For some servers that are not on your system path (e.g., `jdtls`, `elixirls`), you will be required to manually add `cmd` as an entry in the table passed to `setup`. Most language servers can be installed in less than a minute.
In order to automatically launch a language server, lspconfig searches up the directory tree from your current buffer to find a file matching the `root_dir` pattern defined in each server's configuration. For [pyright](CONFIG.md#pyright), this is any directory containing ".git", "setup.py", "setup.cfg", "pyproject.toml", or "requirements.txt").
## Suggested configuration
Language servers require each project to have a `root` in order to provide completion and search across symbols that may not be defined in your current file, and to avoid having to index your entire filesystem on each startup.
'lspconfig' does not map keybindings or enable completion by default. The following example configuration provides suggested keymaps for the most commonly used language server functions, and manually triggered completion with omnifunc (\<c-x\>\<c-o\>).
## Enabling additional language servers
Enabling most language servers is as easy as installing the language server, ensuring it is on your PATH, and adding the following to your config:
```vim
lua << EOF
require'lspconfig'.rust_analyzer.setup{}
EOF
```
For a full list of servers, see [CONFIG.md](CONFIG.md). This document contains installation instructions and additional, optional customization suggestions for each language server. For some servers that are not on your system path (jdtls, elixirls) you will be required to manually add `cmd` as an entry in the table passed to setup. Most language servers can be installed in less than a minute.
## Keybindings and completion
nvim-lspconfig does not map keybindings or enable completion by default. Manual, triggered completion can be provided by neovim's built-in omnifunc. For autocompletion, a general purpose [autocompletion plugin](https://github.com/neovim/nvim-lspconfig/wiki/Autocompletion) is required. The following example configuration provides suggested keymaps for the most commonly used language server functions, and manually triggered completion with omnifunc (\<c-x\>\<c-o\>).
Note: **you must pass the defined `on_attach` as an argument to every `setup {}` call** and **the keybindings in `on_attach` only take effect after the language server has started (attached to the current buffer)**.
Note: **you must pass the defined `on_attach` as an argument to every `setup {}` call** and **the keybindings in `on_attach` only take effect on buffers with an active language server**.
```lua
lua << EOF
local nvim_lsp = require('lspconfig')
-- Mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
local opts = { noremap=true, silent=true }
vim.api.nvim_set_keymap('n', '<space>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
vim.api.nvim_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
vim.api.nvim_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
vim.api.nvim_set_keymap('n', '<space>q', '<cmd>lua vim.diagnostic.setloclist()<CR>', opts)
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
-- Enable completion triggered by <c-x><c-o>
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
local opts = { noremap=true, silent=true }
-- See `:help vim.lsp.*` for documentation on any of the below functions
buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
buf_set_keymap('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
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', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<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', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
end
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
local servers = { 'pyright', 'rust_analyzer', 'tsserver' }
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup {
for _, lsp in pairs(servers) do
require('lspconfig')[lsp].setup {
on_attach = on_attach,
flags = {
-- This will be the default in neovim 0.7+
debounce_text_changes = 150,
}
}
end
EOF
```
The `on_attach` hook is used to only activate the bindings after the language server attaches to the current buffer.
Manual, triggered completion is provided by neovim's built-in omnifunc. For **auto**completion, a general purpose [autocompletion plugin](https://github.com/neovim/nvim-lspconfig/wiki/Autocompletion) is required.
## Debugging
If you have an issue with lspconfig, the first step is to reproduce with a [minimal configuration](https://github.com/neovim/nvim-lspconfig/blob/master/test/minimal_init.lua).
If you have an issue with 'lspconfig', the first step is to reproduce with a [minimal configuration](https://github.com/neovim/nvim-lspconfig/blob/master/test/minimal_init.lua).
The most common reasons a language server does not start or attach are:
1. The language server is not installed. nvim-lspconfig does not install language servers for you. You should be able to run the `cmd` defined in each server's lua module from the command line and see that the language server starts. If the `cmd` is an executable name, ensure it is on your path.
1. The language server is not installed. 'lspconfig' does not install language servers for you. You should be able to run the `cmd` defined in each server's lua module from the command line and see that the language server starts. If the `cmd` is an executable name instead of an absolute path to the executable, ensure it is on your path.
2. Not triggering root detection. The language server will only start if it is opened in a directory, or child directory, containing a file which signals the *root* of the project. Most of the time, this is a `.git` folder, but each server defines the root config in the lua file. See [CONFIG.md](CONFIG.md) or the source for the list of root directories.
2. Missing filetype plugins. Certain languages are not detecting by vim/neovim because they have not yet been added to the filetype detection system. Ensure `:set ft?` shows the filetype and not an empty value.
3. Misconfiguration. You must pass `on_attach` and `capabilities` for **each** `setup {}` if you want these to take effect. You must also **not call `setup {}` twice for the same server**. The second call to `setup {}` will overwrite the first.
3. Not triggering root detection. **Some** language servers will only start if it is opened in a directory, or child directory, containing a file which signals the *root* of the project. Most of the time, this is a `.git` folder, but each server defines the root config in the lua file. See [server_configurations.md](doc/server_configurations.md) or the source for the list of root directories.
:LspInfo provides a handy overview of your active and configured language servers. Note, that it will not report any configuration changes applied in `on_new_config`.
4. You must pass `on_attach` and `capabilities` for **each** `setup {}` if you want these to take effect.
5. **Do not call `setup {}` twice for the same server**. The second call to `setup {}` will overwrite the first.
Before reporting a bug, check your logs and the output of `:LspInfo`. Add the following to your init.vim to enable logging:
```lua
lua << EOF
vim.lsp.set_log_level("debug")
EOF
```
Attempt to run the language server, and open the log with:
```
:lua vim.cmd('e'..vim.lsp.get_log_path())
```
@ -180,29 +158,23 @@ The following support tab-completion for all arguments:
Please see the [wiki](https://github.com/neovim/nvim-lspconfig/wiki) for additional topics, including:
* [Installing language servers automatically](https://github.com/neovim/nvim-lspconfig/wiki/Installing-language-servers-automatically)
* [Snippets support](https://github.com/neovim/nvim-lspconfig/wiki/Snippets)
* [Project local settings](https://github.com/neovim/nvim-lspconfig/wiki/Project-local-settings)
* [Recommended plugins for enhanced language server features](https://github.com/neovim/nvim-lspconfig/wiki/Language-specific-plugins)
## Windows
In order for neovim to launch certain executables on Windows, it must append `.cmd` to the command name. To work around this, manually append `.cmd` to the entry `cmd` in a given plugin's setup{} call.
## Contributions
If you are missing a language server on the list in [CONFIG.md](CONFIG.md), contributing
If you are missing a language server on the list in [server_configurations.md](doc/server_configurations.md), contributing
a new configuration for it would be appreciated. You can follow these steps:
1. Read [CONTRIBUTING.md](CONTRIBUTING.md).
2. Choose a language from [the coc.nvim wiki](https://github.com/neoclide/coc.nvim/wiki/Language-servers) or
[emacs-lsp](https://github.com/emacs-lsp/lsp-mode#supported-languages).
2. Create a new file at `lua/lspconfig/server_configurations/SERVER_NAME.lua`.
3. Create a new file at `lua/lspconfig/SERVER_NAME.lua`.
- Copy an [existing config](https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/)
- Copy an [existing config](https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/server_configurations/)
to get started. Most configs are simple. For an extensive example see
[texlab.lua](https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/texlab.lua).
[texlab.lua](https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/server_configurations/texlab.lua).
4. Ask questions on our [Discourse](https://neovim.discourse.group/c/7-category/7) or in the [Neovim Gitter](https://gitter.im/neovim/neovim).
3. Ask questions on our [Discourse](https://neovim.discourse.group/c/7-category/7) or in the [Neovim Gitter](https://gitter.im/neovim/neovim).
You can also help out by testing [PRs with the `needs-testing`](https://github.com/neovim/nvim-lspconfig/issues?q=is%3Apr+is%3Aopen+label%3Aneeds-testing) label) that affect language servers you use regularly.

View File

@ -1,4 +0,0 @@
function! health#lspconfig#check()
call health#report_start('Checking language server protocol configuration')
lua require 'lspconfig/health'.check_health()
endfunction

View File

@ -1,17 +1,52 @@
*lspconfig.txt* For Nvim version 0.6.1+ Last change: 2021 Nov 7
==============================================================================
1. nvim-lspconfig *lspconfig-nvim-lspconfig*
TABLE OF CONTENTS *lspconfig-toc*
1. Introduction (|lspconfig|)
2. LSP overview (|lspconfig-lsp|)
3. Quickstart (|lspconfig-quickstart|)
4. Setup {} (|lspconfig-setup|)
5. Global defaults (|lspconfig-global-defaults|)
6. Server configurations (|lspconfig-configurations|)
6a. Adding servers (|lspconfig-adding-servers|)
7. Root directories (|lspconfig-root-detection|)
7a. Advanced detection (|lspconfig-root-advanced|)
7b. Single file support (|lspconfig-single-file-support|)
8. Commands (|lspconfig-commands|)
9. Keybindings (|lspconfig-keybindings|)
10. Completion (|lspconfig-completion|)
11. Debugging (|lspconfig-debugging|)
12. Logging (|lspconfig-logging|)
13. Scope (|lspconfig-scope|)
A collection of common configurations for Neovim's built-in [language server client](https://neovim.io/doc/user/lsp.html).
This repo handles automatically launching and initializing language servers
that are installed on your system.
==============================================================================
2. LSP overview *lspconfig-lsp-overview*
INTRODUCTION *lspconfig*
`lspconfig` is a collection of community contributed configurations for the
built-in language server client in Neovim core. This plugin provides four
primary functionalities:
- default launch commands, initialization options, and settings for each
server
- a root directory resolver which attempts to detect the root of your project
- an autocommand mapping that either launches a new language server or
attempts to attach a language server to each opened buffer if it falls
under a tracked project
- utility commands such as LspInfo, LspStart, LspStop, and LspRestart for
managing language server instances
`lspconfig` is not required to use the built-in client, it is only one front-end
interface for when a language server specific plugin is not available.
See |lspconfig-server-configurations| by typing `K` over it for the complete
list of language servers configurations.
==============================================================================
LSP OVERVIEW *lspconfig-lsp*
Nvim supports the Language Server Protocol (LSP) via the built-in language
server client. LSP facilitates many features, some of which include:
Neovim supports the Language Server Protocol (LSP), which means it acts as a
client to language servers and includes a Lua framework `vim.lsp` for building
enhanced LSP tools. LSP facilitates features like:
- go-to-definition
- find-references
- hover
@ -19,222 +54,583 @@ enhanced LSP tools. LSP facilitates features like:
- rename
- format
- refactor
Neovim provides an interface for all of these features, and the language server
client is designed to be highly extensible to allow plugins to integrate
language server features which are not yet present in Neovim core such as [**auto**-completion](https://github.com/neovim/nvim-lspconfig/wiki/Autocompletion)
(as opposed to manual completion with omnifunc) and [snippet integration](https://github.com/neovim/nvim-lspconfig/wiki/Snippets).
These features are not implemented in this repo, but in Neovim core. See `:help
lsp` for more details.
These features are implemented in Neovim core, not `lspconfig`. See `:help lsp`
for more details.
NOTE: Feature availability depends on the implementation details of the
server. A server may implement only a subset of these features. Always
consult the server documentation before filing a bug report on a missing
feature.
==============================================================================
3. Install *lspconfig-install*
QUICKSTART *lspconfig-quickstart*
- ensure the server is installed and executable from the command line
* Requires [Neovim v0.5.0](https://github.com/neovim/neovim/releases/tag/v0.5.0) or [Nightly](https://github.com/neovim/neovim/releases/tag/nightly). Update Neovim and nvim-lspconfig before reporting an issue.
* Install nvim-lspconfig like any other Vim plugin, e.g. with [vim-plug](https://github.com/junegunn/vim-plug):
- enable the server in your Neovim configuration (Lua example):
>
require'lspconfig'.clangd.setup{}
<
- create a new project, ensure that it contains a root marker which matches the
server requirements specified in |lspconfig-server-configurations|.
- open a file within that project, such as `main.c`.
- If you need more information about a server configuration, read the corresponding
entry in |lspconfig-server-configurations|.
```vim
Plug 'neovim/nvim-lspconfig'
```
==============================================================================
4. Quickstart *lspconfig-quickstart*
THE SETUP METAMETHOD *lspconfig-setup*
`lspconfig` consists of a collection of language server configurations. Each
configuration exposes a `setup {}` metamethod which makes it easy to directly
use the default configuration or selectively override the defaults.
`setup {}` is the primary interface by which users interact with `lspconfig`.
1. Install a language server, e.g. [pyright](CONFIG.md#pyright)
Using the default configuration for a server is simple:
>
require'lspconfig'.clangd.setup{}
<
The available server names are listed in |lspconfig-server-configurations| and
match the server name in `config.SERVER_NAME` defined in each configuration's
source file.
```bash
npm i -g pyright
```
2. Add the language server setup to your init.vim. The server name must match those found in the table of contents in [CONFIG.md](CONFIG.md)
The purpose of `setup{}` is to wrap the call to Nvim's built-in
`vim.lsp.start_client()` with an autocommand that automatically launch a
language server.
```lua
lua << EOF
require'lspconfig'.pyright.setup{}
EOF
```
3. Create a project, this project must contain a file matching the root directory trigger. See [Automatically launching language servers](#Automatically-launching-language-servers) for additional info.
This autocommand calls `start_client()` or `vim.lsp.buf_attach_client()`
depending on whether the current file belongs to a project with a currently
running client. See |lspconfig-root-detection| for more details.
```bash
mkdir test_python_project
cd test_python_project
git init
touch main.py
```
4. Launch neovim, the language server will now be attached and providing diagnostics (see `:LspInfo`)
The `setup{}` function takes a table which contains a superset of the keys
listed in `:help vim.lsp.start_client()` with the following unique entries:
```
nvim main.py
```
5. See [Keybindings and completion](#Keybindings-and-completion) for mapping useful functions and enabling omnifunc completion
- {root_dir}
`function(filename, bufnr)`
Returns either a filepath (string) or nil. The language server will only
start if the function returns a filepath.
If a root directory (string) is returned which is unique from any
previously returned root_dir, a new server will be spawned with that
root directory. See |lspconfig-root-detection| for more details
- {name}
`string`
Defaults to the server's name (`clangd`, `pyright`, etc.).
- {filetypes}
`list[string] | nil`
Set of filetypes for which to attempt to resolve {root_dir}.
May be empty, or server may specify a default value.
- {autostart}
`bool` (default: true)
Controls if the `FileType` autocommand that launches a language server is
created. If `false`, allows for deferring language servers until manually
launched with `:LspStart` (|lspconfig-commands|).
- {single_file_support}
`bool` (default: nil)
Determines if a server is started without a matching root directory.
See |lspconfig-single-file-support|.
- {on_new_config}
`function(new_config, new_root_dir)`
Function executed after a root directory is detected. This is used to
modify the server configuration (including `cmd` itself). Most commonly,
this is used to inject additional arguments into `cmd`.
If overriding `on_new_config`, ensure that you read the
`on_new_config` defined in the source file of the default configuration
in `lspconfig`. The original `on_new_config` snippet for a given server
should likely be included in your new override. Some configurations
use `on_new_config` to dynamically set or modify `cmd`.
Note: all entries passed to `setup {}` override the entry in the default
configuration. There is no composition.
All `config` elements described in `:help vim.lsp.start_client()` can
additionally be overridden via the `setup {}` call. The most commonly
passed overrides to `setup {}` are:
- {capabilities} `table <string, string|table|bool|function>`
a table which represents the neovim client capabilities. Useful for
broadcasting to the server additional functionality (snippets, off-protocol
features) provided by plugins.
- {cmd} `list[string]`
a list where each entry corresponds to the blankspace delimited part of
the command that launches the server. The first entry is the binary used
to run the language server. Additional entries are passed as arguments.
The equivalent `cmd` for:
>
foo --bar baz
<
is:
>
{'foo', '--bar', 'baz}
<
- {handlers} `list[functions]`
a list of handlers which override the function used to process a response
from a given language server. Applied only to the server referenced by
setup. See |lsp-handler|.
- {init_options} `table <string, string|table|bool>`
a table passed during the initialization notification after launching
a language server. Equivalent to the `initializationOptions` field found
in `InitializeParams` in the LSP specification.
See upstream server documentation for available initialization
options.
- {on_attach} `function(client, bufnr)`
Callback invoked by Nvim's built-in client when attaching a buffer to a
language server. Often used to set Nvim (buffer or global) options or to
override the Nvim client properties (`resolved_capabilities`) after a
language server attaches. Most commonly used for settings buffer
local keybindings. See |lspconfig-keybindings| for a usage example.
- {settings} `table <string, string|table|bool>`
The `settings` table is sent in `on_init` via a
`workspace/didChangeConfiguration` notification from the Nvim client to
the language server. These settings allow a user to change optional runtime
settings of the language server.
As an example, to set the following settings found in the pyright
documentation:
`pyright.disableLanguageServices`: `boolean`
`pyright.disableOrganizeImports`: `boolean`
Nested keys need to be translated into a nested table and passed to
the settings field in `setup {}` as follows:
>
require('lspconfig').pyright.setup{
settings = {
pyright = {
disableLanguageServices = true,
disableOrganizeImports = true,
}
}
}
<
==============================================================================
5. Automatically launching language servers*lspconfig-automatically-launching-language-servers*
OVERRIDING GLOBAL DEFAULTS *lspconfig-global-defaults*
The global defaults for all servers can be overridden by extending the
`default_config` table.
>
local lspconfig = require'lspconfig'
lspconfig.util.default_config = vim.tbl_extend(
"force",
lspconfig.util.default_config,
{
autostart = false,
handlers = {
["window/logMessage"] = function(err, method, params, client_id)
if params and params.type <= vim.lsp.protocol.MessageType.Log then
vim.lsp.handlers["window/logMessage"](err, method, params, client_id)
end
end;
["window/showMessage"] = function(err, method, params, client_id)
if params and params.type <= vim.lsp.protocol.MessageType.Warning.Error then
vim.lsp.handlers["window/showMessage"](err, method, params, client_id)
end
end;
}
}
)
<
`setup {}` can additionally override these defaults in subsequent calls.
==============================================================================
SERVER CONFIGURATIONS *lspconfig-configurations*
See |lspconfig-server-configurations| by typing `K` over it for the complete
list of language servers configurations.
While the `setup {}` function is the primary interface to `lspconfig`, for
servers for which there is not a configuration, it is necessary to define a
configuration directly. This can be useful if there is an outstanding PR that
is in review, or when developing a language server that is unavailable
publicly. This can be done through the `configs` module.
The `configs` module is a singleton where configs are defined. The schema for
validating using `vim.validate` is:
>
configs.SERVER_NAME = {
default_config = {'t'};
on_new_config = {'f', true};
on_attach = {'f', true};
commands = {'t', true};
docs = {'t', true};
}
<
where the structure of the docs table is as follows:
>
docs = {
description = {'s', true};
default_config = {'t', true};
}
<
`commands` is a map of `name:definition` key:value pairs, where `definition`
is a list whose first value is a function implementing the command, and the
rest are either array values which will be formed into flags for the command,
or special keys like `description`. Example:
>
commands = {
TexlabBuild = {
function()
buf_build(0)
end;
"-range";
description = "Build the current buffer";
};
};
<
The `configs.__newindex` metamethod consumes the config definition and returns
an object with a `setup()` method, to be invoked by users:
>
require'lspconfig'.SERVER_NAME.setup{}
After you set `configs.SERVER_NAME` you can add arbitrary language-specific
functions to it if necessary.
Example:
>
configs.texlab.buf_build = buf_build
<
==============================================================================
ADDING NEW SERVERS *lspconfig-adding-servers*
The three steps for adding and enabling a new server configuration are:
- load the `lspconfig` module (note that this is a stylistic choice)
>
local lspconfig = require 'lspconfig'
<
- define the configuration
>
local configs = require 'lspconfig.configs'
-- Check if the config is already defined (useful when reloading this file)
if not configs.foo_lsp then
configs.foo_lsp = {
default_config = {
cmd = {'/home/neovim/lua-language-server/run.sh'};
filetypes = {'lua'};
root_dir = function(fname)
return lspconfig.util.find_git_ancestor(fname)
end;
settings = {};
};
}
end
- call `setup()` to enable the FileType autocmd
>
lspconfig.foo_lsp.setup{}
<
==============================================================================
ROOT DETECTION *lspconfig-root-detection*
*lspconfig-root-dir*
A project's `root_dir` is used by `lspconfig` to determine whether `lspconfig`
should start a new server, or attach a previous one, to the current file.
`lspconfig` automatically launches language servers by defining a filetype
autocommand based on the `filetypes` specified in the default configuration of
each server, optionally overridable by the `filetypes` table passed to
`setup`.
This autocommand triggers a search from the current file position in the
filesystem hierarchy up to the top level directory of your filesystem. The
`root_dir` entry of each configuration is a function that returns true if the
current directory in this traversal matches a given root pattern.
The following utility functions are provided by `lspconfig`. Each function call
below returns a function that takes as its argument the current buffer path.
- `util.root_pattern`: function which takes multiple arguments, each
corresponding to a different root pattern against which the contents of the
current directory are matched using |vim.fin.glob()| while traversing up the
filesystem.
>
root_dir = util.root_pattern('pyproject.toml', 'requirements.txt')
<
- `util.find_git_ancestor`: a function that locates the first parent directory
containing a `.git` directory.
>
root_dir = util.find_git_ancestor
- `util.find_node_modules_ancestor`: a function that locates the first parent
directory containing a `node_modules` directory.
>
root_dir = util.find_node_modules_ancestor
<
- `util.find_package_json_ancestor`: a function that locates the first parent
directory containing a `package.json`.
>
root_dir = util.find_json_ancestor
<
Note: On Windows, `lspconfig` always assumes forward slash normalized paths with
capitalized drive letters.
==============================================================================
ADVANCED ROOT DIRECTORY DETECTION *lspconfig-root-advanced*
*lspconfig-root-composition*
The `root_dir` key in `config` and `setup` can hold any function of the form
>
function custom_root_dir(filename, bufnr)
returns nil | string
>
This allows for rich composition of root directory patterns which is necessary
for some project structures. Example (for Kotlin):
>
local root_files = {
'settings.gradle', -- Gradle (multi-project)
'settings.gradle.kts', -- Gradle (multi-project)
'build.xml', -- Ant
'pom.xml', -- Maven
}
local fallback_root_files = {
'build.gradle', -- Gradle
'build.gradle.kts', -- Gradle
}
root_dir = function(fname)
local primary = util.root_pattern(unpack(root_files))(fname)
local fallback = util.root_pattern(unpack(fallback_root_files))(fname)
return primary or fallback
end
<
Browsing the source of the default configurations is recommended.
==============================================================================
SINGLE FILE SUPPORT *lspconfig-single-file-support*
In order to automatically launch a language server, lspconfig searches up the
directory tree from your current buffer to find a file matching the `root_dir`
pattern defined in each server's configuration. For [pyright](CONFIG.md#pyright)
, this is any directory containing ".git", "setup.py", "setup.cfg",
"pyproject.toml", or "requirements.txt").
Language servers require each project to have a `root` in order to provide
completion and search across symbols that may not be defined in your current
file, and to avoid having to index your entire filesystem on each startup.
features that require cross-file indexing.
Some servers support not passing a root directory as a proxy for single file
mode under which cross-file features may be degraded.
`lspconfig` offers limited support for an implicit single-file mode by:
- first trying to resolve the root directory pattern
- then, if `single_file_support` is enabled for a given language server
configuration, starting the server without sending `rootDirectory` or
`workspaceFolders` during initialization.
- attaching subsequent files in the parent directory to the same server
instance, depending on filetype.
Cross-file features (navigation, hover) may or may not work depending on the
language server. For a full feature-set, consider moving your files to a
directory with a project structure `lspconfig` can infer.
Note that in the event that the LSP specification is extended to support a
standard for single-file mode, lspconfig will adopt that standard.
==============================================================================
6. Enabling additional language servers*lspconfig-enabling-additional-language-servers*
COMMANDS *lspconfig-commands*
- `:LspInfo` shows the status of active and configured language servers. Note
that client id refers to the Nvim RPC instance connected to a given
language server.
Enabling most language servers is as easy as installing the language server,
ensuring it is on your PATH, and adding the following to your config:
The following commands support tab-completion for all arguments. All commands
that require a client id can either leverage tab-completion or the info
contained in `:LspInfo`:
- `:LspStart <config_name>` launches the requested (configured) client, but only
if it successfully resolves a root directory. Note: Defaults to all
configured servers matching the current buffer filetype.
- `:LspStop <client_id>` stops the server with the given client id. Defaults to
stopping all servers active on the current buffer.
- `:LspRestart <client_id>` restarts the client with the given client id, and
will attempt to reattach to all previously attached buffers.
==============================================================================
EXAMPLE KEYBINDINGS *lspconfig-keybindings*
`lspconfig`, and the core client, do not map any keybindings by default. The
following is an example Lua block which demonstrates how to leverage
`on-attach` to selectively apply keybindings after a language servers has
attached to a given buffer.
>
lua << EOF
require'lspconfig'.rust_analyzer.setup{}
EOF
<
For a full list of servers, see [CONFIG.md](CONFIG.md). This document contains
installation instructions and additional, optional customization suggestions
for each language server. For some servers that are not on your system path
(jdtls, elixirls) you will be required to manually add `cmd` as an entry in the
table passed to setup. Most language servers can be installed in less than a
minute.
==============================================================================
7. Keybindings *lspconfig-keybindings*
nvim-lspconfig does not map keybindings or enable completion by default.
Manual, triggered completion can be provided by neovim's built-in omnifunc. For
autocompletion, a general purpose [autocompletion plugin](https://github.com/neovim/nvim-lspconfig/wiki/Autocompletion)
is required. The following example configuration provides suggested keymaps for
the most commonly used language server functions, and manually triggered
completion with omnifunc ( \< c-x \> \< c-o \> ). Note: **you must pass the
defined `on_attach` as an argument to every `setup {}` call** and **the
keybindings in `on_attach` only take effect after the language server has
started (attached to the current buffer)**.
>
lua << EOF
local nvim_lsp = require('lspconfig')
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
-- Enable completion triggered by <c-x><c-o>
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
local opts = { noremap=true, silent=true }
-- See `:help vim.lsp.*` for documentation on any of the below functions
buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
buf_set_keymap('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
end
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
local servers = { 'pyright', 'rust_analyzer', 'tsserver' }
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup {
on_attach = on_attach,
flags = {
debounce_text_changes = 150,
}
}
end
EOF
-- Mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
local opts = { noremap=true, silent=true }
vim.api.nvim_set_keymap('n', '<space>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
vim.api.nvim_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
vim.api.nvim_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
vim.api.nvim_set_keymap('n', '<space>q', '<cmd>lua vim.diagnostic.setloclist()<CR>', opts)
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
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', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<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', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
end
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
local servers = { 'pyright', 'rust_analyzer', 'tsserver' }
for _, lsp in pairs(servers) do
require('lspconfig')[lsp].setup {
on_attach = on_attach,
flags = {
-- This will be the default in neovim 0.7+
debounce_text_changes = 150,
}
}
end
<
Note: these keymappings are meant for illustration and override some
infrequently used default mappings.
The `on_attach` hook is used to only activate the bindings after the language
server attaches to the current buffer.
==============================================================================
8. Debugging *lspconfig-debugging*
COMPLETION SUPPORT *lspconfig-completion*
Manually triggered completion can be provided by Nvim's built-in omnifunc.
See `:help omnifunc` for more details.
If you have an issue with lspconfig, the first step is to reproduce with a [minimal configuration](https://github.com/neovim/nvim-lspconfig/blob/master/test/minimal_init.lua).
The most common reasons a language server does not start or attach are:
1. The language server is not installed. nvim-lspconfig does not install language servers for you. You should be able to run the `cmd` defined in each server's lua module from the command line and see that the language server starts. If the `cmd` is an executable name, ensure it is on your path.
2. Not triggering root detection. The language server will only start if it is opened in a directory, or child directory, containing a file which signals the *root* of the project. Most of the time, this is a `.git` folder, but each server defines the root config in the lua file. See [CONFIG.md](CONFIG.md) or the source for the list of root directories.
3. Misconfiguration. You must pass `on_attach` and `capabilities` for **each** `setup {}` if you want these to take effect. You must also **not call `setup {}` twice for the same server**. The second call to `setup {}` will overwrite the first.
:LspInfo provides a handy overview of your active and configured language
servers. Note, that it will not report any configuration changes applied in
For autocompletion, Nvim does not offer built-in functionality at this time.
Consult the `lspconfig` wiki, which provides configuration examples for using a
completion plugin with the built-in client
==============================================================================
DEBUGGING *lspconfig-debugging*
While using language servers should be easy, debugging issues can be
challenging. First, it is important to identify the source of the issue, which
is typically (in rough order):
- the language server itself
- a plugin
- overrides in a user configuration
- the built-in client in Nvim core
- `lspconfig`
The first step in debugging is to test with a minimal configuration (such as
`../test/minimal_init.lua`). Historically, many users problems are due to
plugins or misconfiguration.
Should that fail, identifying which component is the culprit is challenging.
The following are the only categories of bugs that pertain to `lspconfig`.
- The root directory inferred for your project is wrong, or it should be
detected but is not due to a bug in the `lspconfig` path utilities.
- The server is launching, but you believe that the default settings,
initialization options, or command arguments are suboptimal and should be
replaced based on your understanding of the server documentation.
All bugs Nvim's built-in client should be reported to the Nvim core issue
tracker. All bugs pertaining to plugins should be reported to the respective
plugin. All missing features in a language server should be reported to the
upstream language server issue tracker.
For debugging `lspconfig` issues, the most common hurdles users face are:
- The language server is not installed or is otherwise not executable.
`lspconfig` does not install language servers for you. Ensure the `cmd`
defined in `server_configurations.md` is executable from the command
line. If the absolute path to the binary is not supplied in `cmd`, ensure
it is on your PATH.
- No root detected. `lspconfig` is built around the concept of projects. See
|lspconfig-root-detection| for more details. Most of the time,
initializing a git repo will suffice.
- Misconfiguration. Often users will override `cmd`, `on_init`, or
`handlers`. Ensure that you debug by using a stock configuration to ensure
your customizations are not introducing issues.
|LspInfo| provides an overview of your active and configured language servers
which can be useful for debugging.
Note that it will not report any configuration changes applied in
`on_new_config`.
Before reporting a bug, check your logs and the output of `:LspInfo`. Add the
following to your init.vim to enable logging:
==============================================================================
LOGGING *lspconfig-logging*
When debugging language servers, it is helpful to enable additional logging in
the built-in client, specifically considering the RPC logs. Example:
>
lua << EOF
vim.lsp.set_log_level("debug")
EOF
vim.lsp.set_log_level 'trace'
if vim.fn.has 'nvim-0.5.1' == 1 then
require('vim.lsp.log').set_format_func(vim.inspect)
end
<
Attempt to run the language server, and open the log with:
>
:lua vim.cmd('e'..vim.lsp.get_log_path())
<
Note that `ERROR` messages containing `stderr` only indicate that the log was
sent to `stderr`. Many servers counter-intuitively send harmless messages
via stderr.
Most of the time, the reason for failure is present in the logs.
==============================================================================
9. Built-in commands *lspconfig-built-in-commands*
SCOPE *lspconfig-scope*
`lspconfig` is a community effort to create default configurations that fit
within the scope of an official plugin for Nvim. All features that are not
strictly providing default configurations for language servers will be removed
from `lspconfig` in time. The power of the Neovim LSP ecosystem is in the
composability and flexibility of integrating multiple plugins which maximizes
user choice and freedom.
`lspconfig` also opts to adhere strictly to the LSP specification, with some
small allowances when small modifications to a server configuration are
necessary to enable features critical to its usability. For more featureful
options, the `lspconfig` wiki lists community created plugins that build upon
the built-in client to provide functionality tailored to specific language
servers.
* `:LspInfo` shows the status of active and configured language servers.
The following support tab-completion for all arguments:
* `:LspStart <config_name>` Start the requested server name. Will only successfully start if the command detects a root directory matching the current config. Pass `autostart = false` to your `.setup{}` call for a language server if you would like to launch clients solely with this command. Defaults to all servers matching current buffer filetype.
* `:LspStop <client_id>` Defaults to stopping all buffer clients.
* `:LspRestart <client_id>` Defaults to restarting all buffer clients.
==============================================================================
10. The wiki *lspconfig-the-wiki*
Please see the [wiki](https://github.com/neovim/nvim-lspconfig/wiki) for
additional topics, including:
* [Installing language servers automatically](https://github.com/neovim/nvim-lspconfig/wiki/Installing-language-servers-automatically)
* [Snippets support](https://github.com/neovim/nvim-lspconfig/wiki/Snippets)
* [Project local settings](https://github.com/neovim/nvim-lspconfig/wiki/Project-local-settings)
* [Recommended plugins for enhanced language server features](https://github.com/neovim/nvim-lspconfig/wiki/Language-specific-plugins)
==============================================================================
11. Windows *lspconfig-windows*
In order for neovim to launch certain executables on Windows, it must append
`.cmd` to the command name. To work around this, manually append `.cmd` to the
entry `cmd` in a given plugin's setup{} call.
==============================================================================
12. Contributions *lspconfig-contributions*
If you are missing a language server on the list in [CONFIG.md](CONFIG.md) ,
contributing a new configuration for it would be appreciated. You can follow
these steps:
1. Read [CONTRIBUTING.md](CONTRIBUTING.md).
2. Choose a language from [the coc.nvim wiki](https://github.com/neoclide/coc.nvim/wiki/Language-servers) or
[emacs-lsp](https://github.com/emacs-lsp/lsp-mode#supported-languages).
3. Create a new file at `lua/lspconfig/SERVER_NAME.lua`.
- Copy an [existing config](https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/)
to get started. Most configs are simple. For an extensive example see
[texlab.lua](https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/texlab.lua).
4. Ask questions on our [Discourse](https://neovim.discourse.group/c/7-category/7) or in the [Neovim Gitter](https://gitter.im/neovim/neovim).
vim:tw=78:ts=8:ft=help:norl:
vim:tw=78:ts=8:ft=help:norl:

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,27 @@
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1642700792,
"narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "846b2ae0fc4cc943637d3d1def4454213e203cba",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1626644568,
"narHash": "sha256-+WxW0u6AJUn/AzIxUuNKtEDxSRcUP0v/iZ/tRXhLGEc=",
"lastModified": 1643202076,
"narHash": "sha256-EcrUSBkBnw3KtDBoDwHvvwR1R6YF0axNFE4Vd2++iok=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "d5bd34ebf2c2c2b380b76cb86bc68522bc6af4d7",
"rev": "e722007bf05802573b41701c49da6c8814878171",
"type": "github"
},
"original": {
@ -16,6 +31,7 @@
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
}

View File

@ -1,17 +1,19 @@
{
description = "Quickstart configurations for the Nvim LSP client";
outputs = { self, nixpkgs }: let
pkgs = import nixpkgs { system = "x86_64-linux";};
in {
inputs.flake-utils.url = "github:numtide/flake-utils";
devShell."x86_64-linux" = pkgs.mkShell {
buildInputs = [
pkgs.stylua
pkgs.luaPackages.luacheck
];
};
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let pkgs = nixpkgs.legacyPackages.${system}; in
rec {
devShell = pkgs.mkShell {
buildInputs = [
pkgs.stylua
pkgs.luaPackages.luacheck
pkgs.selene
];
};
}
);
}

View File

@ -1,11 +1,9 @@
local configs = require 'lspconfig/configs'
local configs = require 'lspconfig.configs'
local M = {
util = require 'lspconfig/util',
util = require 'lspconfig.util',
}
local script_path = M.util.script_path()
M._root = {}
function M.available_servers()
@ -18,7 +16,7 @@ function M._root._setup()
M._root.commands = {
LspInfo = {
function()
require 'lspconfig/ui/lspinfo'()
require 'lspconfig.ui.lspinfo'()
end,
'-nargs=0',
description = '`:LspInfo` Displays attached, active, and configured language servers',
@ -26,15 +24,15 @@ function M._root._setup()
LspStart = {
function(server_name)
if server_name then
require('lspconfig')[server_name].autostart()
if configs[server_name] then
configs[server_name].launch()
end
else
local buffer_filetype = vim.bo.filetype
for client_name, config in pairs(configs) do
if config.filetypes then
for _, filetype_match in ipairs(config.filetypes) do
if buffer_filetype == filetype_match then
require('lspconfig')[client_name].autostart()
end
for _, config in pairs(configs) do
for _, filetype_match in ipairs(config.filetypes or {}) do
if buffer_filetype == filetype_match then
config.launch()
end
end
end
@ -44,39 +42,25 @@ function M._root._setup()
description = '`:LspStart` Manually launches a language server.',
},
LspStop = {
function(client_id)
if not client_id then
vim.lsp.stop_client(vim.lsp.get_active_clients())
else
local client = vim.lsp.get_client_by_id(tonumber(client_id))
if client then
client.stop()
end
function(cmd_args)
for _, client in ipairs(M.util.get_clients_from_cmd_args(cmd_args)) do
client.stop()
end
end,
'-nargs=? -complete=customlist,v:lua.lsp_get_active_client_ids',
description = '`:LspStop` Manually stops the given language client.',
description = '`:LspStop` Manually stops the given language client(s).',
},
LspRestart = {
function(client_id)
local clients
if client_id == nil then
clients = vim.lsp.buf_get_clients(0)
else
clients = { vim.lsp.get_client_by_id(tonumber(client_id)) }
end
for _, client in pairs(clients) do
local client_name = client.name
function(cmd_args)
for _, client in ipairs(M.util.get_clients_from_cmd_args(cmd_args)) do
client.stop()
vim.defer_fn(function()
require('lspconfig')[client_name].autostart()
configs[client.name].launch()
end, 500)
end
end,
'-nargs=? -complete=customlist,v:lua.lsp_get_active_client_ids',
description = '`:LspRestart` Manually restart the given language client.',
description = '`:LspRestart` Manually restart the given language client(s).',
},
}
@ -86,9 +70,21 @@ end
local mt = {}
function mt:__index(k)
if configs[k] == nil then
-- dofile is used here as a performance hack to increase the speed of calls to setup({})
-- dofile does not cache module lookups, and requires the absolute path to the target file
pcall(dofile, script_path .. 'lspconfig/' .. k .. '.lua')
local success, config = pcall(require, 'lspconfig.server_configurations.' .. k)
if success then
configs[k] = config
else
vim.notify(
string.format(
'[lspconfig] Cannot access configuration for %s. Ensure this server is listed in '
.. '`server_configurations.md` or added as a custom server.',
k
),
vim.log.levels.WARN
)
-- Return a dummy function for compatibility with user configs
return { setup = function() end }
end
end
return configs[k]
end

View File

@ -1,39 +0,0 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local server_name = 'ansiblels'
configs[server_name] = {
default_config = {
cmd = { 'ansible-language-server', '--stdio' },
settings = {
ansible = {
python = {
interpreterPath = 'python',
},
ansibleLint = {
path = 'ansible-lint',
enabled = true,
},
ansible = {
path = 'ansible',
},
},
},
filetypes = { 'yaml' },
root_dir = function(fname)
return util.root_pattern { '*.yml', '*.yaml' }(fname)
end,
},
docs = {
description = [[
https://github.com/ansible/ansible-language-server
Language server for the ansible configuration management tool.
`ansible-language-server` can be installed via `yarn`:
```sh
yarn global add ansible-language-server
```
]],
},
}

View File

@ -1,20 +0,0 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
configs.clojure_lsp = {
default_config = {
cmd = { 'clojure-lsp' },
filetypes = { 'clojure', 'edn' },
root_dir = util.root_pattern('project.clj', 'deps.edn', '.git'),
},
docs = {
description = [[
https://github.com/snoe/clojure-lsp
Clojure Language Server
]],
default_config = {
root_dir = [[root_pattern("project.clj", "deps.edn", ".git")]],
},
},
}

View File

@ -1,4 +1,4 @@
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
local api, validate, lsp = vim.api, vim.validate, vim.lsp
local tbl_extend = vim.tbl_extend
@ -33,7 +33,7 @@ function configs.__newindex(t, config_name, config_def)
function M.setup(config)
validate {
cmd = { config.cmd, 't', true },
root_dir = { config.root_dir, 'f', default_config.root_dir ~= nil },
root_dir = { config.root_dir, 'f', true },
filetypes = { config.filetype, 't', true },
on_new_config = { config.on_new_config, 'f', true },
on_attach = { config.on_attach, 'f', true },
@ -54,38 +54,68 @@ function configs.__newindex(t, config_name, config_def)
pcall(util.on_setup, config)
end
local trigger
if config.filetypes then
trigger = 'FileType ' .. table.concat(config.filetypes, ',')
else
trigger = 'BufReadPost *'
end
if not (config.autostart == false) then
if config.autostart == true then
local event
local pattern
if config.filetypes then
event = 'FileType'
pattern = table.concat(config.filetypes, ',')
else
event = 'BufReadPost'
pattern = '*'
end
api.nvim_command(
string.format("autocmd %s unsilent lua require'lspconfig'[%q].manager.try_add()", trigger, config.name)
string.format(
"autocmd %s %s unsilent lua require'lspconfig'[%q].manager.try_add()",
event,
pattern,
config.name
)
)
end
local get_root_dir = config.root_dir
function M.autostart()
local root_dir = get_root_dir(api.nvim_buf_get_name(0), api.nvim_get_current_buf())
if not root_dir then
vim.notify(string.format('Autostart for %s failed: matching root directory not detected.', config_name))
return
end
api.nvim_command(
string.format(
"autocmd %s unsilent lua require'lspconfig'[%q].manager.try_add_wrapper()",
'BufReadPost ' .. root_dir .. '/*',
config.name
)
)
for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do
local buf_dir = api.nvim_buf_get_name(bufnr)
if buf_dir:sub(1, root_dir:len()) == root_dir then
M.manager.try_add_wrapper(bufnr)
function M.launch()
local root_dir
if get_root_dir then
local bufnr = api.nvim_get_current_buf()
local bufname = api.nvim_buf_get_name(bufnr)
if not util.bufname_valid(bufname) then
return
end
root_dir = get_root_dir(util.path.sanitize(bufname), bufnr)
end
if root_dir then
api.nvim_command(
string.format(
"autocmd BufReadPost %s/* unsilent lua require'lspconfig'[%q].manager.try_add_wrapper()",
vim.fn.fnameescape(root_dir),
config.name
)
)
for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do
local bufname = api.nvim_buf_get_name(bufnr)
if util.bufname_valid(bufname) then
local buf_dir = util.path.sanitize(bufname)
if buf_dir:sub(1, root_dir:len()) == root_dir then
M.manager.try_add_wrapper(bufnr)
end
end
end
elseif config.single_file_support then
-- This allows on_new_config to use the parent directory of the file
-- Effectively this is the root from lspconfig's perspective, as we use
-- this to attach additional files in the same parent folder to the same server.
-- We just no longer send rootDirectory or workspaceFolders during initialization.
local bufname = api.nvim_buf_get_name(0)
if not util.bufname_valid(bufname) then
return
end
local pseudo_root = util.path.dirname(util.path.sanitize(bufname))
local client_id = M.manager.add(pseudo_root, true)
vim.lsp.buf_attach_client(vim.api.nvim_get_current_buf(), client_id)
end
end
@ -94,7 +124,7 @@ function configs.__newindex(t, config_name, config_def)
M.filetypes = config.filetypes
M.handlers = config.handlers
M.cmd = config.cmd
M._autostart = config.autostart
M.autostart = config.autostart
-- In the case of a reload, close existing things.
local reload = false
@ -123,7 +153,13 @@ function configs.__newindex(t, config_name, config_def)
pcall(config.on_new_config, new_config, _root_dir)
end
new_config.on_init = util.add_hook_after(new_config.on_init, function(client, _result)
new_config.on_init = util.add_hook_after(new_config.on_init, function(client, result)
-- Handle offset encoding by default
if result.offsetEncoding then
client.offset_encoding = result.offsetEncoding
end
-- Send `settings to server via workspace/didChangeConfiguration
function client.workspace_did_change_configuration(settings)
if not settings then
return
@ -159,6 +195,12 @@ function configs.__newindex(t, config_name, config_def)
end)
new_config.root_dir = _root_dir
new_config.workspace_folders = {
{
uri = vim.uri_from_fname(_root_dir),
name = string.format('%s', _root_dir),
},
}
return new_config
end
@ -168,23 +210,48 @@ function configs.__newindex(t, config_name, config_def)
function manager.try_add(bufnr)
bufnr = bufnr or api.nvim_get_current_buf()
if vim.api.nvim_buf_get_option(bufnr, 'buftype') == 'nofile' then
return
end
local root_dir = get_root_dir(api.nvim_buf_get_name(bufnr), bufnr)
local id = manager.add(root_dir)
local id
local root_dir
local bufname = api.nvim_buf_get_name(bufnr)
if not util.bufname_valid(bufname) then
return
end
local buf_path = util.path.sanitize(bufname)
if get_root_dir then
root_dir = get_root_dir(buf_path, bufnr)
end
if root_dir then
id = manager.add(root_dir, false)
elseif config.single_file_support then
local pseudo_root = util.path.dirname(buf_path)
id = manager.add(pseudo_root, true)
end
if id then
lsp.buf_attach_client(bufnr, id)
end
end
function manager.try_add_wrapper(bufnr)
bufnr = bufnr or api.nvim_get_current_buf()
local buf_filetype = vim.api.nvim_buf_get_option(bufnr, 'filetype')
for _, filetype in ipairs(config.filetypes) do
if buf_filetype == filetype then
manager.try_add(bufnr)
return
if config.filetypes then
for _, filetype in ipairs(config.filetypes) do
if buf_filetype == filetype then
manager.try_add(bufnr)
return
end
end
else
manager.try_add(bufnr)
end
end

View File

@ -1,29 +0,0 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
configs.cucumber_language_server = {
default_config = {
cmd = { 'cucumber-language-server', '--stdio' },
filetypes = { 'cucumber' },
root_dir = util.root_pattern '.git',
},
docs = {
package_json = 'https://raw.githubusercontent.com/cucumber/common/main/language-server/javascript/package.json',
description = [[
https://cucumber.io
https://github.com/cucumber/common
https://www.npmjs.com/package/@cucumber/language-server
Language server for Cucumber.
`cucumber-language-server` can be installed via `npm`:
```sh
npm install -g @cucumber/language-server
```
]],
default_config = {
root_dir = [[root_pattern(".git")]],
},
},
}
-- vim:et ts=2 sw=2

View File

@ -1,158 +0,0 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local lsp = vim.lsp
local server_name = 'denols'
local function deno_uri_to_uri(uri)
-- denols returns deno:/https/deno.land/std%400.85.0/http/server.ts
-- nvim-lsp only handles deno://
if string.sub(uri, 1, 6) == 'deno:/' and string.sub(uri, 7, 7) ~= '/' then
return string.gsub(uri, '^deno:/', 'deno://', 1)
end
return uri
end
local function uri_to_deno_uri(uri)
-- denols use deno:/ and nvim-lsp use deno:// as buffer_uri.
-- When buffer_uri is deno://, change uri to deno:/.
if string.sub(uri, 1, 7) == 'deno://' and string.sub(uri, 8, 8) ~= '/' then
return string.gsub(uri, '^deno://', 'deno:/', 1)
end
return uri
end
local function buf_cache(bufnr)
local params = {}
params['referrer'] = { uri = vim.uri_from_bufnr(bufnr) }
params['uris'] = {}
lsp.buf_request(bufnr, 'deno/cache', params, function(err)
if err then
error(tostring(err))
end
end)
end
local function virtual_text_document_handler(uri, result)
if not result then
return nil
end
for client_id, res in pairs(result) do
local lines = vim.split(res.result, '\n')
local bufnr = vim.uri_to_bufnr(deno_uri_to_uri(uri))
local current_buf = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
if #current_buf ~= 0 then
return nil
end
vim.api.nvim_buf_set_lines(bufnr, 0, -1, nil, lines)
vim.api.nvim_buf_set_option(bufnr, 'readonly', true)
vim.api.nvim_buf_set_option(bufnr, 'modified', false)
vim.api.nvim_buf_set_option(bufnr, 'modifiable', false)
lsp.buf_attach_client(bufnr, client_id)
end
end
local function virtual_text_document(uri)
local params = {
textDocument = {
uri = uri,
},
}
local result = lsp.buf_request_sync(0, 'deno/virtualTextDocument', params)
virtual_text_document_handler(uri, result)
end
local function denols_handler(err, method, result)
if not result or vim.tbl_isempty(result) then
return nil
end
for _, res in pairs(result) do
local uri = res.uri or res.targetUri
if string.sub(uri, 1, 6) == 'deno:/' then
virtual_text_document(uri)
res['uri'] = deno_uri_to_uri(uri)
res['targetUri'] = deno_uri_to_uri(uri)
end
end
lsp.handlers[method](err, method, result)
end
local function denols_definition()
local params = lsp.util.make_position_params()
params.textDocument.uri = uri_to_deno_uri(params.textDocument.uri)
lsp.buf_request(0, 'textDocument/definition', params)
end
local function denols_references(context)
vim.validate { context = { context, 't', true } }
local params = lsp.util.make_position_params()
params.context = context or {
includeDeclaration = true,
}
params[vim.type_idx] = vim.types.dictionary
params.textDocument.uri = uri_to_deno_uri(params.textDocument.uri)
lsp.buf_request(0, 'textDocument/references', params)
end
configs[server_name] = {
default_config = {
cmd = { 'deno', 'lsp' },
filetypes = {
'javascript',
'javascriptreact',
'javascript.jsx',
'typescript',
'typescriptreact',
'typescript.tsx',
},
root_dir = util.root_pattern('package.json', 'tsconfig.json', '.git'),
init_options = {
enable = true,
lint = false,
unstable = false,
},
handlers = {
['textDocument/definition'] = denols_handler,
['textDocument/references'] = denols_handler,
},
},
commands = {
DenolsDefinition = {
denols_definition,
description = 'Jump to definition. This handle deno:/ schema in deno:// buffer.',
},
DenolsReferences = {
function()
denols_references { includeDeclaration = true }
end,
description = 'List references. This handle deno:/ schema in deno:// buffer.',
},
DenolsCache = {
function()
buf_cache(0)
end,
description = 'Cache a module and all of its dependencies.',
},
},
docs = {
description = [[
https://github.com/denoland/deno
Deno's built-in language server
]],
default_config = {
root_dir = [[root_pattern("package.json", "tsconfig.json", ".git")]],
},
},
}
configs.denols.definition = denols_definition
configs.denols.references = denols_references
configs.denols.buf_cache = buf_cache
configs.denols.virtual_text_document = virtual_text_document
-- vim:et ts=2 sw=2

View File

@ -1,29 +0,0 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local server_name = 'dotls'
local bin_name = 'dot-language-server'
local root_files = {
'.git',
}
configs[server_name] = {
default_config = {
cmd = { bin_name, '--stdio' },
filetypes = { 'dot' },
root_dir = function(fname)
return util.root_pattern(unpack(root_files))(fname) or util.path.dirname(fname)
end,
},
docs = {
description = [[
https://github.com/nikeee/dot-language-server
`dot-language-server` can be installed via `npm`:
```sh
npm install -g dot-language-server
```
]],
},
}

View File

@ -1,28 +0,0 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local server_name = 'graphql'
local bin_name = 'graphql-lsp'
configs[server_name] = {
default_config = {
cmd = { bin_name, 'server', '-m', 'stream' },
filetypes = { 'graphql' },
root_dir = util.root_pattern('.git', '.graphqlrc*', '.graphql.config.*'),
},
docs = {
description = [[
https://github.com/graphql/graphiql/tree/main/packages/graphql-language-service-cli
`graphql-lsp` can be installed via `npm`:
```sh
npm install -g graphql-language-service-cli
```
]],
default_config = {
root_dir = [[root_pattern('.git', '.graphqlrc*', '.graphql.config.*')]],
},
},
}

View File

@ -1,25 +0,0 @@
local M = {}
function M.check_health()
local configs = require 'lspconfig/configs'
for _, top_level_config in pairs(configs) do
-- Only check configs that have a make_config function.
if not (top_level_config.make_config == nil) then
-- the folder needs to exist
local config = top_level_config.make_config '.'
local status, cmd = pcall(vim.lsp._cmd_parts, config.cmd)
if not status then
vim.fn['health#report_error'](string.format('%s: config.cmd error, %s', config.name, cmd))
else
if not (vim.fn.executable(cmd) == 1) then
vim.fn['health#report_error'](string.format('%s: The given command %q is not executable.', config.name, cmd))
else
vim.fn['health#report_info'](string.format('%s: configuration checked.', config.name))
end
end
end
end
end
return M

View File

@ -1,22 +0,0 @@
local lspconfig = require 'lspconfig'
local configs = require 'lspconfig/configs'
local name = 'java_language_server'
configs[name] = {
default_config = {
filetypes = { 'java' },
root_dir = lspconfig.util.root_pattern('build.gradle', 'pom.xml', '.git'),
settings = {},
},
docs = {
package_json = 'https://raw.githubusercontent.com/georgewfraser/java-language-server/master/package.json',
description = [[
https://github.com/georgewfraser/java-language-server
Java language server
Point `cmd` to `lang_server_linux.sh` or the equivalent script for macOS/Windows provided by java-language-server
]],
},
}

View File

@ -1,47 +0,0 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
configs.leanls = {
default_config = {
cmd = { 'lean', '--server' },
filetypes = { 'lean' },
root_dir = function(fname)
-- check if inside elan stdlib
local stdlib_dir
do
local _, endpos = fname:find(util.path.sep .. util.path.join('lib', 'lean'))
if endpos then
stdlib_dir = fname:sub(1, endpos)
end
end
return util.root_pattern 'leanpkg.toml'(fname)
or stdlib_dir
or util.find_git_ancestor(fname)
or util.path.dirname(fname)
end,
on_new_config = function(config, root)
if not config.cmd_cwd then
config.cmd_cwd = root
end
end,
},
docs = {
description = [[
https://github.com/leanprover/lean4
Lean installation instructions can be found
[here](https://leanprover-community.github.io/get_started.html#regular-install).
The Lean 4 language server is built-in with a Lean 4 install
(and can be manually run with, e.g., `lean --server`).
Note: that if you're using [lean.nvim](https://github.com/Julian/lean.nvim),
that plugin fully handles the setup of the Lean language server,
and you shouldn't set up `leanls` both with it and `lspconfig`.
]],
default_config = {
root_dir = [[root_pattern("leanpkg.toml") or root_pattern(".git") or path.dirname]],
},
},
}

View File

@ -1,32 +0,0 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local server_name = 'lemminx'
configs[server_name] = {
default_config = {
filetypes = { 'xml', 'xsd', 'svg' },
root_dir = function(filename)
return util.root_pattern '.git'(filename) or util.path.dirname(filename)
end,
},
docs = {
description = [[
https://github.com/eclipse/lemminx
The easiest way to install the server is to get a binary at https://download.jboss.org/jbosstools/vscode/stable/lemminx-binary/ and place it in your PATH.
**By default, lemminx doesn't have a `cmd` set.** This is because nvim-lspconfig does not make assumptions about your path. You must add the following to your init.vim or init.lua to set `cmd` to the absolute path ($HOME and ~ are not expanded) of your unzipped lemminx.
```lua
require'lspconfig'.lemminx.setup{
cmd = { "/path/to/lemminx/lemminx" };
...
}
NOTE to macOS users: Binaries from unidentified developers are blocked by default. If you trust the downloaded binary from jboss.org, run it once, cancel the prompt, then remove the binary from Gatekeeper quarantine with `xattr -d com.apple.quarantine lemminx`. It should now run without being blocked.
]],
},
}
-- vim:et ts=2 sw=2

View File

@ -1,41 +0,0 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
configs.pasls = {
default_config = {
cmd = { 'pasls' },
filetypes = { 'pascal' },
root_dir = function(fname)
return util.find_git_ancestor(fname) or util.path.dirname(fname)
end,
},
docs = {
description = [[
https://github.com/genericptr/pascal-language-server
An LSP server implementation for Pascal variants that are supported by Free Pascal, including Object Pascal. It uses CodeTools from Lazarus as backend.
First set `cmd` to the Pascal lsp binary.
Customization options are passed to pasls as environment variables for example in your `.bashrc`:
```bash
export FPCDIR='/usr/lib/fpc/src',
export PP='/usr/lib/fpc/3.2.2/ppcx64',
export LAZARUSDIR='/usr/lib/lazarus',
export FPCTARGET='',
export FPCTARGETCPU='x86_64',
```
`FPCDIR` : FPC source directory (This is the only required option for the server to work).
`PP` : Path to the Free Pascal compiler executable.
`LAZARUSDIR` : Path to the Lazarus sources.
`FPCTARGET` : Target operating system for cross compiling.
`FPCTARGETCPU` : Target CPU for cross compiling.
]],
},
}

View File

@ -1,30 +0,0 @@
local util = require 'lspconfig/util'
local configs = require 'lspconfig/configs'
configs.r_language_server = {
default_config = {
cmd = { 'R', '--slave', '-e', 'languageserver::run()' },
filetypes = { 'r', 'rmd' },
root_dir = function(fname)
return util.find_git_ancestor(fname) or vim.loop.os_homedir()
end,
log_level = vim.lsp.protocol.MessageType.Warning,
},
docs = {
package_json = 'https://raw.githubusercontent.com/REditorSupport/vscode-r-lsp/master/package.json',
description = [[
[languageserver](https://github.com/REditorSupport/languageserver) is an
implementation of the Microsoft's Language Server Protocol for the R
language.
It is released on CRAN and can be easily installed by
```R
install.packages("languageserver")
```
]],
default_config = {
root_dir = [[root_pattern(".git") or os_homedir]],
},
},
}

View File

@ -1,21 +1,17 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local server_name = 'als'
local util = require 'lspconfig.util'
local bin_name = 'ada_language_server'
if vim.fn.has 'win32' == 1 then
bin_name = 'ada_language_server.exe'
end
configs[server_name] = {
return {
default_config = {
cmd = { bin_name },
filetypes = { 'ada' },
-- *.gpr and *.adc would be nice to have here
root_dir = util.root_pattern('Makefile', '.git'),
root_dir = util.root_pattern('Makefile', '.git', '*.gpr', '*.adc'),
},
docs = {
package_json = 'https://raw.githubusercontent.com/AdaCore/ada_language_server/master/integration/vscode/ada/package.json',
description = [[
https://github.com/AdaCore/ada_language_server
@ -35,7 +31,7 @@ require('lspconfig').als.setup{
```
]],
default_config = {
root_dir = [[util.root_pattern("Makefile", ".git")]],
root_dir = [[util.root_pattern("Makefile", ".git", "*.gpr", "*.adc")]],
},
},
}

View File

@ -1,7 +1,4 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local server_name = 'angularls'
local util = require 'lspconfig.util'
-- Angular requires a node_modules directory to probe for @angular/language-service and typescript
-- in order to use your projects configured versions.
@ -14,16 +11,24 @@ end
local default_probe_dir = get_probe_dir(vim.fn.getcwd())
configs[server_name] = {
local bin_name = 'ngserver'
local args = {
'--stdio',
'--tsProbeLocations',
default_probe_dir,
'--ngProbeLocations',
default_probe_dir,
}
local cmd = { bin_name, unpack(args) }
if vim.fn.has 'win32' == 1 then
cmd = { 'cmd.exe', '/C', bin_name, unpack(args) }
end
return {
default_config = {
cmd = {
'ngserver',
'--stdio',
'--tsProbeLocations',
default_probe_dir,
'--ngProbeLocations',
default_probe_dir,
},
cmd = cmd,
filetypes = { 'typescript', 'html', 'typescriptreact', 'typescript.tsx' },
-- Check for angular.json or .git first since that is the root of the project.
-- Don't check for tsconfig.json or package.json since there are multiple of these

View File

@ -0,0 +1,47 @@
local util = require 'lspconfig.util'
local bin_name = 'ansible-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,
settings = {
ansible = {
python = {
interpreterPath = 'python',
},
ansibleLint = {
path = 'ansible-lint',
enabled = true,
},
ansible = {
path = 'ansible',
},
executionEnvironment = {
enabled = false,
},
},
},
filetypes = { 'yaml.ansible' },
root_dir = util.root_pattern('ansible.cfg', '.ansible-lint'),
single_file_support = true,
},
docs = {
description = [[
https://github.com/ansible/ansible-language-server
Language server for the ansible configuration management tool.
`ansible-language-server` can be installed via `npm`:
```sh
npm install -g @ansible/ansible-language-server
```
]],
},
}

View File

@ -1,15 +1,13 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
configs.arduino_language_server = {
return {
default_config = {
cmd = { 'arduino-language-server' },
filetypes = { 'arduino' },
root_dir = function(fname)
return util.root_pattern '*.ino'(fname)
end,
docs = {
description = [[
root_dir = util.root_pattern '*.ino',
},
docs = {
description = [[
https://github.com/arduino/arduino-language-server
Language server for Arduino
@ -48,8 +46,5 @@ lspconfig.arduino_language_server.setup({
For further instruction about configuration options, run `arduino-language-server --help`.
]],
},
},
}
-- vim:et ts=2 sw=2

View File

@ -0,0 +1,19 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'asm-lsp' },
filetypes = { 'asm', 'vmasm' },
root_dir = util.find_git_ancestor,
},
docs = {
description = [[
https://github.com/bergercookie/asm-lsp
Language Server for GAS/GO Assembly
`asm-lsp` can be installed via cargo:
cargo install asm-lsp
]],
},
}

View File

@ -0,0 +1,22 @@
if vim.version().major == 0 and vim.version().minor < 7 then
vim.notify('The AWK language server requires nvim >= 0.7', vim.log.levels.ERROR)
return
end
return {
default_config = {
cmd = { 'awk-language-server' },
filetypes = { 'awk' },
single_file_support = true,
},
docs = {
description = [[
https://github.com/Beaglefoot/awk-language-server/
`awk-language-server` can be installed via `npm`:
```sh
npm install -g awk-language-server
```
]],
},
}

View File

@ -1,11 +1,15 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
local server_name = 'bashls'
local bin_name = 'bash-language-server'
local cmd = { bin_name, 'start' }
configs[server_name] = {
if vim.fn.has 'win32' == 1 then
cmd = { 'cmd.exe', '/C', bin_name, 'start' }
end
return {
default_config = {
cmd = { 'bash-language-server', 'start' },
cmd = cmd,
cmd_env = {
-- Prevent recursive scanning which will cause issues when opening a file
-- directly in the home directory (e.g. ~/foo.sh).
@ -14,18 +18,22 @@ configs[server_name] = {
GLOB_PATTERN = vim.env.GLOB_PATTERN or '*@(.sh|.inc|.bash|.command)',
},
filetypes = { 'sh' },
root_dir = function(fname)
return util.root_pattern '.git'(fname) or util.path.dirname(fname)
end,
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 = "vim's starting directory",
root_dir = [[util.find_git_ancestor]],
},
},
}

View File

@ -1,16 +1,11 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
local server_name = 'beancount'
local bin_name = 'beancount-langserver'
configs[server_name] = {
return {
default_config = {
cmd = { bin_name },
cmd = { 'beancount-langserver', '--stdio' },
filetypes = { 'beancount' },
root_dir = function(fname)
return util.find_git_ancestor(fname) or util.path.dirname(fname)
end,
root_dir = util.find_git_ancestor,
single_file_support = true,
init_options = {
-- this is the path to the beancout journal file
journalFile = '',

View File

@ -1,15 +1,13 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local server_name = 'bicep'
local util = require 'lspconfig.util'
configs[server_name] = {
return {
default_config = {
filetypes = { 'bicep' },
root_dir = util.root_pattern '.git',
root_dir = util.find_git_ancestor,
init_options = {},
},
docs = {
description = [[
description = [=[
https://github.com/azure/bicep
Bicep language server
@ -17,7 +15,14 @@ Bicep language server can be installed by downloading and extracting a release o
Bicep language server requires the [dotnet-sdk](https://dotnet.microsoft.com/download) to be installed.
**By default, bicep language server doesn't have a `cmd` set.** This is because nvim-lspconfig does not make assumptions about your path. You must add the following to your init.vim or init.lua to set `cmd` to the absolute path ($HOME and ~ are not expanded) of the unzipped run script or binary.
Neovim does not have built-in support for the bicep filetype which is required for lspconfig to automatically launch the language server.
Filetype detection can be added via an autocmd:
```lua
vim.cmd [[ autocmd BufNewFile,BufRead *.bicep set filetype=bicep ]]
```
**By default, bicep language server does not have a `cmd` set.** This is because nvim-lspconfig does not make assumptions about your path. You must add the following to your init.vim or init.lua to set `cmd` to the absolute path ($HOME and ~ are not expanded) of the unzipped run script or binary.
```lua
local bicep_lsp_bin = "/path/to/bicep-langserver/Bicep.LangServer.dll"
@ -34,6 +39,9 @@ To download the latest release and place in /usr/local/bin/bicep-langserver:
&& rm -rf /usr/local/bin/bicep-langserver \
&& unzip -d /usr/local/bin/bicep-langserver bicep-langserver.zip)
```
]],
]=],
default_config = {
root_dir = [[util.find_git_ancestor]],
},
},
}

View File

@ -0,0 +1,19 @@
local util = require 'lspconfig.util'
return {
default_config = {
filetypes = { 'bsl', 'os' },
root_dir = util.find_git_ancestor,
},
docs = {
description = [[
https://github.com/1c-syntax/bsl-language-server
Language Server Protocol implementation for 1C (BSL) - 1C:Enterprise 8 and OneScript languages.
]],
default_config = {
root_dir = [[root_pattern(".git")]],
},
},
}

View File

@ -1,22 +1,21 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
configs.ccls = {
return {
default_config = {
cmd = { 'ccls' },
filetypes = { 'c', 'cpp', 'objc', 'objcpp' },
root_dir = function(fname)
return util.root_pattern('compile_commands.json', '.ccls', 'compile_flags.txt', '.git')(fname)
or util.path.dirname(fname)
end,
root_dir = util.root_pattern('compile_commands.json', '.ccls', '.git'),
offset_encoding = 'utf-32',
-- ccls does not support sending a null root directory
single_file_support = false,
},
docs = {
description = [[
https://github.com/MaskRay/ccls/wiki
ccls relies on a [JSON compilation database](https://clang.llvm.org/docs/JSONCompilationDatabase.html) specified
as compile_commands.json or, for simpler projects, a compile_flags.txt.
For details on how to automatically generate one using CMake look [here](https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html).
as compile_commands.json or, for simpler projects, a .ccls.
For details on how to automatically generate one using CMake look [here](https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html). Alternatively, you can use [Bear](https://github.com/rizsotto/Bear).
Customization options are passed to ccls at initialization time via init_options, a list of available options can be found [here](https://github.com/MaskRay/ccls/wiki/Customization#initialization-options). For example:
@ -38,7 +37,7 @@ lspconfig.ccls.setup {
]],
default_config = {
root_dir = [[root_pattern("compile_commands.json", ".ccls", "compile_flags.txt", ".git") or dirname]],
root_dir = [[root_pattern("compile_commands.json", ".ccls", ".git")]],
},
},
}

View File

@ -1,15 +1,12 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
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) }
vim.lsp.buf_request(
bufnr,
'textDocument/switchSourceHeader',
params,
util.compat_handler(function(err, result)
if clangd_client then
clangd_client.request('textDocument/switchSourceHeader', params, function(err, result)
if err then
error(tostring(err))
end
@ -18,8 +15,10 @@ local function switch_source_header(bufnr)
return
end
vim.api.nvim_command('edit ' .. vim.uri_to_fname(result))
end)
)
end, bufnr)
else
print 'method textDocument/switchSourceHeader is not supported by any servers active on the current buffer'
end
end
local root_pattern = util.root_pattern('compile_commands.json', 'compile_flags.txt', '.git')
@ -37,19 +36,15 @@ local default_capabilities = vim.tbl_deep_extend(
}
)
configs.clangd = {
return {
default_config = {
cmd = { 'clangd', '--background-index' },
cmd = { 'clangd' },
filetypes = { 'c', 'cpp', 'objc', 'objcpp' },
root_dir = function(fname)
local filename = util.path.is_absolute(fname) and fname or util.path.join(vim.loop.cwd(), fname)
return root_pattern(filename) or util.path.dirname(filename)
end,
on_init = function(client, result)
if result.offsetEncoding then
client.offset_encoding = result.offsetEncoding
end
return root_pattern(filename)
end,
single_file_support = true,
capabilities = default_capabilities,
},
commands = {
@ -68,14 +63,11 @@ https://clangd.llvm.org/installation.html
clangd relies on a [JSON compilation database](https://clang.llvm.org/docs/JSONCompilationDatabase.html) specified
as compile_commands.json or, for simpler projects, a compile_flags.txt.
For details on how to automatically generate one using CMake look [here](https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html).
For details on how to automatically generate one using CMake look [here](https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html). Alternatively, you can use [Bear](https://github.com/rizsotto/Bear).
]],
default_config = {
root_dir = [[root_pattern("compile_commands.json", "compile_flags.txt", ".git") or dirname]],
on_init = [[function to handle changing offsetEncoding]],
capabilities = [[default capabilities, with offsetEncoding utf-8]],
},
},
}
configs.clangd.switch_source_header = switch_source_header

View File

@ -0,0 +1,24 @@
local util = require 'lspconfig.util'
local bin_name = 'clarity-lsp'
if vim.fn.has 'win32' == 1 then
bin_name = bin_name .. '.cmd'
end
return {
default_config = {
cmd = { bin_name },
filetypes = { 'clar', 'clarity' },
root_dir = util.root_pattern '.git',
},
docs = {
description = [[
`clarity-lsp` is a language server for the Clarity language. Clarity is a decidable smart contract language that optimizes for predictability and security. Smart contracts allow developers to encode essential business logic on a blockchain.
To learn how to configure the clarity language server, see the [clarity-lsp documentation](https://github.com/hirosystems/clarity-lsp).
]],
default_config = {
root_dir = [[root_pattern(".git")]],
},
},
}

View File

@ -0,0 +1,19 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'clojure-lsp' },
filetypes = { 'clojure', 'edn' },
root_dir = util.root_pattern('project.clj', 'deps.edn', 'build.boot', 'shadow-cljs.edn', '.git'),
},
docs = {
description = [[
https://github.com/snoe/clojure-lsp
Clojure Language Server
]],
default_config = {
root_dir = [[root_pattern("project.clj", "deps.edn", "build.boot", "shadow-cljs.edn", ".git")]],
},
},
}

View File

@ -1,13 +1,11 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
configs.cmake = {
return {
default_config = {
cmd = { 'cmake-language-server' },
filetypes = { 'cmake' },
root_dir = function(fname)
return util.root_pattern('.git', 'compile_commands.json', 'build')(fname) or util.path.dirname(fname)
end,
root_dir = util.root_pattern('.git', 'compile_commands.json', 'build'),
single_file_support = true,
init_options = {
buildDirectory = 'build',
},

View File

@ -1,17 +1,10 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
local server_name = 'codeqlls'
local root_pattern = util.root_pattern 'qlpack.yml'
configs[server_name] = {
return {
default_config = {
cmd = { 'codeql', 'execute', 'language-server', '--check-errors', 'ON_CHANGE', '-q' },
filetypes = { 'ql' },
root_dir = function(fname)
return root_pattern(fname) or util.path.dirname(fname)
end,
root_dir = util.root_pattern 'qlpack.yml',
log_level = vim.lsp.protocol.MessageType.Warning,
before_init = function(initialize_params)
initialize_params['workspaceFolders'] = {

View File

@ -1,13 +1,11 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
configs.crystalline = {
return {
default_config = {
cmd = { 'crystalline' },
filetypes = { 'crystal' },
root_dir = function(fname)
return util.root_pattern 'shard.yml'(fname) or util.find_git_ancestor(fname) or util.path.dirname(fname)
end,
root_dir = util.root_pattern 'shard.yml' or util.find_git_ancestor,
single_file_support = true,
},
docs = {
description = [[

View File

@ -1,9 +1,6 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
local server_name = 'csharp_ls'
configs[server_name] = {
return {
default_config = {
cmd = { 'csharp-ls' },
root_dir = util.root_pattern('*.sln', '*.csproj', '.git'),

View File

@ -1,16 +1,18 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
local server_name = 'cssls'
local bin_name = 'vscode-css-language-server'
local cmd = { bin_name, '--stdio' }
configs[server_name] = {
if vim.fn.has 'win32' == 1 then
cmd = { 'cmd.exe', '/C', bin_name, '--stdio' }
end
return {
default_config = {
cmd = { bin_name, '--stdio' },
cmd = cmd,
filetypes = { 'css', 'scss', 'less' },
root_dir = function(fname)
return util.root_pattern('package.json', '.git')(fname) or util.path.dirname(fname)
end,
root_dir = util.root_pattern('package.json', '.git'),
single_file_support = true,
settings = {
css = { validate = true },
scss = { validate = true },

View File

@ -0,0 +1,31 @@
local util = require 'lspconfig.util'
local bin_name = 'cssmodules-language-server'
local cmd = { bin_name }
if vim.fn.has 'win32' == 1 then
cmd = { 'cmd.exe', '/C', bin_name }
end
return {
default_config = {
cmd = cmd,
filetypes = { 'javascript', 'javascriptreact', 'typescript', 'typescriptreact' },
root_dir = util.find_package_json_ancestor,
},
docs = {
description = [[
https://github.com/antonk52/cssmodules-language-server
Language server for autocompletion and go-to-definition functionality for CSS modules.
You can install cssmodules-language-server via npm:
```sh
npm install -g cssmodules-language-server
```
]],
default_config = {
root_dir = [[root_pattern("package.json")]],
},
},
}

View File

@ -0,0 +1,33 @@
local util = require 'lspconfig.util'
local bin_name = 'cucumber-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 = { 'cucumber' },
root_dir = util.find_git_ancestor,
},
docs = {
description = [[
https://cucumber.io
https://github.com/cucumber/common
https://www.npmjs.com/package/@cucumber/language-server
Language server for Cucumber.
`cucumber-language-server` can be installed via `npm`:
```sh
npm install -g @cucumber/language-server
```
]],
default_config = {
root_dir = [[util.find_git_ancestor]],
},
},
}

View File

@ -1,7 +1,5 @@
local util = require 'lspconfig/util'
local configs = require 'lspconfig/configs'
local util = require 'lspconfig.util'
local server_name = 'dartls'
local bin_name = 'dart'
local find_dart_sdk_root_path = function()
@ -30,21 +28,26 @@ local analysis_server_snapshot_path = function()
return snapshot
end
configs[server_name] = {
return {
default_config = {
cmd = { bin_name, analysis_server_snapshot_path(), '--lsp' },
filetypes = { 'dart' },
root_dir = util.root_pattern 'pubspec.yaml',
init_options = {
onlyAnalyzeProjectsWithOpenFiles = false,
onlyAnalyzeProjectsWithOpenFiles = true,
suggestFromUnimportedLibraries = true,
closingLabels = false,
outline = false,
flutterOutline = false,
closingLabels = true,
outline = true,
flutterOutline = true,
},
settings = {
dart = {
completeFunctionCalls = true,
showTodos = true,
},
},
},
docs = {
package_json = 'https://raw.githubusercontent.com/Dart-Code/Dart-Code/master/package.json',
description = [[
https://github.com/dart-lang/sdk/tree/master/pkg/analysis_server/tool/lsp_spec
@ -55,4 +58,3 @@ Language server for dart.
},
},
}
-- vim:et ts=2 sw=2

View File

@ -0,0 +1,114 @@
local util = require 'lspconfig.util'
local lsp = vim.lsp
local function buf_cache(bufnr)
local params = {}
params['referrer'] = { uri = vim.uri_from_bufnr(bufnr) }
params['uris'] = {}
lsp.buf_request(bufnr, 'deno/cache', params, function(err)
if err then
error(tostring(err))
end
end)
end
local function virtual_text_document_handler(uri, result)
if not result then
return nil
end
for client_id, res in pairs(result) do
local lines = vim.split(res.result, '\n')
local bufnr = vim.uri_to_bufnr(uri)
local current_buf = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
if #current_buf ~= 0 then
return nil
end
vim.api.nvim_buf_set_lines(bufnr, 0, -1, nil, lines)
vim.api.nvim_buf_set_option(bufnr, 'readonly', true)
vim.api.nvim_buf_set_option(bufnr, 'modified', false)
vim.api.nvim_buf_set_option(bufnr, 'modifiable', false)
lsp.buf_attach_client(bufnr, client_id)
end
end
local function virtual_text_document(uri)
local params = {
textDocument = {
uri = uri,
},
}
local result = lsp.buf_request_sync(0, 'deno/virtualTextDocument', params)
virtual_text_document_handler(uri, result)
end
local function denols_handler(err, result, ctx)
if not result or vim.tbl_isempty(result) then
return nil
end
for _, res in pairs(result) do
local uri = res.uri or res.targetUri
if uri:match '^deno:' then
virtual_text_document(uri)
res['uri'] = uri
res['targetUri'] = uri
end
end
lsp.handlers[ctx.method](err, result, ctx)
end
return {
default_config = {
cmd = { 'deno', 'lsp' },
filetypes = {
'javascript',
'javascriptreact',
'javascript.jsx',
'typescript',
'typescriptreact',
'typescript.tsx',
},
root_dir = util.root_pattern('deno.json', 'deno.jsonc', 'tsconfig.json', '.git'),
init_options = {
enable = true,
lint = false,
unstable = false,
},
handlers = {
['textDocument/definition'] = denols_handler,
['textDocument/references'] = denols_handler,
},
},
commands = {
DenolsCache = {
function()
buf_cache(0)
end,
description = 'Cache a module and all of its dependencies.',
},
},
docs = {
description = [[
https://github.com/denoland/deno
Deno's built-in language server
To approrpiately highlight codefences returned from denols, you will need to augment vim.g.markdown_fenced languages
in your init.lua. Example:
```lua
vim.g.markdown_fenced_languages = {
"ts=typescript"
}
```
]],
default_config = {
root_dir = [[root_pattern("deno.json", "deno.jsonc", "tsconfig.json", ".git")]],
},
},
}

View File

@ -1,15 +1,14 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
configs.dhall_lsp_server = {
return {
default_config = {
cmd = { 'dhall-lsp-server' },
filetypes = { 'dhall' },
root_dir = function(fname)
return util.root_pattern '.git'(fname) or util.path.dirname(fname)
end,
docs = {
description = [[
root_dir = util.find_git_ancestor,
single_file_support = true,
},
docs = {
description = [[
https://github.com/dhall-lang/dhall-haskell/tree/master/dhall-lsp-server
language server for dhall
@ -20,9 +19,8 @@ cabal install dhall-lsp-server
```
prebuilt binaries can be found [here](https://github.com/dhall-lang/dhall-haskell/releases).
]],
default_config = {
root_dir = [[root_pattern(".git") or dirname]],
},
default_config = {
root_dir = [[root_pattern(".git") or dirname]],
},
},
}

View File

@ -1,17 +1,18 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
local server_name = 'diagnosticls'
local bin_name = 'diagnostic-languageserver'
local cmd = { bin_name, '--stdio' }
if vim.fn.has 'win32' == 1 then
bin_name = bin_name .. '.cmd'
cmd = { 'cmd.exe', '/C', bin_name, '--stdio' }
end
configs[server_name] = {
return {
default_config = {
cmd = { bin_name, '--stdio' },
cmd = cmd,
root_dir = util.find_git_ancestor,
single_file_support = true,
filetypes = {},
root_dir = util.path.dirname,
},
docs = {
description = [[

View File

@ -1,14 +1,18 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
local server_name = 'dockerls'
local bin_name = 'docker-langserver'
local cmd = { bin_name, '--stdio' }
configs[server_name] = {
if vim.fn.has 'win32' == 1 then
cmd = { 'cmd.exe', '/C', bin_name, '--stdio' }
end
return {
default_config = {
cmd = { bin_name, '--stdio' },
filetypes = { 'Dockerfile', 'dockerfile' },
cmd = cmd,
filetypes = { 'dockerfile' },
root_dir = util.root_pattern 'Dockerfile',
single_file_support = true,
},
docs = {
description = [[
@ -24,5 +28,3 @@ npm install -g dockerfile-language-server-nodejs
},
},
}
-- vim:et ts=2 sw=2

View File

@ -0,0 +1,27 @@
local util = require 'lspconfig.util'
local bin_name = 'dot-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 = { 'dot' },
root_dir = util.find_git_ancestor,
single_file_support = true,
},
docs = {
description = [[
https://github.com/nikeee/dot-language-server
`dot-language-server` can be installed via `npm`:
```sh
npm install -g dot-language-server
```
]],
},
}

View File

@ -1,15 +1,10 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
local server_name = 'efm'
local bin_name = 'efm-langserver'
configs[server_name] = {
return {
default_config = {
cmd = { bin_name },
root_dir = function(fname)
return util.root_pattern '.git'(fname) or util.path.dirname(fname)
end,
cmd = { 'efm-langserver' },
root_dir = util.find_git_ancestor,
single_file_support = true,
},
docs = {
@ -18,6 +13,17 @@ https://github.com/mattn/efm-langserver
General purpose Language Server that can use specified error message format generated from specified command.
Requires at minimum EFM version [v0.0.38](https://github.com/mattn/efm-langserver/releases/tag/v0.0.38) to support
launching the language server on single files. If on an older version of EFM, disable single file support:
```lua
require('lspconfig')['efm'].setup{
settings = ..., -- You must populate this according to the EFM readme
filetypes = ..., -- Populate this according to the note below
single_file_support = false, -- This is the important line for supporting older version of EFM
}
```
Note: In order for neovim's built-in language server client to send the appropriate `languageId` to EFM, **you must
specify `filetypes` in your call to `setup{}`**. Otherwise `lspconfig` will launch EFM on the `BufEnter` instead
of the `FileType` autocommand, and the `filetype` variable used to populate the `languageId` will not yet be set.
@ -31,8 +37,7 @@ require('lspconfig')['efm'].setup{
]],
default_config = {
root_dir = [[util.root_pattern(".git")(fname) or util.path.dirname(fname)]],
root_dir = [[util.root_pattern(".git")]],
},
},
}
-- vim:et ts=2 sw=2

View File

@ -1,8 +1,6 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
local server_name = 'elixirls'
configs[server_name] = {
return {
default_config = {
filetypes = { 'elixir', 'eelixir' },
root_dir = function(fname)
@ -10,7 +8,6 @@ configs[server_name] = {
end,
},
docs = {
package_json = 'https://raw.githubusercontent.com/elixir-lsp/vscode-elixir-ls/master/package.json',
description = [[
https://github.com/elixir-lsp/elixir-ls
@ -40,5 +37,3 @@ require'lspconfig'.elixirls.setup{
},
},
}
-- vim:et ts=2 sw=2

View File

@ -1,18 +1,21 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
local lsp = vim.lsp
local api = vim.api
local server_name = 'elmls'
local bin_name = 'elm-language-server'
local cmd = { bin_name }
if vim.fn.has 'win32' == 1 then
cmd = { 'cmd.exe', '/C', bin_name }
end
local default_capabilities = lsp.protocol.make_client_capabilities()
default_capabilities.offsetEncoding = { 'utf-8', 'utf-16' }
local elm_root_pattern = util.root_pattern 'elm.json'
configs[server_name] = {
return {
default_config = {
cmd = { bin_name },
cmd = cmd,
-- TODO(ashkan) if we comment this out, it will allow elmls to operate on elm.json. It seems like it could do that, but no other editor allows it right now.
filetypes = { 'elm' },
root_dir = function(fname)
@ -22,14 +25,10 @@ configs[server_name] = {
end
end,
init_options = {
elmPath = 'elm',
elmFormatPath = 'elm-format',
elmTestPath = 'elm-test',
elmAnalyseTrigger = 'change',
},
},
docs = {
package_json = 'https://raw.githubusercontent.com/elm-tooling/elm-language-client-vscode/master/package.json',
description = [[
https://github.com/elm-tooling/elm-language-server#installation
@ -43,5 +42,3 @@ npm install -g elm elm-test elm-format @elm-tooling/elm-language-server
},
},
}
-- vim:et ts=2 sw=2

View File

@ -1,12 +1,15 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
local server_name = 'ember'
local bin_name = 'ember-language-server'
local cmd = { bin_name, '--stdio' }
configs[server_name] = {
if vim.fn.has 'win32' == 1 then
cmd = { 'cmd.exe', '/C', bin_name, '--stdio' }
end
return {
default_config = {
cmd = { bin_name, '--stdio' },
cmd = cmd,
filetypes = { 'handlebars', 'typescript', 'javascript' },
root_dir = util.root_pattern('ember-cli-build.js', '.git'),
},
@ -25,5 +28,3 @@ npm install -g @lifeart/ember-language-server
},
},
}
-- vim:et ts=2 sw=2

View File

@ -0,0 +1,31 @@
local util = require 'lspconfig.util'
local bin_name = 'emmet-ls'
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', 'css' },
root_dir = util.find_git_ancestor,
single_file_support = true,
},
docs = {
description = [[
https://github.com/aca/emmet-ls
Package can be installed via `npm`:
```sh
npm install -g emmet-ls
```
]],
default_config = {
root_dir = 'git root',
single_file_support = true,
},
},
}

View File

@ -1,13 +1,16 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
configs.erlangls = {
local cmd = { 'erlang_ls' }
if vim.fn.has 'win32' == 1 then
cmd = { 'cmd.exe', '/C', 'erlang_ls.cmd' }
end
return {
default_config = {
cmd = { 'erlang_ls' },
cmd = cmd,
filetypes = { 'erlang' },
root_dir = function(fname)
return util.root_pattern('rebar.config', 'erlang.mk', '.git')(fname) or util.path.dirname(fname)
end,
root_dir = util.root_pattern('rebar.config', 'erlang.mk', '.git'),
single_file_support = true,
},
docs = {
description = [[
@ -25,7 +28,7 @@ Installation requirements:
- [rebar3 3.9.1+](https://github.com/erlang/rebar3)
]],
default_config = {
root_dir = [[root_pattern('rebar.config', 'erlang.mk', '.git') or util.path.dirname(fname)]],
root_dir = [[root_pattern('rebar.config', 'erlang.mk', '.git')]],
},
},
}

View File

@ -0,0 +1,55 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'python3', '-m', 'esbonio' },
filetypes = { 'rst' },
root_dir = util.find_git_ancestor,
},
docs = {
description = [[
https://github.com/swyddfa/esbonio
Esbonio is a language server for [Sphinx](https://www.sphinx-doc.org/en/master/) documentation projects.
The language server can be installed via pip
```
pip install esbonio
```
Since Sphinx is highly extensible you will get best results if you install the language server in the same
Python environment as the one used to build your documentation. To ensure that the correct Python environment
is picked up, you can either launch `nvim` with the correct environment activated.
```
source env/bin/activate
nvim
```
Or you can modify the default `cmd` to include the full path to the Python interpreter.
```lua
require'lspconfig'.esbonio.setup {
cmd = { '/path/to/virtualenv/bin/python', '-m', 'esbonio' }
}
```
Esbonio supports a number of config values passed as `init_options` on startup, for example.
```lua
require'lspconfig'.esbonio.setup {
init_options = {
server = {
logLevel = "debug"
},
sphinx = {
confDir = "/path/to/docs",
srcDir = "${confDir}/../docs-src"
}
}
```
A full list and explanation of the available options can be found [here](https://swyddfa.github.io/esbonio/docs/lsp/editors/index.html)
]],
},
}

View File

@ -0,0 +1,172 @@
local util = require 'lspconfig.util'
local lsp = vim.lsp
local get_eslint_client = function()
local active_clients = lsp.get_active_clients()
for _, client in ipairs(active_clients) do
if client.name == 'eslint' then
return client
end
end
return nil
end
local function fix_all(opts)
opts = opts or {}
local eslint_lsp_client = get_eslint_client()
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.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'),
}
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: A linting engine for JavaScript / Typescript
`vscode-eslint-language-server` 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 document on save
```vim
autocmd BufWritePre <buffer> <cmd>EslintFixAll<CR>
```
See [vscode-eslint](https://github.com/microsoft/vscode-eslint/blob/55871979d7af184bf09af491b6ea35ebd56822cf/server/src/eslintServer.ts#L216-L229) for configuration options.
Additional messages you can handle: eslint/noConfig
Messages already handled in lspconfig: eslint/openDoc, eslint/confirmESLintExecution, eslint/probeFailed, eslint/noLibrary
]],
},
}

View File

@ -1,14 +1,12 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
configs.flow = {
return {
default_config = {
cmd = { 'npx', '--no-install', 'flow', 'lsp' },
filetypes = { 'javascript', 'javascriptreact', 'javascript.jsx' },
root_dir = util.root_pattern '.flowconfig',
},
docs = {
package_json = 'https://raw.githubusercontent.com/flowtype/flow-for-vscode/master/package.json',
description = [[
https://flow.org/
https://github.com/facebook/flow
@ -27,4 +25,3 @@ npx flow lsp --help
},
},
}
-- vim:et ts=2 sw=2

View File

@ -0,0 +1,22 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'flux-lsp' },
filetypes = { 'flux' },
root_dir = util.find_git_ancestor,
single_file_support = true,
},
docs = {
description = [[
https://github.com/influxdata/flux-lsp
`flux-lsp` can be installed via `cargo`:
```sh
cargo install --git https://github.com/influxdata/flux-lsp
```
]],
default_config = {
root_dir = [[util.find_git_ancestor]],
},
},
}

View File

@ -0,0 +1,31 @@
local util = require 'lspconfig.util'
local bin_name = 'foam-ls'
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 = { 'foam', 'OpenFOAM' },
root_dir = function(fname)
return util.search_ancestors(fname, function(path)
if util.path.exists(util.path.join(path, 'system', 'controlDict')) then
return path
end
end)
end,
},
docs = {
description = [[
https://github.com/FoamScience/foam-language-server
`foam-language-server` can be installed via `npm`
```sh
npm install -g foam-language-server
```
]],
},
}

View File

@ -1,17 +1,17 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
configs.fortls = {
return {
default_config = {
cmd = { 'fortls' },
filetypes = { 'fortran' },
root_dir = util.root_pattern '.fortls',
root_dir = function(fname)
return util.root_pattern '.fortls'(fname) or util.find_git_ancestor(fname)
end,
settings = {
nthreads = 1,
},
},
docs = {
package_json = 'https://raw.githubusercontent.com/hansec/vscode-fortran-ls/master/package.json',
description = [[
https://github.com/hansec/fortran-language-server
@ -22,4 +22,3 @@ Fortran Language Server for the Language Server Protocol
},
},
}
-- vim:et ts=2 sw=2

View File

@ -1,11 +1,8 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
local server_name = 'fsautocomplete'
configs[server_name] = {
return {
default_config = {
cmd = { 'dotnet', 'fsautocomplete', '--background-service-enabled' },
cmd = { 'fsautocomplete', '--background-service-enabled' },
root_dir = util.root_pattern('*.sln', '*.fsproj', '.git'),
filetypes = { 'fsharp' },
init_options = {

View File

@ -0,0 +1,19 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'fstar.exe', '--lsp' },
filetypes = { 'fstar' },
root_dir = util.find_git_ancestor,
},
docs = {
description = [[
https://github.com/FStarLang/FStar
LSP support is included in FStar. Make sure `fstar.exe` is in your PATH.
]],
default_config = {
root_dir = [[util.find_git_ancestor]],
},
},
}

View File

@ -1,7 +1,6 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
configs.gdscript = {
return {
default_config = {
cmd = { 'nc', 'localhost', '6008' },
filetypes = { 'gd', 'gdscript', 'gdscript3' },
@ -18,5 +17,3 @@ Language server for GDScript, used by Godot Engine.
},
},
}
-- vim:et ts=2 sw=2

View File

@ -1,7 +1,6 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
configs.ghcide = {
return {
default_config = {
cmd = { 'ghcide', '--lsp' },
filetypes = { 'haskell', 'lhaskell' },

View File

@ -0,0 +1,34 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'golangci-lint-langserver' },
filetypes = { 'go', 'gomod' },
init_options = {
command = { 'golangci-lint', 'run', '--out-format', 'json' },
},
root_dir = function(fname)
return util.root_pattern 'go.work'(fname) or util.root_pattern('go.mod', '.golangci.yaml', '.git')(fname)
end,
},
docs = {
description = [[
Combination of both lint server and client
https://github.com/nametake/golangci-lint-langserver
https://github.com/golangci/golangci-lint
Installation of binaries needed is done via
```
go install github.com/nametake/golangci-lint-langserver@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.42.1
```
]],
default_config = {
root_dir = [[root_pattern('go.work') or root_pattern('go.mod', '.golangci.yaml', '.git')]],
},
},
}

View File

@ -1,13 +1,13 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
configs.gopls = {
return {
default_config = {
cmd = { 'gopls' },
filetypes = { 'go', 'gomod' },
filetypes = { 'go', 'gomod', 'gotmpl' },
root_dir = function(fname)
return util.root_pattern 'go.work'(fname) or util.root_pattern('go.mod', '.git')(fname)
end,
single_file_support = true,
},
docs = {
description = [[

View File

@ -0,0 +1,37 @@
local util = require 'lspconfig.util'
local bin_name = 'gradle-language-server'
if vim.fn.has 'win32' == 1 then
bin_name = bin_name .. '.bat'
end
local root_files = {
'settings.gradle', -- Gradle (multi-project)
}
local fallback_root_files = {
'build.gradle', -- Gradle
}
return {
default_config = {
filetypes = { 'groovy' },
root_dir = function(fname)
return util.root_pattern(unpack(root_files))(fname) or util.root_pattern(unpack(fallback_root_files))(fname)
end,
cmd = { bin_name },
},
docs = {
description = [[
https://github.com/microsoft/vscode-gradle
Microsoft's lsp server for gradle files
If you're setting this up manually, build vscode-gradle using `./gradlew installDist` and point `cmd` to the `gradle-language-server` generated in the build directory
]],
default_config = {
root_dir = [[root_pattern("settings.gradle")]],
cmd = { 'gradle-language-server' },
},
},
}

View File

@ -0,0 +1,38 @@
local util = require 'lspconfig.util'
local bin_name = 'unofficial-grammarly-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 = { 'markdown' },
root_dir = util.find_git_ancestor,
single_file_support = true,
handlers = {
['$/updateDocumentState'] = function()
return ''
end,
},
},
docs = {
description = [[
https://github.com/emacs-grammarly/unofficial-grammarly-language-server
`unofficial-grammarly-language-server` can be installed via `npm`:
```sh
npm i -g @emacs-grammarly/unofficial-grammarly-language-server
```
WARNING: Since this language server uses Grammarly's API, any document you open with it running is shared with them. Please evaluate their [privacy policy](https://www.grammarly.com/privacy-policy) before using this.
]],
default_config = {
root_dir = [[util.find_git_ancestor]],
},
},
}

View File

@ -0,0 +1,33 @@
local util = require 'lspconfig.util'
local bin_name = 'graphql-lsp'
local cmd = { bin_name, 'server', '-m', 'stream' }
if vim.fn.has 'win32' == 1 then
cmd = { 'cmd.exe', '/C', bin_name, 'server', '-m', 'stream' }
end
return {
default_config = {
cmd = cmd,
filetypes = { 'graphql', 'typescriptreact', 'javascriptreact' },
root_dir = util.root_pattern('.git', '.graphqlrc*', '.graphql.config.*', 'graphql.config.*'),
},
docs = {
description = [[
https://github.com/graphql/graphiql/tree/main/packages/graphql-language-service-cli
`graphql-lsp` can be installed via `npm`:
```sh
npm install -g graphql-language-service-cli
```
Note that you must also have [the graphql package](https://github.com/graphql/graphql-js) installed and create a [GraphQL config file](https://www.graphql-config.com/docs/user/user-introduction).
]],
default_config = {
root_dir = [[root_pattern('.git', '.graphqlrc*', '.graphql.config.*')]],
},
},
}

View File

@ -1,18 +1,16 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
local name = 'groovyls'
local bin_name = 'groovy-language-server-all.jar'
configs[name] = {
return {
default_config = {
cmd = {
'java',
'-jar',
bin_name,
'groovy-language-server-all.jar',
},
filetypes = { 'groovy' },
root_dir = util.root_pattern '.git' or vim.loop.os_homedir(),
root_dir = function(fname)
return util.root_pattern 'Jenkinsfile'(fname) or util.find_git_ancestor(fname)
end,
},
docs = {
description = [[
@ -34,14 +32,5 @@ require'lspconfig'.groovyls.setup{
}
```
]],
default_config = {
cmd = {
'java',
'-jar',
bin_name,
},
filetypes = { 'groovy' },
root_dir = [[root_pattern(".git") or vim.loop.os_homedir()]],
},
},
}

View File

@ -1,7 +1,6 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
configs.haxe_language_server = {
return {
default_config = {
cmd = { 'haxe-language-server' },
filetypes = { 'haxe' },

View File

@ -0,0 +1,20 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'hdl_checker', '--lsp' },
filetypes = { 'vhdl', 'verilog', 'systemverilog' },
root_dir = util.find_git_ancestor,
single_file_support = true,
},
docs = {
description = [[
https://github.com/suoto/hdl_checker
Language server for hdl-checker.
Install using: `pip install hdl-checker --upgrade`
]],
default_config = {
root_dir = [[util.find_git_ancestor]],
},
},
}

View File

@ -0,0 +1,21 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'hh_client', 'lsp' },
filetypes = { 'php', 'hack' },
root_dir = util.root_pattern '.hhconfig',
},
docs = {
description = [[
Language server for programs written in Hack
https://hhvm.com/
https://github.com/facebook/hhvm
See below for how to setup HHVM & typechecker:
https://docs.hhvm.com/hhvm/getting-started/getting-started
]],
default_config = {
root_dir = [[root_pattern(".hhconfig")]],
},
},
}

View File

@ -1,7 +1,6 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
configs.hie = {
return {
default_config = {
cmd = { 'hie-wrapper', '--lsp' },
filetypes = { 'haskell' },
@ -9,7 +8,6 @@ configs.hie = {
},
docs = {
package_json = 'https://raw.githubusercontent.com/alanz/vscode-hie-server/master/package.json',
description = [[
https://github.com/haskell/haskell-ide-engine

View File

@ -1,11 +1,11 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
configs.hls = {
return {
default_config = {
cmd = { 'haskell-language-server-wrapper', '--lsp' },
filetypes = { 'haskell', 'lhaskell' },
root_dir = util.root_pattern('*.cabal', 'stack.yaml', 'cabal.project', 'package.yaml', 'hie.yaml'),
single_file_support = true,
settings = {
haskell = {
formattingProvider = 'ormolu',

View File

@ -1,18 +1,21 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
local server_name = 'html'
local bin_name = 'vscode-html-language-server'
local cmd = { bin_name, '--stdio' }
configs[server_name] = {
if vim.fn.has 'win32' == 1 then
cmd = { 'cmd.exe', '/C', bin_name, '--stdio' }
end
return {
default_config = {
cmd = { bin_name, '--stdio' },
cmd = cmd,
filetypes = { 'html' },
root_dir = function(fname)
return util.root_pattern('package.json', '.git')(fname) or util.path.dirname(fname)
end,
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' },
},
@ -29,6 +32,8 @@ 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()

View File

@ -1,7 +1,6 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
configs.idris2_lsp = {
return {
default_config = {
cmd = { 'idris2-lsp' },
filetypes = { 'idris2' },

View File

@ -1,12 +1,15 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
local server_name = 'intelephense'
local bin_name = 'intelephense'
local cmd = { bin_name, '--stdio' }
configs[server_name] = {
if vim.fn.has 'win32' == 1 then
cmd = { 'cmd.exe', '/C', bin_name, '--stdio' }
end
return {
default_config = {
cmd = { bin_name, '--stdio' },
cmd = cmd,
filetypes = { 'php' },
root_dir = function(pattern)
local cwd = vim.loop.cwd()
@ -26,7 +29,6 @@ npm install -g intelephense
```
]],
default_config = {
package_json = 'https://raw.githubusercontent.com/bmewburn/vscode-intelephense/master/package.json',
root_dir = [[root_pattern("composer.json", ".git")]],
init_options = [[{
storagePath = Optional absolute path to storage dir. Defaults to os.tmpdir().

View File

@ -0,0 +1,18 @@
local util = require 'lspconfig.util'
return {
default_config = {
filetypes = { 'java' },
root_dir = util.root_pattern('build.gradle', 'pom.xml', '.git'),
settings = {},
},
docs = {
description = [[
https://github.com/georgewfraser/java-language-server
Java language server
Point `cmd` to `lang_server_linux.sh` or the equivalent script for macOS/Windows provided by java-language-server
]],
},
}

View File

@ -1,9 +1,6 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
local handlers = require 'vim.lsp.handlers'
local server_name = 'jdtls'
local sysname = vim.loop.os_uname().sysname
local env = {
HOME = vim.loop.os_homedir(),
@ -38,14 +35,6 @@ local function get_jdtls_config()
end
end
-- Non-standard notification that can be used to display progress
local function on_language_status(_, _, result)
local command = vim.api.nvim_command
command 'echohl ModeMsg'
command(string.format('echo "%s"', result.message))
command 'echohl None'
end
-- TextDocument version is reported as 0, override with nil so that
-- the client doesn't think the document is newer and refuses to update
-- See: https://github.com/eclipse/eclipse.jdt.ls/issues/1695
@ -61,6 +50,35 @@ local function fix_zero_version(workspace_edit)
return workspace_edit
end
local function on_textdocument_codeaction(err, actions, ctx)
for _, action in ipairs(actions) do
-- TODO: (steelsojka) Handle more than one edit?
if action.command == 'java.apply.workspaceEdit' then -- 'action' is Command in java format
action.edit = fix_zero_version(action.edit or action.arguments[1])
elseif type(action.command) == 'table' and action.command.command == 'java.apply.workspaceEdit' then -- 'action' is CodeAction in java format
action.edit = fix_zero_version(action.edit or action.command.arguments[1])
end
end
handlers[ctx.method](err, actions, ctx)
end
local function on_textdocument_rename(err, workspace_edit, ctx)
handlers[ctx.method](err, fix_zero_version(workspace_edit), ctx)
end
local function on_workspace_applyedit(err, workspace_edit, ctx)
handlers[ctx.method](err, fix_zero_version(workspace_edit), ctx)
end
-- Non-standard notification that can be used to display progress
local function on_language_status(_, result)
local command = vim.api.nvim_command
command 'echohl ModeMsg'
command(string.format('echo "%s"', result.message))
command 'echohl None'
end
local root_files = {
-- Single-module projects
{
@ -73,7 +91,7 @@ local root_files = {
{ 'build.gradle', 'build.gradle.kts' },
}
configs[server_name] = {
return {
default_config = {
cmd = {
get_java_executable(),
@ -84,17 +102,17 @@ configs[server_name] = {
'-Dlog.level=ALL',
'-Xms1g',
'-Xmx2G',
'--add-modules=ALL-SYSTEM',
'--add-opens',
'java.base/java.util=ALL-UNNAMED',
'--add-opens',
'java.base/java.lang=ALL-UNNAMED',
'-jar',
get_jdtls_jar(),
'-configuration',
get_jdtls_config(),
'-data',
get_workspace_dir(),
'--add-modules=ALL-SYSTEM',
'--add-opens',
'java.base/java.util=ALL-UNNAMED',
'--add-opens',
'java.base/java.lang=ALL-UNNAMED',
},
filetypes = { 'java' },
root_dir = function(fname)
@ -104,8 +122,8 @@ configs[server_name] = {
return root
end
end
return vim.fn.getcwd()
end,
single_file_support = true,
init_options = {
workspace = get_workspace_dir(),
jvm_args = {},
@ -114,31 +132,13 @@ configs[server_name] = {
handlers = {
-- Due to an invalid protocol implementation in the jdtls we have to conform these to be spec compliant.
-- https://github.com/eclipse/eclipse.jdt.ls/issues/376
['textDocument/codeAction'] = function(a, b, actions)
for _, action in ipairs(actions) do
-- TODO: (steelsojka) Handle more than one edit?
if action.command == 'java.apply.workspaceEdit' then -- 'action' is Command in java format
action.edit = fix_zero_version(action.edit or action.arguments[1])
elseif type(action.command) == 'table' and action.command.command == 'java.apply.workspaceEdit' then -- 'action' is CodeAction in java format
action.edit = fix_zero_version(action.edit or action.command.arguments[1])
end
end
handlers['textDocument/codeAction'](a, b, actions)
end,
['textDocument/rename'] = function(a, b, workspace_edit)
handlers['textDocument/rename'](a, b, fix_zero_version(workspace_edit))
end,
['workspace/applyEdit'] = function(a, b, workspace_edit)
handlers['workspace/applyEdit'](a, b, fix_zero_version(workspace_edit))
end,
['textDocument/codeAction'] = on_textdocument_codeaction,
['textDocument/rename'] = on_textdocument_rename,
['workspace/applyEdit'] = on_workspace_applyedit,
['language/status'] = vim.schedule_wrap(on_language_status),
},
},
docs = {
package_json = 'https://raw.githubusercontent.com/redhat-developer/vscode-java/master/package.json',
description = [[
https://projects.eclipse.org/projects/eclipse.jdt.ls

View File

@ -1,12 +1,19 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig.util'
configs.jedi_language_server = {
local root_files = {
'pyproject.toml',
'setup.py',
'setup.cfg',
'requirements.txt',
'Pipfile',
}
return {
default_config = {
cmd = { 'jedi-language-server' },
filetypes = { 'python' },
root_dir = function(fname)
return vim.fn.getcwd()
end,
root_dir = util.root_pattern(unpack(root_files)),
single_file_support = true,
},
docs = {
description = [[

View File

@ -1,23 +1,24 @@
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
local util = require 'lspconfig.util'
local server_name = 'jsonls'
local bin_name = 'vscode-json-language-server'
local cmd = { bin_name, '--stdio' }
configs[server_name] = {
if vim.fn.has 'win32' == 1 then
cmd = { 'cmd.exe', '/C', bin_name, '--stdio' }
end
return {
default_config = {
cmd = { bin_name, '--stdio' },
filetypes = { 'json' },
cmd = cmd,
filetypes = { 'json', 'jsonc' },
init_options = {
provideFormatter = true,
},
root_dir = function(fname)
return util.root_pattern '.git'(fname) or util.path.dirname(fname)
end,
root_dir = util.find_git_ancestor,
single_file_support = true,
},
docs = {
-- this language server config is in VSCode built-in package.json
package_json = 'https://raw.githubusercontent.com/microsoft/vscode/master/extensions/json-language-features/package.json',
description = [[
https://github.com/hrsh7th/vscode-langservers-extracted
@ -28,20 +29,6 @@ vscode-json-language-server, a language server for JSON and JSON schema
npm i -g vscode-langservers-extracted
```
vscode-json-language-server only provides range formatting. You can map a command that applies range formatting to the entire document:
```lua
require'lspconfig'.jsonls.setup {
commands = {
Format = {
function()
vim.lsp.buf.range_formatting({},{0,0},{vim.fn.line("$"),0})
end
}
}
}
```
Neovim does not currently include built-in snippets. `vscode-json-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
@ -55,7 +42,7 @@ require'lspconfig'.jsonls.setup {
```
]],
default_config = {
root_dir = [[root_pattern(".git") or dirname]],
root_dir = [[util.find_git_ancestor]],
},
},
}

View File

@ -0,0 +1,40 @@
local util = require 'lspconfig.util'
-- common jsonnet library paths
local function jsonnet_path(root_dir)
local paths = {
util.path.join(root_dir, 'lib'),
util.path.join(root_dir, 'vendor'),
}
return table.concat(paths, ':')
end
return {
default_config = {
cmd = { 'jsonnet-language-server' },
filetypes = { 'jsonnet', 'libsonnet' },
root_dir = function(fname)
return util.root_pattern 'jsonnetfile.json'(fname) or util.find_git_ancestor(fname)
end,
on_new_config = function(new_config, root_dir)
new_config.cmd_env = {
JSONNET_PATH = jsonnet_path(root_dir),
}
end,
},
docs = {
description = [[
https://github.com/grafana/jsonnet-language-server
A Language Server Protocol (LSP) server for Jsonnet.
The language server can be installed with `go`:
```sh
go install github.com/grafana/jsonnet-language-server@latest
```
]],
default_config = {
root_dir = [[root_pattern("jsonnetfile.json")]],
},
},
}

Some files were not shown because too many files have changed in this diff Show More