diff options
-rw-r--r-- | Cargo.lock | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 20 | ||||
-rw-r--r-- | crates/ra_ide/src/references.rs | 25 | ||||
-rw-r--r-- | crates/ra_ide_db/src/defs.rs | 12 | ||||
-rw-r--r-- | crates/rust-analyzer/src/bin/main.rs | 7 | ||||
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 60 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 19 | ||||
-rw-r--r-- | crates/rust-analyzer/tests/heavy_tests/support.rs | 1 | ||||
-rw-r--r-- | docs/dev/README.md | 2 | ||||
-rw-r--r-- | docs/user/readme.adoc | 2 |
10 files changed, 104 insertions, 48 deletions
diff --git a/Cargo.lock b/Cargo.lock index eefa9a676..5a319a040 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -1221,9 +1221,9 @@ dependencies = [ | |||
1221 | 1221 | ||
1222 | [[package]] | 1222 | [[package]] |
1223 | name = "ra_vfs" | 1223 | name = "ra_vfs" |
1224 | version = "0.6.0" | 1224 | version = "0.6.1" |
1225 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1225 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1226 | checksum = "fcaa5615f420134aea7667253db101d03a5c5f300eac607872dc2a36407b2ac9" | 1226 | checksum = "cbf31a173fc77ec59c27cf39af6baa137b40f4dbd45a8b3eccb1b2e4cfc922c1" |
1227 | dependencies = [ | 1227 | dependencies = [ |
1228 | "crossbeam-channel", | 1228 | "crossbeam-channel", |
1229 | "jod-thread", | 1229 | "jod-thread", |
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 3fc2eccdd..e8e3211fc 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -148,6 +148,26 @@ impl ModuleDef { | |||
148 | ModuleDef::BuiltinType(_) => None, | 148 | ModuleDef::BuiltinType(_) => None, |
149 | } | 149 | } |
150 | } | 150 | } |
151 | |||
152 | pub fn definition_visibility(&self, db: &dyn HirDatabase) -> Option<Visibility> { | ||
153 | let module = match self { | ||
154 | ModuleDef::Module(it) => it.parent(db)?, | ||
155 | ModuleDef::Function(it) => return Some(it.visibility(db)), | ||
156 | ModuleDef::Adt(it) => it.module(db), | ||
157 | ModuleDef::EnumVariant(it) => { | ||
158 | let parent = it.parent_enum(db); | ||
159 | let module = it.module(db); | ||
160 | return module.visibility_of(db, &ModuleDef::Adt(Adt::Enum(parent))); | ||
161 | } | ||
162 | ModuleDef::Const(it) => return Some(it.visibility(db)), | ||
163 | ModuleDef::Static(it) => it.module(db), | ||
164 | ModuleDef::Trait(it) => it.module(db), | ||
165 | ModuleDef::TypeAlias(it) => return Some(it.visibility(db)), | ||
166 | ModuleDef::BuiltinType(_) => return None, | ||
167 | }; | ||
168 | |||
169 | module.visibility_of(db, self) | ||
170 | } | ||
151 | } | 171 | } |
152 | 172 | ||
153 | pub use hir_def::{ | 173 | pub use hir_def::{ |
diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index 555ccf295..074284b42 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs | |||
@@ -593,6 +593,31 @@ mod tests { | |||
593 | check_result(refs, "i BIND_PAT FileId(1) 36..37 Other", &["FileId(1) 51..52 Other Write"]); | 593 | check_result(refs, "i BIND_PAT FileId(1) 36..37 Other", &["FileId(1) 51..52 Other Write"]); |
594 | } | 594 | } |
595 | 595 | ||
596 | #[test] | ||
597 | fn test_find_struct_function_refs_outside_module() { | ||
598 | let code = r#" | ||
599 | mod foo { | ||
600 | pub struct Foo; | ||
601 | |||
602 | impl Foo { | ||
603 | pub fn new<|>() -> Foo { | ||
604 | Foo | ||
605 | } | ||
606 | } | ||
607 | } | ||
608 | |||
609 | fn main() { | ||
610 | let _f = foo::Foo::new(); | ||
611 | }"#; | ||
612 | |||
613 | let refs = get_all_refs(code); | ||
614 | check_result( | ||
615 | refs, | ||
616 | "new FN_DEF FileId(1) 87..150 94..97 Other", | ||
617 | &["FileId(1) 227..230 StructLiteral"], | ||
618 | ); | ||
619 | } | ||
620 | |||
596 | fn get_all_refs(text: &str) -> ReferenceSearchResult { | 621 | fn get_all_refs(text: &str) -> ReferenceSearchResult { |
597 | let (analysis, position) = single_file_with_position(text); | 622 | let (analysis, position) = single_file_with_position(text); |
598 | analysis.find_all_refs(position, None).unwrap().unwrap() | 623 | analysis.find_all_refs(position, None).unwrap().unwrap() |
diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs index f990e3bb9..60c11178e 100644 --- a/crates/ra_ide_db/src/defs.rs +++ b/crates/ra_ide_db/src/defs.rs | |||
@@ -6,7 +6,7 @@ | |||
6 | // FIXME: this badly needs rename/rewrite (matklad, 2020-02-06). | 6 | // FIXME: this badly needs rename/rewrite (matklad, 2020-02-06). |
7 | 7 | ||
8 | use hir::{ | 8 | use hir::{ |
9 | Adt, Field, HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, Name, PathResolution, | 9 | Field, HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, Name, PathResolution, |
10 | Semantics, TypeParam, Visibility, | 10 | Semantics, TypeParam, Visibility, |
11 | }; | 11 | }; |
12 | use ra_prof::profile; | 12 | use ra_prof::profile; |
@@ -42,18 +42,10 @@ impl Definition { | |||
42 | } | 42 | } |
43 | 43 | ||
44 | pub fn visibility(&self, db: &RootDatabase) -> Option<Visibility> { | 44 | pub fn visibility(&self, db: &RootDatabase) -> Option<Visibility> { |
45 | let module = self.module(db); | ||
46 | |||
47 | match self { | 45 | match self { |
48 | Definition::Macro(_) => None, | 46 | Definition::Macro(_) => None, |
49 | Definition::Field(sf) => Some(sf.visibility(db)), | 47 | Definition::Field(sf) => Some(sf.visibility(db)), |
50 | Definition::ModuleDef(def) => match def { | 48 | Definition::ModuleDef(def) => def.definition_visibility(db), |
51 | ModuleDef::EnumVariant(id) => { | ||
52 | let parent = id.parent_enum(db); | ||
53 | module?.visibility_of(db, &ModuleDef::Adt(Adt::Enum(parent))) | ||
54 | } | ||
55 | _ => module?.visibility_of(db, def), | ||
56 | }, | ||
57 | Definition::SelfType(_) => None, | 49 | Definition::SelfType(_) => None, |
58 | Definition::Local(_) => None, | 50 | Definition::Local(_) => None, |
59 | Definition::TypeParam(_) => None, | 51 | Definition::TypeParam(_) => None, |
diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs index 22a84b50c..09908458d 100644 --- a/crates/rust-analyzer/src/bin/main.rs +++ b/crates/rust-analyzer/src/bin/main.rs | |||
@@ -60,7 +60,7 @@ fn main() -> Result<()> { | |||
60 | 60 | ||
61 | fn setup_logging() -> Result<()> { | 61 | fn setup_logging() -> Result<()> { |
62 | std::env::set_var("RUST_BACKTRACE", "short"); | 62 | std::env::set_var("RUST_BACKTRACE", "short"); |
63 | env_logger::try_init()?; | 63 | env_logger::try_init_from_env("RA_LOG")?; |
64 | ra_prof::init(); | 64 | ra_prof::init(); |
65 | Ok(()) | 65 | Ok(()) |
66 | } | 66 | } |
@@ -100,9 +100,8 @@ fn run_server() -> Result<()> { | |||
100 | if let Some(value) = &initialize_params.initialization_options { | 100 | if let Some(value) = &initialize_params.initialization_options { |
101 | config.update(value); | 101 | config.update(value); |
102 | } | 102 | } |
103 | if let Some(caps) = &initialize_params.capabilities.text_document { | 103 | config.update_caps(&initialize_params.capabilities); |
104 | config.update_caps(caps); | 104 | |
105 | } | ||
106 | config | 105 | config |
107 | }; | 106 | }; |
108 | 107 | ||
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index ccc38e3bb..53aee833d 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs | |||
@@ -9,7 +9,7 @@ | |||
9 | 9 | ||
10 | use std::{ffi::OsString, path::PathBuf}; | 10 | use std::{ffi::OsString, path::PathBuf}; |
11 | 11 | ||
12 | use lsp_types::TextDocumentClientCapabilities; | 12 | use lsp_types::ClientCapabilities; |
13 | use ra_flycheck::FlycheckConfig; | 13 | use ra_flycheck::FlycheckConfig; |
14 | use ra_ide::{CompletionConfig, InlayHintsConfig}; | 14 | use ra_ide::{CompletionConfig, InlayHintsConfig}; |
15 | use ra_project_model::CargoConfig; | 15 | use ra_project_model::CargoConfig; |
@@ -70,6 +70,7 @@ pub struct ClientCapsConfig { | |||
70 | pub line_folding_only: bool, | 70 | pub line_folding_only: bool, |
71 | pub hierarchical_symbols: bool, | 71 | pub hierarchical_symbols: bool, |
72 | pub code_action_literals: bool, | 72 | pub code_action_literals: bool, |
73 | pub work_done_progress: bool, | ||
73 | } | 74 | } |
74 | 75 | ||
75 | impl Default for Config { | 76 | impl Default for Config { |
@@ -208,30 +209,43 @@ impl Config { | |||
208 | } | 209 | } |
209 | } | 210 | } |
210 | 211 | ||
211 | pub fn update_caps(&mut self, caps: &TextDocumentClientCapabilities) { | 212 | pub fn update_caps(&mut self, caps: &ClientCapabilities) { |
212 | if let Some(value) = caps.definition.as_ref().and_then(|it| it.link_support) { | 213 | if let Some(doc_caps) = caps.text_document.as_ref() { |
213 | self.client_caps.location_link = value; | 214 | if let Some(value) = doc_caps.definition.as_ref().and_then(|it| it.link_support) { |
214 | } | 215 | self.client_caps.location_link = value; |
215 | if let Some(value) = caps.folding_range.as_ref().and_then(|it| it.line_folding_only) { | 216 | } |
216 | self.client_caps.line_folding_only = value | 217 | if let Some(value) = doc_caps.folding_range.as_ref().and_then(|it| it.line_folding_only) |
217 | } | 218 | { |
218 | if let Some(value) = | 219 | self.client_caps.line_folding_only = value |
219 | caps.document_symbol.as_ref().and_then(|it| it.hierarchical_document_symbol_support) | 220 | } |
220 | { | 221 | if let Some(value) = doc_caps |
221 | self.client_caps.hierarchical_symbols = value | 222 | .document_symbol |
222 | } | 223 | .as_ref() |
223 | if let Some(value) = | 224 | .and_then(|it| it.hierarchical_document_symbol_support) |
224 | caps.code_action.as_ref().and_then(|it| Some(it.code_action_literal_support.is_some())) | 225 | { |
225 | { | 226 | self.client_caps.hierarchical_symbols = value |
226 | self.client_caps.code_action_literals = value; | 227 | } |
227 | } | 228 | if let Some(value) = doc_caps |
228 | self.completion.allow_snippets(false); | 229 | .code_action |
229 | if let Some(completion) = &caps.completion { | 230 | .as_ref() |
230 | if let Some(completion_item) = &completion.completion_item { | 231 | .and_then(|it| Some(it.code_action_literal_support.is_some())) |
231 | if let Some(value) = completion_item.snippet_support { | 232 | { |
232 | self.completion.allow_snippets(value); | 233 | self.client_caps.code_action_literals = value; |
234 | } | ||
235 | self.completion.allow_snippets(false); | ||
236 | if let Some(completion) = &doc_caps.completion { | ||
237 | if let Some(completion_item) = &completion.completion_item { | ||
238 | if let Some(value) = completion_item.snippet_support { | ||
239 | self.completion.allow_snippets(value); | ||
240 | } | ||
233 | } | 241 | } |
234 | } | 242 | } |
235 | } | 243 | } |
244 | |||
245 | if let Some(window_caps) = caps.window.as_ref() { | ||
246 | if let Some(value) = window_caps.work_done_progress { | ||
247 | self.client_caps.work_done_progress = value; | ||
248 | } | ||
249 | } | ||
236 | } | 250 | } |
237 | } | 251 | } |
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 3f12dd718..13d305b97 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -415,7 +415,8 @@ fn loop_turn( | |||
415 | }); | 415 | }); |
416 | } | 416 | } |
417 | 417 | ||
418 | let show_progress = !loop_state.workspace_loaded; | 418 | let show_progress = |
419 | !loop_state.workspace_loaded && world_state.config.client_caps.work_done_progress; | ||
419 | 420 | ||
420 | if !loop_state.workspace_loaded | 421 | if !loop_state.workspace_loaded |
421 | && loop_state.roots_scanned == loop_state.roots_total | 422 | && loop_state.roots_scanned == loop_state.roots_total |
@@ -750,12 +751,16 @@ fn on_check_task( | |||
750 | } | 751 | } |
751 | 752 | ||
752 | CheckTask::Status(progress) => { | 753 | CheckTask::Status(progress) => { |
753 | let params = lsp_types::ProgressParams { | 754 | if world_state.config.client_caps.work_done_progress { |
754 | token: lsp_types::ProgressToken::String("rustAnalyzer/cargoWatcher".to_string()), | 755 | let params = lsp_types::ProgressParams { |
755 | value: lsp_types::ProgressParamsValue::WorkDone(progress), | 756 | token: lsp_types::ProgressToken::String( |
756 | }; | 757 | "rustAnalyzer/cargoWatcher".to_string(), |
757 | let not = notification_new::<lsp_types::notification::Progress>(params); | 758 | ), |
758 | task_sender.send(Task::Notify(not)).unwrap(); | 759 | value: lsp_types::ProgressParamsValue::WorkDone(progress), |
760 | }; | ||
761 | let not = notification_new::<lsp_types::notification::Progress>(params); | ||
762 | task_sender.send(Task::Notify(not)).unwrap(); | ||
763 | } | ||
759 | } | 764 | } |
760 | }; | 765 | }; |
761 | 766 | ||
diff --git a/crates/rust-analyzer/tests/heavy_tests/support.rs b/crates/rust-analyzer/tests/heavy_tests/support.rs index 8756ad4a3..9acbae066 100644 --- a/crates/rust-analyzer/tests/heavy_tests/support.rs +++ b/crates/rust-analyzer/tests/heavy_tests/support.rs | |||
@@ -80,6 +80,7 @@ impl<'a> Project<'a> { | |||
80 | client_caps: ClientCapsConfig { | 80 | client_caps: ClientCapsConfig { |
81 | location_link: true, | 81 | location_link: true, |
82 | code_action_literals: true, | 82 | code_action_literals: true, |
83 | work_done_progress: true, | ||
83 | ..Default::default() | 84 | ..Default::default() |
84 | }, | 85 | }, |
85 | with_sysroot: self.with_sysroot, | 86 | with_sysroot: self.with_sysroot, |
diff --git a/docs/dev/README.md b/docs/dev/README.md index f230dc1db..a20ead0b6 100644 --- a/docs/dev/README.md +++ b/docs/dev/README.md | |||
@@ -134,7 +134,7 @@ To log all communication between the server and the client, there are two choice | |||
134 | 134 | ||
135 | * you can log on the server side, by running something like | 135 | * you can log on the server side, by running something like |
136 | ``` | 136 | ``` |
137 | env RUST_LOG=gen_lsp_server=trace code . | 137 | env RA_LOG=gen_lsp_server=trace code . |
138 | ``` | 138 | ``` |
139 | 139 | ||
140 | * you can log on the client side, by enabling `"rust-analyzer.trace.server": | 140 | * you can log on the client side, by enabling `"rust-analyzer.trace.server": |
diff --git a/docs/user/readme.adoc b/docs/user/readme.adoc index f6ce0accf..d750c7705 100644 --- a/docs/user/readme.adoc +++ b/docs/user/readme.adoc | |||
@@ -108,7 +108,7 @@ Here are some useful self-diagnostic commands: | |||
108 | 108 | ||
109 | * **Rust Analyzer: Show RA Version** shows the version of `rust-analyzer` binary | 109 | * **Rust Analyzer: Show RA Version** shows the version of `rust-analyzer` binary |
110 | * **Rust Analyzer: Status** prints some statistics about the server, like the few latest LSP requests | 110 | * **Rust Analyzer: Status** prints some statistics about the server, like the few latest LSP requests |
111 | * To enable server-side logging, run with `env RUST_LOG=info` and see `Output > Rust Analyzer Language Server` in VS Code's panel. | 111 | * To enable server-side logging, run with `env RA_LOG=info` and see `Output > Rust Analyzer Language Server` in VS Code's panel. |
112 | * To log all LSP requests, add `"rust-analyzer.trace.server": "verbose"` to the settings and look for `Server Trace` in the panel. | 112 | * To log all LSP requests, add `"rust-analyzer.trace.server": "verbose"` to the settings and look for `Server Trace` in the panel. |
113 | * To enable client-side logging, add `"rust-analyzer.trace.extension": true` to the settings and open the `Console` tab of VS Code developer tools. | 113 | * To enable client-side logging, add `"rust-analyzer.trace.extension": true` to the settings and open the `Console` tab of VS Code developer tools. |
114 | 114 | ||