Crates.io | bacon-ls |
lib.rs | bacon-ls |
version | 0.23.0 |
created_at | 2024-05-17 22:49:59.955751+00 |
updated_at | 2025-09-19 14:05:42.44285+00 |
description | Bacon Language Server |
homepage | https://github.com/crisidev/bacon-ls |
repository | https://github.com/crisidev/bacon-ls |
max_upload_size | |
id | 1243779 |
size | 3,685,064 |
Are you tired of rust-analyzer diagnostics being slow?
LSP Server wrapper for the exceptional Bacon exposing textDocument/diagnostic and workspace/diagnostic capabilities.
bacon-ls
🐽 does not substitute rust-analyzer
, it's a companion tool that can help with large
codebases where rust-analyzer
can become slow dealing with diagnostics.
bacon-ls
🐽 does not help with completion, analysis, refactor, etc... For these, rust-analyzer
must be running.
See bacon-ls
🐽 blog post: https://lmno.lol/crisidev/bacon-language-server
bacon-ls
🐽 is meant to be easy to include in your IDE configuration.
clippy
.bacon
preferences to ensure bacon-ls
can work with them.bacon
in background based on user preferences (requires bacon
3.8.0).First, install Bacon.
The VSCode extension is available on both VSCE and OVSX:
VSCE
https://marketplace.visualstudio.com/items?itemName=MatteoBigoi.bacon-ls-vscodeOVSX
https://open-vsx.org/extension/MatteoBigoi/bacon-ls-vscodeBoth Bacon and Bacon-ls are installable via mason.nvim:
:MasonInstall bacon bacon-ls
First, install Bacon and bacon-ls
🐽
❯❯❯ cargo install --locked bacon bacon-ls
❯❯❯ bacon --version
bacon 3.8.0 # make sure you have at least 3.8.0
❯❯❯ bacon-ls --version
0.14.0 # make sure you have at least 0.14.0
Both bacon and bacon-ls can be consumed from their Nix flakes.
This backend will just run cargo
with json diagnostics enabled, parse them and update diagnostics.
**NOTE: from bacon-ls
v0.23.0, this is the default backend because it is faster and lighter than running bacon
.
NOTE: This works only with bacon-ls
is configured with initOptions = { useBaconBackend = true }
Configure Bacon export settings with bacon-ls
🐽 export format and proper span support in the bacon
preference file.
To find where the file should be saved, you can use the command bacon --prefs
:
[jobs.bacon-ls]
command = [
"cargo", "clippy",
"--workspace", "--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}|:|{diagnostic.rendered}|:|\
{span.suggested_replacement}\
"""
path = ".bacon-locations"
NOTE: bacon
MUST be running to generate the export locations with the bacon-ls
job: bacon -j bacon-ls
.
From bacon-ls
0.10.0, this is done automatically if the option runBaconInBackground
is set to true.
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).useBaconBackend
if true
, the backend spawning bacon
will be used instead of the native (faster) Cargo backend.validateBaconPreferences
: Try to validate that bacon
preferences are setup correctly to work with bacon-ls
(default: true).createBaconPreferencesFile
: If no bacon
preferences file is found, create a new preferences file with the bacon-ls
job definition (default: true).runBaconInBackground
: Run bacon
in background for the bacon-ls
job (default: true)runBaconInBackgroundCommand
: Path to the command used to run bacon
in the background (defaults to find in $PATH
).runBaconInBackgroundCommandArguments
: Command line arguments to pass to bacon
running in background (default "--headless -j bacon-ls")synchronizeAllOpenFilesWaitMillis
: How many milliseconds to wait between background diagnostics check to synchronize all open files (default: 2000).vim.g.lazyvim_rust_diagnostics = "bacon-ls"
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
...
}
})
For rust-analyzer
, these 2 options must be turned off:
rust-analyzer.checkOnSave.enable = false
rust-analyzer.diagnostics.enable = false
The extension can be configured using the VSCode settings interface.
It is very important that rust-analyzer Check On Save
and Diagnostics
are turned off for bacon-ls
to work properly:
Rust-analyzer -> general -> Check On Save
Rust-analyzer -> diagnostics -> Enable
call coc#config('languageserver', {
\ 'bacon-ls': {
\ 'command': '~/.cargo/bin/bacon-ls',
\ 'filetypes': ['rust'],
\ 'rootPatterns': ['.git/', 'Cargo.lock', 'Cargo.toml'],
\ 'initializationOptions': {
\ 'updateOnSave': v:true,
\ 'updateOnSaveWaitMillis': 1000,
\ },
\ 'settings': {}
\ }
\ })
Extend your languages.toml
with the following:
[[language]]
name = "rust"
language-servers = ["rust-analyzer", "bacon-ls"]
[language-server.rust-analyzer.config]
checkOnSave = { enable = false }
diagnostics = { enable = false }
[language-server.bacon-ls]
command = "bacon-ls"
bacon-ls
🐽 can produce a log file in the folder where its running by exporting the RUST_LOG
variable in the shell:
If the bacon
preference are not correct, an error message will be published to the LSP client, advising the user to
check the README.
❯❯❯ export RUST_LOG=debug
❯❯❯ nvim src/some-file.rs # or vim src/some-file.rs
# the variable can also be exported for the current command and not for the whole shell
❯❯❯ RUST_LOG=debug nvim src/some-file.rs # or RUST_LOG=debug vim src/some-file.rs
❯❯❯ tail -F ./bacon-ls.log
Enable debug logging in the extension options.
❯❯❯ tail -F ./bacon-ls.log
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
.
bacon-ls
🐽 has been inspired by typos-lsp.
textDocument/diagnostic
and workspace/diagnostic
bacon-ls
to nvim-lspconfig - https://github.com/neovim/nvim-lspconfig/pull/3160bacon
and bacon-ls
to mason.nvim - https://github.com/mason-org/mason-registry/pull/5774bacon-ls
to LazyVim Rust extras - https://github.com/LazyVim/LazyVim/pull/3212bacon
3.7 and bacon-ls
0.6.0bacon-ls
to bacon
website - https://github.com/Canop/bacon/pull/289bacon
preferences and return an error to the LSP client if they are not compatible with bacon
- working from bacon-ls
0.9.0bacon
preferences file if not found on disk - working from bacon-ls
0.10.0bacon
in background based on user preferences - working from bacon-ls
0.10.0bacon-ls
0.10.0bacon-ls
0.12.0bacon-ls
0.14.0bacon-ls
0.23.0