aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/release.yaml9
-rw-r--r--Cargo.lock12
-rw-r--r--crates/ide/src/display/navigation_target.rs8
-rw-r--r--crates/ide/src/references/rename.rs103
-rw-r--r--crates/ide/src/syntax_highlighting/highlight.rs9
-rw-r--r--crates/ide/src/syntax_highlighting/test_data/highlighting.html4
-rw-r--r--crates/project_model/src/build_data.rs2
-rw-r--r--crates/rust-analyzer/Cargo.toml2
-rw-r--r--crates/rust-analyzer/build.rs2
-rw-r--r--crates/rust-analyzer/src/config.rs2
-rw-r--r--crates/rust-analyzer/src/main_loop.rs6
-rw-r--r--crates/stdx/src/lib.rs15
-rw-r--r--docs/user/generated_config.adoc5
-rw-r--r--editors/code/language-configuration.json3
-rw-r--r--editors/code/package.json5
-rw-r--r--editors/code/src/config.ts1
-rw-r--r--editors/code/src/inlay_hints.ts52
-rw-r--r--xtask/src/dist.rs24
-rw-r--r--xtask/src/flags.rs9
-rw-r--r--xtask/src/main.rs8
-rw-r--r--xtask/src/release.rs11
21 files changed, 223 insertions, 69 deletions
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
index 307096ef3..d5c93f69b 100644
--- a/.github/workflows/release.yaml
+++ b/.github/workflows/release.yaml
@@ -109,12 +109,7 @@ jobs:
109 node-version: 12.x 109 node-version: 12.x
110 110
111 - name: Dist 111 - name: Dist
112 if: github.ref == 'refs/heads/release' 112 run: cargo xtask dist --client-patch-version $GITHUB_RUN_NUMBER
113 run: cargo xtask dist --client 0.2.$GITHUB_RUN_NUMBER
114
115 - name: Dist
116 if: github.ref != 'refs/heads/release'
117 run: cargo xtask dist --nightly --client 0.3.$GITHUB_RUN_NUMBER-nightly
118 113
119 - name: Run analysis-stats on rust-analyzer 114 - name: Run analysis-stats on rust-analyzer
120 run: target/${{ env.RA_TARGET }}/release/rust-analyzer analysis-stats . 115 run: target/${{ env.RA_TARGET }}/release/rust-analyzer analysis-stats .
@@ -266,7 +261,7 @@ jobs:
266 with: 261 with:
267 node-version: 12.x 262 node-version: 12.x
268 263
269 - run: echo "TAG=$(date --iso --utc)" >> $GITHUB_ENV 264 - run: echo "TAG=$(date --iso -u)" >> $GITHUB_ENV
270 if: github.ref == 'refs/heads/release' 265 if: github.ref == 'refs/heads/release'
271 - run: echo "TAG=nightly" >> $GITHUB_ENV 266 - run: echo "TAG=nightly" >> $GITHUB_ENV
272 if: github.ref != 'refs/heads/release' 267 if: github.ref != 'refs/heads/release'
diff --git a/Cargo.lock b/Cargo.lock
index 907973412..ba6862e98 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -841,9 +841,9 @@ dependencies = [
841 841
842[[package]] 842[[package]]
843name = "lsp-server" 843name = "lsp-server"
844version = "0.5.0" 844version = "0.5.1"
845source = "registry+https://github.com/rust-lang/crates.io-index" 845source = "registry+https://github.com/rust-lang/crates.io-index"
846checksum = "69b18dfe0e4a380b872aa79d8e0ee6c3d7a9682466e84b83ad807c88b3545f79" 846checksum = "6825d7042d5ca1825a366c40c9446928ec7b30e2be97243a13b164aee6583992"
847dependencies = [ 847dependencies = [
848 "crossbeam-channel", 848 "crossbeam-channel",
849 "log", 849 "log",
@@ -1303,9 +1303,9 @@ dependencies = [
1303 1303
1304[[package]] 1304[[package]]
1305name = "regex" 1305name = "regex"
1306version = "1.4.5" 1306version = "1.4.6"
1307source = "registry+https://github.com/rust-lang/crates.io-index" 1307source = "registry+https://github.com/rust-lang/crates.io-index"
1308checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19" 1308checksum = "2a26af418b574bd56588335b3a3659a65725d4e636eb1016c2f9e3b38c7cc759"
1309dependencies = [ 1309dependencies = [
1310 "regex-syntax", 1310 "regex-syntax",
1311] 1311]
@@ -1582,9 +1582,9 @@ dependencies = [
1582 1582
1583[[package]] 1583[[package]]
1584name = "syn" 1584name = "syn"
1585version = "1.0.69" 1585version = "1.0.70"
1586source = "registry+https://github.com/rust-lang/crates.io-index" 1586source = "registry+https://github.com/rust-lang/crates.io-index"
1587checksum = "48fe99c6bd8b1cc636890bcc071842de909d902c81ac7dab53ba33c421ab8ffb" 1587checksum = "b9505f307c872bab8eb46f77ae357c8eba1fdacead58ee5a850116b1d7f82883"
1588dependencies = [ 1588dependencies = [
1589 "proc-macro2", 1589 "proc-macro2",
1590 "quote", 1590 "quote",
diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs
index 364be260c..2079c22a3 100644
--- a/crates/ide/src/display/navigation_target.rs
+++ b/crates/ide/src/display/navigation_target.rs
@@ -20,7 +20,7 @@ use syntax::{
20 20
21use crate::FileSymbol; 21use crate::FileSymbol;
22 22
23/// `NavigationTarget` represents and element in the editor's UI which you can 23/// `NavigationTarget` represents an element in the editor's UI which you can
24/// click on to navigate to a particular piece of code. 24/// click on to navigate to a particular piece of code.
25/// 25///
26/// Typically, a `NavigationTarget` corresponds to some element in the source 26/// Typically, a `NavigationTarget` corresponds to some element in the source
@@ -35,12 +35,10 @@ pub struct NavigationTarget {
35 /// Clients should use this range to answer "is the cursor inside the 35 /// Clients should use this range to answer "is the cursor inside the
36 /// element?" question. 36 /// element?" question.
37 pub full_range: TextRange, 37 pub full_range: TextRange,
38 /// A "most interesting" range withing the `full_range`. 38 /// A "most interesting" range within the `full_range`.
39 /// 39 ///
40 /// Typically, `full_range` is the whole syntax node, including doc 40 /// Typically, `full_range` is the whole syntax node, including doc
41 /// comments, and `focus_range` is the range of the identifier. "Most 41 /// comments, and `focus_range` is the range of the identifier.
42 /// interesting" range within the full range, typically the range of
43 /// identifier.
44 /// 42 ///
45 /// Clients should place the cursor on this range when navigating to this target. 43 /// Clients should place the cursor on this range when navigating to this target.
46 pub focus_range: Option<TextRange>, 44 pub focus_range: Option<TextRange>,
diff --git a/crates/ide/src/references/rename.rs b/crates/ide/src/references/rename.rs
index 2408a0181..175e7a31d 100644
--- a/crates/ide/src/references/rename.rs
+++ b/crates/ide/src/references/rename.rs
@@ -50,6 +50,17 @@ pub(crate) fn prepare_rename(
50 let sema = Semantics::new(db); 50 let sema = Semantics::new(db);
51 let source_file = sema.parse(position.file_id); 51 let source_file = sema.parse(position.file_id);
52 let syntax = source_file.syntax(); 52 let syntax = source_file.syntax();
53
54 let def = find_definition(&sema, syntax, position)?;
55 match def {
56 Definition::SelfType(_) => bail!("Cannot rename `Self`"),
57 Definition::ModuleDef(ModuleDef::BuiltinType(_)) => bail!("Cannot rename builtin type"),
58 _ => {}
59 };
60 let nav =
61 def.try_to_nav(sema.db).ok_or_else(|| format_err!("No references found at position"))?;
62 nav.focus_range.ok_or_else(|| format_err!("No identifier available to rename"))?;
63
53 let name_like = sema 64 let name_like = sema
54 .find_node_at_offset_with_descend(&syntax, position.offset) 65 .find_node_at_offset_with_descend(&syntax, position.offset)
55 .ok_or_else(|| format_err!("No references found at position"))?; 66 .ok_or_else(|| format_err!("No references found at position"))?;
@@ -507,7 +518,8 @@ fn source_edit_from_def(
507 def.try_to_nav(sema.db).ok_or_else(|| format_err!("No references found at position"))?; 518 def.try_to_nav(sema.db).ok_or_else(|| format_err!("No references found at position"))?;
508 519
509 let mut replacement_text = String::new(); 520 let mut replacement_text = String::new();
510 let mut repl_range = nav.focus_or_full_range(); 521 let mut repl_range =
522 nav.focus_range.ok_or_else(|| format_err!("No identifier available to rename"))?;
511 if let Definition::Local(local) = def { 523 if let Definition::Local(local) = def {
512 if let Either::Left(pat) = local.source(sema.db).value { 524 if let Either::Left(pat) = local.source(sema.db).value {
513 if matches!( 525 if matches!(
@@ -626,6 +638,49 @@ foo!(Foo$0);",
626 } 638 }
627 639
628 #[test] 640 #[test]
641 fn test_prepare_rename_tuple_field() {
642 check_prepare(
643 r#"
644struct Foo(i32);
645
646fn baz() {
647 let mut x = Foo(4);
648 x.0$0 = 5;
649}
650"#,
651 expect![[r#"No identifier available to rename"#]],
652 );
653 }
654
655 #[test]
656 fn test_prepare_rename_builtin() {
657 check_prepare(
658 r#"
659fn foo() {
660 let x: i32$0 = 0;
661}
662"#,
663 expect![[r#"Cannot rename builtin type"#]],
664 );
665 }
666
667 #[test]
668 fn test_prepare_rename_self() {
669 check_prepare(
670 r#"
671struct Foo {}
672
673impl Foo {
674 fn foo(self) -> Self$0 {
675 self
676 }
677}
678"#,
679 expect![[r#"Cannot rename `Self`"#]],
680 );
681 }
682
683 #[test]
629 fn test_rename_to_underscore() { 684 fn test_rename_to_underscore() {
630 check("_", r#"fn main() { let i$0 = 1; }"#, r#"fn main() { let _ = 1; }"#); 685 check("_", r#"fn main() { let i$0 = 1; }"#, r#"fn main() { let _ = 1; }"#);
631 } 686 }
@@ -1787,4 +1842,50 @@ fn foo() {
1787"#, 1842"#,
1788 ) 1843 )
1789 } 1844 }
1845
1846 #[test]
1847 fn test_rename_tuple_field() {
1848 check(
1849 "foo",
1850 r#"
1851struct Foo(i32);
1852
1853fn baz() {
1854 let mut x = Foo(4);
1855 x.0$0 = 5;
1856}
1857"#,
1858 "error: No identifier available to rename",
1859 );
1860 }
1861
1862 #[test]
1863 fn test_rename_builtin() {
1864 check(
1865 "foo",
1866 r#"
1867fn foo() {
1868 let x: i32$0 = 0;
1869}
1870"#,
1871 "error: Cannot rename builtin type",
1872 );
1873 }
1874
1875 #[test]
1876 fn test_rename_self() {
1877 check(
1878 "foo",
1879 r#"
1880struct Foo {}
1881
1882impl Foo {
1883 fn foo(self) -> Self$0 {
1884 self
1885 }
1886}
1887"#,
1888 "error: Cannot rename `Self`",
1889 );
1890 }
1790} 1891}
diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs
index 8731699dc..b586dcc17 100644
--- a/crates/ide/src/syntax_highlighting/highlight.rs
+++ b/crates/ide/src/syntax_highlighting/highlight.rs
@@ -286,8 +286,13 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
286 let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Function)); 286 let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Function));
287 if let Some(item) = func.as_assoc_item(db) { 287 if let Some(item) = func.as_assoc_item(db) {
288 h |= HlMod::Associated; 288 h |= HlMod::Associated;
289 if func.self_param(db).is_none() { 289 match func.self_param(db) {
290 h |= HlMod::Static 290 Some(sp) => {
291 if let hir::Access::Exclusive = sp.access(db) {
292 h |= HlMod::Mutable;
293 }
294 }
295 None => h |= HlMod::Static,
291 } 296 }
292 297
293 match item.container(db) { 298 match item.container(db) {
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlighting.html b/crates/ide/src/syntax_highlighting/test_data/highlighting.html
index 4319e8b50..df4192194 100644
--- a/crates/ide/src/syntax_highlighting/test_data/highlighting.html
+++ b/crates/ide/src/syntax_highlighting/test_data/highlighting.html
@@ -81,7 +81,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
81 <span class="value_param">f</span><span class="operator">.</span><span class="function associated consuming">baz</span><span class="parenthesis">(</span><span class="self_keyword consuming mutable">self</span><span class="parenthesis">)</span> 81 <span class="value_param">f</span><span class="operator">.</span><span class="function associated consuming">baz</span><span class="parenthesis">(</span><span class="self_keyword consuming mutable">self</span><span class="parenthesis">)</span>
82 <span class="brace">}</span> 82 <span class="brace">}</span>
83 83
84 <span class="keyword">fn</span> <span class="function associated declaration">qux</span><span class="parenthesis">(</span><span class="operator">&</span><span class="keyword">mut</span> <span class="self_keyword declaration mutable">self</span><span class="parenthesis">)</span> <span class="brace">{</span> 84 <span class="keyword">fn</span> <span class="function associated declaration mutable">qux</span><span class="parenthesis">(</span><span class="operator">&</span><span class="keyword">mut</span> <span class="self_keyword declaration mutable">self</span><span class="parenthesis">)</span> <span class="brace">{</span>
85 <span class="self_keyword mutable">self</span><span class="operator">.</span><span class="field">x</span> <span class="operator">=</span> <span class="numeric_literal">0</span><span class="semicolon">;</span> 85 <span class="self_keyword mutable">self</span><span class="operator">.</span><span class="field">x</span> <span class="operator">=</span> <span class="numeric_literal">0</span><span class="semicolon">;</span>
86 <span class="brace">}</span> 86 <span class="brace">}</span>
87 87
@@ -100,7 +100,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
100 <span class="value_param">f</span><span class="operator">.</span><span class="function associated">baz</span><span class="parenthesis">(</span><span class="self_keyword">self</span><span class="parenthesis">)</span> 100 <span class="value_param">f</span><span class="operator">.</span><span class="function associated">baz</span><span class="parenthesis">(</span><span class="self_keyword">self</span><span class="parenthesis">)</span>
101 <span class="brace">}</span> 101 <span class="brace">}</span>
102 102
103 <span class="keyword">fn</span> <span class="function associated declaration">qux</span><span class="parenthesis">(</span><span class="operator">&</span><span class="keyword">mut</span> <span class="self_keyword declaration mutable">self</span><span class="parenthesis">)</span> <span class="brace">{</span> 103 <span class="keyword">fn</span> <span class="function associated declaration mutable">qux</span><span class="parenthesis">(</span><span class="operator">&</span><span class="keyword">mut</span> <span class="self_keyword declaration mutable">self</span><span class="parenthesis">)</span> <span class="brace">{</span>
104 <span class="self_keyword mutable">self</span><span class="operator">.</span><span class="field">x</span> <span class="operator">=</span> <span class="numeric_literal">0</span><span class="semicolon">;</span> 104 <span class="self_keyword mutable">self</span><span class="operator">.</span><span class="field">x</span> <span class="operator">=</span> <span class="numeric_literal">0</span><span class="semicolon">;</span>
105 <span class="brace">}</span> 105 <span class="brace">}</span>
106 106
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"
33threadpool = "1.7.1" 33threadpool = "1.7.1"
34rayon = "1.5" 34rayon = "1.5"
35mimalloc = { version = "0.1.19", default-features = false, optional = true } 35mimalloc = { version = "0.1.19", default-features = false, optional = true }
36lsp-server = "0.5.0" 36lsp-server = "0.5.1"
37tracing = "0.1" 37tracing = "0.1"
38tracing-subscriber = { version = "0.2", default-features = false, features = ["env-filter", "registry"] } 38tracing-subscriber = { version = "0.2", default-features = false, features = ["env-filter", "registry"] }
39tracing-tree = { version = "0.1.4" } 39tracing-tree = { version = "0.1.4" }
diff --git a/crates/rust-analyzer/build.rs b/crates/rust-analyzer/build.rs
index 25627c7e9..bca6611d6 100644
--- a/crates/rust-analyzer/build.rs
+++ b/crates/rust-analyzer/build.rs
@@ -55,7 +55,7 @@ fn commit_hash() -> Option<String> {
55} 55}
56 56
57fn build_date() -> Option<String> { 57fn build_date() -> Option<String> {
58 output_to_string("date --iso --utc") 58 output_to_string("date -u +%Y-%m-%d")
59} 59}
60 60
61fn output_to_string(command: &str) -> Option<String> { 61fn output_to_string(command: &str) -> Option<String> {
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/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 6ea775d68..a766aacad 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -571,6 +571,12 @@ impl GlobalState {
571 this.cancel(id); 571 this.cancel(id);
572 Ok(()) 572 Ok(())
573 })? 573 })?
574 .on::<lsp_types::notification::WorkDoneProgressCancel>(|_this, _params| {
575 // Just ignore this. It is OK to continue sending progress
576 // notifications for this token, as the client can't know when
577 // we accepted notification.
578 Ok(())
579 })?
574 .on::<lsp_types::notification::DidOpenTextDocument>(|this, params| { 580 .on::<lsp_types::notification::DidOpenTextDocument>(|this, params| {
575 if let Ok(path) = from_proto::vfs_path(&params.text_document.uri) { 581 if let Ok(path) = from_proto::vfs_path(&params.text_document.uri) {
576 if this 582 if this
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]
16pub fn timeit(label: &'static str) -> impl Drop { 16pub 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]
182pub fn defer<F: FnOnce()>(f: F) -> impl Drop { 173pub 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--
235Whether to show inlay type hints for variables. 235Whether to show inlay type hints for variables.
236-- 236--
237[[rust-analyzer.inlayHints.smallerHints]]rust-analyzer.inlayHints.smallerHints (default: `true`)::
238+
239--
240Whether 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/language-configuration.json b/editors/code/language-configuration.json
index b20e0d978..382484bc7 100644
--- a/editors/code/language-configuration.json
+++ b/editors/code/language-configuration.json
@@ -23,7 +23,8 @@
23 ["(", ")"], 23 ["(", ")"],
24 ["<", ">"], 24 ["<", ">"],
25 ["\"", "\""], 25 ["\"", "\""],
26 ["'", "'"] 26 ["'", "'"],
27 ["|", "|"]
27 ], 28 ],
28 "indentationRules": { 29 "indentationRules": {
29 "increaseIndentPattern": "^.*\\{[^}\"']*$|^.*\\([^\\)\"']*$", 30 "increaseIndentPattern": "^.*\\{[^}\"']*$|^.*\\([^\\)\"']*$",
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';
5import { Ctx, Disposable } from './ctx'; 5import { Ctx, Disposable } from './ctx';
6import { sendRequestWithRetry, isRustDocument, RustDocument, RustEditor, sleep } from './util'; 6import { sendRequestWithRetry, isRustDocument, RustDocument, RustEditor, sleep } from './util';
7 7
8interface InlayHintStyle {
9 decorationType: vscode.TextEditorDecorationType;
10 toDecoration(hint: ra.InlayHint, conv: lc.Protocol2CodeConverter): vscode.DecorationOptions;
11};
12
13interface InlayHintsStyles {
14 typeHints: InlayHintStyle;
15 paramHints: InlayHintStyle;
16 chainingHints: InlayHintStyle;
17}
18
8 19
9export function activateInlayHints(ctx: Ctx) { 20export 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
42const typeHints = createHintStyle("type"); 54function createHintStyle(hintKind: "type" | "parameter" | "chaining", smallerHints: boolean): InlayHintStyle {
43const paramHints = createHintStyle("parameter");
44const chainingHints = createHintStyle("chaining");
45
46function 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
84const smallHintsStyles = {
85 typeHints: createHintStyle("type", true),
86 paramHints: createHintStyle("parameter", true),
87 chainingHints: createHintStyle("chaining", true),
88};
89
90const biggerHintsStyles = {
91 typeHints: createHintStyle("type", false),
92 paramHints: createHintStyle("parameter", false),
93 chainingHints: createHintStyle("chaining", false),
94};
95
76class HintsUpdater implements Disposable { 96class 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
diff --git a/xtask/src/dist.rs b/xtask/src/dist.rs
index d1c005954..12a7fea1e 100644
--- a/xtask/src/dist.rs
+++ b/xtask/src/dist.rs
@@ -9,24 +9,28 @@ use anyhow::Result;
9use flate2::{write::GzEncoder, Compression}; 9use flate2::{write::GzEncoder, Compression};
10use xshell::{cmd, cp, mkdir_p, pushd, pushenv, read_file, rm_rf, write_file}; 10use xshell::{cmd, cp, mkdir_p, pushd, pushenv, read_file, rm_rf, write_file};
11 11
12use crate::{date_iso, project_root}; 12use crate::{date_iso, flags, project_root};
13 13
14pub(crate) struct DistCmd { 14impl flags::Dist {
15 pub(crate) nightly: bool,
16 pub(crate) client_version: Option<String>,
17}
18
19impl DistCmd {
20 pub(crate) fn run(self) -> Result<()> { 15 pub(crate) fn run(self) -> Result<()> {
16 let stable =
17 std::env::var("GITHUB_REF").unwrap_or_default().as_str() == "refs/heads/release";
18
21 let dist = project_root().join("dist"); 19 let dist = project_root().join("dist");
22 rm_rf(&dist)?; 20 rm_rf(&dist)?;
23 mkdir_p(&dist)?; 21 mkdir_p(&dist)?;
24 22
25 if let Some(version) = self.client_version { 23 if let Some(patch_version) = self.client_patch_version {
26 let release_tag = if self.nightly { "nightly".to_string() } else { date_iso()? }; 24 let version = if stable {
25 format!("0.2.{}", patch_version)
26 } else {
27 // A hack to make VS Code prefer nightly over stable.
28 format!("0.3.{}", patch_version)
29 };
30 let release_tag = if stable { date_iso()? } else { "nightly".to_string() };
27 dist_client(&version, &release_tag)?; 31 dist_client(&version, &release_tag)?;
28 } 32 }
29 let release_channel = if self.nightly { "nightly" } else { "stable" }; 33 let release_channel = if stable { "stable" } else { "nightly" };
30 dist_server(release_channel)?; 34 dist_server(release_channel)?;
31 Ok(()) 35 Ok(())
32 } 36 }
diff --git a/xtask/src/flags.rs b/xtask/src/flags.rs
index 4cd2b1ddb..f80a5dd16 100644
--- a/xtask/src/flags.rs
+++ b/xtask/src/flags.rs
@@ -37,8 +37,7 @@ xflags::xflags! {
37 optional --dry-run 37 optional --dry-run
38 } 38 }
39 cmd dist { 39 cmd dist {
40 optional --nightly 40 optional --client-patch-version version: String
41 optional --client version: String
42 } 41 }
43 cmd metrics { 42 cmd metrics {
44 optional --dry-run 43 optional --dry-run
@@ -86,9 +85,6 @@ pub struct Install {
86} 85}
87 86
88#[derive(Debug)] 87#[derive(Debug)]
89pub struct Lint;
90
91#[derive(Debug)]
92pub struct FuzzTests; 88pub struct FuzzTests;
93 89
94#[derive(Debug)] 90#[derive(Debug)]
@@ -106,8 +102,7 @@ pub struct Promote {
106 102
107#[derive(Debug)] 103#[derive(Debug)]
108pub struct Dist { 104pub struct Dist {
109 pub nightly: bool, 105 pub client_patch_version: Option<String>,
110 pub client: Option<String>,
111} 106}
112 107
113#[derive(Debug)] 108#[derive(Debug)]
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index 960927fc0..ce3353410 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -28,8 +28,6 @@ use std::{
28use walkdir::{DirEntry, WalkDir}; 28use walkdir::{DirEntry, WalkDir};
29use xshell::{cmd, cp, pushd, pushenv}; 29use xshell::{cmd, cp, pushd, pushenv};
30 30
31use crate::dist::DistCmd;
32
33fn main() -> Result<()> { 31fn main() -> Result<()> {
34 let _d = pushd(project_root())?; 32 let _d = pushd(project_root())?;
35 33
@@ -44,9 +42,7 @@ fn main() -> Result<()> {
44 flags::XtaskCmd::PreCache(cmd) => cmd.run(), 42 flags::XtaskCmd::PreCache(cmd) => cmd.run(),
45 flags::XtaskCmd::Release(cmd) => cmd.run(), 43 flags::XtaskCmd::Release(cmd) => cmd.run(),
46 flags::XtaskCmd::Promote(cmd) => cmd.run(), 44 flags::XtaskCmd::Promote(cmd) => cmd.run(),
47 flags::XtaskCmd::Dist(flags) => { 45 flags::XtaskCmd::Dist(cmd) => cmd.run(),
48 DistCmd { nightly: flags.nightly, client_version: flags.client }.run()
49 }
50 flags::XtaskCmd::Metrics(cmd) => cmd.run(), 46 flags::XtaskCmd::Metrics(cmd) => cmd.run(),
51 flags::XtaskCmd::Bb(cmd) => { 47 flags::XtaskCmd::Bb(cmd) => {
52 { 48 {
@@ -112,7 +108,7 @@ fn run_fuzzer() -> Result<()> {
112} 108}
113 109
114fn date_iso() -> Result<String> { 110fn date_iso() -> Result<String> {
115 let res = cmd!("date --iso --utc").read()?; 111 let res = cmd!("date -u +%Y-%m-%d").read()?;
116 Ok(res) 112 Ok(res)
117} 113}
118 114
diff --git a/xtask/src/release.rs b/xtask/src/release.rs
index 22bb50467..452f351d0 100644
--- a/xtask/src/release.rs
+++ b/xtask/src/release.rs
@@ -10,7 +10,16 @@ impl flags::Release {
10 cmd!("git switch release").run()?; 10 cmd!("git switch release").run()?;
11 cmd!("git fetch upstream --tags --force").run()?; 11 cmd!("git fetch upstream --tags --force").run()?;
12 cmd!("git reset --hard tags/nightly").run()?; 12 cmd!("git reset --hard tags/nightly").run()?;
13 cmd!("git push").run()?; 13 // The `release` branch sometimes has a couple of cherry-picked
14 // commits for patch releases. If that's the case, just overwrite
15 // it. As we are setting `release` branch to an up-to-date `nightly`
16 // tag, this shouldn't be problematic in general.
17 //
18 // Note that, as we tag releases, we don't worry about "losing"
19 // commits -- they'll be kept alive by the tag. More generally, we
20 // don't care about historic releases all that much, it's fine even
21 // to delete old tags.
22 cmd!("git push --force").run()?;
14 } 23 }
15 codegen::docs()?; 24 codegen::docs()?;
16 25