diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ide/src/display/navigation_target.rs | 8 | ||||
-rw-r--r-- | crates/ide/src/references/rename.rs | 103 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/highlight.rs | 9 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/test_data/highlighting.html | 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/build.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 6 | ||||
-rw-r--r-- | crates/stdx/src/lib.rs | 15 |
10 files changed, 128 insertions, 25 deletions
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 | ||
21 | use crate::FileSymbol; | 21 | use 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#" | ||
644 | struct Foo(i32); | ||
645 | |||
646 | fn 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#" | ||
659 | fn 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#" | ||
671 | struct Foo {} | ||
672 | |||
673 | impl 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#" | ||
1851 | struct Foo(i32); | ||
1852 | |||
1853 | fn 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#" | ||
1867 | fn 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#" | ||
1880 | struct Foo {} | ||
1881 | |||
1882 | impl 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" | |||
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/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 | ||
57 | fn build_date() -> Option<String> { | 57 | fn build_date() -> Option<String> { |
58 | output_to_string("date --iso --utc") | 58 | output_to_string("date -u +%Y-%m-%d") |
59 | } | 59 | } |
60 | 60 | ||
61 | fn output_to_string(command: &str) -> Option<String> { | 61 | fn 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(¶ms.text_document.uri) { | 581 | if let Ok(path) = from_proto::vfs_path(¶ms.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] |
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> { |