Add lspconfig with example setup

This commit is contained in:
Anthony Rose 2024-04-06 14:39:53 +01:00
parent 4b2b69d4f6
commit 457cb42dc7
322 changed files with 37744 additions and 0 deletions

View file

@ -2,3 +2,42 @@ vim.cmd("runtime vimrc")
vim.opt.number = true vim.opt.number = true
vim.opt.numberwidth = 8 vim.opt.numberwidth = 8
local lspconfig = require('lspconfig')
lspconfig.clangd.setup {}
lspconfig.cmake.setup {}
lspconfig.gopls.setup {}
lspconfig.ltex.setup {}
lspconfig.omnisharp.setup {}
lspconfig.rls.setup {}
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist)
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
callback = function(ev)
vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
local opts = { buffer = ev.buf }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
vim.keymap.set('n', '<space>f', function()
vim.lsp.buf.format { async = true }
end, opts)
end,
})

View file

@ -0,0 +1,3 @@
als
edn
esy

View file

@ -0,0 +1,13 @@
root = true
[*]
indent_style = space
indent_size = 2
tab_width = 8
end_of_line = lf
insert_final_newline = true
charset = utf-8
[{Makefile,**/Makefile,runtime/doc/*.txt}]
indent_style = tab
indent_size = 8

View file

@ -0,0 +1,6 @@
* @glepnir
/.github/ @dundargoc
/flake.lock @teto
/flake.nix @teto

View file

@ -0,0 +1,77 @@
name: Bug report
description: Report a problem in nvim-lspconfig
labels: [bug]
body:
- type: markdown
attributes:
value: |
Before reporting: search existing issues and ensure you are running the latest nightly of neovim and the latest version of nvim-lspconfig. Note that this repository implements configuration and initialization of language servers. Implementation of the language server spec itself is located in the neovim core repository.
- type: textarea
attributes:
label: "Description"
description: "A short description of the problem you are reporting."
validations:
required: true
- type: textarea
attributes:
label: "Neovim version"
description: "Output of `nvim --version`"
placeholder: |
NVIM v0.6.0-dev+209-g0603eba6e
Build type: Release
LuaJIT 2.1.0-beta3
validations:
required: true
- type: input
attributes:
label: "Nvim-lspconfig version"
description: "Commit hash"
placeholder: 1344a859864d4e6d23d3f3adf56d49e6386ec0d2
- type: input
attributes:
label: "Operating system and version"
placeholder: "macOS 11.5"
validations:
required: true
- type: input
attributes:
label: "Affected language servers"
description: "If this issue is specific to one or more language servers, list them here. If not, write 'all'."
placeholder: "clangd"
validations:
required: true
- type: textarea
attributes:
label: "Steps to reproduce"
description: "Steps to reproduce using the minimal config provided below."
placeholder: |
1. `nvim -nu minimal.lua`
2. ...
validations:
required: true
- type: textarea
attributes:
label: "Actual behavior"
description: "Observed behavior."
validations:
required: true
- type: textarea
attributes:
label: "Expected behavior"
description: "A description of the behavior you expected."
- type: textarea
attributes:
label: "Minimal config"
render: Lua
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: input
attributes:
label: "LSP log"
description: "If not using the `minimal_init.lua`, add `vim.lsp.set_log_level('debug')` to your LSP setup, upload the log file at `$HOME/.cache/nvim/lsp.log` to https://gist.github.com, and paste the link here."
validations:
required: true

View file

@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: Question
url: https://vi.stackexchange.com/
about: Usage questions and support requests

View file

@ -0,0 +1,24 @@
name: Feature request
description: Request a feature in nvim-lspconfig
labels: [enhancement]
body:
- type: markdown
attributes:
value: |
Before requesting a new feature, search existing issues. Implementation of the language server protocol itself is located in the neovim core repository, and general feature requests may be better suited for core.
- type: input
attributes:
label: "Language server"
description: "Is the feature specific to a language server? If so, which one(s)?"
placeholder: "clangd"
- type: textarea
attributes:
label: "Requested feature"
validations:
required: true
- type: input
attributes:
label: "Other clients which have this feature"
description: "Is the feature already implemented in another LSP client for (Neo)Vim? If so, which one(s)?"
placeholder: "vim-lsp"

View file

@ -0,0 +1,5 @@
---
name: Pull Request
about: Submit a pull request
title: ''
---

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,8 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
commit-message:
prefix: "ci"

View file

@ -0,0 +1,11 @@
name: codespell
on: [pull_request]
jobs:
codespell:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install codespell
run: pip install codespell
- name: Use codespell
run: codespell --quiet-level=2 --check-hidden --skip=./doc/server_configurations.md,./doc/server_configurations.txt --ignore-words=.codespellignorewords

View file

@ -0,0 +1,20 @@
name: "Check 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@v4
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 comment $PR_NUMBER --body 'Do not change `server_configurations.md` directly. Edit the lua source file instead. See https://github.com/neovim/nvim-lspconfig/blob/master/CONTRIBUTING.md#generating-docs'
exit 1
fi

View file

@ -0,0 +1,12 @@
on: [pull_request]
jobs:
lint-commits:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: npm install --save-dev @commitlint/{cli,config-conventional}
- run: |
echo "module.exports = { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js
- run: npx commitlint --from HEAD~1 --to HEAD --verbose

View file

@ -0,0 +1,32 @@
name: docgen
on:
push:
branches:
- master
jobs:
docgen:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: rhysd/action-setup-vim@v1
with:
neovim: true
version: nightly
- name: Run docgen
run: |
scripts/docgen.sh
- name: Commit changes
env:
COMMIT_MSG: |
docs: update server_configurations.md
skip-checks: true
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
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)

View file

@ -0,0 +1,37 @@
name: lint
on:
pull_request:
branches:
- master
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Run luacheck
uses: lunarmodules/luacheck@v1
with:
args: lua/* test/*
- name: Run selene
uses: NTBBloodbath/selene-action@v1.0.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --display-style=quiet .
style-lint:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Lint with stylua
uses: JohnnyMorganz/stylua-action@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: latest
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,21 @@
name: "release"
on:
push:
tags:
- '*'
jobs:
luarocks-upload:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: LuaRocks Upload
uses: nvim-neorocks/luarocks-tag-release@v5
env:
LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }}
with:
summary: "A collection of common configurations for Neovim's built-in language server client."
detailed_description: |
This plugin allows for declaratively configuring,
launching, and initializing language servers you have installed on your system.
Language server configurations are community-maintained.
licence: "Apache/2.0"

View file

@ -0,0 +1,14 @@
name: "Dirname Checker"
on: [pull_request]
jobs:
disallowed-root-checker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- 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

@ -0,0 +1,36 @@
name: test
on:
pull_request:
branches:
- master
jobs:
test:
name: Run Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- uses: rhysd/action-setup-vim@v1
id: vim
with:
neovim: true
version: nightly
- name: luajit
uses: leafo/gh-actions-lua@v10
with:
luaVersion: "luajit-2.1.0-beta3"
- name: luarocks
uses: leafo/gh-actions-luarocks@v4
- name: run test
shell: bash
run: |
luarocks install luacheck
luarocks install vusted
vusted ./test

View file

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

View file

@ -0,0 +1,15 @@
-- vim: ft=lua tw=80
-- Rerun tests only if their modification time changed.
cache = true
ignore = {
"122", -- Setting a read-only field of a global variable.
"212", -- Unused argument, In the case of callback function, _arg_name is easier to understand than _, so this option is set to off.
"631", -- max_line_length, vscode pkg URL is too long
}
-- Global objects defined by the C code
read_globals = {
"vim",
}

View file

@ -0,0 +1,6 @@
column_width = 120
line_endings = "Unix"
indent_type = "Spaces"
indent_width = 2
quote_style = "AutoPreferSingle"
call_parentheses = "None"

View file

@ -0,0 +1,121 @@
## Requirements
- [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 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
cmd = { 'typescript-language-server', '--stdio' }
```
* `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/lsp/3.17/specification/#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/lsp/3.17/specification/#didChangeConfigurationParams) shortly after server initialization. This is an undocumented convention for most language servers. There is often some duplication with initOptions.
An example for adding a new language server is shown below for `pyright`, a python language server included in lspconfig:
```lua
local util = require 'lspconfig.util'
local root_files = {
'pyproject.toml',
'setup.py',
'setup.cfg',
'requirements.txt',
'Pipfile',
'pyrightconfig.json',
}
local function organize_imports()
local params = {
command = 'pyright.organizeimports',
arguments = { vim.uri_from_bufnr(0) },
}
vim.lsp.buf.execute_command(params)
end
return {
default_config = {
cmd = { 'pyright-langserver', '--stdio' },
filetypes = { 'python' },
root_dir = util.root_pattern(unpack(root_files)),
single_file_support = true,
settings = {
python = {
analysis = {
autoSearchPaths = true,
useLibraryCodeForTypes = true,
diagnosticMode = 'workspace',
},
},
},
},
commands = {
PyrightOrganizeImports = {
organize_imports,
description = 'Organize Imports',
},
},
docs = {
description = [[
https://github.com/microsoft/pyright
`pyright`, a static type checker and language server for python
]],
},
}
```
## 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](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
## Generating docs
GitHub Actions automatically generates `server_configurations.md`. Only modify `scripts/README_template.md` or the `docs` table in the server config Lua file. Do not modify `server_configurations.md` directly.
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'

View file

@ -0,0 +1,176 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS

View file

@ -0,0 +1,12 @@
test:
vusted ./test
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

View file

@ -0,0 +1,162 @@
# nvim-lspconfig
[Configs](doc/server_configurations.md) for the [Nvim LSP client](https://neovim.io/doc/user/lsp.html) (`:help lsp`).
* **Do not file Nvim LSP client issues here.** The Nvim LSP client does not live here. This is only a collection of LSP configs.
* If you found a bug in the Nvim LSP client, [report it at the Nvim core repo](https://github.com/neovim/neovim/issues/new?assignees=&labels=bug%2Clsp&template=lsp_bug_report.yml).
* These configs are **best-effort and unsupported.** See [contributions](#contributions).
See also `:help lspconfig`.
## Install
[![LuaRocks](https://img.shields.io/luarocks/v/neovim/nvim-lspconfig?logo=lua&color=purple)](https://luarocks.org/modules/neovim/nvim-lspconfig)
* Requires neovim version 0.8 above. Update Nvim and nvim-lspconfig before reporting an issue.
* Install nvim-lspconfig as a normal plugin through neovim builtin `packadd` or a plugin manager
## Quickstart
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.lua.
```lua
require'lspconfig'.pyright.setup{}
```
3. Launch Nvim, the language server will attach and provide diagnostics.
```
nvim main.py
```
4. Run `:LspInfo` to see the status or to troubleshoot.
5. See [Suggested configuration](#Suggested-configuration) to setup common mappings and omnifunc completion.
See [server_configurations.md](doc/server_configurations.md) (`:help lspconfig-all` from Nvim) for the full list of configs, including installation instructions and additional, optional, customization suggestions for each language server. For servers that are not on your system path (e.g., `jdtls`, `elixirls`), you must manually add `cmd` to the `setup` parameter. Most language servers can be installed in less than a minute.
## Suggested configuration
nvim-lspconfig does not set 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\>).
```lua
-- Setup language servers.
local lspconfig = require('lspconfig')
lspconfig.pyright.setup {}
lspconfig.tsserver.setup {}
lspconfig.rust_analyzer.setup {
-- Server-specific settings. See `:help lspconfig-setup`
settings = {
['rust-analyzer'] = {},
},
}
-- Global mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist)
-- Use LspAttach autocommand to only map the following keys
-- after the language server attaches to the current buffer
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
callback = function(ev)
-- Enable completion triggered by <c-x><c-o>
vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
vim.keymap.set('n', '<space>f', function()
vim.lsp.buf.format { async = true }
end, opts)
end,
})
```
Manual, triggered completion is provided by Nvim's builtin omnifunc. For *auto*completion, a general purpose [autocompletion plugin](https://github.com/neovim/nvim-lspconfig/wiki/Autocompletion) is required.
## Troubleshooting
If you have an issue, 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 instead of an absolute path to the executable, ensure it is on your path.
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. 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.
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
vim.lsp.set_log_level("debug")
```
Attempt to run the language server, and open the log with:
```
:LspLog
```
Most of the time, the reason for failure is present in the logs.
## Commands
* `:LspInfo` shows the status of active and configured language servers.
* `: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.
## Wiki
See the [wiki](https://github.com/neovim/nvim-lspconfig/wiki) for additional topics, including:
* [Automatic server installation](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)
## Contributions
If you are missing a language server on the list in [server_configurations.md](doc/server_configurations.md), contributing
a new configuration for it helps others, especially if the server requires special setup. Follow these steps:
1. Read [CONTRIBUTING.md](CONTRIBUTING.md).
2. Create a new file at `lua/lspconfig/server_configurations/SERVER_NAME.lua`.
- 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/server_configurations/texlab.lua).
3. Ask questions on [GitHub Discussions](https://github.com/neovim/neovim/discussions) or in the [Neovim Matrix room](https://app.element.io/#/room/#neovim:matrix.org).
### Release process
To publish a release:
- Create and push a new [tag](https://github.com/neovim/nvim-lspconfig/tags).
- After pushing the tag, a [GitHub action](./.github/workflows/release.yml)
will automatically package the plugin and publish the release to LuaRocks.
## License
Copyright Neovim contributors. All rights reserved.
nvim-lspconfig is licensed under the terms of the Apache 2.0 license.
See [LICENSE.md](./LICENSE.md)

View file

@ -0,0 +1,646 @@
*lspconfig.txt* For Nvim version 0.8+
nvim-lspconfig provides user-contributed configs for the Nvim |lsp| client.
Type |gO| to see the table of contents.
==============================================================================
INTRODUCTION *lspconfig*
nvim-lspconfig is a collection of community-contributed configurations for the
built-in language server client in Nvim 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
nvim-lspconfig is not required to use the builtin Nvim |lsp| client, it is
just a convenience layer.
See |lspconfig-all| for the complete list of language server configurations.
==============================================================================
QUICKSTART *lspconfig-quickstart*
- ensure the server is installed and executable from the command line
- 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-all|.
- 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-all|.
==============================================================================
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`.
Using the default configuration for a server is simple:
>
require'lspconfig'.clangd.setup{}
<
The available server names are listed in |lspconfig-all| and match the server
name in `config.SERVER_NAME` defined in each configuration's source file.
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.
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.
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:
- {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 (`server_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,
}
}
}
<
==============================================================================
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.
==============================================================================
SETUP HOOK *lspconfig-setup-hook*
`lspconfig` will execute the `on_setup` hook for each setup call to a server after
validating its configuration, and before attempting to launch the server
itself. One typical usage is to allow ad-hoc substitution for any
configuration entry, such as `cmd`.
>
local lspconfig = require 'lspconfig'
lspconfig.util.on_setup = lspconfig.util.add_hook_before(lspconfig.util.on_setup, function(config)
if some_condition and config.name == "clangd" then
local custom_server_prefix = "/my/custom/server/prefix"
config.cmd = { custom_server_prefix .. "/bin/clangd" }
end
end)
Note: This is primarily targeted at plugins developers, so make sure to use
`util.add_hook_before()` as a wrapper instead of overriding the original function
completely, to void breaking external integrations with lspconfig.
==============================================================================
SERVER CONFIGURATIONS *lspconfig-configurations*
See |lspconfig-all| for the complete list of language server 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`.
Warning: Commands is deprecated and will be removed in future releases.
It is recommended to use `vim.api.nvim_create_user_command()` instead in an `on_attach` function.
Example:
>
local function organize_imports()
local params = {
command = 'pyright.organizeimports',
arguments = { vim.uri_from_bufnr(0) },
}
vim.lsp.buf.execute_command(params)
end
local on_attach = function(client, bufnr)
if client.name == "pyright" then
vim.api.nvim_create_user_command("PyrightOrganizeImports", organize_imports, {desc = 'Organize Imports'})
end
end
require("lspconfig")['pyright'].setup({
on_attach = on_attach
})
<
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-new*
The steps for adding and enabling a new server configuration are:
1. load the `lspconfig` module (note that this is a stylistic choice) >
local lspconfig = require 'lspconfig'
<
2. 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
3. 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.fn.glob()| while traversing up the
filesystem. Parent directories are traversed once per pattern, in the order
the patterns are specified.
>
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*
Language servers require each project to have a `root` in order to provide
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.
- also supports unnamed buffer if filetype matches the server filetype
settings.
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.
==============================================================================
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.
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. if you want to force stop
a language server you can do it like `:LspStop <client_id> ++force`
- `: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
`LspAttach` (Nvim 0.8+) autocommand to apply keybindings after a language
servers has attached to a given buffer.
>
-- Setup language servers.
local lspconfig = require('lspconfig')
lspconfig.pyright.setup {}
lspconfig.tsserver.setup {}
lspconfig.rust_analyzer.setup {
-- Server-specific settings. See `:help lspconfig-setup`
settings = {
['rust-analyzer'] = {},
},
}
-- Global mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist)
-- Use LspAttach autocommand to only map the following keys
-- after the language server attaches to the current buffer
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
callback = function(ev)
-- Enable completion triggered by <c-x><c-o>
vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
vim.keymap.set('n', '<space>f', function()
vim.lsp.buf.format { async = true }
end, opts)
end,
})
==============================================================================
COMPLETION SUPPORT *lspconfig-completion*
Manually triggered completion can be provided by Nvim's built-in omnifunc.
See |lspconfig|.
For autocompletion, Nvim does not provide built-in functionality. Consult the
nvim-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
- nvim-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 nvim-lspconfig.
- The root directory inferred for your project is wrong, or it should be
detected but is not due to a bug in the nvim-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 nvim-lspconfig issues, the most common hurdles users face are:
- The language server is not installed or is otherwise not executable.
nvim-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. nvim-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`.
==============================================================================
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:
>
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:
>
:LspLog
<
Note that `ERROR` messages containing `stderr` only indicate that the log was
sent to `stderr`. Many servers counter-intuitively send harmless messages
via stderr.
==============================================================================
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.
==============================================================================
Highlights *lspconfig-highlight*
LspInfoTitle Client name
LspInfoList Server name list
LspInfoFiletype `filetypes` area
LspInfoTip Tip
LspInfoBorder Window border
To set the border use: >
require('lspconfig.ui.windows').default_options.border = 'single'
< Accepts the same values as the `border` option to |nvim_open_win()|
==============================================================================
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

@ -0,0 +1,60 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1699906975,
"narHash": "sha256-tvLhyy1iQj3vdW8tYt2uPNoTWt6FB87tG2HaaErk6tk=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "5c6e85ee472d37c904dd43f8f76b680602b9128f",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

View file

@ -0,0 +1,21 @@
{
description = "Quickstart configurations for the Nvim LSP client";
inputs.nixpkgs.url = "github:NixOS/nixpkgs";
inputs.flake-utils.url = "github:numtide/flake-utils";
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.luajitPackages.vusted
pkgs.selene
];
};
}
);
}

View file

@ -0,0 +1,59 @@
local configs = require 'lspconfig.configs'
local M = {
util = require 'lspconfig.util',
}
---@class Alias
---@field to string The new name of the server
---@field version string The version that the alias will be removed in
---@param name string
---@return Alias
local function server_alias(name)
local aliases = {
['fennel-ls'] = {
to = 'fennel_ls',
version = '0.2.0',
},
['starlark-rust'] = {
to = 'starlark_rust',
version = '0.2.0',
},
sumneko_lua = {
to = 'lua_ls',
version = '0.2.0',
},
}
return aliases[name]
end
local mt = {}
function mt:__index(k)
if configs[k] == nil then
local alias = server_alias(k)
if alias then
vim.deprecate(k, alias.to, alias.version, 'lspconfig', false)
k = alias.to
end
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
return setmetatable(M, mt)

View file

@ -0,0 +1,70 @@
local M = {}
function M.run(func)
coroutine.resume(coroutine.create(function()
local status, err = pcall(func)
if not status then
vim.notify(('[lspconfig] unhandled error: %s'):format(tostring(err)), vim.log.levels.WARN)
end
end))
end
--- @param cmd string|string[]
--- @return string[]?
function M.run_command(cmd)
local co = assert(coroutine.running())
local stdout = {}
local stderr = {}
local exit_code = nil
local jobid = vim.fn.jobstart(cmd, {
on_stdout = function(_, data, _)
data = table.concat(data, '\n')
if #data > 0 then
stdout[#stdout + 1] = data
end
end,
on_stderr = function(_, data, _)
stderr[#stderr + 1] = table.concat(data, '\n')
end,
on_exit = function(_, code, _)
exit_code = code
coroutine.resume(co)
end,
stdout_buffered = true,
stderr_buffered = true,
})
if jobid <= 0 then
vim.notify(('[lspconfig] unable to run cmd: %s'):format(cmd), vim.log.levels.WARN)
return nil
end
coroutine.yield()
if exit_code ~= 0 then
vim.notify(
('[lspconfig] cmd failed with code %d: %s\n%s'):format(exit_code, cmd, table.concat(stderr, '')),
vim.log.levels.WARN
)
return nil
end
if next(stdout) == nil then
return nil
end
return stdout and stdout or nil
end
function M.reenter()
if vim.in_fast_event() then
local co = assert(coroutine.running())
vim.schedule(function()
coroutine.resume(co)
end)
coroutine.yield()
end
end
return M

View file

@ -0,0 +1,295 @@
local util = require 'lspconfig.util'
local async = require 'lspconfig.async'
local api, validate, lsp, uv, fn = vim.api, vim.validate, vim.lsp, vim.loop, vim.fn
local tbl_deep_extend = vim.tbl_deep_extend
local configs = {}
--- @class lspconfig.Config : lsp.ClientConfig
--- @field enabled? boolean
--- @field single_file_support? boolean
--- @field filetypes? string[]
--- @field filetype? string
--- @field on_new_config? function
--- @field autostart? boolean
--- @field package _on_attach? fun(client: lsp.Client, bufnr: integer)
--- @param cmd any
local function sanitize_cmd(cmd)
if cmd and type(cmd) == 'table' and not vim.tbl_isempty(cmd) then
local original = cmd[1]
cmd[1] = vim.fn.exepath(cmd[1])
if #cmd[1] == 0 then
cmd[1] = original
end
end
end
function configs.__newindex(t, config_name, config_def)
validate {
name = { config_name, 's' },
default_config = { config_def.default_config, 't' },
on_new_config = { config_def.on_new_config, 'f', true },
on_attach = { config_def.on_attach, 'f', true },
commands = { config_def.commands, 't', true },
}
if config_def.default_config.deprecate then
vim.deprecate(
config_name,
config_def.default_config.deprecate.to,
config_def.default_config.deprecate.version,
'lspconfig',
false
)
end
if config_def.commands then
for k, v in pairs(config_def.commands) do
validate {
['command.name'] = { k, 's' },
['command.fn'] = { v[1], 'f' },
}
end
else
config_def.commands = {}
end
local M = {}
local default_config = tbl_deep_extend('keep', config_def.default_config, util.default_config)
-- Force this part.
default_config.name = config_name
--- @param user_config lspconfig.Config
function M.setup(user_config)
local lsp_group = api.nvim_create_augroup('lspconfig', { clear = false })
validate {
cmd = {
user_config.cmd,
{ 'f', 't' },
true,
},
root_dir = { user_config.root_dir, 'f', true },
filetypes = { user_config.filetype, 't', true },
on_new_config = { user_config.on_new_config, 'f', true },
on_attach = { user_config.on_attach, 'f', true },
commands = { user_config.commands, 't', true },
}
if user_config.commands then
for k, v in pairs(user_config.commands) do
validate {
['command.name'] = { k, 's' },
['command.fn'] = { v[1], 'f' },
}
end
end
local config = tbl_deep_extend('keep', user_config, default_config)
sanitize_cmd(config.cmd)
if util.on_setup then
pcall(util.on_setup, config, user_config)
end
if config.autostart == true then
local event_conf = config.filetypes and { event = 'FileType', pattern = config.filetypes }
or { event = 'BufReadPost' }
api.nvim_create_autocmd(event_conf.event, {
pattern = event_conf.pattern or '*',
callback = function(opt)
M.manager:try_add(opt.buf)
end,
group = lsp_group,
desc = string.format(
'Checks whether server %s should start a new instance or attach to an existing one.',
config.name
),
})
end
local get_root_dir = config.root_dir
function M.launch(bufnr)
bufnr = bufnr or api.nvim_get_current_buf()
if not api.nvim_buf_is_valid(bufnr) then
return
end
local bufname = api.nvim_buf_get_name(bufnr)
if (#bufname == 0 and not config.single_file_support) or (#bufname ~= 0 and not util.bufname_valid(bufname)) then
return
end
local pwd = uv.cwd()
async.run(function()
local root_dir
if get_root_dir then
root_dir = get_root_dir(util.path.sanitize(bufname), bufnr)
async.reenter()
if not api.nvim_buf_is_valid(bufnr) then
return
end
end
if root_dir then
api.nvim_create_autocmd('BufReadPost', {
pattern = fn.fnameescape(root_dir) .. '/*',
callback = function(arg)
M.manager:try_add_wrapper(arg.buf, root_dir)
end,
group = lsp_group,
desc = string.format(
'Checks whether server %s should attach to a newly opened buffer inside workspace %q.',
config.name,
root_dir
),
})
for _, buf in ipairs(api.nvim_list_bufs()) do
local buf_name = api.nvim_buf_get_name(buf)
if util.bufname_valid(buf_name) then
local buf_dir = util.path.sanitize(buf_name)
if buf_dir:sub(1, root_dir:len()) == root_dir then
M.manager:try_add_wrapper(buf, root_dir)
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.
if not api.nvim_buf_is_valid(bufnr) or (#bufname ~= 0 and not util.bufname_valid(bufname)) then
return
end
local pseudo_root = #bufname == 0 and pwd or util.path.dirname(util.path.sanitize(bufname))
M.manager:add(pseudo_root, true, bufnr)
end
end)
end
-- Used by :LspInfo
M.get_root_dir = get_root_dir
M.filetypes = config.filetypes
M.handlers = config.handlers
M.cmd = config.cmd
M.autostart = config.autostart
-- In the case of a reload, close existing things.
local reload = false
if M.manager then
for _, client in ipairs(M.manager:clients()) do
client.stop(true)
end
reload = true
M.manager = nil
end
local make_config = function(root_dir)
local new_config = tbl_deep_extend('keep', vim.empty_dict(), config) --[[@as lspconfig.Config]]
new_config.capabilities = tbl_deep_extend('keep', new_config.capabilities, {
workspace = {
configuration = true,
},
})
if config_def.on_new_config then
pcall(config_def.on_new_config, new_config, root_dir)
end
if config.on_new_config then
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)
-- 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
end
if vim.tbl_isempty(settings) then
settings = { [vim.type_idx] = vim.types.dictionary }
end
return client.notify('workspace/didChangeConfiguration', {
settings = settings,
})
end
if not vim.tbl_isempty(new_config.settings) then
client.workspace_did_change_configuration(new_config.settings)
end
end)
-- Save the old _on_attach so that we can reference it via the BufEnter.
new_config._on_attach = new_config.on_attach
new_config.on_attach = function(client, bufnr)
if bufnr == api.nvim_get_current_buf() then
M._setup_buffer(client.id, bufnr)
else
if api.nvim_buf_is_valid(bufnr) then
api.nvim_create_autocmd('BufEnter', {
callback = function()
M._setup_buffer(client.id, bufnr)
end,
group = lsp_group,
buffer = bufnr,
once = true,
desc = 'Reattaches the server with the updated configurations if changed.',
})
end
end
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
local manager = require('lspconfig.manager').new(config, make_config)
M.manager = manager
M.make_config = make_config
if reload and config.autostart ~= false then
for _, bufnr in ipairs(api.nvim_list_bufs()) do
manager:try_add_wrapper(bufnr)
end
end
end
function M._setup_buffer(client_id, bufnr)
local client = lsp.get_client_by_id(client_id)
if not client then
return
end
local config = client.config --[[@as lspconfig.Config]]
if config._on_attach then
config._on_attach(client, bufnr)
end
if client.config.commands and not vim.tbl_isempty(client.config.commands) then
M.commands = vim.tbl_deep_extend('force', M.commands, client.config.commands)
end
if not M.commands_created and not vim.tbl_isempty(M.commands) then
util.create_module_commands(config_name, M.commands)
end
end
M.commands = config_def.commands
M.name = config_name
M.document_config = config_def
rawset(t, config_name, M)
end
return setmetatable({}, configs)

View file

@ -0,0 +1,297 @@
local api = vim.api
local lsp = vim.lsp
local uv = vim.loop
local async = require 'lspconfig.async'
local util = require 'lspconfig.util'
---@param client lsp.Client
---@param root_dir string
---@return boolean
local function check_in_workspace(client, root_dir)
if not client.workspace_folders then
return false
end
for _, dir in ipairs(client.workspace_folders) do
if (root_dir .. '/'):sub(1, #dir.name + 1) == dir.name .. '/' then
return true
end
end
return false
end
--- @class lspconfig.Manager
--- @field _clients table<string,table>
--- @field config lspconfig.Config
--- @field make_config fun(root_dir: string): lspconfig.Config
local M = {}
--- @param config lspconfig.Config
--- @param make_config fun(root_dir: string): lspconfig.Config
--- @return lspconfig.Manager
function M.new(config, make_config)
return setmetatable({
_clients = {},
config = config,
make_config = make_config,
}, {
__index = M,
})
end
--- @private
function M:_get_client_from_cache(root_dir, client_name)
local clients = self._clients
if vim.tbl_count(clients) == 0 then
return
end
if clients[root_dir] then
for _, id in pairs(clients[root_dir]) do
local client = lsp.get_client_by_id(id)
if client and client.name == client_name then
return client
end
end
end
local all_client_ids = {}
vim.tbl_map(function(val)
vim.list_extend(all_client_ids, { unpack(val) })
end, clients)
for _, id in ipairs(all_client_ids) do
local client = lsp.get_client_by_id(id)
if client and client.name == client_name then
return client
end
end
end
--- @private
--- @param bufnr integer
--- @param root string
--- @param client_id integer
function M:_attach_and_cache(bufnr, root, client_id)
local clients = self._clients
lsp.buf_attach_client(bufnr, client_id)
if not clients[root] then
clients[root] = {}
end
if not vim.tbl_contains(clients[root], client_id) then
clients[root][#clients[root] + 1] = client_id
end
end
--- @private
--- @param bufnr integer
--- @param root_dir string
--- @param client lsp.Client
function M:_register_workspace_folders(bufnr, root_dir, client)
local params = {
event = {
added = { { uri = vim.uri_from_fname(root_dir), name = root_dir } },
removed = {},
},
}
client.rpc.notify('workspace/didChangeWorkspaceFolders', params)
if not client.workspace_folders then
client.workspace_folders = {}
end
client.workspace_folders[#client.workspace_folders + 1] = params.event.added[1]
self:_attach_and_cache(bufnr, root_dir, client.id)
end
--- @private
--- @param bufnr integer
--- @param new_config lspconfig.Config
--- @param root_dir string
--- @param single_file boolean
function M:_start_new_client(bufnr, new_config, root_dir, single_file)
-- do nothing if the client is not enabled
if new_config.enabled == false then
return
end
if not new_config.cmd then
vim.notify(
string.format(
'[lspconfig] cmd not defined for %q. Manually set cmd in the setup {} call according to server_configurations.md, see :help lspconfig-index.',
new_config.name
),
vim.log.levels.ERROR
)
return
end
local clients = self._clients
new_config.on_exit = util.add_hook_before(new_config.on_exit, function()
for index, id in pairs(clients[root_dir]) do
local exist = assert(lsp.get_client_by_id(id))
if exist.name == new_config.name then
table.remove(clients[root_dir], index)
end
end
end)
-- Launch the server in the root directory used internally by lspconfig, if otherwise unset
-- also check that the path exist
if not new_config.cmd_cwd and uv.fs_realpath(root_dir) then
new_config.cmd_cwd = root_dir
end
-- Sending rootDirectory and workspaceFolders as null is not explicitly
-- codified in the spec. Certain servers crash if initialized with a NULL
-- root directory.
if single_file then
new_config.root_dir = nil
new_config.workspace_folders = nil
end
local client_id = lsp.start_client(new_config)
if not client_id then
return
end
self:_attach_and_cache(bufnr, root_dir, client_id)
end
--- @private
--- @param bufnr integer
--- @param new_config lspconfig.Config
--- @param root_dir string
--- @param client lsp.Client
--- @param single_file boolean
function M:_attach_or_spawn(bufnr, new_config, root_dir, client, single_file)
if check_in_workspace(client, root_dir) then
return self:_attach_and_cache(bufnr, root_dir, client.id)
end
local supported = vim.tbl_get(client, 'server_capabilities', 'workspace', 'workspaceFolders', 'supported')
if supported then
return self:_register_workspace_folders(bufnr, root_dir, client)
end
self:_start_new_client(bufnr, new_config, root_dir, single_file)
end
--- @private
--- @param bufnr integer
--- @param new_config lspconfig.Config
--- @param root_dir string
--- @param client lsp.Client
--- @param single_file boolean
function M:_attach_after_client_initialized(bufnr, new_config, root_dir, client, single_file)
local timer = assert(vim.loop.new_timer())
timer:start(
0,
10,
vim.schedule_wrap(function()
if client.initialized and client.server_capabilities and not timer:is_closing() then
self:_attach_or_spawn(bufnr, new_config, root_dir, client, single_file)
timer:stop()
timer:close()
end
end)
)
end
---@param root_dir string
---@param single_file boolean
---@param bufnr integer
function M:add(root_dir, single_file, bufnr)
root_dir = util.path.sanitize(root_dir)
local new_config = self.make_config(root_dir)
local client = self:_get_client_from_cache(root_dir, new_config.name)
if not client then
return self:_start_new_client(bufnr, new_config, root_dir, single_file)
end
if self._clients[root_dir] or single_file then
lsp.buf_attach_client(bufnr, client.id)
return
end
-- make sure neovim had exchanged capabilities from language server
-- it's useful to check server support workspaceFolders or not
if client.initialized and client.server_capabilities then
self:_attach_or_spawn(bufnr, new_config, root_dir, client, single_file)
else
self:_attach_after_client_initialized(bufnr, new_config, root_dir, client, single_file)
end
end
--- @return lsp.Client[]
function M:clients()
local res = {}
for _, client_ids in pairs(self._clients) do
for _, id in ipairs(client_ids) do
res[#res + 1] = lsp.get_client_by_id(id)
end
end
return res
end
--- Try to attach the buffer `bufnr` to a client using this config, creating
--- a new client if one doesn't already exist for `bufnr`.
--- @param bufnr integer
--- @param project_root? string
function M:try_add(bufnr, project_root)
bufnr = bufnr or api.nvim_get_current_buf()
if vim.bo[bufnr].buftype == 'nofile' then
return
end
local bufname = api.nvim_buf_get_name(bufnr)
if #bufname == 0 and not self.config.single_file_support then
return
end
if #bufname ~= 0 and not util.bufname_valid(bufname) then
return
end
if project_root then
self:add(project_root, false, bufnr)
return
end
local buf_path = util.path.sanitize(bufname)
local get_root_dir = self.config.root_dir
local pwd = assert(uv.cwd())
async.run(function()
local root_dir
if get_root_dir then
root_dir = get_root_dir(buf_path, bufnr)
async.reenter()
if not api.nvim_buf_is_valid(bufnr) then
return
end
end
if root_dir then
self:add(root_dir, false, bufnr)
elseif self.config.single_file_support then
local pseudo_root = #bufname == 0 and pwd or util.path.dirname(buf_path)
self:add(pseudo_root, true, bufnr)
end
end)
end
--- Check that the buffer `bufnr` has a valid filetype according to
--- `config.filetypes`, then do `manager.try_add(bufnr)`.
--- @param bufnr integer
--- @param project_root? string
function M:try_add_wrapper(bufnr, project_root)
local config = self.config
-- `config.filetypes = nil` means all filetypes are valid.
if not config.filetypes or vim.tbl_contains(config.filetypes, vim.bo[bufnr].filetype) then
self:try_add(bufnr, project_root)
end
end
return M

View file

@ -0,0 +1,25 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'aiken', 'lsp' },
filetypes = { 'aiken' },
root_dir = function(fname)
return util.root_pattern('aiken.toml', '.git')(fname)
end,
},
docs = {
description = [[
https://github.com/aiken-lang/aiken
A language server for Aiken Programming Language.
[Installation](https://aiken-lang.org/installation-instructions)
It can be i
]],
default_config = {
cmd = { 'aiken', 'lsp' },
root_dir = [[root_pattern("aiken.toml", ".git")]],
},
},
}

View file

@ -0,0 +1,37 @@
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
return {
default_config = {
cmd = { bin_name },
filetypes = { 'ada' },
root_dir = util.root_pattern('Makefile', '.git', '*.gpr', '*.adc'),
},
docs = {
description = [[
https://github.com/AdaCore/ada_language_server
Installation instructions can be found [here](https://github.com/AdaCore/ada_language_server#Install).
Can be configured by passing a "settings" object to `als.setup{}`:
```lua
require('lspconfig').als.setup{
settings = {
ada = {
projectFile = "project.gpr";
scenarioVariables = { ... };
}
}
}
```
]],
default_config = {
root_dir = [[util.root_pattern("Makefile", ".git", "*.gpr", "*.adc")]],
},
},
}

View file

@ -0,0 +1,78 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'anakinls' },
filetypes = { 'python' },
root_dir = function(fname)
local root_files = {
'pyproject.toml',
'setup.py',
'setup.cfg',
'requirements.txt',
'Pipfile',
}
return util.root_pattern(unpack(root_files))(fname) or util.find_git_ancestor(fname)
end,
single_file_support = true,
settings = {
anakinls = {
pyflakes_errors = {
-- Full list: https://github.com/PyCQA/pyflakes/blob/master/pyflakes/messages.py
'ImportStarNotPermitted',
'UndefinedExport',
'UndefinedLocal',
'UndefinedName',
'DuplicateArgument',
'MultiValueRepeatedKeyLiteral',
'MultiValueRepeatedKeyVariable',
'FutureFeatureNotDefined',
'LateFutureImport',
'ReturnOutsideFunction',
'YieldOutsideFunction',
'ContinueOutsideLoop',
'BreakOutsideLoop',
'TwoStarredExpressions',
'TooManyExpressionsInStarredAssignment',
'ForwardAnnotationSyntaxError',
'RaiseNotImplemented',
'StringDotFormatExtraPositionalArguments',
'StringDotFormatExtraNamedArguments',
'StringDotFormatMissingArgument',
'StringDotFormatMixingAutomatic',
'StringDotFormatInvalidFormat',
'PercentFormatInvalidFormat',
'PercentFormatMixedPositionalAndNamed',
'PercentFormatUnsupportedFormat',
'PercentFormatPositionalCountMismatch',
'PercentFormatExtraNamedArguments',
'PercentFormatMissingArgument',
'PercentFormatExpectedMapping',
'PercentFormatExpectedSequence',
'PercentFormatStarRequiresSequence',
},
},
},
},
docs = {
description = [[
https://pypi.org/project/anakin-language-server/
`anakin-language-server` is yet another Jedi Python language server.
Available options:
* Initialization: https://github.com/muffinmad/anakin-language-server#initialization-option
* Configuration: https://github.com/muffinmad/anakin-language-server#configuration-options
]],
},
}

View file

@ -0,0 +1,67 @@
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.
-- This defaults to the vim cwd, but will get overwritten by the resolved root of the file.
local function get_probe_dir(root_dir)
local project_root = util.find_node_modules_ancestor(root_dir)
return project_root and (project_root .. '/node_modules') or ''
end
local default_probe_dir = get_probe_dir(vim.fn.getcwd())
return {
default_config = {
cmd = {
'ngserver',
'--stdio',
'--tsProbeLocations',
default_probe_dir,
'--ngProbeLocations',
default_probe_dir,
},
filetypes = { 'typescript', 'html', 'typescriptreact', 'typescript.tsx' },
-- Check for angular.json since that is the root of the project.
-- Don't check for tsconfig.json or package.json since there are multiple of these
-- in an angular monorepo setup.
root_dir = util.root_pattern 'angular.json',
},
on_new_config = function(new_config, new_root_dir)
local new_probe_dir = get_probe_dir(new_root_dir)
-- We need to check our probe directories because they may have changed.
new_config.cmd = {
'ngserver',
'--stdio',
'--tsProbeLocations',
new_probe_dir,
'--ngProbeLocations',
new_probe_dir,
}
end,
docs = {
description = [[
https://github.com/angular/vscode-ng-language-service
`angular-language-server` can be installed via npm `npm install -g @angular/language-server`.
Note, that if you override the default `cmd`, you must also update `on_new_config` to set `new_config.cmd` during startup.
```lua
local project_library_path = "/path/to/project/lib"
local cmd = {"ngserver", "--stdio", "--tsProbeLocations", project_library_path , "--ngProbeLocations", project_library_path}
require'lspconfig'.angularls.setup{
cmd = cmd,
on_new_config = function(new_config,new_root_dir)
new_config.cmd = cmd
end,
}
```
]],
default_config = {
root_dir = [[root_pattern("angular.json")]],
},
},
}

View file

@ -0,0 +1,43 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'ansible-language-server', '--stdio' },
settings = {
ansible = {
python = {
interpreterPath = 'python',
},
ansible = {
path = 'ansible',
},
executionEnvironment = {
enabled = false,
},
validation = {
enabled = true,
lint = {
enabled = true,
path = 'ansible-lint',
},
},
},
},
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

@ -0,0 +1,19 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'antlersls', '--stdio' },
filetypes = { 'html', 'antlers' },
root_dir = util.root_pattern 'composer.json',
},
docs = {
description = [[
https://www.npmjs.com/package/antlers-language-server
`antlersls` can be installed via `npm`:
```sh
npm install -g antlers-language-server
```
]],
},
}

View file

@ -0,0 +1,46 @@
local util = require 'lspconfig.util'
return {
default_config = {
filetypes = { 'apexcode' },
root_dir = util.root_pattern 'sfdx-project.json',
on_new_config = function(config)
if not config.cmd and config.apex_jar_path then
config.cmd = {
vim.env.JAVA_HOME and util.path.join(vim.env.JAVA_HOME, 'bin', 'java') or 'java',
'-cp',
config.apex_jar_path,
'-Ddebug.internal.errors=true',
'-Ddebug.semantic.errors=' .. tostring(config.apex_enable_semantic_errors or false),
'-Ddebug.completion.statistics=' .. tostring(config.apex_enable_completion_statistics or false),
'-Dlwc.typegeneration.disabled=true',
}
if config.apex_jvm_max_heap then
table.insert(config.cmd, '-Xmx' .. config.apex_jvm_max_heap)
end
table.insert(config.cmd, 'apex.jorje.lsp.ApexLanguageServerLauncher')
end
end,
},
docs = {
description = [[
https://github.com/forcedotcom/salesforcedx-vscode
Language server for Apex.
For manual installation, download the JAR file from the [VSCode
extension](https://github.com/forcedotcom/salesforcedx-vscode/tree/develop/packages/salesforcedx-vscode-apex).
```lua
require'lspconfig'.apex_ls.setup {
apex_jar_path = '/path/to/apex-jorje-lsp.jar',
apex_enable_semantic_errors = false, -- Whether to allow Apex Language Server to surface semantic errors
apex_enable_completion_statistics = false, -- Whether to allow Apex Language Server to collect telemetry on code completion usage
}
```
]],
default_config = {
root_dir = [[root_pattern('sfdx-project.json')]],
},
},
}

View file

@ -0,0 +1,87 @@
local util = require 'lspconfig.util'
local default_capabilities = vim.lsp.protocol.make_client_capabilities()
default_capabilities.textDocument.semanticTokens = vim.NIL
default_capabilities.workspace.semanticTokens = vim.NIL
return {
default_config = {
filetypes = { 'arduino' },
root_dir = util.root_pattern '*.ino',
cmd = {
'arduino-language-server',
},
capabilities = default_capabilities,
},
docs = {
description = [[
https://github.com/arduino/arduino-language-server
Language server for Arduino
The `arduino-language-server` can be installed by running:
```
go install github.com/arduino/arduino-language-server@latest
```
The `arduino-cli` tool must also be installed. Follow [these
installation instructions](https://arduino.github.io/arduino-cli/latest/installation/) for
your platform.
After installing `arduino-cli`, follow [these
instructions](https://arduino.github.io/arduino-cli/latest/getting-started/#create-a-configuration-file)
for generating a configuration file if you haven't done so already, and make
sure you [install any relevant platforms
libraries](https://arduino.github.io/arduino-cli/latest/getting-started/#install-the-core-for-your-board).
The language server also requires `clangd` to be installed. Follow [these
installation instructions](https://clangd.llvm.org/installation) for your
platform.
If you don't have a sketch yet create one.
```sh
$ arduino-cli sketch new test
$ cd test
```
You will need a `sketch.yaml` file in order for the language server to understand your project. It will also save you passing options to `arduino-cli` each time you compile or upload a file. You can generate the file like using the following commands.
First gather some information about your board. Make sure your board is connected and run the following:
```sh
$ arduino-cli board list
Port Protocol Type Board Name FQBN Core
/dev/ttyACM0 serial Serial Port (USB) Arduino Uno arduino:avr:uno arduino:avr
```
Then generate the file:
```sh
arduino-cli board attach -p /dev/ttyACM0 -b arduino:avr:uno test.ino
```
The resulting file should like like this:
```yaml
default_fqbn: arduino:avr:uno
default_port: /dev/ttyACM0
```
Your folder structure should look like this:
```
.
test.ino
sketch.yaml
```
For further instruction about configuration options, run `arduino-language-server --help`.
Note that an upstream bug makes keywords in some cases become undefined by the language server.
Ref: https://github.com/arduino/arduino-ide/issues/159
]],
},
}

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,38 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'ast-grep', 'lsp' },
filetypes = { -- https://ast-grep.github.io/reference/languages.html
'c',
'cpp',
'rust',
'go',
'java',
'python',
'javascript',
'typescript',
'html',
'css',
'kotlin',
'dart',
'lua',
},
root_dir = util.root_pattern('sgconfig.yaml', 'sgconfig.yml'),
single_file_support = true,
},
docs = {
description = [[
https://ast-grep.github.io/
ast-grep(sg) is a fast and polyglot tool for code structural search, lint, rewriting at large scale.
ast-grep LSP only works in projects that have `sgconfig.y[a]ml` in their root directories.
```sh
npm install [-g] @ast-grep/cli
```
]],
default_config = {
root_dir = [[root_pattern('sgconfig.yaml', 'sgconfig.yml')]],
},
},
}

View file

@ -0,0 +1,35 @@
local util = require 'lspconfig.util'
local function get_typescript_server_path(root_dir)
local project_root = util.find_node_modules_ancestor(root_dir)
return project_root and (util.path.join(project_root, 'node_modules', 'typescript', 'lib')) or ''
end
return {
default_config = {
cmd = { 'astro-ls', '--stdio' },
filetypes = { 'astro' },
root_dir = util.root_pattern('package.json', 'tsconfig.json', 'jsconfig.json', '.git'),
init_options = {
typescript = {},
},
on_new_config = function(new_config, new_root_dir)
if vim.tbl_get(new_config.init_options, 'typescript') and not new_config.init_options.typescript.tsdk then
new_config.init_options.typescript.tsdk = get_typescript_server_path(new_root_dir)
end
end,
},
docs = {
description = [[
https://github.com/withastro/language-tools/tree/main/packages/language-server
`astro-ls` can be installed via `npm`:
```sh
npm install -g @astrojs/language-server
```
]],
default_config = {
root_dir = [[root_pattern("package.json", "tsconfig.json", "jsconfig.json", ".git")]],
},
},
}

View file

@ -0,0 +1,29 @@
local util = require 'lspconfig.util'
local root_files = { 'configure.ac', 'Makefile', 'Makefile.am', '*.mk' }
return {
default_config = {
cmd = { 'autotools-language-server' },
filetypes = { 'config', 'automake', 'make' },
root_dir = function(fname)
return util.root_pattern(unpack(root_files))(fname)
end,
single_file_support = true,
},
docs = {
description = [[
https://github.com/Freed-Wu/autotools-language-server
`autotools-language-server` can be installed via `pip`:
```sh
pip install autotools-language-server
```
Language server for autoconf, automake and make using tree sitter in python.
]],
default_config = {
root_dir = { 'configure.ac', 'Makefile', 'Makefile.am', '*.mk' },
},
},
}

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

@ -0,0 +1,44 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'azure-pipelines-language-server', '--stdio' },
filetypes = { 'yaml' },
root_dir = util.root_pattern 'azure-pipelines.yml',
single_file_support = true,
settings = {},
},
docs = {
description = [[
https://github.com/microsoft/azure-pipelines-language-server
An Azure Pipelines language server
`azure-pipelines-ls` can be installed via `npm`:
```sh
npm install -g azure-pipelines-language-server
```
By default `azure-pipelines-ls` will only work in files named `azure-pipelines.yml`, this can be changed by providing additional settings like so:
```lua
require("lspconfig").azure_pipelines_ls.setup {
... -- other configuration for setup {}
settings = {
yaml = {
schemas = {
["https://raw.githubusercontent.com/microsoft/azure-pipelines-vscode/master/service-schema.json"] = {
"/azure-pipeline*.y*l",
"/*.azure*",
"Azure-Pipelines/**/*.y*l",
"Pipelines/*.y*l",
},
},
},
},
}
```
The Azure Pipelines LSP is a fork of `yaml-language-server` and as such the same settings can be passed to it as `yaml-language-server`.
]],
},
}

View file

@ -0,0 +1,37 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'bash-language-server', 'start' },
settings = {
bashIde = {
-- Glob pattern for finding and parsing shell script files in the workspace.
-- Used by the background analysis features across files.
-- Prevent recursive scanning which will cause issues when opening a file
-- directly in the home directory (e.g. ~/foo.sh).
--
-- Default upstream pattern is "**/*@(.sh|.inc|.bash|.command)".
globPattern = vim.env.GLOB_PATTERN or '*@(.sh|.inc|.bash|.command)',
},
},
filetypes = { 'sh' },
root_dir = util.find_git_ancestor,
single_file_support = true,
},
docs = {
description = [[
https://github.com/bash-lsp/bash-language-server
`bash-language-server` can be installed via `npm`:
```sh
npm i -g bash-language-server
```
Language server for bash, written using tree sitter in typescript.
]],
default_config = {
root_dir = [[util.find_git_ancestor]],
},
},
}

View file

@ -0,0 +1,24 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'beancount-language-server', '--stdio' },
filetypes = { 'beancount', 'bean' },
root_dir = util.find_git_ancestor,
single_file_support = true,
init_options = {
-- this is the path to the beancout journal file
journalFile = '',
},
},
docs = {
description = [[
https://github.com/polarmutex/beancount-language-server#installation
See https://github.com/polarmutex/beancount-language-server#configuration for configuration options
]],
default_config = {
root_dir = [[root_pattern(".git")]],
},
},
}

View file

@ -0,0 +1,47 @@
local util = require 'lspconfig.util'
return {
default_config = {
filetypes = { 'bicep' },
root_dir = util.find_git_ancestor,
init_options = {},
},
docs = {
description = [=[
https://github.com/azure/bicep
Bicep language server
Bicep language server can be installed by downloading and extracting a release of bicep-langserver.zip from [Bicep GitHub releases](https://github.com/Azure/bicep/releases).
Bicep language server requires the [dotnet-sdk](https://dotnet.microsoft.com/download) to be installed.
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"
require'lspconfig'.bicep.setup{
cmd = { "dotnet", bicep_lsp_bin };
...
}
```
To download the latest release and place in /usr/local/bin/bicep-langserver:
```bash
(cd $(mktemp -d) \
&& curl -fLO https://github.com/Azure/bicep/releases/latest/download/bicep-langserver.zip \
&& 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,36 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'biome', 'lsp-proxy' },
filetypes = {
'javascript',
'javascriptreact',
'json',
'jsonc',
'typescript',
'typescript.tsx',
'typescriptreact',
},
root_dir = function(fname)
return util.find_package_json_ancestor(fname)
or util.find_node_modules_ancestor(fname)
or util.find_git_ancestor(fname)
end,
single_file_support = true,
},
docs = {
description = [[
https://biomejs.dev
Toolchain of the web. [Successor of Rome](https://biomejs.dev/blog/annoucing-biome).
```sh
npm install [-g] @biomejs/biome
```
]],
default_config = {
root_dir = [[root_pattern('package.json', 'node_modules', '.git', 'biome.json')]],
},
},
}

View file

@ -0,0 +1,30 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'blueprint-compiler', 'lsp' },
cmd_env = {
-- Prevent recursive scanning which will cause issues when opening a file
-- directly in the home directory (e.g. ~/foo.sh).
--
-- Default upstream pattern is "**/*@(.sh|.inc|.bash|.command)".
GLOB_PATTERN = vim.env.GLOB_PATTERN or '*@(.blp)',
},
filetypes = { 'blueprint' },
root_dir = util.find_git_ancestor,
single_file_support = true,
},
docs = {
description = [[
https://gitlab.gnome.org/jwestman/blueprint-compiler
`blueprint-compiler` can be installed via your system package manager.
Language server for the blueprint markup language, written in python and part
of the blueprint-compiler.
]],
default_config = {
root_dir = [[util.find_git_ancestor]],
},
},
}

View file

@ -0,0 +1,23 @@
local util = require 'lspconfig/util'
return {
default_config = {
cmd = { 'bsc', '--lsp', '--stdio' },
filetypes = { 'brs' },
single_file_support = true,
root_dir = util.root_pattern('makefile', 'Makefile', '.git'),
},
docs = {
description = [[
https://github.com/RokuCommunity/brighterscript
`brightscript` can be installed via `npm`:
```sh
npm install -g brighterscript
```
]],
default_config = {
root_dir = [[root_pattern(".git")]],
},
},
}

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

@ -0,0 +1,27 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'buck2', 'lsp' },
filetypes = { 'bzl' },
root_dir = function(fname)
return util.root_pattern '.buckconfig'(fname)
end,
},
docs = {
description = [=[
https://github.com/facebook/buck2
Build system, successor to Buck
To better detect Buck2 project files, the following can be added:
```
vim.cmd [[ autocmd BufRead,BufNewFile *.bxl,BUCK,TARGETS set filetype=bzl ]]
```
]=],
default_config = {
root_dir = [[root_pattern(".buckconfig")]],
},
},
}

View file

@ -0,0 +1,18 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'buddy-lsp-server' },
filetypes = { 'mlir' },
root_dir = util.find_git_ancestor,
single_file_support = true,
},
docs = {
description = [[
https://github.com/buddy-compiler/buddy-mlir#buddy-lsp-server
The Language Server for the buddy-mlir, a drop-in replacement for mlir-lsp-server,
supporting new dialects defined in buddy-mlir.
`buddy-lsp-server` can be installed at the buddy-mlir repository (buddy-compiler/buddy-mlir)
]],
},
}

View file

@ -0,0 +1,26 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'bufls', 'serve' },
filetypes = { 'proto' },
root_dir = function(fname)
return util.root_pattern('buf.work.yaml', '.git')(fname)
end,
},
docs = {
description = [[
https://github.com/bufbuild/buf-language-server
`buf-language-server` can be installed via `go install`:
```sh
go install github.com/bufbuild/buf-language-server/cmd/bufls@latest
```
bufls is a Protobuf language server compatible with Buf modules and workspaces
]],
default_config = {
root_dir = [[root_pattern("buf.work.yaml", ".git")]],
},
},
}

View file

@ -0,0 +1,32 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'flow', 'cadence', 'language-server' },
filetypes = { 'cdc' },
init_options = {
numberOfAccounts = '1',
},
root_dir = function(fname, _)
return util.root_pattern 'flow.json'(fname) or vim.env.HOME
end,
on_new_config = function(new_config, new_root_dir)
new_config.init_options.configPath = util.path.join(new_root_dir, 'flow.json')
end,
},
docs = {
description = [[
[Cadence Language Server](https://github.com/onflow/cadence-tools/tree/master/languageserver)
using the [flow-cli](https://developers.flow.com/tools/flow-cli).
The `flow` command from flow-cli must be available. For install instructions see
[the docs](https://developers.flow.com/tools/flow-cli/install#install-the-flow-cli) or the
[Github page](https://github.com/onflow/flow-cli).
By default the configuration is taken from the closest `flow.json` or the `flow.json` in the users home directory.
]],
default_config = {
root_dir = [[util.root_pattern('flow.json') or vim.env.HOME]],
},
},
}

View file

@ -0,0 +1,30 @@
local util = require 'lspconfig.util'
local bin_name = 'cairo-language-server'
local cmd = { bin_name, '/C', '--node-ipc' }
return {
default_config = {
init_options = { hostInfo = 'neovim' },
cmd = cmd,
filetypes = { 'cairo' },
root_dir = util.root_pattern('Scarb.toml', 'cairo_project.toml', '.git'),
},
docs = {
description = [[
[Cairo Language Server](https://github.com/starkware-libs/cairo/tree/main/crates/cairo-lang-language-server)
First, install cairo following [this tutorial](https://medium.com/@elias.tazartes/ahead-of-the-curve-install-cairo-1-0-alpha-and-prepare-for-regenesis-85f4e3940e20)
Then enable cairo language server in your lua configuration.
```lua
require'lspconfig'.cairo_ls.setup{}
```
*cairo-language-server is still under active development, some features might not work yet !*
]],
default_config = {
root_dir = [[root_pattern("Scarb.toml", "cairo_project.toml", ".git")]],
},
},
}

View file

@ -0,0 +1,50 @@
local util = require 'lspconfig.util'
local root_files = {
'compile_commands.json',
'.ccls',
}
return {
default_config = {
cmd = { 'ccls' },
filetypes = { 'c', 'cpp', 'objc', 'objcpp', 'cuda' },
root_dir = function(fname)
return util.root_pattern(unpack(root_files))(fname) or util.find_git_ancestor(fname)
end,
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 .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:
```lua
local lspconfig = require'lspconfig'
lspconfig.ccls.setup {
init_options = {
compilationDatabaseDirectory = "build";
index = {
threads = 0;
};
clang = {
excludeArgs = { "-frounding-math"} ;
};
}
}
```
]],
default_config = {
root_dir = [[root_pattern('compile_commands.json', '.ccls', '.git')]],
},
},
}

View file

@ -0,0 +1,17 @@
local util = require 'lspconfig/util'
return {
default_config = {
cmd = { 'circom-lsp' },
filetypes = { 'circom' },
root_dir = util.find_git_ancestor,
single_file_support = true,
},
docs = {
description = [[
[Circom Language Server](https://github.com/rubydusa/circom-lsp)
`circom-lsp`, the language server for the Circom language.
]],
},
}

View file

@ -0,0 +1,88 @@
local util = require 'lspconfig.util'
-- https://clangd.llvm.org/extensions.html#switch-between-sourceheader
local function switch_source_header(bufnr)
bufnr = util.validate_bufnr(bufnr)
local clangd_client = util.get_active_client_by_name(bufnr, 'clangd')
local params = { uri = vim.uri_from_bufnr(bufnr) }
if clangd_client then
clangd_client.request('textDocument/switchSourceHeader', params, function(err, result)
if err then
error(tostring(err))
end
if not result then
print 'Corresponding file cannot be determined'
return
end
vim.api.nvim_command('edit ' .. vim.uri_to_fname(result))
end, bufnr)
else
print 'method textDocument/switchSourceHeader is not supported by any servers active on the current buffer'
end
end
local root_files = {
'.clangd',
'.clang-tidy',
'.clang-format',
'compile_commands.json',
'compile_flags.txt',
'configure.ac', -- AutoTools
}
local default_capabilities = {
textDocument = {
completion = {
editsNearCursor = true,
},
},
offsetEncoding = { 'utf-8', 'utf-16' },
}
return {
default_config = {
cmd = { 'clangd' },
filetypes = { 'c', 'cpp', 'objc', 'objcpp', 'cuda', 'proto' },
root_dir = function(fname)
return util.root_pattern(unpack(root_files))(fname) or util.find_git_ancestor(fname)
end,
single_file_support = true,
capabilities = default_capabilities,
},
commands = {
ClangdSwitchSourceHeader = {
function()
switch_source_header(0)
end,
description = 'Switch between source/header',
},
},
docs = {
description = [[
https://clangd.llvm.org/installation.html
- **NOTE:** Clang >= 11 is recommended! See [#23](https://github.com/neovim/nvim-lsp/issues/23).
- If `compile_commands.json` lives in a build directory, you should
symlink it to the root of your source tree.
```
ln -s /path/to/myproject/build/compile_commands.json /path/to/myproject/
```
- clangd relies on a [JSON compilation database](https://clang.llvm.org/docs/JSONCompilationDatabase.html)
specified as compile_commands.json, see https://clangd.llvm.org/installation#compile_commandsjson
]],
default_config = {
root_dir = [[
root_pattern(
'.clangd',
'.clang-tidy',
'.clang-format',
'compile_commands.json',
'compile_flags.txt',
'configure.ac',
'.git'
)
]],
capabilities = [[default capabilities, with offsetEncoding utf-8]],
},
},
}

View file

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

View file

@ -0,0 +1,26 @@
local util = require 'lspconfig.util'
local root_files = { 'CMakePresets.json', 'CTestConfig.cmake', '.git', 'build', 'cmake' }
return {
default_config = {
cmd = { 'cmake-language-server' },
filetypes = { 'cmake' },
root_dir = function(fname)
return util.root_pattern(unpack(root_files))(fname)
end,
single_file_support = true,
init_options = {
buildDirectory = 'build',
},
},
docs = {
description = [[
https://github.com/regen100/cmake-language-server
CMake LSP Implementation
]],
default_config = {
root_dir = [[root_pattern('CMakePresets.json', 'CTestConfig.cmake', '.git', 'build', 'cmake')]],
},
},
}

View file

@ -0,0 +1,17 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'cobol-language-support' },
filetypes = { 'cobol' },
root_dir = util.find_git_ancestor,
},
docs = {
description = [[
Cobol language support
]],
default_config = {
root_dir = [[util.find_git_ancestor]],
},
},
}

View file

@ -0,0 +1,48 @@
local util = require 'lspconfig.util'
local workspace_folders = {}
return {
default_config = {
cmd = { 'codeql', 'execute', 'language-server', '--check-errors', 'ON_CHANGE', '-q' },
filetypes = { 'ql' },
root_dir = util.root_pattern 'qlpack.yml',
log_level = vim.lsp.protocol.MessageType.Warning,
before_init = function(initialize_params)
table.insert(workspace_folders, { name = 'workspace', uri = initialize_params['rootUri'] })
initialize_params['workspaceFolders'] = workspace_folders
end,
settings = {
search_path = vim.empty_dict(),
},
},
docs = {
description = [[
Reference:
https://codeql.github.com/docs/codeql-cli/
Binaries:
https://github.com/github/codeql-cli-binaries
]],
default_config = {
settings = {
search_path = [[list containing all search paths, eg: '~/codeql-home/codeql-repo']],
},
},
},
on_new_config = function(config)
if type(config.settings.search_path) == 'table' and not vim.tbl_isempty(config.settings.search_path) then
local search_path = '--search-path='
for _, path in ipairs(config.settings.search_path) do
search_path = search_path .. vim.fn.expand(path) .. ':'
table.insert(workspace_folders, {
name = 'workspace',
uri = string.format('file://%s', path),
})
end
config.cmd = { 'codeql', 'execute', 'language-server', '--check-errors', 'ON_CHANGE', '-q', search_path }
else
config.cmd = { 'codeql', 'execute', 'language-server', '--check-errors', 'ON_CHANGE', '-q' }
end
end,
}

View file

@ -0,0 +1,21 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'coffeesense-language-server', '--stdio' },
filetypes = { 'coffee' },
root_dir = util.root_pattern 'package.json',
single_file_support = true,
},
docs = {
description = [[
https://github.com/phil294/coffeesense
CoffeeSense Language Server
`coffeesense-language-server` can be installed via `npm`:
```sh
npm install -g coffeesense-language-server
```
]],
},
}

View file

@ -0,0 +1,21 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'Contextive.LanguageServer' },
root_dir = util.root_pattern('.contextive', '.git'),
},
docs = {
description = [[
https://github.com/dev-cycles/contextive
Language Server for Contextive.
Contextive allows you to define terms in a central file and provides auto-completion suggestions and hover panels for these terms wherever they're used.
To install the language server, you need to download the appropriate [GitHub release asset](https://github.com/dev-cycles/contextive/releases/) for your operating system and architecture.
After the download unzip the Contextive.LanguageServer binary and copy the file into a folder that is included in your system's PATH.
]],
},
}

View file

@ -0,0 +1,17 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'coq-lsp' },
filetypes = { 'coq' },
root_dir = function(fname)
return util.root_pattern '_CoqProject'(fname) or util.find_git_ancestor(fname)
end,
single_file_support = true,
},
docs = {
description = [[
https://github.com/ejgallego/coq-lsp/
]],
},
}

View file

@ -0,0 +1,20 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'crystalline' },
filetypes = { 'crystal' },
root_dir = util.root_pattern 'shard.yml' or util.find_git_ancestor,
single_file_support = true,
},
docs = {
description = [[
https://github.com/elbywan/crystalline
Crystal language server.
]],
default_config = {
root_dir = [[root_pattern('shard.yml', '.git')]],
},
},
}

View file

@ -0,0 +1,23 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'csharp-ls' },
root_dir = util.root_pattern('*.sln', '*.csproj', '*.fsproj', '.git'),
filetypes = { 'cs' },
init_options = {
AutomaticWorkspaceInit = true,
},
},
docs = {
description = [[
https://github.com/razzmatazz/csharp-language-server
Language Server for C#.
csharp-ls requires the [dotnet-sdk](https://dotnet.microsoft.com/download) to be installed.
The preferred way to install csharp-ls is with `dotnet tool install --global csharp-ls`.
]],
},
}

View file

@ -0,0 +1,42 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'vscode-css-language-server', '--stdio' },
filetypes = { 'css', 'scss', 'less' },
root_dir = util.root_pattern('package.json', '.git'),
single_file_support = true,
settings = {
css = { validate = true },
scss = { validate = true },
less = { validate = true },
},
},
docs = {
description = [[
https://github.com/hrsh7th/vscode-langservers-extracted
`css-languageserver` can be installed via `npm`:
```sh
npm i -g vscode-langservers-extracted
```
Neovim does not currently include built-in snippets. `vscode-css-language-server` only provides completions when snippet support is enabled. To enable completion, install a snippet plugin and add the following override to your language client capabilities during setup.
```lua
--Enable (broadcasting) snippet capability for completion
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
require'lspconfig'.cssls.setup {
capabilities = capabilities,
}
```
]],
default_config = {
root_dir = [[root_pattern("package.json", ".git") or bufdir]],
},
},
}

View file

@ -0,0 +1,24 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'cssmodules-language-server' },
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,26 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'cucumber-language-server', '--stdio' },
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

@ -0,0 +1,39 @@
local util = require 'lspconfig.util'
return {
default_config = {
init_options = { hostInfo = 'neovim' },
cmd = { 'custom-elements-languageserver', '--stdio' },
root_dir = util.root_pattern('tsconfig.json', 'package.json', 'jsconfig.json', '.git'),
},
docs = {
description = [[
https://github.com/Matsuuu/custom-elements-language-server
`custom-elements-languageserver` depends on `typescript`. Both packages can be installed via `npm`:
```sh
npm install -g typescript custom-elements-languageserver
```
To configure typescript language server, add a
[`tsconfig.json`](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) or
[`jsconfig.json`](https://code.visualstudio.com/docs/languages/jsconfig) to the root of your
project.
Here's an example that disables type checking in JavaScript files.
```json
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"checkJs": false
},
"exclude": [
"node_modules"
]
}
```
]],
default_config = {
root_dir = [[root_pattern("tsconfig.json", "package.json", "jsconfig.json", ".git")]],
},
},
}

View file

@ -0,0 +1,23 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'cypher-language-server', '--stdio' },
filetypes = { 'cypher' },
root_dir = util.find_git_ancestor,
single_file_support = true,
},
docs = {
description = [[
https://github.com/neo4j/cypher-language-support/tree/main/packages/language-server
`cypher-language-server`, language server for Cypher query language.
Part of the umbrella project cypher-language-support: https://github.com/neo4j/cypher-language-support
`cypher-language-server` can be installed via `npm`:
```sh
npm i -g @neo4j-cypher/language-server
```
]],
},
}

View file

@ -0,0 +1,22 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'dafny', 'server' },
filetypes = { 'dfy', 'dafny' },
root_dir = function(fname)
util.find_git_ancestor(fname)
end,
single_file_support = true,
},
docs = {
description = [[
Support for the Dafny language server.
The default `cmd` uses "dafny server", which works on Dafny 4.0.0+. For
older versions of Dafny, you can compile the language server from source at
[dafny-lang/language-server-csharp](https://github.com/dafny-lang/language-server-csharp)
and set `cmd = {"dotnet", "<Path to your language server>"}`.
]],
},
}

View file

@ -0,0 +1,22 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'cuelsp' },
filetypes = { 'cue' },
root_dir = function(fname)
return util.root_pattern('cue.mod', '.git')(fname)
end,
single_file_support = true,
},
docs = {
description = [[
https://github.com/dagger/cuelsp
Dagger's lsp server for cuelang.
]],
default_config = {
root_dir = [[root_pattern("cue.mod", ".git")]],
},
},
}

View file

@ -0,0 +1,32 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'dart', 'language-server', '--protocol=lsp' },
filetypes = { 'dart' },
root_dir = util.root_pattern 'pubspec.yaml',
init_options = {
onlyAnalyzeProjectsWithOpenFiles = true,
suggestFromUnimportedLibraries = true,
closingLabels = true,
outline = true,
flutterOutline = true,
},
settings = {
dart = {
completeFunctionCalls = true,
showTodos = true,
},
},
},
docs = {
description = [[
https://github.com/dart-lang/sdk/tree/master/pkg/analysis_server/tool/lsp_spec
Language server for dart.
]],
default_config = {
root_dir = [[root_pattern("pubspec.yaml")]],
},
},
}

View file

@ -0,0 +1,138 @@
local util = require 'lspconfig.util'
local lsp = vim.lsp
local function buf_cache(bufnr, client)
local params = {}
params['referrer'] = { uri = vim.uri_from_bufnr(bufnr) }
params['uris'] = {}
client.request('deno/cache', params, function(err, _result, ctx)
if err then
local uri = ctx.params.referrer.uri
vim.api.nvim_err_writeln('cache command failed for ' .. vim.uri_to_fname(uri))
end
end, bufnr)
end
local function virtual_text_document_handler(uri, res, client)
if not res then
return nil
end
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, false, 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
local function virtual_text_document(uri, client)
local params = {
textDocument = {
uri = uri,
},
}
local result = client.request_sync('deno/virtualTextDocument', params)
virtual_text_document_handler(uri, result, client)
end
local function denols_handler(err, result, ctx, config)
if not result or vim.tbl_isempty(result) then
return nil
end
local client = vim.lsp.get_client_by_id(ctx.client_id)
for _, res in pairs(result) do
local uri = res.uri or res.targetUri
if uri:match '^deno:' then
virtual_text_document(uri, client)
res['uri'] = uri
res['targetUri'] = uri
end
end
lsp.handlers[ctx.method](err, result, ctx, config)
end
return {
default_config = {
cmd = { 'deno', 'lsp' },
cmd_env = { NO_COLOR = true },
filetypes = {
'javascript',
'javascriptreact',
'javascript.jsx',
'typescript',
'typescriptreact',
'typescript.tsx',
},
root_dir = util.root_pattern('deno.json', 'deno.jsonc', '.git'),
settings = {
deno = {
enable = true,
suggest = {
imports = {
hosts = {
['https://deno.land'] = true,
['https://crux.land'] = true,
['https://x.nest.land'] = true,
},
},
},
},
},
handlers = {
['textDocument/definition'] = denols_handler,
['textDocument/typeDefinition'] = denols_handler,
['textDocument/references'] = denols_handler,
['workspace/executeCommand'] = function(err, result, context, config)
if context.params.command == 'deno.cache' then
buf_cache(context.bufnr, vim.lsp.get_client_by_id(context.client_id))
else
lsp.handlers[context.method](err, result, context, config)
end
end,
},
},
commands = {
DenolsCache = {
function()
local clients = vim.lsp.get_active_clients()
for _, client in ipairs(clients) do
if client.name == 'denols' then
buf_cache(0, client)
break
end
end
end,
description = 'Cache a module and all of its dependencies.',
},
},
docs = {
description = [[
https://github.com/denoland/deno
Deno's built-in language server
To appropriately 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", ".git")]],
},
},
}

View file

@ -0,0 +1,26 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'dhall-lsp-server' },
filetypes = { 'dhall' },
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
`dhall-lsp-server` can be installed via cabal:
```sh
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")]],
},
},
}

View file

@ -0,0 +1,22 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'diagnostic-languageserver', '--stdio' },
root_dir = util.find_git_ancestor,
single_file_support = true,
filetypes = {},
},
docs = {
description = [[
https://github.com/iamcco/diagnostic-languageserver
Diagnostic language server integrate with linters.
]],
default_config = {
filetypes = 'Empty by default, override to add filetypes',
root_dir = "Vim's starting directory",
init_options = 'Configuration from https://github.com/iamcco/diagnostic-languageserver#config--document',
},
},
}

View file

@ -0,0 +1,21 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'digestif' },
filetypes = { 'tex', 'plaintex', 'context' },
root_dir = util.find_git_ancestor,
single_file_support = true,
},
docs = {
description = [[
https://github.com/astoff/digestif
Digestif is a code analyzer, and a language server, for LaTeX, ConTeXt et caterva. It provides
context-sensitive completion, documentation, code navigation, and related functionality to any
text editor that speaks the LSP protocol.
]],
},
}

View file

@ -0,0 +1,25 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'docker-compose-langserver', '--stdio' },
filetypes = { 'yaml.docker-compose' },
root_dir = util.root_pattern 'docker-compose.yaml',
single_file_support = true,
},
docs = {
description = [[
https://github.com/microsoft/compose-language-service
This project contains a language service for Docker Compose.
`compose-language-service` can be installed via `npm`:
```sh
npm install @microsoft/compose-language-service
```
]],
default_config = {
root_dir = [[root_pattern("docker-compose.yaml")]],
},
},
}

View file

@ -0,0 +1,23 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'docker-langserver', '--stdio' },
filetypes = { 'dockerfile' },
root_dir = util.root_pattern 'Dockerfile',
single_file_support = true,
},
docs = {
description = [[
https://github.com/rcjsuen/dockerfile-language-server-nodejs
`docker-langserver` can be installed via `npm`:
```sh
npm install -g dockerfile-language-server-nodejs
```
]],
default_config = {
root_dir = [[root_pattern("Dockerfile")]],
},
},
}

View file

@ -0,0 +1,20 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'dolmenls' },
filetypes = { 'smt2', 'tptp', 'p', 'cnf', 'icnf', 'zf' },
root_dir = util.find_git_ancestor,
single_file_support = true,
},
docs = {
description = [[
https://github.com/Gbury/dolmen/blob/master/doc/lsp.md
`dolmenls` can be installed via `opam`
```sh
opam install dolmen_lsp
```
]],
},
}

View file

@ -0,0 +1,20 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'dot-language-server', '--stdio' },
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

@ -0,0 +1,81 @@
local util = require 'lspconfig.util'
local function get_java_bin(config)
local java_bin = vim.tbl_get(config, 'drools', 'java', 'bin')
if not java_bin then
java_bin = vim.env.JAVA_HOME and util.path.join(vim.env.JAVA_HOME, 'bin', 'java') or 'java'
if vim.fn.has 'win32' == 1 then
java_bin = java_bin .. '.exe'
end
end
return java_bin
end
local function get_java_opts(config)
local java_opts = vim.tbl_get(config, 'drools', 'java', 'opts')
return java_opts and java_opts or {}
end
local function get_jar(config)
local jar = vim.tbl_get(config, 'drools', 'jar')
return jar and jar or 'drools-lsp-server-jar-with-dependencies.jar'
end
local function get_cmd(config)
local cmd = vim.tbl_get(config, 'cmd')
if not cmd then
cmd = { get_java_bin(config) }
for _, o in ipairs(get_java_opts(config)) do
table.insert(cmd, o)
end
---@diagnostic disable-next-line:missing-parameter
vim.list_extend(cmd, { '-jar', get_jar(config) })
end
return cmd
end
return {
default_config = {
filetypes = { 'drools' },
root_dir = util.find_git_ancestor(),
single_file_support = true,
on_new_config = function(new_config)
new_config.cmd = get_cmd(new_config)
end,
},
docs = {
description = [=[
https://github.com/kiegroup/drools-lsp
Language server for the [Drools Rule Language (DRL)](https://docs.drools.org/latest/drools-docs/docs-website/drools/language-reference/#con-drl_drl-rules).
The `drools-lsp` server is a self-contained java jar file (`drools-lsp-server-jar-with-dependencies.jar`), and can be downloaded from [https://github.com/kiegroup/drools-lsp/releases/](https://github.com/kiegroup/drools-lsp/releases/).
Configuration information:
```lua
-- Option 1) Specify the entire command:
require('lspconfig').drools_lsp.setup {
cmd = { '/path/to/java', '-jar', '/path/to/drools-lsp-server-jar-with-dependencies.jar' },
}
-- Option 2) Specify just the jar path (the JAVA_HOME environment variable will be respected if present):
require('lspconfig').drools_lsp.setup {
drools = { jar = '/path/to/drools-lsp-server-jar-with-dependencies.jar' },
}
-- Option 3) Specify the java bin and/or java opts in addition to the jar path:
require('lspconfig').drools_lsp.setup {
drools = {
java = { bin = '/path/to/java', opts = { '-Xmx100m' } },
jar = '/path/to/drools-lsp-server-jar-with-dependencies.jar',
},
}
```
Neovim does not yet have automatic detection for the `drools` filetype, but it can be added with:
```lua
vim.cmd [[ autocmd BufNewFile,BufRead *.drl set filetype=drools ]]
```
]=],
},
}

View file

@ -0,0 +1,80 @@
local util = require 'lspconfig.util'
local bin_name = 'ds-pinyin-lsp'
if vim.fn.has 'win32' == 1 then
bin_name = bin_name .. '.exe'
end
local function ds_pinyin_lsp_off(bufnr)
bufnr = util.validate_bufnr(bufnr)
local ds_pinyin_lsp_client = util.get_active_client_by_name(bufnr, 'ds_pinyin_lsp')
if ds_pinyin_lsp_client then
ds_pinyin_lsp_client.notify('$/turn/completion', {
['completion_on'] = false,
})
else
vim.notify 'notification $/turn/completion is not supported by any servers active on the current buffer'
end
end
local function ds_pinyin_lsp_on(bufnr)
bufnr = util.validate_bufnr(bufnr)
local ds_pinyin_lsp_client = util.get_active_client_by_name(bufnr, 'ds_pinyin_lsp')
if ds_pinyin_lsp_client then
ds_pinyin_lsp_client.notify('$/turn/completion', {
['completion_on'] = true,
})
else
vim.notify 'notification $/turn/completion is not supported by any servers active on the current buffer'
end
end
return {
default_config = {
cmd = { bin_name },
filetypes = { 'markdown', 'org' },
root_dir = util.find_git_ancestor,
single_file_support = true,
init_options = {
completion_on = true,
show_symbols = true,
show_symbols_only_follow_by_hanzi = false,
show_symbols_by_n_times = 0,
match_as_same_as_input = true,
match_long_input = true,
max_suggest = 15,
},
},
commands = {
DsPinyinCompletionOff = {
function()
ds_pinyin_lsp_off(0)
end,
description = 'Turn off the ds-pinyin-lsp completion',
},
DsPinyinCompletionOn = {
function()
ds_pinyin_lsp_on(0)
end,
description = 'Turn on the ds-pinyin-lsp completion',
},
},
docs = {
description = [=[
https://github.com/iamcco/ds-pinyin-lsp
Dead simple Pinyin language server for input Chinese without IME(input method).
To install, download the latest [release](https://github.com/iamcco/ds-pinyin-lsp/releases) and ensure `ds-pinyin-lsp` is on your path.
And make ensure the database file `dict.db3` is also downloaded. And put the path to `dict.dbs` in the following code.
```lua
require('lspconfig').ds_pinyin_lsp.setup {
init_options = {
db_path = "your_path_to_database"
}
}
```
]=],
},
}

View file

@ -0,0 +1,21 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'ecsact_lsp_server', '--stdio' },
filetypes = { 'ecsact' },
root_dir = util.root_pattern '.git',
single_file_support = true,
},
docs = {
description = [[
https://github.com/ecsact-dev/ecsact_lsp_server
Language server for Ecsact.
The default cmd assumes `ecsact_lsp_server` is in your PATH. Typically from the
Ecsact SDK: https://ecsact.dev/start
]],
},
}

View file

@ -0,0 +1,43 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'efm-langserver' },
root_dir = util.find_git_ancestor,
single_file_support = true,
},
docs = {
description = [[
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.
```lua
require('lspconfig')['efm'].setup{
settings = ..., -- You must populate this according to the EFM readme
filetypes = { 'python','cpp','lua' }
}
```
]],
default_config = {
root_dir = [[util.root_pattern(".git")]],
},
},
}

View file

@ -0,0 +1,39 @@
local util = require 'lspconfig.util'
return {
default_config = {
filetypes = { 'elixir', 'eelixir', 'heex', 'surface' },
root_dir = function(fname)
return util.root_pattern 'mix.exs'(fname) or util.find_git_ancestor(fname) or vim.loop.os_homedir()
end,
},
docs = {
description = [[
https://github.com/elixir-lsp/elixir-ls
`elixir-ls` can be installed by following the instructions [here](https://github.com/elixir-lsp/elixir-ls#building-and-running).
```bash
curl -fLO https://github.com/elixir-lsp/elixir-ls/releases/latest/download/elixir-ls.zip
unzip elixir-ls.zip -d /path/to/elixir-ls
# Unix
chmod +x /path/to/elixir-ls/language_server.sh
```
**By default, elixir-ls 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 elixir-ls.
```lua
require'lspconfig'.elixirls.setup{
-- Unix
cmd = { "/path/to/elixir-ls/language_server.sh" };
-- Windows
cmd = { "/path/to/elixir-ls/language_server.bat" };
...
}
```
]],
default_config = {
root_dir = [[util.find_git_ancestor(fname) or util.root_pattern 'mix.exs'(fname) or vim.loop.os_homedir()]],
},
},
}

View file

@ -0,0 +1,37 @@
local util = require 'lspconfig.util'
local lsp = vim.lsp
local api = vim.api
local default_capabilities = lsp.protocol.make_client_capabilities()
default_capabilities.offsetEncoding = { 'utf-8', 'utf-16' }
local elm_root_pattern = util.root_pattern 'elm.json'
return {
default_config = {
cmd = { 'elm-language-server' },
-- 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)
local filetype = api.nvim_buf_get_option(0, 'filetype')
if filetype == 'elm' or (filetype == 'json' and fname:match 'elm%.json$') then
return elm_root_pattern(fname)
end
end,
init_options = {
elmAnalyseTrigger = 'change',
},
},
docs = {
description = [[
https://github.com/elm-tooling/elm-language-server#installation
If you don't want to use Nvim to install it, then you can use:
```sh
npm install -g elm elm-test elm-format @elm-tooling/elm-language-server
```
]],
default_config = {
root_dir = [[root_pattern("elm.json")]],
},
},
}

View file

@ -0,0 +1,21 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'elp', 'server' },
filetypes = { 'erlang' },
root_dir = util.root_pattern('rebar.config', 'erlang.mk', '.git'),
single_file_support = true,
},
docs = {
description = [[
https://whatsapp.github.io/erlang-language-platform
ELP integrates Erlang into modern IDEs via the language server protocol and was
inspired by rust-analyzer.
]],
default_config = {
root_dir = [[root_pattern('rebar.config', 'erlang.mk', '.git')]],
},
},
}

View file

@ -0,0 +1,23 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'ember-language-server', '--stdio' },
filetypes = { 'handlebars', 'typescript', 'javascript', 'typescript.glimmer', 'javascript.glimmer' },
root_dir = util.root_pattern('ember-cli-build.js', '.git'),
},
docs = {
description = [[
https://github.com/lifeart/ember-language-server
`ember-language-server` can be installed via `npm`:
```sh
npm install -g @lifeart/ember-language-server
```
]],
default_config = {
root_dir = [[root_pattern("ember-cli-build.js", ".git")]],
},
},
}

View file

@ -0,0 +1,35 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'emmet-language-server', '--stdio' },
filetypes = {
'css',
'eruby',
'html',
'htmldjango',
'javascriptreact',
'less',
'pug',
'sass',
'scss',
'typescriptreact',
},
root_dir = util.find_git_ancestor,
single_file_support = true,
},
docs = {
description = [[
https://github.com/olrtg/emmet-language-server
Package can be installed via `npm`:
```sh
npm install -g @olrtg/emmet-language-server
```
]],
default_config = {
root_dir = 'git root',
single_file_support = true,
},
},
}

View file

@ -0,0 +1,38 @@
local util = require 'lspconfig.util'
return {
default_config = {
cmd = { 'emmet-ls', '--stdio' },
filetypes = {
'astro',
'css',
'eruby',
'html',
'htmldjango',
'javascriptreact',
'less',
'pug',
'sass',
'scss',
'svelte',
'typescriptreact',
'vue',
},
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,
},
},
}

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