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.
- Features
- Installation
- Configuration
- Troubleshooting
- How does it work?
- Thanks
- Roadmap to 1.0 - β done π in progress π future
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.
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.
- Read diagnostics from produced by Bacon.
- Push diagnostics to the LSP client on certain events like saving or files changes.
- Precise diagnostics positions.
- Ability to react to changes over document saves and changes that can be configured.
- Replacement code actions as suggested by
clippy
. - Automatic validation of
bacon
preferences to ensurebacon-ls
can work with them.
- Diagnostics are only synced to the currently open file - #11
- To sync diagnostics to other files, the files must be open and saved or changed.
- Windows support is not tested and probably broken - #10
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-vscode
Both 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.7.0 # make sure you have at least 3.7.0
β―β―β― bacon-ls --version
0.9.0 # make sure you have at least 0.9.0
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", "--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}|:|{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
.
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).validateBaconPreferences
: Try to validate thatbacon
preferences are setup correctly to work withbacon-ls
(default: true).
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
updateOnChange = false
...
}
})
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 disabled for bacon-ls
to work properly:
- Untick
Rust-analyzer -> general -> Check On Save
- Untick
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,
\ 'updateOnChange': v:false
\ },
\ 'settings': {}
\ }
\ })
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.
- β
Implement LSP server interface for
textDocument/diagnostic
andworkspace/diagnostic
- β Manual Neovim configuration
- β Manual LazyVim configuration
- β
Automatic NeoVim configuration
- β
Add
bacon-ls
to nvim-lspconfig - neovim/nvim-lspconfig#3160 - β
Add
bacon
andbacon-ls
to mason.nvim - mason-org/mason-registry#5774 - β
Add
bacon-ls
to LazyVim Rust extras - LazyVim/LazyVim#3212
- β
Add
- β Add compiler hints to Bacon export locations - Canop/bacon#187 Canop/bacon#188
- β
Support correct span in Bacon export locations - working from
bacon
3.7 andbacon-ls
0.6.0 - β VSCode extension and configuration - available on the release page from 0.6.0
- β VSCode extension published available on Marketplace
- β
Add
bacon-ls
tobacon
website - Canop/bacon#289 - β Smarter handling of parsing the Bacon locations file
- β Faster response after a save event
- β Replacement code actions
- β
Validate
bacon
preferences and return an error to the LSP client if they are not compatible withbacon
- working frombacon-ls
0.9.0 - π Start
bacon
in background based on user preferences - π Emacs configuration