diff options
-rw-r--r-- | Cargo.lock | 4 | ||||
-rw-r--r-- | crates/project_model/src/build_data.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 2 | ||||
-rw-r--r-- | crates/stdx/src/lib.rs | 15 | ||||
-rw-r--r-- | docs/user/generated_config.adoc | 5 | ||||
-rw-r--r-- | editors/code/package-lock.json | 4 | ||||
-rw-r--r-- | editors/code/package.json | 5 | ||||
-rw-r--r-- | editors/code/src/config.ts | 1 | ||||
-rw-r--r-- | editors/code/src/inlay_hints.ts | 52 |
10 files changed, 66 insertions, 26 deletions
diff --git a/Cargo.lock b/Cargo.lock index 8e50ac8b0..ba6862e98 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -841,9 +841,9 @@ dependencies = [ | |||
841 | 841 | ||
842 | [[package]] | 842 | [[package]] |
843 | name = "lsp-server" | 843 | name = "lsp-server" |
844 | version = "0.5.0" | 844 | version = "0.5.1" |
845 | source = "registry+https://github.com/rust-lang/crates.io-index" | 845 | source = "registry+https://github.com/rust-lang/crates.io-index" |
846 | checksum = "69b18dfe0e4a380b872aa79d8e0ee6c3d7a9682466e84b83ad807c88b3545f79" | 846 | checksum = "6825d7042d5ca1825a366c40c9446928ec7b30e2be97243a13b164aee6583992" |
847 | dependencies = [ | 847 | dependencies = [ |
848 | "crossbeam-channel", | 848 | "crossbeam-channel", |
849 | "log", | 849 | "log", |
diff --git a/crates/project_model/src/build_data.rs b/crates/project_model/src/build_data.rs index faca336de..7b88dca63 100644 --- a/crates/project_model/src/build_data.rs +++ b/crates/project_model/src/build_data.rs | |||
@@ -143,7 +143,7 @@ impl WorkspaceBuildData { | |||
143 | cmd.env("RA_RUSTC_WRAPPER", "1"); | 143 | cmd.env("RA_RUSTC_WRAPPER", "1"); |
144 | } | 144 | } |
145 | 145 | ||
146 | cmd.args(&["check", "--workspace", "--message-format=json", "--manifest-path"]) | 146 | cmd.args(&["check", "--quiet", "--workspace", "--message-format=json", "--manifest-path"]) |
147 | .arg(cargo_toml.as_ref()); | 147 | .arg(cargo_toml.as_ref()); |
148 | 148 | ||
149 | // --all-targets includes tests, benches and examples in addition to the | 149 | // --all-targets includes tests, benches and examples in addition to the |
diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml index 0571a912c..3e8f4bf89 100644 --- a/crates/rust-analyzer/Cargo.toml +++ b/crates/rust-analyzer/Cargo.toml | |||
@@ -33,7 +33,7 @@ serde_path_to_error = "0.1" | |||
33 | threadpool = "1.7.1" | 33 | threadpool = "1.7.1" |
34 | rayon = "1.5" | 34 | rayon = "1.5" |
35 | mimalloc = { version = "0.1.19", default-features = false, optional = true } | 35 | mimalloc = { version = "0.1.19", default-features = false, optional = true } |
36 | lsp-server = "0.5.0" | 36 | lsp-server = "0.5.1" |
37 | tracing = "0.1" | 37 | tracing = "0.1" |
38 | tracing-subscriber = { version = "0.2", default-features = false, features = ["env-filter", "registry"] } | 38 | tracing-subscriber = { version = "0.2", default-features = false, features = ["env-filter", "registry"] } |
39 | tracing-tree = { version = "0.1.4" } | 39 | tracing-tree = { version = "0.1.4" } |
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index d81ee94ee..28bbbce19 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs | |||
@@ -145,6 +145,8 @@ config_data! { | |||
145 | inlayHints_parameterHints: bool = "true", | 145 | inlayHints_parameterHints: bool = "true", |
146 | /// Whether to show inlay type hints for variables. | 146 | /// Whether to show inlay type hints for variables. |
147 | inlayHints_typeHints: bool = "true", | 147 | inlayHints_typeHints: bool = "true", |
148 | /// Whether inlay hints font size should be smaller than editor's font size. | ||
149 | inlayHints_smallerHints: bool = "true", | ||
148 | 150 | ||
149 | /// Whether to show `Debug` lens. Only applies when | 151 | /// Whether to show `Debug` lens. Only applies when |
150 | /// `#rust-analyzer.lens.enable#` is set. | 152 | /// `#rust-analyzer.lens.enable#` is set. |
diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs index 857567a85..1b6211044 100644 --- a/crates/stdx/src/lib.rs +++ b/crates/stdx/src/lib.rs | |||
@@ -14,18 +14,8 @@ pub fn is_ci() -> bool { | |||
14 | 14 | ||
15 | #[must_use] | 15 | #[must_use] |
16 | pub fn timeit(label: &'static str) -> impl Drop { | 16 | pub fn timeit(label: &'static str) -> impl Drop { |
17 | struct Guard { | 17 | let start = Instant::now(); |
18 | label: &'static str, | 18 | defer(move || eprintln!("{}: {:.2?}", label, start.elapsed())) |
19 | start: Instant, | ||
20 | } | ||
21 | |||
22 | impl Drop for Guard { | ||
23 | fn drop(&mut self) { | ||
24 | eprintln!("{}: {:.2?}", self.label, self.start.elapsed()) | ||
25 | } | ||
26 | } | ||
27 | |||
28 | Guard { label, start: Instant::now() } | ||
29 | } | 19 | } |
30 | 20 | ||
31 | /// Prints backtrace to stderr, useful for debugging. | 21 | /// Prints backtrace to stderr, useful for debugging. |
@@ -179,6 +169,7 @@ where | |||
179 | start..start + len | 169 | start..start + len |
180 | } | 170 | } |
181 | 171 | ||
172 | #[must_use] | ||
182 | pub fn defer<F: FnOnce()>(f: F) -> impl Drop { | 173 | pub fn defer<F: FnOnce()>(f: F) -> impl Drop { |
183 | struct D<F: FnOnce()>(Option<F>); | 174 | struct D<F: FnOnce()>(Option<F>); |
184 | impl<F: FnOnce()> Drop for D<F> { | 175 | impl<F: FnOnce()> Drop for D<F> { |
diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc index e28423e99..db3c5f7bb 100644 --- a/docs/user/generated_config.adoc +++ b/docs/user/generated_config.adoc | |||
@@ -234,6 +234,11 @@ site. | |||
234 | -- | 234 | -- |
235 | Whether to show inlay type hints for variables. | 235 | Whether to show inlay type hints for variables. |
236 | -- | 236 | -- |
237 | [[rust-analyzer.inlayHints.smallerHints]]rust-analyzer.inlayHints.smallerHints (default: `true`):: | ||
238 | + | ||
239 | -- | ||
240 | Whether inlay hints font size should be smaller than editor's font size. | ||
241 | -- | ||
237 | [[rust-analyzer.lens.debug]]rust-analyzer.lens.debug (default: `true`):: | 242 | [[rust-analyzer.lens.debug]]rust-analyzer.lens.debug (default: `true`):: |
238 | + | 243 | + |
239 | -- | 244 | -- |
diff --git a/editors/code/package-lock.json b/editors/code/package-lock.json index 198c17556..4c2d16881 100644 --- a/editors/code/package-lock.json +++ b/editors/code/package-lock.json | |||
@@ -830,7 +830,6 @@ | |||
830 | "dependencies": { | 830 | "dependencies": { |
831 | "anymatch": "~3.1.1", | 831 | "anymatch": "~3.1.1", |
832 | "braces": "~3.0.2", | 832 | "braces": "~3.0.2", |
833 | "fsevents": "~2.3.1", | ||
834 | "glob-parent": "~5.1.0", | 833 | "glob-parent": "~5.1.0", |
835 | "is-binary-path": "~2.1.0", | 834 | "is-binary-path": "~2.1.0", |
836 | "is-glob": "~4.0.1", | 835 | "is-glob": "~4.0.1", |
@@ -2680,9 +2679,6 @@ | |||
2680 | "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.39.1.tgz", | 2679 | "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.39.1.tgz", |
2681 | "integrity": "sha512-9rfr0Z6j+vE+eayfNVFr1KZ+k+jiUl2+0e4quZafy1x6SFCjzFspfRSO2ZZQeWeX9noeDTUDgg6eCENiEPFvQg==", | 2680 | "integrity": "sha512-9rfr0Z6j+vE+eayfNVFr1KZ+k+jiUl2+0e4quZafy1x6SFCjzFspfRSO2ZZQeWeX9noeDTUDgg6eCENiEPFvQg==", |
2682 | "dev": true, | 2681 | "dev": true, |
2683 | "dependencies": { | ||
2684 | "fsevents": "~2.3.1" | ||
2685 | }, | ||
2686 | "bin": { | 2682 | "bin": { |
2687 | "rollup": "dist/bin/rollup" | 2683 | "rollup": "dist/bin/rollup" |
2688 | }, | 2684 | }, |
diff --git a/editors/code/package.json b/editors/code/package.json index fa5632f90..97d92e43c 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -653,6 +653,11 @@ | |||
653 | "default": true, | 653 | "default": true, |
654 | "type": "boolean" | 654 | "type": "boolean" |
655 | }, | 655 | }, |
656 | "rust-analyzer.inlayHints.smallerHints": { | ||
657 | "markdownDescription": "Whether inlay hints font size should be smaller than editor's font size.", | ||
658 | "default": true, | ||
659 | "type": "boolean" | ||
660 | }, | ||
656 | "rust-analyzer.lens.debug": { | 661 | "rust-analyzer.lens.debug": { |
657 | "markdownDescription": "Whether to show `Debug` lens. Only applies when\n`#rust-analyzer.lens.enable#` is set.", | 662 | "markdownDescription": "Whether to show `Debug` lens. Only applies when\n`#rust-analyzer.lens.enable#` is set.", |
658 | "default": true, | 663 | "default": true, |
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 82f0a0566..03f7d7cc3 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts | |||
@@ -115,6 +115,7 @@ export class Config { | |||
115 | typeHints: this.get<boolean>("inlayHints.typeHints"), | 115 | typeHints: this.get<boolean>("inlayHints.typeHints"), |
116 | parameterHints: this.get<boolean>("inlayHints.parameterHints"), | 116 | parameterHints: this.get<boolean>("inlayHints.parameterHints"), |
117 | chainingHints: this.get<boolean>("inlayHints.chainingHints"), | 117 | chainingHints: this.get<boolean>("inlayHints.chainingHints"), |
118 | smallerHints: this.get<boolean>("inlayHints.smallerHints"), | ||
118 | maxLength: this.get<null | number>("inlayHints.maxLength"), | 119 | maxLength: this.get<null | number>("inlayHints.maxLength"), |
119 | }; | 120 | }; |
120 | } | 121 | } |
diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts index 61db6b8d0..c23d6f738 100644 --- a/editors/code/src/inlay_hints.ts +++ b/editors/code/src/inlay_hints.ts | |||
@@ -5,6 +5,17 @@ import * as ra from './lsp_ext'; | |||
5 | import { Ctx, Disposable } from './ctx'; | 5 | import { Ctx, Disposable } from './ctx'; |
6 | import { sendRequestWithRetry, isRustDocument, RustDocument, RustEditor, sleep } from './util'; | 6 | import { sendRequestWithRetry, isRustDocument, RustDocument, RustEditor, sleep } from './util'; |
7 | 7 | ||
8 | interface InlayHintStyle { | ||
9 | decorationType: vscode.TextEditorDecorationType; | ||
10 | toDecoration(hint: ra.InlayHint, conv: lc.Protocol2CodeConverter): vscode.DecorationOptions; | ||
11 | }; | ||
12 | |||
13 | interface InlayHintsStyles { | ||
14 | typeHints: InlayHintStyle; | ||
15 | paramHints: InlayHintStyle; | ||
16 | chainingHints: InlayHintStyle; | ||
17 | } | ||
18 | |||
8 | 19 | ||
9 | export function activateInlayHints(ctx: Ctx) { | 20 | export function activateInlayHints(ctx: Ctx) { |
10 | const maybeUpdater = { | 21 | const maybeUpdater = { |
@@ -19,6 +30,7 @@ export function activateInlayHints(ctx: Ctx) { | |||
19 | 30 | ||
20 | await sleep(100); | 31 | await sleep(100); |
21 | if (this.updater) { | 32 | if (this.updater) { |
33 | this.updater.updateInlayHintsStyles(); | ||
22 | this.updater.syncCacheAndRenderHints(); | 34 | this.updater.syncCacheAndRenderHints(); |
23 | } else { | 35 | } else { |
24 | this.updater = new HintsUpdater(ctx); | 36 | this.updater = new HintsUpdater(ctx); |
@@ -39,11 +51,7 @@ export function activateInlayHints(ctx: Ctx) { | |||
39 | maybeUpdater.onConfigChange().catch(console.error); | 51 | maybeUpdater.onConfigChange().catch(console.error); |
40 | } | 52 | } |
41 | 53 | ||
42 | const typeHints = createHintStyle("type"); | 54 | function createHintStyle(hintKind: "type" | "parameter" | "chaining", smallerHints: boolean): InlayHintStyle { |
43 | const paramHints = createHintStyle("parameter"); | ||
44 | const chainingHints = createHintStyle("chaining"); | ||
45 | |||
46 | function createHintStyle(hintKind: "type" | "parameter" | "chaining") { | ||
47 | // U+200C is a zero-width non-joiner to prevent the editor from forming a ligature | 55 | // U+200C is a zero-width non-joiner to prevent the editor from forming a ligature |
48 | // between code and type hints | 56 | // between code and type hints |
49 | const [pos, render] = ({ | 57 | const [pos, render] = ({ |
@@ -61,7 +69,7 @@ function createHintStyle(hintKind: "type" | "parameter" | "chaining") { | |||
61 | backgroundColor: bg, | 69 | backgroundColor: bg, |
62 | fontStyle: "normal", | 70 | fontStyle: "normal", |
63 | fontWeight: "normal", | 71 | fontWeight: "normal", |
64 | textDecoration: ";font-size:smaller", | 72 | textDecoration: smallerHints ? ";font-size:smaller" : "none", |
65 | }, | 73 | }, |
66 | }), | 74 | }), |
67 | toDecoration(hint: ra.InlayHint, conv: lc.Protocol2CodeConverter): vscode.DecorationOptions { | 75 | toDecoration(hint: ra.InlayHint, conv: lc.Protocol2CodeConverter): vscode.DecorationOptions { |
@@ -73,9 +81,23 @@ function createHintStyle(hintKind: "type" | "parameter" | "chaining") { | |||
73 | }; | 81 | }; |
74 | } | 82 | } |
75 | 83 | ||
84 | const smallHintsStyles = { | ||
85 | typeHints: createHintStyle("type", true), | ||
86 | paramHints: createHintStyle("parameter", true), | ||
87 | chainingHints: createHintStyle("chaining", true), | ||
88 | }; | ||
89 | |||
90 | const biggerHintsStyles = { | ||
91 | typeHints: createHintStyle("type", false), | ||
92 | paramHints: createHintStyle("parameter", false), | ||
93 | chainingHints: createHintStyle("chaining", false), | ||
94 | }; | ||
95 | |||
76 | class HintsUpdater implements Disposable { | 96 | class HintsUpdater implements Disposable { |
77 | private sourceFiles = new Map<string, RustSourceFile>(); // map Uri -> RustSourceFile | 97 | private sourceFiles = new Map<string, RustSourceFile>(); // map Uri -> RustSourceFile |
78 | private readonly disposables: Disposable[] = []; | 98 | private readonly disposables: Disposable[] = []; |
99 | private pendingDisposeDecorations: undefined | InlayHintsStyles = undefined; | ||
100 | private inlayHintsStyles!: InlayHintsStyles; | ||
79 | 101 | ||
80 | constructor(private readonly ctx: Ctx) { | 102 | constructor(private readonly ctx: Ctx) { |
81 | vscode.window.onDidChangeVisibleTextEditors( | 103 | vscode.window.onDidChangeVisibleTextEditors( |
@@ -100,6 +122,7 @@ class HintsUpdater implements Disposable { | |||
100 | } | 122 | } |
101 | )); | 123 | )); |
102 | 124 | ||
125 | this.updateInlayHintsStyles(); | ||
103 | this.syncCacheAndRenderHints(); | 126 | this.syncCacheAndRenderHints(); |
104 | } | 127 | } |
105 | 128 | ||
@@ -114,6 +137,15 @@ class HintsUpdater implements Disposable { | |||
114 | this.syncCacheAndRenderHints(); | 137 | this.syncCacheAndRenderHints(); |
115 | } | 138 | } |
116 | 139 | ||
140 | updateInlayHintsStyles() { | ||
141 | const inlayHintsStyles = this.ctx.config.inlayHints.smallerHints ? smallHintsStyles : biggerHintsStyles; | ||
142 | |||
143 | if (inlayHintsStyles !== this.inlayHintsStyles) { | ||
144 | this.pendingDisposeDecorations = this.inlayHintsStyles; | ||
145 | this.inlayHintsStyles = inlayHintsStyles; | ||
146 | } | ||
147 | } | ||
148 | |||
117 | syncCacheAndRenderHints() { | 149 | syncCacheAndRenderHints() { |
118 | this.sourceFiles.forEach((file, uri) => this.fetchHints(file).then(hints => { | 150 | this.sourceFiles.forEach((file, uri) => this.fetchHints(file).then(hints => { |
119 | if (!hints) return; | 151 | if (!hints) return; |
@@ -161,12 +193,20 @@ class HintsUpdater implements Disposable { | |||
161 | } | 193 | } |
162 | 194 | ||
163 | private renderDecorations(editor: RustEditor, decorations: InlaysDecorations) { | 195 | private renderDecorations(editor: RustEditor, decorations: InlaysDecorations) { |
196 | const { typeHints, paramHints, chainingHints } = this.inlayHintsStyles; | ||
197 | if (this.pendingDisposeDecorations !== undefined) { | ||
198 | const { typeHints, paramHints, chainingHints } = this.pendingDisposeDecorations; | ||
199 | editor.setDecorations(typeHints.decorationType, []); | ||
200 | editor.setDecorations(paramHints.decorationType, []); | ||
201 | editor.setDecorations(chainingHints.decorationType, []); | ||
202 | } | ||
164 | editor.setDecorations(typeHints.decorationType, decorations.type); | 203 | editor.setDecorations(typeHints.decorationType, decorations.type); |
165 | editor.setDecorations(paramHints.decorationType, decorations.param); | 204 | editor.setDecorations(paramHints.decorationType, decorations.param); |
166 | editor.setDecorations(chainingHints.decorationType, decorations.chaining); | 205 | editor.setDecorations(chainingHints.decorationType, decorations.chaining); |
167 | } | 206 | } |
168 | 207 | ||
169 | private hintsToDecorations(hints: ra.InlayHint[]): InlaysDecorations { | 208 | private hintsToDecorations(hints: ra.InlayHint[]): InlaysDecorations { |
209 | const { typeHints, paramHints, chainingHints } = this.inlayHintsStyles; | ||
170 | const decorations: InlaysDecorations = { type: [], param: [], chaining: [] }; | 210 | const decorations: InlaysDecorations = { type: [], param: [], chaining: [] }; |
171 | const conv = this.ctx.client.protocol2CodeConverter; | 211 | const conv = this.ctx.client.protocol2CodeConverter; |
172 | 212 | ||