Skip to content

Commit

Permalink
feat: deprecate rust-analyzer.json
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Sep 14, 2024
1 parent 5610d5e commit 7d917be
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- Deprecate `rust-analyzer.json` in favour of `.vscode/settings.json`
or `:h exrc`.

## [5.4.2] - 2024-09-12

### Fixed
Expand Down
21 changes: 3 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -799,30 +799,15 @@ end

### How to dynamically load different `rust-analyzer` settings per project

By default, this plugin will look for a `rust-analyzer.json`[^2]
file in the project root directory, and attempt to load it.
By default, this plugin will look for a `.vscode/settings.json`[^2]
file and attempt to load it.
If the file does not exist, or it can't be decoded,
the `server.default_settings` will be used.

[^2]: See [this example](https://github.com/rust-analyzer/rust-project.json-example/blob/master/.vscode/settings.json)
and the rust-analyzer [configuration manual](https://rust-analyzer.github.io/manual.html#configuration).

You can change this behaviour with the `server.settings` config:

```lua
vim.g.rustaceanvim = {
-- ...
server = {
---@param project_root string Path to the project root
settings = function(project_root)
local ra = require('rustaceanvim.config.server')
return ra.load_rust_analyzer_settings(project_root, {
settings_file_pattern = 'rust-analyzer.json'
})
end,
},
}
```
Another option is to use `:h exrc`.

## :stethoscope: Troubleshooting

Expand Down
8 changes: 6 additions & 2 deletions lua/rustaceanvim/config/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
local server = {}

---@class rustaceanvim.LoadRASettingsOpts
---@field settings_file_pattern string|nil File name or pattern to search for. Defaults to 'rust-analyzer.json'
---@field default_settings table|nil Default settings to merge the loaded settings into
---
---(deprecated) File name or pattern to search for. Defaults to 'rust-analyzer.json'
---@field settings_file_pattern string|nil
---Default settings to merge the loaded settings into.
---@field default_settings table|nil

--- Load rust-analyzer settings from a JSON file,
--- falling back to the default settings if none is found or if it cannot be decoded.
Expand Down Expand Up @@ -43,6 +46,7 @@ function server.load_rust_analyzer_settings(project_root, opts)
if #results == 0 then
return default_settings
end
vim.deprecate('rust-analyzer.json', "'.vscode/settings.json' or ':h exrc'", '6.0.0', 'rustaceanvim')
local config_json = results[1]
local content = os.read_file(config_json)
if not content then
Expand Down

0 comments on commit 7d917be

Please sign in to comment.