Skip to content

Commit

Permalink
Update Rust Analyzer to 2023-05-15 (#93)
Browse files Browse the repository at this point in the history
* Update Rust analyzer tag and settings comparison instructions.

* Update `rust-analyzer.check.target` setting to `rust-analyzer.check.targets`.

* Support a few more rust-analyzer settings.

* Prevent crash when Rust Analyzer invokes `triggerParameterHints`.

* update to 2023-05-15

* improve schema

* portable script

---------

Co-authored-by: Rafal Chlodnicki <[email protected]>
  • Loading branch information
azriel91 and rchl authored May 16, 2023
1 parent 5f01b4d commit 23b36c4
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
images/ export-ignore
scripts/ export-ignore
57 changes: 47 additions & 10 deletions LSP-rust-analyzer.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
// Extra environment variables that will be set when running cargo,
// rustc or other commands within the workspace. Useful for setting RUSTFLAGS.
"rust-analyzer.cargo.extraEnv": {},
// Extra arguments that are passed to every cargo invocation.
//
// ```json
// "rust-analyzer.cargo.extraArgs": ["--all-features"],
// ```
"rust-analyzer.cargo.extraArgs": [],
// List of features to activate.
// Set this to `"all"` to pass `--all-features` to cargo.
"rust-analyzer.cargo.features": [],
Expand All @@ -60,6 +66,13 @@
// Relative path to the sysroot, or "discover" to try to automatically find
// it via "rustc --print sysroot". Unsetting this disables sysroot loading.
"rust-analyzer.cargo.sysroot": "discover",
// Relative path to the sysroot library sources. If left unset, this will default to
// `{cargo.sysroot}/lib/rustlib/src/rust/library`.
//
// ```json
// "rust-analyzer.cargo.sysrootSrc": "/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library",
// ```
"rust-analyzer.cargo.sysrootSrc": null,
// Compilation target override (target triple).
"rust-analyzer.cargo.target": null,
// Unsets `#[cfg(test)]` for the specified crates.
Expand Down Expand Up @@ -114,9 +127,11 @@
// ```
// .
"rust-analyzer.check.overrideCommand": null,
// Check for a specific target. Defaults to
// `#rust-analyzer.cargo.target#`.
"rust-analyzer.check.target": null,
// Check for a specific target. Defaults to `#rust-analyzer.cargo.target#`.
//
// Can be a single target, e.g. `\"x86_64-unknown-linux-gnu\"` or a list of targets, e.g.
//`[\"aarch64-apple-darwin\", \"x86_64-apple-darwin\"]`
"rust-analyzer.check.targets": null,
// Toggles the additional completions that automatically add imports when completed.
// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
"rust-analyzer.completion.autoimport.enable": true,
Expand All @@ -126,6 +141,14 @@
// Whether to add parenthesis and argument snippets when completing function.
// possible values: fill_arguments, add_parentheses, none
"rust-analyzer.completion.callable.snippets": "fill_arguments",
// Maximum number of completions to return. If `null`, the limit is infinite.
//
// For a maximum of 5, use:
//
// ```json
// "rust-analyzer.completion.limit": 5,
// ```
"rust-analyzer.completion.limit": null,
// Whether to show postfix snippets like `dbg`, `if`, `not`, etc.
"rust-analyzer.completion.postfix.enable": true,
// Enables completions of private items and fields that are defined in the current workspace even if they are not visible
Expand Down Expand Up @@ -202,6 +225,8 @@
"rust-analyzer.files.watcher": "client",
// Enables highlighting of related references while the cursor is on `break`, `loop`, `while`, or `for` keywords.
"rust-analyzer.highlightRelated.breakPoints.enable": true,
// Enables highlighting of all captures of a closure while the cursor is on the `|` or move keyword of a closure.
"rust-analyzer.highlightRelated.closureCaptures.enable": true,
// Enables highlighting of all exit points while the cursor is on any `return`, `?`, `fn`, or return type arrow (`->`).
"rust-analyzer.highlightRelated.exitPoints.enable": true,
// Enables highlighting of related references while the cursor is on any identifier.
Expand Down Expand Up @@ -231,8 +256,10 @@
// Whether to show keyword hover popups. Only applies when
// `#rust-analyzer.hover.documentation.enable#` is set.
"rust-analyzer.hover.documentation.keywords.enable": true,
// Use markdown syntax for links in hover.
// Use markdown syntax for links on hover.
"rust-analyzer.hover.links.enable": true,
// Whether to show memory layout data on hover.
"rust-analyzer.hover.memoryLayout.enable": true,
// Whether to enforce the import granularity setting for all files. If set to false rust-analyzer will try to keep import
// styles consistent per file.
"rust-analyzer.imports.granularity.enforce": false,
Expand All @@ -258,9 +285,13 @@
// Minimum number of lines required before the `}` until the hint is shown (set to 0 or 1
// to always show them).
"rust-analyzer.inlayHints.closingBraceHints.minLines": 25,
// Whether to show inlay hints for closure captures.
"rust-analyzer.inlayHints.closureCaptureHints.enable": false,
// Whether to show inlay type hints for return types of closures.
// possible values: always, never, with_block
"rust-analyzer.inlayHints.closureReturnTypeHints.enable": "never",
// Closure notation in type and chaining inlay hints.
"rust-analyzer.inlayHints.closureStyle": "impl_fn",
// Whether to show enum variant discriminant hints.
"rust-analyzer.inlayHints.discriminantHints.enable": "never",
// Whether to show inlay hints for type adjustments.
Expand Down Expand Up @@ -290,6 +321,8 @@
"rust-analyzer.inlayHints.typeHints.hideClosureInitialization": false,
// Whether to hide inlay type hints for constructors.
"rust-analyzer.inlayHints.typeHints.hideNamedConstructor": false,
// Enables the experimental support for interpreting tests.
"rust-analyzer.interpret.tests": false,
// Join lines merges consecutive declaration and initialization of an assignment.
"rust-analyzer.joinLines.joinAssignments": true,
// Join lines inserts else between consecutive ifs.
Expand Down Expand Up @@ -333,6 +366,8 @@
"rust-analyzer.linkedProjects": [],
// Number of syntax trees rust-analyzer keeps in memory. Defaults to 128.
"rust-analyzer.lru.capacity": null,
// Sets the LRU capacity of the specified queries.
"rust-analyzer.lru.query.capacities": {},
// Whether to show `can't find Cargo.toml` error message.
"rust-analyzer.notifications.cargoTomlNotFound": true,
// How many worker threads in the main loop. The default `null` means to pick automatically.
Expand All @@ -344,8 +379,7 @@
// These proc-macros will be ignored when trying to expand them.
// This config takes a map of crate names with the exported proc-macro names to ignore as values.
"rust-analyzer.procMacro.ignored": {},
// Internal config, path to proc-macro server executable (typically,
// this is rust-analyzer itself, but we override this in tests).
// Internal config, path to proc-macro server executable.
"rust-analyzer.procMacro.server": null,
// Exclude imports from find-all-references.
"rust-analyzer.references.excludeImports": false,
Expand All @@ -367,8 +401,9 @@
"rust-analyzer.rustc.source": null,
// Additional arguments to `rustfmt`.
"rust-analyzer.rustfmt.extraArgs": [],
// Advanced option, fully override the command rust-analyzer uses for
// formatting.
// Advanced option, fully override the command rust-analyzer uses for formatting. This should be the equivalent
// of `rustfmt` here, and not that of `cargo fmt`. The file contents will be passed on the standard input and
// the formatted result will be read from the standard output.
"rust-analyzer.rustfmt.overrideCommand": null,
// Enables the use of rustfmt's unstable range formatting command for the
// `textDocument/rangeFormatting` request. The rustfmt option is unstable and only
Expand All @@ -378,6 +413,8 @@
// When enabled, rust-analyzer will highlight rust source in doc comments as well as intra
// doc links.
"rust-analyzer.semanticHighlighting.doc.comment.inject.enable": true,
// Whether the server is allowed to emit non-standard tokens and modifiers.
"rust-analyzer.semanticHighlighting.nonStandardTokens": true,
// Use semantic tokens for operators.
// When disabled, rust-analyzer will emit semantic tokens only for operator tokens when
// they are tagged with modifiers.
Expand All @@ -386,14 +423,14 @@
// When enabled, rust-analyzer will emit special token types for operator tokens instead
// of the generic `operator` token type.
"rust-analyzer.semanticHighlighting.operator.specialization.enable": false,
// Use semantic tokens for punctuations.
// Use semantic tokens for punctuation.
// When disabled, rust-analyzer will emit semantic tokens only for punctuation tokens when
// they are tagged with modifiers or have a special role.
"rust-analyzer.semanticHighlighting.punctuation.enable": false,
// When enabled, rust-analyzer will emit a punctuation semantic token for the `!` of macro
// calls.
"rust-analyzer.semanticHighlighting.punctuation.separate.macro.bang": false,
// Use specialized semantic tokens for punctuations.
// Use specialized semantic tokens for punctuation.
// When enabled, rust-analyzer will emit special token types for punctuation tokens instead
// of the generic `punctuation` token type.
"rust-analyzer.semanticHighlighting.punctuation.specialization.enable": false,
Expand Down
20 changes: 14 additions & 6 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@

SESSION_NAME = "rust-analyzer"

# Update this single git tag to download a newer version.
# After changing this tag, go through the server settings again to see
# if any new server settings are added or old ones removed.
# Compare the previous and new tags's editors/code/package.json with
# https://github.com/rust-lang/rust-analyzer/compare/2023-01-16...2023-01-30
TAG = "2023-01-30"
TAG = "2023-05-15"
"""
Update this single git tag to download a newer version.
After changing this tag, go through the server settings again to see
if any new server settings are added or old ones removed.
Compare the previous and new tags's editors/code/package.json with
https://github.com/rust-lang/rust-analyzer/compare/2023-01-30...2023-05-15
The script in `./scripts/new_settings.sh can be used to find the keys that are in the `rust-analyzer`
package.json, but not in `LSP-rust-analyzer`'s sublime-settings.
"""

URL = "https://github.com/rust-analyzer/rust-analyzer/releases/download/{tag}/rust-analyzer-{arch}-{platform}.gz"

Expand Down Expand Up @@ -186,6 +191,9 @@ def on_pre_server_command(self, command: Mapping[str, Any], done_callback: Calla
return True
elif command_name == "rust-analyzer.showReferences":
return self._handle_show_references(session, command, done_callback)
elif command_name == "rust-analyzer.triggerParameterHints":
done_callback()
return True
else:
return False
except Exception as ex:
Expand Down
30 changes: 30 additions & 0 deletions scripts/new_settings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

# The following script finds the keys that are in the `rust-analyzer`
# package.json, but not in `LSP-rust-analyzer`'s sublime-settings.

# exit when any command fails
set -e

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
LSP_REPO_DIR="$SCRIPT_DIR/.."

read -rp 'Provide directory path to the rust-analyzer repository (for example: /usr/local/github/rust-analyzer/): ' RA_REPO_DIR
if [ ! -d "$RA_REPO_DIR" ]; then
echo "Directory path '$RA_REPO_DIR' DOES NOT exist."
exit
fi

lsp_ra_settings=$(rg -o '"rust-analyzer.([^"]+)"' "${LSP_REPO_DIR}/LSP-rust-analyzer.sublime-settings" | sort)
ra_settings=$(jq '.contributes.configuration.properties
| to_entries
| map(.key)
| .[] | select(. != "$generated-start" and . != "$generated-end")' \
"${RA_REPO_DIR}/editors/code/package.json" | sort)

# Missing settings in LSP-rust-analyzer
rg -vf <(echo "${lsp_ra_settings}") <(echo "${ra_settings}")

# Settings in LSP-rust-analyzer that are no longer relevant
rg -vf <(echo "${ra_settings}") <(echo "${lsp_ra_settings}") \
| rg -v 'terminusAutoClose|terminusUsePanel'
Loading

0 comments on commit 23b36c4

Please sign in to comment.