diff options
-rw-r--r-- | .github/workflows/release.yaml | 1 | ||||
-rw-r--r-- | Cargo.lock | 8 | ||||
-rw-r--r-- | crates/ra_flycheck/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_prof/src/hprof.rs | 45 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 15 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/tokens.rs | 17 | ||||
-rw-r--r-- | crates/rust-analyzer/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/conv.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop/handlers.rs | 49 | ||||
-rw-r--r-- | crates/rust-analyzer/src/req.rs | 15 | ||||
-rw-r--r-- | crates/rust-analyzer/src/semantic_tokens.rs | 117 | ||||
-rw-r--r-- | crates/rust-analyzer/tests/heavy_tests/main.rs | 27 | ||||
-rw-r--r-- | xtask/src/dist.rs | 8 |
13 files changed, 165 insertions, 143 deletions
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 2c1192f07..3f52f31f8 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml | |||
@@ -39,7 +39,6 @@ jobs: | |||
39 | with: | 39 | with: |
40 | toolchain: stable | 40 | toolchain: stable |
41 | profile: minimal | 41 | profile: minimal |
42 | target: x86_64-unknown-linux-musl | ||
43 | override: true | 42 | override: true |
44 | 43 | ||
45 | - name: Install Nodejs | 44 | - name: Install Nodejs |
diff --git a/Cargo.lock b/Cargo.lock index 367ff3f82..e933598fb 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -68,9 +68,9 @@ dependencies = [ | |||
68 | 68 | ||
69 | [[package]] | 69 | [[package]] |
70 | name = "base64" | 70 | name = "base64" |
71 | version = "0.11.0" | 71 | version = "0.12.0" |
72 | source = "registry+https://github.com/rust-lang/crates.io-index" | 72 | source = "registry+https://github.com/rust-lang/crates.io-index" |
73 | checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" | 73 | checksum = "7d5ca2cd0adc3f48f9e9ea5a6bbdf9ccc0bfade884847e484d452414c7ccffb3" |
74 | 74 | ||
75 | [[package]] | 75 | [[package]] |
76 | name = "bitflags" | 76 | name = "bitflags" |
@@ -645,9 +645,9 @@ dependencies = [ | |||
645 | 645 | ||
646 | [[package]] | 646 | [[package]] |
647 | name = "lsp-types" | 647 | name = "lsp-types" |
648 | version = "0.73.0" | 648 | version = "0.74.0" |
649 | source = "registry+https://github.com/rust-lang/crates.io-index" | 649 | source = "registry+https://github.com/rust-lang/crates.io-index" |
650 | checksum = "93d0cf64ea141b43d9e055f6b9df13f0bce32b103d84237509ce0a571ab9b159" | 650 | checksum = "820f746e5716ab9a2d664794636188bd003023b72e55404ee27105dc22869922" |
651 | dependencies = [ | 651 | dependencies = [ |
652 | "base64", | 652 | "base64", |
653 | "bitflags", | 653 | "bitflags", |
diff --git a/crates/ra_flycheck/Cargo.toml b/crates/ra_flycheck/Cargo.toml index 76e5cada4..324c33d9d 100644 --- a/crates/ra_flycheck/Cargo.toml +++ b/crates/ra_flycheck/Cargo.toml | |||
@@ -6,7 +6,7 @@ authors = ["rust-analyzer developers"] | |||
6 | 6 | ||
7 | [dependencies] | 7 | [dependencies] |
8 | crossbeam-channel = "0.4.0" | 8 | crossbeam-channel = "0.4.0" |
9 | lsp-types = { version = "0.73.0", features = ["proposed"] } | 9 | lsp-types = { version = "0.74.0", features = ["proposed"] } |
10 | log = "0.4.8" | 10 | log = "0.4.8" |
11 | cargo_metadata = "0.9.1" | 11 | cargo_metadata = "0.9.1" |
12 | serde_json = "1.0.48" | 12 | serde_json = "1.0.48" |
diff --git a/crates/ra_prof/src/hprof.rs b/crates/ra_prof/src/hprof.rs index 2b8a90363..a3f5321fb 100644 --- a/crates/ra_prof/src/hprof.rs +++ b/crates/ra_prof/src/hprof.rs | |||
@@ -30,8 +30,9 @@ pub fn init_from(spec: &str) { | |||
30 | pub type Label = &'static str; | 30 | pub type Label = &'static str; |
31 | 31 | ||
32 | /// This function starts a profiling scope in the current execution stack with a given description. | 32 | /// This function starts a profiling scope in the current execution stack with a given description. |
33 | /// It returns a Profile structure and measure elapsed time between this method invocation and Profile structure drop. | 33 | /// It returns a `Profile` struct that measures elapsed time between this method invocation and `Profile` struct drop. |
34 | /// It supports nested profiling scopes in case when this function invoked multiple times at the execution stack. In this case the profiling information will be nested at the output. | 34 | /// It supports nested profiling scopes in case when this function is invoked multiple times at the execution stack. |
35 | /// In this case the profiling information will be nested at the output. | ||
35 | /// Profiling information is being printed in the stderr. | 36 | /// Profiling information is being printed in the stderr. |
36 | /// | 37 | /// |
37 | /// # Example | 38 | /// # Example |
@@ -58,36 +59,35 @@ pub type Label = &'static str; | |||
58 | /// ``` | 59 | /// ``` |
59 | pub fn profile(label: Label) -> Profiler { | 60 | pub fn profile(label: Label) -> Profiler { |
60 | assert!(!label.is_empty()); | 61 | assert!(!label.is_empty()); |
61 | let enabled = PROFILING_ENABLED.load(Ordering::Relaxed) | 62 | |
62 | && PROFILE_STACK.with(|stack| stack.borrow_mut().push(label)); | 63 | if PROFILING_ENABLED.load(Ordering::Relaxed) |
63 | let label = if enabled { Some(label) } else { None }; | 64 | && PROFILE_STACK.with(|stack| stack.borrow_mut().push(label)) |
64 | Profiler { label, detail: None } | 65 | { |
66 | Profiler(Some(ProfilerImpl { label, detail: None })) | ||
67 | } else { | ||
68 | Profiler(None) | ||
69 | } | ||
65 | } | 70 | } |
66 | 71 | ||
67 | pub struct Profiler { | 72 | pub struct Profiler(Option<ProfilerImpl>); |
68 | label: Option<Label>, | 73 | |
74 | struct ProfilerImpl { | ||
75 | label: Label, | ||
69 | detail: Option<String>, | 76 | detail: Option<String>, |
70 | } | 77 | } |
71 | 78 | ||
72 | impl Profiler { | 79 | impl Profiler { |
73 | pub fn detail(mut self, detail: impl FnOnce() -> String) -> Profiler { | 80 | pub fn detail(mut self, detail: impl FnOnce() -> String) -> Profiler { |
74 | if self.label.is_some() { | 81 | if let Some(profiler) = &mut self.0 { |
75 | self.detail = Some(detail()) | 82 | profiler.detail = Some(detail()) |
76 | } | 83 | } |
77 | self | 84 | self |
78 | } | 85 | } |
79 | } | 86 | } |
80 | 87 | ||
81 | impl Drop for Profiler { | 88 | impl Drop for ProfilerImpl { |
82 | fn drop(&mut self) { | 89 | fn drop(&mut self) { |
83 | match self { | 90 | PROFILE_STACK.with(|it| it.borrow_mut().pop(self.label, self.detail.take())); |
84 | Profiler { label: Some(label), detail } => { | ||
85 | PROFILE_STACK.with(|stack| { | ||
86 | stack.borrow_mut().pop(label, detail.take()); | ||
87 | }); | ||
88 | } | ||
89 | Profiler { label: None, .. } => (), | ||
90 | } | ||
91 | } | 91 | } |
92 | } | 92 | } |
93 | 93 | ||
@@ -179,21 +179,18 @@ impl ProfileStack { | |||
179 | pub fn pop(&mut self, label: Label, detail: Option<String>) { | 179 | pub fn pop(&mut self, label: Label, detail: Option<String>) { |
180 | let start = self.starts.pop().unwrap(); | 180 | let start = self.starts.pop().unwrap(); |
181 | let duration = start.elapsed(); | 181 | let duration = start.elapsed(); |
182 | let level = self.starts.len(); | ||
183 | self.messages.finish(Message { duration, label, detail }); | 182 | self.messages.finish(Message { duration, label, detail }); |
184 | if level == 0 { | 183 | if self.starts.is_empty() { |
185 | let longer_than = self.filter.longer_than; | 184 | let longer_than = self.filter.longer_than; |
186 | // Convert to millis for comparison to avoid problems with rounding | 185 | // Convert to millis for comparison to avoid problems with rounding |
187 | // (otherwise we could print `0ms` despite user's `>0` filter when | 186 | // (otherwise we could print `0ms` despite user's `>0` filter when |
188 | // `duration` is just a few nanos). | 187 | // `duration` is just a few nanos). |
189 | if duration.as_millis() > longer_than.as_millis() { | 188 | if duration.as_millis() > longer_than.as_millis() { |
190 | let stderr = stderr(); | ||
191 | if let Some(root) = self.messages.root() { | 189 | if let Some(root) = self.messages.root() { |
192 | print(&self.messages, root, 0, longer_than, &mut stderr.lock()); | 190 | print(&self.messages, root, 0, longer_than, &mut stderr().lock()); |
193 | } | 191 | } |
194 | } | 192 | } |
195 | self.messages.clear(); | 193 | self.messages.clear(); |
196 | assert!(self.starts.is_empty()) | ||
197 | } | 194 | } |
198 | } | 195 | } |
199 | } | 196 | } |
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 7fca5661e..a716e525b 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -243,6 +243,21 @@ fn test_comments_preserve_trailing_whitespace() { | |||
243 | } | 243 | } |
244 | 244 | ||
245 | #[test] | 245 | #[test] |
246 | fn test_four_slash_line_comment() { | ||
247 | let file = SourceFile::parse( | ||
248 | r#" | ||
249 | //// too many slashes to be a doc comment | ||
250 | /// doc comment | ||
251 | mod foo {} | ||
252 | "#, | ||
253 | ) | ||
254 | .ok() | ||
255 | .unwrap(); | ||
256 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); | ||
257 | assert_eq!("doc comment", module.doc_comment_text().unwrap()); | ||
258 | } | ||
259 | |||
260 | #[test] | ||
246 | fn test_where_predicates() { | 261 | fn test_where_predicates() { |
247 | fn assert_bound(text: &str, bound: Option<TypeBound>) { | 262 | fn assert_bound(text: &str, bound: Option<TypeBound>) { |
248 | assert_eq!(text, bound.unwrap().syntax().text().to_string()); | 263 | assert_eq!(text, bound.unwrap().syntax().text().to_string()); |
diff --git a/crates/ra_syntax/src/ast/tokens.rs b/crates/ra_syntax/src/ast/tokens.rs index 3865729b8..74906d8a6 100644 --- a/crates/ra_syntax/src/ast/tokens.rs +++ b/crates/ra_syntax/src/ast/tokens.rs | |||
@@ -13,7 +13,12 @@ impl Comment { | |||
13 | } | 13 | } |
14 | 14 | ||
15 | pub fn prefix(&self) -> &'static str { | 15 | pub fn prefix(&self) -> &'static str { |
16 | prefix_by_kind(self.kind()) | 16 | for (prefix, k) in COMMENT_PREFIX_TO_KIND.iter() { |
17 | if *k == self.kind() && self.text().starts_with(prefix) { | ||
18 | return prefix; | ||
19 | } | ||
20 | } | ||
21 | unreachable!() | ||
17 | } | 22 | } |
18 | } | 23 | } |
19 | 24 | ||
@@ -48,6 +53,7 @@ pub enum CommentPlacement { | |||
48 | const COMMENT_PREFIX_TO_KIND: &[(&str, CommentKind)] = { | 53 | const COMMENT_PREFIX_TO_KIND: &[(&str, CommentKind)] = { |
49 | use {CommentPlacement::*, CommentShape::*}; | 54 | use {CommentPlacement::*, CommentShape::*}; |
50 | &[ | 55 | &[ |
56 | ("////", CommentKind { shape: Line, doc: None }), | ||
51 | ("///", CommentKind { shape: Line, doc: Some(Outer) }), | 57 | ("///", CommentKind { shape: Line, doc: Some(Outer) }), |
52 | ("//!", CommentKind { shape: Line, doc: Some(Inner) }), | 58 | ("//!", CommentKind { shape: Line, doc: Some(Inner) }), |
53 | ("/**", CommentKind { shape: Block, doc: Some(Outer) }), | 59 | ("/**", CommentKind { shape: Block, doc: Some(Outer) }), |
@@ -69,15 +75,6 @@ fn kind_by_prefix(text: &str) -> CommentKind { | |||
69 | panic!("bad comment text: {:?}", text) | 75 | panic!("bad comment text: {:?}", text) |
70 | } | 76 | } |
71 | 77 | ||
72 | fn prefix_by_kind(kind: CommentKind) -> &'static str { | ||
73 | for (prefix, k) in COMMENT_PREFIX_TO_KIND.iter() { | ||
74 | if *k == kind { | ||
75 | return prefix; | ||
76 | } | ||
77 | } | ||
78 | unreachable!() | ||
79 | } | ||
80 | |||
81 | impl Whitespace { | 78 | impl Whitespace { |
82 | pub fn spans_multiple_lines(&self) -> bool { | 79 | pub fn spans_multiple_lines(&self) -> bool { |
83 | let text = self.text(); | 80 | let text = self.text(); |
diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml index cee0248b6..514d6d1a9 100644 --- a/crates/rust-analyzer/Cargo.toml +++ b/crates/rust-analyzer/Cargo.toml | |||
@@ -20,7 +20,7 @@ globset = "0.4.4" | |||
20 | itertools = "0.9.0" | 20 | itertools = "0.9.0" |
21 | jod-thread = "0.1.0" | 21 | jod-thread = "0.1.0" |
22 | log = "0.4.8" | 22 | log = "0.4.8" |
23 | lsp-types = { version = "0.73.0", features = ["proposed"] } | 23 | lsp-types = { version = "0.74.0", features = ["proposed"] } |
24 | parking_lot = "0.10.0" | 24 | parking_lot = "0.10.0" |
25 | pico-args = "0.3.1" | 25 | pico-args = "0.3.1" |
26 | rand = { version = "0.7.3", features = ["small_rng"] } | 26 | rand = { version = "0.7.3", features = ["small_rng"] } |
diff --git a/crates/rust-analyzer/src/conv.rs b/crates/rust-analyzer/src/conv.rs index ffe3ea84d..7be5ebcdb 100644 --- a/crates/rust-analyzer/src/conv.rs +++ b/crates/rust-analyzer/src/conv.rs | |||
@@ -150,7 +150,7 @@ impl ConvWith<(&LineIndex, LineEndings)> for CompletionItem { | |||
150 | detail: self.detail().map(|it| it.to_string()), | 150 | detail: self.detail().map(|it| it.to_string()), |
151 | filter_text: Some(self.lookup().to_string()), | 151 | filter_text: Some(self.lookup().to_string()), |
152 | kind: self.kind().map(|it| it.conv()), | 152 | kind: self.kind().map(|it| it.conv()), |
153 | text_edit: Some(text_edit), | 153 | text_edit: Some(text_edit.into()), |
154 | additional_text_edits: Some(additional_text_edits), | 154 | additional_text_edits: Some(additional_text_edits), |
155 | documentation: self.documentation().map(|it| it.conv()), | 155 | documentation: self.documentation().map(|it| it.conv()), |
156 | deprecated: Some(self.deprecated()), | 156 | deprecated: Some(self.deprecated()), |
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs index 6caaf5f88..8db2dfa0c 100644 --- a/crates/rust-analyzer/src/main_loop/handlers.rs +++ b/crates/rust-analyzer/src/main_loop/handlers.rs | |||
@@ -326,10 +326,10 @@ pub fn handle_workspace_symbol( | |||
326 | 326 | ||
327 | pub fn handle_goto_definition( | 327 | pub fn handle_goto_definition( |
328 | world: WorldSnapshot, | 328 | world: WorldSnapshot, |
329 | params: req::TextDocumentPositionParams, | 329 | params: req::GotoDefinitionParams, |
330 | ) -> Result<Option<req::GotoDefinitionResponse>> { | 330 | ) -> Result<Option<req::GotoDefinitionResponse>> { |
331 | let _p = profile("handle_goto_definition"); | 331 | let _p = profile("handle_goto_definition"); |
332 | let position = params.try_conv_with(&world)?; | 332 | let position = params.text_document_position_params.try_conv_with(&world)?; |
333 | let nav_info = match world.analysis().goto_definition(position)? { | 333 | let nav_info = match world.analysis().goto_definition(position)? { |
334 | None => return Ok(None), | 334 | None => return Ok(None), |
335 | Some(it) => it, | 335 | Some(it) => it, |
@@ -340,10 +340,10 @@ pub fn handle_goto_definition( | |||
340 | 340 | ||
341 | pub fn handle_goto_implementation( | 341 | pub fn handle_goto_implementation( |
342 | world: WorldSnapshot, | 342 | world: WorldSnapshot, |
343 | params: req::TextDocumentPositionParams, | 343 | params: req::GotoImplementationParams, |
344 | ) -> Result<Option<req::GotoImplementationResponse>> { | 344 | ) -> Result<Option<req::GotoImplementationResponse>> { |
345 | let _p = profile("handle_goto_implementation"); | 345 | let _p = profile("handle_goto_implementation"); |
346 | let position = params.try_conv_with(&world)?; | 346 | let position = params.text_document_position_params.try_conv_with(&world)?; |
347 | let nav_info = match world.analysis().goto_implementation(position)? { | 347 | let nav_info = match world.analysis().goto_implementation(position)? { |
348 | None => return Ok(None), | 348 | None => return Ok(None), |
349 | Some(it) => it, | 349 | Some(it) => it, |
@@ -354,10 +354,10 @@ pub fn handle_goto_implementation( | |||
354 | 354 | ||
355 | pub fn handle_goto_type_definition( | 355 | pub fn handle_goto_type_definition( |
356 | world: WorldSnapshot, | 356 | world: WorldSnapshot, |
357 | params: req::TextDocumentPositionParams, | 357 | params: req::GotoTypeDefinitionParams, |
358 | ) -> Result<Option<req::GotoTypeDefinitionResponse>> { | 358 | ) -> Result<Option<req::GotoTypeDefinitionResponse>> { |
359 | let _p = profile("handle_goto_type_definition"); | 359 | let _p = profile("handle_goto_type_definition"); |
360 | let position = params.try_conv_with(&world)?; | 360 | let position = params.text_document_position_params.try_conv_with(&world)?; |
361 | let nav_info = match world.analysis().goto_type_definition(position)? { | 361 | let nav_info = match world.analysis().goto_type_definition(position)? { |
362 | None => return Ok(None), | 362 | None => return Ok(None), |
363 | Some(it) => it, | 363 | Some(it) => it, |
@@ -487,10 +487,10 @@ pub fn handle_folding_range( | |||
487 | 487 | ||
488 | pub fn handle_signature_help( | 488 | pub fn handle_signature_help( |
489 | world: WorldSnapshot, | 489 | world: WorldSnapshot, |
490 | params: req::TextDocumentPositionParams, | 490 | params: req::SignatureHelpParams, |
491 | ) -> Result<Option<req::SignatureHelp>> { | 491 | ) -> Result<Option<req::SignatureHelp>> { |
492 | let _p = profile("handle_signature_help"); | 492 | let _p = profile("handle_signature_help"); |
493 | let position = params.try_conv_with(&world)?; | 493 | let position = params.text_document_position_params.try_conv_with(&world)?; |
494 | if let Some(call_info) = world.analysis().call_info(position)? { | 494 | if let Some(call_info) = world.analysis().call_info(position)? { |
495 | let concise = !world.config.call_info_full; | 495 | let concise = !world.config.call_info_full; |
496 | let mut active_parameter = call_info.active_parameter.map(|it| it as i64); | 496 | let mut active_parameter = call_info.active_parameter.map(|it| it as i64); |
@@ -509,12 +509,9 @@ pub fn handle_signature_help( | |||
509 | } | 509 | } |
510 | } | 510 | } |
511 | 511 | ||
512 | pub fn handle_hover( | 512 | pub fn handle_hover(world: WorldSnapshot, params: req::HoverParams) -> Result<Option<Hover>> { |
513 | world: WorldSnapshot, | ||
514 | params: req::TextDocumentPositionParams, | ||
515 | ) -> Result<Option<Hover>> { | ||
516 | let _p = profile("handle_hover"); | 513 | let _p = profile("handle_hover"); |
517 | let position = params.try_conv_with(&world)?; | 514 | let position = params.text_document_position_params.try_conv_with(&world)?; |
518 | let info = match world.analysis().hover(position)? { | 515 | let info = match world.analysis().hover(position)? { |
519 | None => return Ok(None), | 516 | None => return Ok(None), |
520 | Some(info) => info, | 517 | Some(info) => info, |
@@ -878,8 +875,14 @@ pub fn handle_code_lens( | |||
878 | .map(|it| { | 875 | .map(|it| { |
879 | let range = it.node_range.conv_with(&line_index); | 876 | let range = it.node_range.conv_with(&line_index); |
880 | let pos = range.start; | 877 | let pos = range.start; |
881 | let lens_params = | 878 | let lens_params = req::GotoImplementationParams { |
882 | req::TextDocumentPositionParams::new(params.text_document.clone(), pos); | 879 | text_document_position_params: req::TextDocumentPositionParams::new( |
880 | params.text_document.clone(), | ||
881 | pos, | ||
882 | ), | ||
883 | work_done_progress_params: Default::default(), | ||
884 | partial_result_params: Default::default(), | ||
885 | }; | ||
883 | CodeLens { | 886 | CodeLens { |
884 | range, | 887 | range, |
885 | command: None, | 888 | command: None, |
@@ -894,7 +897,7 @@ pub fn handle_code_lens( | |||
894 | #[derive(Debug, Serialize, Deserialize)] | 897 | #[derive(Debug, Serialize, Deserialize)] |
895 | #[serde(rename_all = "camelCase")] | 898 | #[serde(rename_all = "camelCase")] |
896 | enum CodeLensResolveData { | 899 | enum CodeLensResolveData { |
897 | Impls(req::TextDocumentPositionParams), | 900 | Impls(req::GotoImplementationParams), |
898 | } | 901 | } |
899 | 902 | ||
900 | pub fn handle_code_lens_resolve(world: WorldSnapshot, code_lens: CodeLens) -> Result<CodeLens> { | 903 | pub fn handle_code_lens_resolve(world: WorldSnapshot, code_lens: CodeLens) -> Result<CodeLens> { |
@@ -927,7 +930,7 @@ pub fn handle_code_lens_resolve(world: WorldSnapshot, code_lens: CodeLens) -> Re | |||
927 | title, | 930 | title, |
928 | command: "rust-analyzer.showReferences".into(), | 931 | command: "rust-analyzer.showReferences".into(), |
929 | arguments: Some(vec![ | 932 | arguments: Some(vec![ |
930 | to_value(&lens_params.text_document.uri).unwrap(), | 933 | to_value(&lens_params.text_document_position_params.text_document.uri).unwrap(), |
931 | to_value(code_lens.range.start).unwrap(), | 934 | to_value(code_lens.range.start).unwrap(), |
932 | to_value(locations).unwrap(), | 935 | to_value(locations).unwrap(), |
933 | ]), | 936 | ]), |
@@ -944,16 +947,16 @@ pub fn handle_code_lens_resolve(world: WorldSnapshot, code_lens: CodeLens) -> Re | |||
944 | 947 | ||
945 | pub fn handle_document_highlight( | 948 | pub fn handle_document_highlight( |
946 | world: WorldSnapshot, | 949 | world: WorldSnapshot, |
947 | params: req::TextDocumentPositionParams, | 950 | params: req::DocumentHighlightParams, |
948 | ) -> Result<Option<Vec<DocumentHighlight>>> { | 951 | ) -> Result<Option<Vec<DocumentHighlight>>> { |
949 | let _p = profile("handle_document_highlight"); | 952 | let _p = profile("handle_document_highlight"); |
950 | let file_id = params.text_document.try_conv_with(&world)?; | 953 | let file_id = params.text_document_position_params.text_document.try_conv_with(&world)?; |
951 | let line_index = world.analysis().file_line_index(file_id)?; | 954 | let line_index = world.analysis().file_line_index(file_id)?; |
952 | 955 | ||
953 | let refs = match world | 956 | let refs = match world.analysis().find_all_refs( |
954 | .analysis() | 957 | params.text_document_position_params.try_conv_with(&world)?, |
955 | .find_all_refs(params.try_conv_with(&world)?, Some(SearchScope::single_file(file_id)))? | 958 | Some(SearchScope::single_file(file_id)), |
956 | { | 959 | )? { |
957 | None => return Ok(None), | 960 | None => return Ok(None), |
958 | Some(refs) => refs, | 961 | Some(refs) => refs, |
959 | }; | 962 | }; |
diff --git a/crates/rust-analyzer/src/req.rs b/crates/rust-analyzer/src/req.rs index ae3448892..0dae6bad4 100644 --- a/crates/rust-analyzer/src/req.rs +++ b/crates/rust-analyzer/src/req.rs | |||
@@ -8,14 +8,15 @@ pub use lsp_types::{ | |||
8 | notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CodeLens, | 8 | notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CodeLens, |
9 | CodeLensParams, CompletionParams, CompletionResponse, ConfigurationItem, ConfigurationParams, | 9 | CodeLensParams, CompletionParams, CompletionResponse, ConfigurationItem, ConfigurationParams, |
10 | DiagnosticTag, DidChangeConfigurationParams, DidChangeWatchedFilesParams, | 10 | DiagnosticTag, DidChangeConfigurationParams, DidChangeWatchedFilesParams, |
11 | DidChangeWatchedFilesRegistrationOptions, DocumentOnTypeFormattingParams, DocumentSymbolParams, | 11 | DidChangeWatchedFilesRegistrationOptions, DocumentHighlightParams, |
12 | DocumentSymbolResponse, FileSystemWatcher, Hover, InitializeResult, MessageType, | 12 | DocumentOnTypeFormattingParams, DocumentSymbolParams, DocumentSymbolResponse, |
13 | PartialResultParams, ProgressParams, ProgressParamsValue, ProgressToken, | 13 | FileSystemWatcher, GotoDefinitionParams, GotoDefinitionResponse, Hover, HoverParams, |
14 | PublishDiagnosticsParams, ReferenceParams, Registration, RegistrationParams, SelectionRange, | 14 | InitializeResult, MessageType, PartialResultParams, ProgressParams, ProgressParamsValue, |
15 | SelectionRangeParams, SemanticTokensParams, SemanticTokensRangeParams, | 15 | ProgressToken, PublishDiagnosticsParams, ReferenceParams, Registration, RegistrationParams, |
16 | SelectionRange, SelectionRangeParams, SemanticTokensParams, SemanticTokensRangeParams, | ||
16 | SemanticTokensRangeResult, SemanticTokensResult, ServerCapabilities, ShowMessageParams, | 17 | SemanticTokensRangeResult, SemanticTokensResult, ServerCapabilities, ShowMessageParams, |
17 | SignatureHelp, SymbolKind, TextDocumentEdit, TextDocumentPositionParams, TextEdit, | 18 | SignatureHelp, SignatureHelpParams, SymbolKind, TextDocumentEdit, TextDocumentPositionParams, |
18 | WorkDoneProgressParams, WorkspaceEdit, WorkspaceSymbolParams, | 19 | TextEdit, WorkDoneProgressParams, WorkspaceEdit, WorkspaceSymbolParams, |
19 | }; | 20 | }; |
20 | use std::path::PathBuf; | 21 | use std::path::PathBuf; |
21 | 22 | ||
diff --git a/crates/rust-analyzer/src/semantic_tokens.rs b/crates/rust-analyzer/src/semantic_tokens.rs index 71f4f58a3..2dc5cb119 100644 --- a/crates/rust-analyzer/src/semantic_tokens.rs +++ b/crates/rust-analyzer/src/semantic_tokens.rs | |||
@@ -4,64 +4,69 @@ use std::ops; | |||
4 | 4 | ||
5 | use lsp_types::{Range, SemanticToken, SemanticTokenModifier, SemanticTokenType, SemanticTokens}; | 5 | use lsp_types::{Range, SemanticToken, SemanticTokenModifier, SemanticTokenType, SemanticTokens}; |
6 | 6 | ||
7 | pub(crate) const ATTRIBUTE: SemanticTokenType = SemanticTokenType::new("attribute"); | 7 | macro_rules! define_semantic_token_types { |
8 | pub(crate) const BUILTIN_TYPE: SemanticTokenType = SemanticTokenType::new("builtinType"); | 8 | ($(($ident:ident, $string:literal)),*$(,)?) => { |
9 | pub(crate) const ENUM_MEMBER: SemanticTokenType = SemanticTokenType::new("enumMember"); | 9 | $(pub(crate) const $ident: SemanticTokenType = SemanticTokenType::new($string);)* |
10 | pub(crate) const LIFETIME: SemanticTokenType = SemanticTokenType::new("lifetime"); | 10 | |
11 | pub(crate) const TYPE_ALIAS: SemanticTokenType = SemanticTokenType::new("typeAlias"); | 11 | pub(crate) const SUPPORTED_TYPES: &[SemanticTokenType] = &[ |
12 | pub(crate) const UNION: SemanticTokenType = SemanticTokenType::new("union"); | 12 | SemanticTokenType::COMMENT, |
13 | pub(crate) const UNRESOLVED_REFERENCE: SemanticTokenType = | 13 | SemanticTokenType::KEYWORD, |
14 | SemanticTokenType::new("unresolvedReference"); | 14 | SemanticTokenType::STRING, |
15 | pub(crate) const FORMAT_SPECIFIER: SemanticTokenType = SemanticTokenType::new("formatSpecifier"); | 15 | SemanticTokenType::NUMBER, |
16 | 16 | SemanticTokenType::REGEXP, | |
17 | pub(crate) const CONSTANT: SemanticTokenModifier = SemanticTokenModifier::new("constant"); | 17 | SemanticTokenType::OPERATOR, |
18 | pub(crate) const CONTROL_FLOW: SemanticTokenModifier = SemanticTokenModifier::new("controlFlow"); | 18 | SemanticTokenType::NAMESPACE, |
19 | pub(crate) const MUTABLE: SemanticTokenModifier = SemanticTokenModifier::new("mutable"); | 19 | SemanticTokenType::TYPE, |
20 | pub(crate) const UNSAFE: SemanticTokenModifier = SemanticTokenModifier::new("unsafe"); | 20 | SemanticTokenType::STRUCT, |
21 | 21 | SemanticTokenType::CLASS, | |
22 | pub(crate) const SUPPORTED_TYPES: &[SemanticTokenType] = &[ | 22 | SemanticTokenType::INTERFACE, |
23 | SemanticTokenType::COMMENT, | 23 | SemanticTokenType::ENUM, |
24 | SemanticTokenType::KEYWORD, | 24 | SemanticTokenType::TYPE_PARAMETER, |
25 | SemanticTokenType::STRING, | 25 | SemanticTokenType::FUNCTION, |
26 | SemanticTokenType::NUMBER, | 26 | SemanticTokenType::MEMBER, |
27 | SemanticTokenType::REGEXP, | 27 | SemanticTokenType::PROPERTY, |
28 | SemanticTokenType::OPERATOR, | 28 | SemanticTokenType::MACRO, |
29 | SemanticTokenType::NAMESPACE, | 29 | SemanticTokenType::VARIABLE, |
30 | SemanticTokenType::TYPE, | 30 | SemanticTokenType::PARAMETER, |
31 | SemanticTokenType::STRUCT, | 31 | SemanticTokenType::LABEL, |
32 | SemanticTokenType::CLASS, | 32 | $($ident),* |
33 | SemanticTokenType::INTERFACE, | 33 | ]; |
34 | SemanticTokenType::ENUM, | 34 | }; |
35 | SemanticTokenType::TYPE_PARAMETER, | 35 | } |
36 | SemanticTokenType::FUNCTION, | 36 | |
37 | SemanticTokenType::MEMBER, | 37 | define_semantic_token_types![ |
38 | SemanticTokenType::PROPERTY, | 38 | (ATTRIBUTE, "attribute"), |
39 | SemanticTokenType::MACRO, | 39 | (BUILTIN_TYPE, "builtinType"), |
40 | SemanticTokenType::VARIABLE, | 40 | (ENUM_MEMBER, "enumMember"), |
41 | SemanticTokenType::PARAMETER, | 41 | (LIFETIME, "lifetime"), |
42 | SemanticTokenType::LABEL, | 42 | (TYPE_ALIAS, "typeAlias"), |
43 | ATTRIBUTE, | 43 | (UNION, "union"), |
44 | BUILTIN_TYPE, | 44 | (UNRESOLVED_REFERENCE, "unresolvedReference"), |
45 | ENUM_MEMBER, | 45 | (FORMAT_SPECIFIER, "formatSpecifier"), |
46 | LIFETIME, | ||
47 | TYPE_ALIAS, | ||
48 | UNION, | ||
49 | UNRESOLVED_REFERENCE, | ||
50 | FORMAT_SPECIFIER, | ||
51 | ]; | 46 | ]; |
52 | 47 | ||
53 | pub(crate) const SUPPORTED_MODIFIERS: &[SemanticTokenModifier] = &[ | 48 | macro_rules! define_semantic_token_modifiers { |
54 | SemanticTokenModifier::DOCUMENTATION, | 49 | ($(($ident:ident, $string:literal)),*$(,)?) => { |
55 | SemanticTokenModifier::DECLARATION, | 50 | $(pub(crate) const $ident: SemanticTokenModifier = SemanticTokenModifier::new($string);)* |
56 | SemanticTokenModifier::DEFINITION, | 51 | |
57 | SemanticTokenModifier::STATIC, | 52 | pub(crate) const SUPPORTED_MODIFIERS: &[SemanticTokenModifier] = &[ |
58 | SemanticTokenModifier::ABSTRACT, | 53 | SemanticTokenModifier::DOCUMENTATION, |
59 | SemanticTokenModifier::DEPRECATED, | 54 | SemanticTokenModifier::DECLARATION, |
60 | SemanticTokenModifier::READONLY, | 55 | SemanticTokenModifier::DEFINITION, |
61 | CONSTANT, | 56 | SemanticTokenModifier::STATIC, |
62 | MUTABLE, | 57 | SemanticTokenModifier::ABSTRACT, |
63 | UNSAFE, | 58 | SemanticTokenModifier::DEPRECATED, |
64 | CONTROL_FLOW, | 59 | SemanticTokenModifier::READONLY, |
60 | $($ident),* | ||
61 | ]; | ||
62 | }; | ||
63 | } | ||
64 | |||
65 | define_semantic_token_modifiers![ | ||
66 | (CONSTANT, "constant"), | ||
67 | (CONTROL_FLOW, "controlFlow"), | ||
68 | (MUTABLE, "mutable"), | ||
69 | (UNSAFE, "unsafe"), | ||
65 | ]; | 70 | ]; |
66 | 71 | ||
67 | #[derive(Default)] | 72 | #[derive(Default)] |
diff --git a/crates/rust-analyzer/tests/heavy_tests/main.rs b/crates/rust-analyzer/tests/heavy_tests/main.rs index f6245ddd4..07b8114c6 100644 --- a/crates/rust-analyzer/tests/heavy_tests/main.rs +++ b/crates/rust-analyzer/tests/heavy_tests/main.rs | |||
@@ -4,8 +4,8 @@ use std::{collections::HashMap, path::PathBuf, time::Instant}; | |||
4 | 4 | ||
5 | use lsp_types::{ | 5 | use lsp_types::{ |
6 | CodeActionContext, DidOpenTextDocumentParams, DocumentFormattingParams, FormattingOptions, | 6 | CodeActionContext, DidOpenTextDocumentParams, DocumentFormattingParams, FormattingOptions, |
7 | PartialResultParams, Position, Range, TextDocumentItem, TextDocumentPositionParams, | 7 | GotoDefinitionParams, HoverParams, PartialResultParams, Position, Range, TextDocumentItem, |
8 | WorkDoneProgressParams, | 8 | TextDocumentPositionParams, WorkDoneProgressParams, |
9 | }; | 9 | }; |
10 | use rust_analyzer::req::{ | 10 | use rust_analyzer::req::{ |
11 | CodeActionParams, CodeActionRequest, Completion, CompletionParams, DidOpenTextDocument, | 11 | CodeActionParams, CodeActionRequest, Completion, CompletionParams, DidOpenTextDocument, |
@@ -610,10 +610,14 @@ fn main() { message(); } | |||
610 | }) | 610 | }) |
611 | .server(); | 611 | .server(); |
612 | server.wait_until_workspace_is_loaded(); | 612 | server.wait_until_workspace_is_loaded(); |
613 | let res = server.send_request::<GotoDefinition>(TextDocumentPositionParams::new( | 613 | let res = server.send_request::<GotoDefinition>(GotoDefinitionParams { |
614 | server.doc_id("src/main.rs"), | 614 | text_document_position_params: TextDocumentPositionParams::new( |
615 | Position::new(2, 15), | 615 | server.doc_id("src/main.rs"), |
616 | )); | 616 | Position::new(2, 15), |
617 | ), | ||
618 | work_done_progress_params: Default::default(), | ||
619 | partial_result_params: Default::default(), | ||
620 | }); | ||
617 | assert!(format!("{}", res).contains("hello.rs")); | 621 | assert!(format!("{}", res).contains("hello.rs")); |
618 | } | 622 | } |
619 | 623 | ||
@@ -692,10 +696,13 @@ pub fn foo(_input: TokenStream) -> TokenStream { | |||
692 | .root("bar") | 696 | .root("bar") |
693 | .server(); | 697 | .server(); |
694 | server.wait_until_workspace_is_loaded(); | 698 | server.wait_until_workspace_is_loaded(); |
695 | let res = server.send_request::<HoverRequest>(TextDocumentPositionParams::new( | 699 | let res = server.send_request::<HoverRequest>(HoverParams { |
696 | server.doc_id("foo/src/main.rs"), | 700 | text_document_position_params: TextDocumentPositionParams::new( |
697 | Position::new(7, 9), | 701 | server.doc_id("foo/src/main.rs"), |
698 | )); | 702 | Position::new(7, 9), |
703 | ), | ||
704 | work_done_progress_params: Default::default(), | ||
705 | }); | ||
699 | 706 | ||
700 | let value = res.get("contents").unwrap().get("value").unwrap().to_string(); | 707 | let value = res.get("contents").unwrap().get("value").unwrap().to_string(); |
701 | assert_eq!(value, r#""```rust\nfoo::Bar\nfn bar()\n```""#) | 708 | assert_eq!(value, r#""```rust\nfoo::Bar\nfn bar()\n```""#) |
diff --git a/xtask/src/dist.rs b/xtask/src/dist.rs index a56eeef8d..aef68089e 100644 --- a/xtask/src/dist.rs +++ b/xtask/src/dist.rs | |||
@@ -50,21 +50,19 @@ fn dist_server(nightly: bool) -> Result<()> { | |||
50 | if cfg!(target_os = "linux") { | 50 | if cfg!(target_os = "linux") { |
51 | std::env::set_var("CC", "clang"); | 51 | std::env::set_var("CC", "clang"); |
52 | run!( | 52 | run!( |
53 | "cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release | 53 | "cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release" |
54 | --target x86_64-unknown-linux-musl | ||
55 | " | ||
56 | // We'd want to add, but that requires setting the right linker somehow | 54 | // We'd want to add, but that requires setting the right linker somehow |
57 | // --features=jemalloc | 55 | // --features=jemalloc |
58 | )?; | 56 | )?; |
59 | if !nightly { | 57 | if !nightly { |
60 | run!("strip ./target/x86_64-unknown-linux-musl/release/rust-analyzer")?; | 58 | run!("strip ./target/release/rust-analyzer")?; |
61 | } | 59 | } |
62 | } else { | 60 | } else { |
63 | run!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release")?; | 61 | run!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release")?; |
64 | } | 62 | } |
65 | 63 | ||
66 | let (src, dst) = if cfg!(target_os = "linux") { | 64 | let (src, dst) = if cfg!(target_os = "linux") { |
67 | ("./target/x86_64-unknown-linux-musl/release/rust-analyzer", "./dist/rust-analyzer-linux") | 65 | ("./target/release/rust-analyzer", "./dist/rust-analyzer-linux") |
68 | } else if cfg!(target_os = "windows") { | 66 | } else if cfg!(target_os = "windows") { |
69 | ("./target/release/rust-analyzer.exe", "./dist/rust-analyzer-windows.exe") | 67 | ("./target/release/rust-analyzer.exe", "./dist/rust-analyzer-windows.exe") |
70 | } else if cfg!(target_os = "macos") { | 68 | } else if cfg!(target_os = "macos") { |