Skip to content

Commit

Permalink
Add configuration guide for Neovim (#270)
Browse files Browse the repository at this point in the history
* docs(neovim): add configuration guide for Neovim as LSP client

Introduce a new documentation file for configuring Neovim as a
Language Server Protocol (LSP) client using nvim-lspconfig and
conform.nvim. This guide provides step-by-step instructions for
setting up Air as an LSP client and enabling automatic formatting
on save. Update the main editors documentation to include a link
to the new Neovim guide, expanding the list of supported editors.

* docs(neovim): simplify LSP client configuration for Air by using default setup method

* Update docs/editor-neovim.qmd

Co-authored-by: Tymoteusz Makowski <[email protected]>

* Update docs/editor-neovim.qmd

Co-authored-by: Tymoteusz Makowski <[email protected]>

* Update docs/editor-neovim.qmd

Tx!

Co-authored-by: Tymoteusz Makowski <[email protected]>

* docs(editor-neovim): simplify conform.nvim configuration example and add link to documentation for further guidance

* Update docs/editor-neovim.qmd

Co-authored-by: Lionel Henry <[email protected]>

* Update docs/editor-neovim.qmd

Co-authored-by: Lionel Henry <[email protected]>

* Update docs/editor-neovim.qmd

Co-authored-by: Lionel Henry <[email protected]>

* Update docs/editor-neovim.qmd

Co-authored-by: Lionel Henry <[email protected]>

* Update docs/editor-neovim.qmd

Co-authored-by: Lionel Henry <[email protected]>

* docs(editor-neovim): update LSP configuration to auto-format R code on save and disable conflicting formatter

* Let Visual Editor do its thing

* Add to sidebar

* Capitalization

* Align with format of other `editor-` guides

* Tweak

---------

Co-authored-by: Tymoteusz Makowski <[email protected]>
Co-authored-by: Lionel Henry <[email protected]>
Co-authored-by: Davis Vaughan <[email protected]>
  • Loading branch information
4 people authored Mar 3, 2025
1 parent aeb4910 commit cc7f6bc
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/_quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ website:
contents:
- editor-rstudio.qmd
- editor-vscode.qmd
- editor-neovim.qmd

- text: "Configuration"
href: configuration.qmd
Expand Down
69 changes: 69 additions & 0 deletions docs/editor-neovim.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
title: "Neovim"
editor:
markdown:
wrap: sentence
canonical: true
---

Air provides first class support for Neovim, which supports the [Language Server Protocol](https://microsoft.github.io/language-server-protocol/).

# Installation

First, install the Air [command line tool](cli.qmd).

We recommend configuring Air as an LSP server via [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig).
While the Air language server currently only supports formatting, it will gain more features in future.
Add the following to your `init.lua`:

``` lua
require("lspconfig").air.setup({
on_attach = function(_, bufnr)
vim.api.nvim_create_autocmd("BufWritePre", {
buffer = bufnr,
callback = function()
vim.lsp.buf.format()
end,
})
end,
})
```

While not required, the `BufWritePre` command ensures that Air automatically formats your R code when you save a file.

## languageserver

If both Air and `languageserver` are installed, you can use the following configuration to disable `languageserver` formatting, ensuring that only Air handles formatting:

``` lua
require("lspconfig").r_language_server.setup({
on_attach = function(client, _)
client.server_capabilities.documentFormattingProvider = false
client.server_capabilities.documentRangeFormattingProvider = false
end,
})
```

# Features

## Format on save

With the `BufWritePre` hook recommended in the configuration step, Air will format your R files on every save.

<!--# Come back and add video -->

## Quarto

As an LSP, Air itself does not provide direct support for Quarto or RMarkdown documents.
However, Air can additionally be configured as a formatter plugin for [conform.nvim](https://github.com/stevearc/conform.nvim), which supports ["injected language formatting"](https://github.com/stevearc/conform.nvim/blob/master/doc/advanced_topics.md#injected-language-formatting-code-blocks) for code blocks in Markdown, Quarto, and RMarkdown.
Conform can be configured by adding the following to your `nvim/lua/plugins/conform.lua`:

``` lua
require("conform").setup({
formatters_by_ft = {
r = { "air" },
},
})
```

See the [conform.nvim documentation](https://github.com/stevearc/conform.nvim?tab=readme-ov-file#installation) for more information on how to configure conform.nvim with your favorite plugin manager.
2 changes: 2 additions & 0 deletions docs/editors.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ Follow one of our editor specific guides to get set up with Air in your preferre
- [Positron](editor-vscode.qmd)

- [RStudio](editor-rstudio.qmd)

- [Neovim](editor-neovim.qmd)

0 comments on commit cc7f6bc

Please sign in to comment.