bacon-ls

Crates.iobacon-ls
lib.rsbacon-ls
version
sourcesrc
created_at2024-05-17 22:49:59.955751
updated_at2025-01-02 17:58:22.955312
descriptionBacon Language Server
homepagehttps://github.com/crisidev/bacon-ls
repositoryhttps://github.com/crisidev/bacon-ls
max_upload_size
id1243779
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Matteo Bigoi (crisidev)

documentation

https://github.com/crisidev/bacon-ls

README

🐽 Bacon Language Server 🐽

Ci Release Crates.io License

NOTE: bacon-ls 0.5 has breaking changes and will work only with bacon 3.7+. The README for bacon-ls 0.4 can be found here.

LSP Server wrapper for the exceptional Bacon exposing textDocument/diagnostic and workspace/diagnostic capabilities.

See bacon-ls 🐽 blog post: https://lmno.lol/crisidev/bacon-language-server

Bacon screenshot

bacon-ls 🐽 is meant to be easy to include in your IDE configuration.

Roadmap to 1.0 - ✅ done 🕖 in progress 🌍 future

Bacon gif

Installation

Mason.nvim

Both Bacon and Bacon-ls are installable via mason.nvim:

:MasonInstall bacon bacon-ls

Manual

First, install Bacon and bacon-ls 🐽

❯❯❯ cargo install --locked bacon bacon-ls
❯❯❯ bacon --version
bacon 3.7.0  # make sure you have at least 3.7.0
❯❯❯ bacon-ls --version
0.5.0        # make sure you have at least 0.5.0

Configuration

Configure Bacon export settings with bacon-ls 🐽 export format and proper span support in ~/.config/bacon/prefs.toml:

[jobs.bacon-ls]
command = [ "cargo", "clippy", "--tests", "--all-targets", "--all-features", "--message-format", "json-diagnostic-rendered-ansi" ]
analyzer = "cargo_json"
need_stdout = true

[exports.cargo-json-spans]
auto = true
exporter = "analyzer"
line_format = "{diagnostic.level}:{span.file_name}:{span.line_start}:{span.line_end}:{span.column_start}:{span.column_end}:{diagnostic.message}"
path = ".bacon-locations"

NOTE: bacon MUST be running to generate the export locations with the bacon-ls job: bacon -j bacon-ls.

The language server can be configured using the appropriate LSP protocol and supports the following values:

  • locationsFile Bacon export filename (default: .bacon-locations).
  • updateOnSave Try to update diagnostics every time the file is saved (default: true).
  • updateOnSaveWaitMillis How many milliseconds to wait before updating diagnostics after a save (default: 1000).
  • updateOnChange Try to update diagnostics every time the file changes (default: false).

Neovim - LazyVim

vim.g.lazyvim_rust_diagnostics = "bacon-ls"

Neovim - Manual

NeoVim requires nvim-lspconfig to be configured and rust-analyzer diagnostics must be turned off for bacon-ls 🐽 to properly function.

bacon-ls is part of nvim-lspconfig from commit 6d2ae9f and it can be configured like any other LSP server works best when vim.diagnostics.opts.update_in_insert is set to true.

require("lspconfig").bacon_ls.setup({
    init_options = {
        updateOnSave = true
        updateOnSaveWaitMillis = 1000
        updateOnChange = true
    }
})

For rust-analyzer, these 2 options must be turned off:

rust-analyzer.checkOnSave.enable = false
rust-analyzer.diagnostics.enable = false

Vscode

The Vscode extension is not ready yet but should be part of Bacon-ls 0.6.0.

Troubleshooting

bacon-ls 🐽 can produce a log file in the folder where its running by exporting the RUST_LOG variable in the shell:

❯❯❯ export RUST_LOG=debug
❯❯❯ nvim src/some-file.rs
# or
❯❯❯ RUST_LOG=debug nvim src/some-file.rs
❯❯❯ tail -F ./bacon-ls.log

How does it work?

bacon-ls 🐽 reads the diagnostics location list generated by Bacon's export-locations and exposes them on STDIO over the LSP protocol to be consumed by the client diagnostics.

It requires Bacon to be running alongside to ensure regular updates of the export locations.

The LSP client reads them as response to textDocument/diagnostic and workspace/diagnostic.

Thanks

bacon-ls 🐽 has been inspired by typos-lsp.

Commit count: 84

cargo fmt