Skip to content

Commit dc6fe89

Browse files
committed
feat: start migrating documentation to be applicable to AstroLSP v4
1 parent 991b203 commit dc6fe89

3 files changed

Lines changed: 58 additions & 108 deletions

File tree

src/content/docs/configuration/lua_completion.mdx

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,6 @@ return {
2828
}
2929
```
3030

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-
---@type AstroLSPOpts
45-
opts = {
46-
---@diagnostic disable: missing-fields
47-
config = {
48-
-- LSP options and server configuration go here...
49-
},
50-
},
51-
}
52-
```
53-
54-
:::
55-
5631
### `opts` Function
5732

5833
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.

src/content/docs/recipes/advanced_lsp.mdx

Lines changed: 57 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@ LSP configuration is mostly done through the help of [AstroLSP](https://github.c
77

88
## Configuring Language Servers
99

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.
1111

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+
```
1321

1422
```lua title="lua/plugins/astrolsp.lua" {5-13}
1523
return {
@@ -31,23 +39,34 @@ return {
3139

3240
### Custom LSP Definition
3341

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`:
3543

36-
```lua title="lua/plugins/astrolsp.lua" {6-31}
44+
```lua title="lsp/prolog_lsp.lua"
3745
return {
38-
"AstroNvim/astrolsp",
39-
-- we need to use the function notation to get access to the `lspconfig` module
40-
---@param opts AstroLSPOpts
41-
opts = function(plugin, opts)
42-
-- insert "prolog_lsp" into our list of servers
43-
opts.servers = opts.servers or {}
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+
```
4561

46-
-- extend our configuration table to have our new prolog server
47-
opts.config = require("astrocore").extend_tbl(opts.config or {}, {
48-
-- this must be a function to get access to the `lspconfig` module
62+
```lua title="lua/plugins/astrolsp.lua" {6-23}
63+
return {
64+
"AstroNvim/astrolsp",
65+
---@type AstroLSPOpts
66+
opts = {
67+
servers = { "prolog_lsp" }, -- always necessary to tell AstroNvim to enable the language server
68+
config = { -- only necessary if not configured through `lsp/`
4969
prolog_lsp = {
50-
-- the command for starting the server
5170
cmd = {
5271
"swipl",
5372
"-g",
@@ -59,34 +78,25 @@ return {
5978
"--",
6079
"stdio",
6180
},
62-
-- the filetypes to attach the server to
6381
filetypes = { "prolog" },
64-
-- root directory detection for detecting the project root
65-
root_dir = require("lspconfig.util").root_pattern("pack.pl"),
82+
root_markers = { "pack.pl" },
6683
},
67-
})
68-
end,
84+
},
85+
},
6986
}
7087
```
7188

7289
### LSP Setup Without Installer
7390

74-
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:
7592

76-
```lua title="lua/plugins/astrolsp.lua" {7-12}
93+
```lua title="lua/plugins/astrolsp.lua" {5}
7794
return {
7895
"AstroNvim/astrolsp",
79-
-- we must use the function override because table merging
80-
-- does not play nicely with list-like tables
81-
---@param opts AstroLSPOpts
82-
opts = function(plugin, opts)
83-
-- safely extend the servers list
84-
opts.servers = opts.servers or {}
85-
vim.list_extend(opts.servers, {
86-
"pyright",
87-
-- add more servers as needed...
88-
})
89-
end,
96+
---@type AstroLSPOpts
97+
opts = {
98+
servers = { "pyright" },
99+
},
90100
}
91101
```
92102

@@ -317,45 +327,6 @@ Many of these can be found pre-configured in the [AstroNvim Community Repository
317327

318328
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:
319329

320-
### Typescript ([typescript.nvim](https://github.com/jose-elias-alvarez/typescript.nvim))
321-
322-
:::tip
323-
324-
This is included in the [AstroCommunity TypeScript language pack](https://github.com/AstroNvim/astrocommunity/tree/main/lua/astrocommunity/pack/typescript)
325-
326-
```lua title="lua/community.lua" ins={3}
327-
return {
328-
"AstroNvim/astrocommunity",
329-
{ import = "astrocommunity.pack.typescript" },
330-
}
331-
```
332-
333-
:::
334-
335-
```lua title="lua/plugins/typescript.lua"
336-
return {
337-
{ "jose-elias-alvarez/typescript.nvim", lazy = true }, -- add lsp plugin
338-
{
339-
"AstroNvim/astrolsp",
340-
---@type AstroLSPOpts
341-
opts = {
342-
setup_handlers = {
343-
-- add custom handler
344-
tsserver = function(_, opts)
345-
require("typescript").setup({ server = opts })
346-
end,
347-
},
348-
},
349-
},
350-
{
351-
"WhoIsSethDaniel/mason-tool-installer.nvim",
352-
opts = {
353-
ensure_installed = { "typescript-language-server" }, -- automatically install lsp
354-
},
355-
},
356-
}
357-
```
358-
359330
### Deno ([deno-nvim](https://github.com/sigmaSd/deno-nvim))
360331

361332
:::tip
@@ -621,19 +592,24 @@ return {
621592
```lua title="lua/plugins/rustaceanvim.lua"
622593
return {
623594
{
624-
'mrcjkb/rustaceanvim', -- add lsp plugin
625-
version = '^5',
595+
"mrcjkb/rustaceanvim", -- add lsp plugin
596+
version = "^5",
626597
lazy = false, -- This plugin is already lazy
627598
opts = function(_, opts)
628599
local astrolsp_avail, astrolsp = pcall(require, "astrolsp")
629-
local astrolsp_opts = (astrolsp_avail and astrolsp.lsp_opts "rust_analyzer") or {}
600+
local astrolsp_opts = (
601+
astrolsp_avail and astrolsp.lsp_opts("rust_analyzer")
602+
) or {}
630603
local server = {
631604
---@type table | (fun(project_root:string|nil, default_settings: table|nil):table) -- The rust-analyzer settings or a function that creates them.
632605
settings = function(project_root, default_settings)
633606
local astrolsp_settings = astrolsp_opts.settings or {}
634607

635-
local merge_table = require("astrocore").extend_tbl(default_settings or {}, astrolsp_settings)
636-
local ra = require "rustaceanvim.config.server"
608+
local merge_table = require("astrocore").extend_tbl(
609+
default_settings or {},
610+
astrolsp_settings
611+
)
612+
local ra = require("rustaceanvim.config.server")
637613
-- load_rust_analyzer_settings merges any found settings with the passed in default settings table and then returns that table
638614
return ra.load_rust_analyzer_settings(project_root, {
639615
settings_file_pattern = "rust-analyzer.json",
@@ -644,8 +620,10 @@ return {
644620
return { server = require("astrocore").extend_tbl(astrolsp_opts, server) }
645621
end,
646622
-- configure `rustaceanvim` by setting the `vim.g.rustaceanvim` variable
647-
config = function(_, opts) vim.g.rustaceanvim = require("astrocore").extend_tbl(opts, vim.g.rustaceanvim) end,
648-
623+
config = function(_, opts)
624+
vim.g.rustaceanvim =
625+
require("astrocore").extend_tbl(opts, vim.g.rustaceanvim)
626+
end,
649627
},
650628
{
651629
"AstroNvim/astrolsp",

src/content/docs/reference/autocmds.mdx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,11 @@ Neovim autocmd events, check the help page with `:h autocmd-events`.
3535
AstroCore. This event fires if a file is read into a buffer that exceeds these
3636
limits.
3737

38-
- `AstroLspSetup`: AstroNvim has a lot of internal tooling surrounding setting
39-
up handlers for the internal LSP mechanisms. `AstroLspSetup` is triggered when
40-
we have finished setting up these handlers and configuring `lspconfig`.
41-
4238
- `AstroUpdateCompleted`: AstroNvim provides a custom command for easily
4339
updating all plugins and packages using `:AstroUpdate`.
4440
`AstroUpdateCompleted` is triggered after all of the available updates have
4541
been applied. Useful for headless updates:
42+
4643
```bash
4744
nvim --headless -c "autocmd User AstroUpdateCompleted quitall" -c "AstroUpdate"
4845
```

0 commit comments

Comments
 (0)