Skip to content

Commit 184ec8c

Browse files
committed
feat(advanced_lsp): add documentation on LSP file operations
1 parent 15f5508 commit 184ec8c

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/content/docs/recipes/advanced_lsp.mdx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,43 @@ return {
270270
}
271271
```
272272

273+
## LSP File Operations
274+
275+
AstroLSP provides a complete implementation of the file manipulation features provided by the [LSP Specification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_willCreateFiles) through the [`astrolsp.file_operations` module](https://github.com/AstroNvim/astrolsp/blob/main/doc/api.md#astrolspfile_operations). These operations are useful when language servers provide functionality such as automatically updating import statements when files are renamed. Currently this includes:
276+
277+
- `workspace/willCreateFiles`
278+
- `workspace/didCreateFiles`
279+
- `workspace/willRenameFiles`
280+
- `workspace/didRenameFiles`
281+
- `workspace/willDeleteFiles`
282+
- `workspace/didDeleteFiles`
283+
284+
This functionality was introduced in AstroNvim v4 disabled by default and will be enabled by default starting in AstroNvim v5. The module is used to integrate with the Neo-tree file explorer out of the box as well as the file renaming capability provided by AstroCore (`require("astrocore").rename_file()` which is bound to `<Leader>R`).
285+
286+
To enable the file operations in AstroNvim v4, you can configure them through the AstroLSP plugin `opts`:
287+
288+
```lua title="lua/plugins/astrolsp.lua" {5-15}
289+
return {
290+
"AstroNvim/astrolsp",
291+
---@type AstroLSPOpts
292+
opts = {
293+
file_operations = {
294+
timeout = 10000, -- default timeout in ms for completing LSP operations
295+
operations = { -- enable all of the file operations
296+
willCreate = true,
297+
didCreate = true,
298+
willRename = true,
299+
didRename = true,
300+
willDelete = true,
301+
didDelete = true,
302+
},
303+
},
304+
},
305+
}
306+
```
307+
308+
The `astrolsp.file_operations` module is meant to provide a simple Lua API to allow easy integration with any file management plugins/workflows that users may have. Some example integration code can be found in the [AstroLSP Documentation](https://github.com/AstroNvim/astrolsp/tree/main#lsp-file-operations). Many of the AstroCommunity plugins such as [`mini.files`](https://astronvim.github.io/astrocommunity/#mini-files) already provide the necessary integration to execute the LSP file operations when appropriate.
309+
273310
## LSP Specific Plugins
274311

275312
:::tip

0 commit comments

Comments
 (0)