You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/configuration/lua_completion.mdx
-25Lines changed: 0 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,31 +28,6 @@ return {
28
28
}
29
29
```
30
30
31
-
:::tip
32
-
33
-
AstroLSP allows for language server configuration completion by utilizing types exposed by the `nvim-lspconfig` plugin. One downside is the type does complain that "fields are missing" even though they are not actually required. To work around this, it can be useful and less noisy if you add
34
-
35
-
```
36
-
---@diagnostic disable: missing-fields
37
-
```
38
-
39
-
before the `config` table. Here is an example:
40
-
41
-
```lua title="lua/plugins/astrolsp.lua" {5}
42
-
return {
43
-
"AstroNvim/astrolsp",
44
-
---@typeAstroLSPOpts
45
-
opts= {
46
-
---@diagnosticdisable:missing-fields
47
-
config= {
48
-
-- LSP options and server configuration go here...
49
-
},
50
-
},
51
-
}
52
-
```
53
-
54
-
:::
55
-
56
31
### `opts` Function
57
32
58
33
Other times a function may be required if you want to include any sort of special logic for calculating the table or for handling cases that table merging doesn't deal with properly such as list-like tables. Here you need to specify the type of the parameter in the function.
Copy file name to clipboardExpand all lines: src/content/docs/recipes/advanced_lsp.mdx
+57-79Lines changed: 57 additions & 79 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,9 +7,17 @@ LSP configuration is mostly done through the help of [AstroLSP](https://github.c
7
7
8
8
## Configuring Language Servers
9
9
10
-
Our main tool for configuring and setting up language servers is with the [nvim-lspconfig plugin](https://github.com/neovim/nvim-lspconfig). This plugin provides configurations for many common language servers (A full list can be found in [nvim-lspconfig server configurations documentation](https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md)). These baseline configuration options are not always sufficient to meet everyone's needs, and are typically configured by calling `require("lspconfig")[<server_name>].setup(opts)` where `opts` is a table of options. For the complete set of options that can be used in the `nvim-lspconfig` setup check out `:h lspconfig-setup` in your editor.
10
+
Our main tool for configuring and setting up language servers is with the [nvim-lspconfig plugin](https://github.com/neovim/nvim-lspconfig). This plugin provides configurations for many common language servers (A full list can be found in [nvim-lspconfig server configurations documentation](https://github.com/neovim/nvim-lspconfig/blob/master/doc/configs.md)). These baseline configuration options are not always sufficient to meet everyone's needs. For the complete set of options that can be used when configuraing language servers, check out `:h lsp-config` in your editor.
11
11
12
-
AstroLSP automatically calls these `setup` functions for language servers installed through Mason and for servers specified manually (See [LSP Setup Without Installer](#lsp-setup-without-installer)). AstroLSP also provides a simple `config` table in the plugin's options for extending the built in server configurations provided by `nvim-lspconfig`.
12
+
AstroLSP automatically enables language servers installed through Mason and for servers specified manually (See [LSP Setup Without Installer](#lsp-setup-without-installer)). Neovim allows for easy language server customization within the `lsp/` folder in the root of your configuration (Check out `:h lsp-config`). While the `lsp/` directory is the recommended way to configurat language servers, AstroLSP also provides a simple `config` table in the plugin's options for extending the built in server configurations provided by `nvim-lspconfig`. This can be helpful if you want to conditionally make modifications in your plugin configuration.
13
+
14
+
```lua title="lsp/clangd.lua"
15
+
return {
16
+
capabilities= {
17
+
offsetEncoding="utf-8",
18
+
},
19
+
}
20
+
```
13
21
14
22
```lua title="lua/plugins/astrolsp.lua" {5-13}
15
23
return {
@@ -31,23 +39,34 @@ return {
31
39
32
40
### Custom LSP Definition
33
41
34
-
`nvim-lspconfig` is great, but it doesn't support all language servers that exist. You may want to set up a custom server where you manually define the `cmd` and the `root_dir`. This can also be done completely through `servers` and `config` tables similar to configuring servers that are supported by `nvim-lspconfig`! For these custom servers, the minimum requirement is defining a `cmd` in the `config` entry, but to get automatic starting of language servers you also need to set `filetypes` and `root_dir`. Here is a simple example setting up a Prolog LSP with `swipl`:
42
+
`nvim-lspconfig` is great, but it doesn't support all language servers that exist. You may want to set up a custom server where you manually define the `cmd` and the `root_markers`. This can be achieved by putting a new file in your `lsp/` folder at the root of your configuration with the necessary information. This can also be done completely through `servers` and `config` tables similar to configuring servers that are supported by `nvim-lspconfig`! For these custom servers, the minimum requirement is defining a `cmd` in the `config` entry, but to get automatic starting of language servers you also need to set `filetypes` and `root_markers`. Here is a simple example setting up a Prolog LSP with `swipl`:
35
43
36
-
```lua title="lua/plugins/astrolsp.lua" {6-31}
44
+
```lua title="lsp/prolog_lsp.lua"
37
45
return {
38
-
"AstroNvim/astrolsp",
39
-
-- we need to use the function notation to get access to the `lspconfig` module
40
-
---@paramoptsAstroLSPOpts
41
-
opts=function(plugin, opts)
42
-
-- insert "prolog_lsp" into our list of servers
43
-
opts.servers=opts.serversor {}
44
-
table.insert(opts.servers, "prolog_lsp")
46
+
cmd= {
47
+
"swipl",
48
+
"-g",
49
+
"use_module(library(lsp_server)).",
50
+
"-g",
51
+
"lsp_server:main",
52
+
"-t",
53
+
"halt",
54
+
"--",
55
+
"stdio",
56
+
},
57
+
filetypes= { "prolog" },
58
+
root_markers= { "pack.pl" },
59
+
}
60
+
```
45
61
46
-
-- extend our configuration table to have our new prolog server
AstroNvim comes with [mason-lspconfig](https://github.com/williamboman/mason-lspconfig.nvim) as an easy interface for setting up language servers installed with Mason, but this might not be adequate for all users. The LSP installer doesn't support all of the language servers that Neovim's LSP config supports and some users may already have the language servers installed on their machine and don't want to reinstall it separately. In these cases we have added an easy interface for setting up these servers. The following plugin specification for AstroLSP simply sets up `pyright` language server for a user with `pyright` already available on their system:
91
+
AstroNvim comes with [mason-lspconfig](https://github.com/williamboman/mason-lspconfig.nvim) as an easy interface for setting up language servers installed with Mason, but this might not be adequate for all users. The LSP installer doesn't support all of the language servers that Neovim's LSP config supports and some users may already have the language servers installed on their machine and don't want to reinstall it separately. In these cases we have added an easy interface for enabling these servers. The following plugin specification for AstroLSP simply sets up `pyright` language server for a user with `pyright` already available on their system:
75
92
76
-
```lua title="lua/plugins/astrolsp.lua" {7-12}
93
+
```lua title="lua/plugins/astrolsp.lua" {5}
77
94
return {
78
95
"AstroNvim/astrolsp",
79
-
-- we must use the function override because table merging
80
-
-- does not play nicely with list-like tables
81
-
---@paramoptsAstroLSPOpts
82
-
opts=function(plugin, opts)
83
-
-- safely extend the servers list
84
-
opts.servers=opts.serversor {}
85
-
vim.list_extend(opts.servers, {
86
-
"pyright",
87
-
-- add more servers as needed...
88
-
})
89
-
end,
96
+
---@typeAstroLSPOpts
97
+
opts= {
98
+
servers= { "pyright" },
99
+
},
90
100
}
91
101
```
92
102
@@ -317,45 +327,6 @@ Many of these can be found pre-configured in the [AstroNvim Community Repository
317
327
318
328
There are some plugins available for doing advanced setup of language servers that require the user to not use the `lspconfig` setup call and instead use their own plugin setup for handling this. AstroNvim provides a nice way to do this while still using `mason.nvim` for installing the language servers. You can use the `setup_handlers` table for specifying how language servers should be setup such as using a language specific plugin. This function for each handler has two parameters, the first is the name of the server and the second is the options we would be passing to the `lspconfig` setup call. These options include things such as our built in `capabilities`, `on_attach`, as well as the user defined options in the `config` table. Here are a couple examples for some common LSP plugins:
This is included in the [AstroCommunity TypeScript language pack](https://github.com/AstroNvim/astrocommunity/tree/main/lua/astrocommunity/pack/typescript)
0 commit comments