aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/assists/src/handlers/extract_module_to_file.rs169
-rw-r--r--crates/rust-analyzer/src/config.rs34
-rw-r--r--docs/user/generated_config.adoc26
-rw-r--r--editors/code/package.json50
-rw-r--r--editors/code/src/main.ts20
5 files changed, 136 insertions, 163 deletions
diff --git a/crates/assists/src/handlers/extract_module_to_file.rs b/crates/assists/src/handlers/extract_module_to_file.rs
index 5fc190fa6..3e67fdca2 100644
--- a/crates/assists/src/handlers/extract_module_to_file.rs
+++ b/crates/assists/src/handlers/extract_module_to_file.rs
@@ -1,5 +1,5 @@
1use ast::edit::IndentLevel; 1use ast::edit::IndentLevel;
2use ide_db::base_db::{AnchoredPathBuf, SourceDatabaseExt}; 2use ide_db::base_db::AnchoredPathBuf;
3use syntax::{ 3use syntax::{
4 ast::{self, edit::AstNodeEdit, NameOwner}, 4 ast::{self, edit::AstNodeEdit, NameOwner},
5 AstNode, 5 AstNode,
@@ -21,43 +21,44 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
21// mod foo; 21// mod foo;
22// ``` 22// ```
23pub(crate) fn extract_module_to_file(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 23pub(crate) fn extract_module_to_file(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
24 let assist_id = AssistId("extract_module_to_file", AssistKind::RefactorExtract);
25 let assist_label = "Extract module to file";
26 let db = ctx.db();
27 let module_ast = ctx.find_node_at_offset::<ast::Module>()?; 24 let module_ast = ctx.find_node_at_offset::<ast::Module>()?;
28 let module_items = module_ast.item_list()?;
29 let dedent_module_items_text = module_items.dedent(IndentLevel(1)).to_string();
30 let module_name = module_ast.name()?; 25 let module_name = module_ast.name()?;
26
27 let module_def = ctx.sema.to_def(&module_ast)?;
28 let parent_module = module_def.parent(ctx.db())?;
29
30 let module_items = module_ast.item_list()?;
31 let target = module_ast.syntax().text_range(); 31 let target = module_ast.syntax().text_range();
32 let anchor_file_id = ctx.frange.file_id; 32 let anchor_file_id = ctx.frange.file_id;
33 let sr = db.file_source_root(anchor_file_id);
34 let sr = db.source_root(sr);
35 let file_path = sr.path_for_file(&anchor_file_id)?;
36 let (file_name, file_ext) = file_path.name_and_extension()?;
37 acc.add(assist_id, assist_label, target, |builder| {
38 builder.replace(target, format!("mod {};", module_name));
39 let path = if is_main_or_lib(file_name) {
40 format!("./{}.{}", module_name, file_ext.unwrap())
41 } else {
42 format!("./{}/{}.{}", file_name, module_name, file_ext.unwrap())
43 };
44 let dst = AnchoredPathBuf { anchor: anchor_file_id, path };
45 let contents = update_module_items_string(dedent_module_items_text);
46 builder.create_file(dst, contents);
47 })
48}
49fn is_main_or_lib(file_name: &str) -> bool {
50 file_name == "main".to_string() || file_name == "lib".to_string()
51}
52fn update_module_items_string(items_str: String) -> String {
53 let mut items_string_lines: Vec<&str> = items_str.lines().collect();
54 items_string_lines.pop(); // Delete last line
55 items_string_lines.reverse();
56 items_string_lines.pop(); // Delete first line
57 items_string_lines.reverse();
58 33
59 let string = items_string_lines.join("\n"); 34 acc.add(
60 format!("{}", string) 35 AssistId("extract_module_to_file", AssistKind::RefactorExtract),
36 "Extract module to file",
37 target,
38 |builder| {
39 let path = {
40 let dir = match parent_module.name(ctx.db()) {
41 Some(name) if !parent_module.is_mod_rs(ctx.db()) => format!("{}/", name),
42 _ => String::new(),
43 };
44 format!("./{}{}.rs", dir, module_name)
45 };
46 let contents = {
47 let items = module_items.dedent(IndentLevel(1)).to_string();
48 let mut items =
49 items.trim_start_matches('{').trim_end_matches('}').trim().to_string();
50 if !items.is_empty() {
51 items.push('\n');
52 }
53 items
54 };
55
56 builder.replace(target, format!("mod {};", module_name));
57
58 let dst = AnchoredPathBuf { anchor: anchor_file_id, path };
59 builder.create_file(dst, contents);
60 },
61 )
61} 62}
62 63
63#[cfg(test)] 64#[cfg(test)]
@@ -67,104 +68,66 @@ mod tests {
67 use super::*; 68 use super::*;
68 69
69 #[test] 70 #[test]
70 fn extract_module_to_file_with_basic_module() { 71 fn extract_from_root() {
71 check_assist( 72 check_assist(
72 extract_module_to_file, 73 extract_module_to_file,
73 r#" 74 r#"
74//- /foo.rs crate:foo
75mod tests {<|> 75mod tests {<|>
76 #[test] fn t() {} 76 #[test] fn t() {}
77} 77}
78"#, 78"#,
79 r#" 79 r#"
80//- /foo.rs 80//- /main.rs
81mod tests; 81mod tests;
82//- /foo/tests.rs 82//- /tests.rs
83#[test] fn t() {}"#, 83#[test] fn t() {}
84 )
85 }
86
87 #[test]
88 fn extract_module_to_file_with_file_path() {
89 check_assist(
90 extract_module_to_file,
91 r#"
92//- /src/foo.rs crate:foo
93mod bar {<|>
94 fn f() {
95
96 }
97}
98fn main() {
99 println!("Hello, world!");
100}
101"#, 84"#,
102 r#" 85 );
103//- /src/foo.rs
104mod bar;
105fn main() {
106 println!("Hello, world!");
107}
108//- /src/foo/bar.rs
109fn f() {
110
111}"#,
112 )
113 } 86 }
114 87
115 #[test] 88 #[test]
116 fn extract_module_to_file_with_main_filw() { 89 fn extract_from_submodule() {
117 check_assist( 90 check_assist(
118 extract_module_to_file, 91 extract_module_to_file,
119 r#" 92 r#"
120//- /main.rs 93//- /main.rs
121mod foo {<|> 94mod submodule;
122 fn f() { 95//- /submodule.rs
123 96mod inner<|> {
124 } 97 fn f() {}
125}
126fn main() {
127 println!("Hello, world!");
128} 98}
99fn g() {}
129"#, 100"#,
130 r#" 101 r#"
131//- /main.rs 102//- /submodule.rs
132mod foo; 103mod inner;
133fn main() { 104fn g() {}
134 println!("Hello, world!"); 105//- /submodule/inner.rs
135} 106fn f() {}
136//- /foo.rs 107"#,
137fn f() { 108 );
138
139}"#,
140 )
141 } 109 }
142 110
143 #[test] 111 #[test]
144 fn extract_module_to_file_with_lib_file() { 112 fn extract_from_mod_rs() {
145 check_assist( 113 check_assist(
146 extract_module_to_file, 114 extract_module_to_file,
147 r#" 115 r#"
148//- /lib.rs 116//- /main.rs
149mod foo {<|> 117mod submodule;
150 fn f() { 118//- /submodule/mod.rs
151 119mod inner<|> {
152 } 120 fn f() {}
153}
154fn main() {
155 println!("Hello, world!");
156} 121}
122fn g() {}
157"#, 123"#,
158 r#" 124 r#"
159//- /lib.rs 125//- /submodule/mod.rs
160mod foo; 126mod inner;
161fn main() { 127fn g() {}
162 println!("Hello, world!"); 128//- /submodule/inner.rs
163} 129fn f() {}
164//- /foo.rs 130"#,
165fn f() { 131 );
166
167}"#,
168 )
169 } 132 }
170} 133}
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 1f4b5c24c..11cdae57f 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -33,7 +33,7 @@ config_data! {
33 callInfo_full: bool = "true", 33 callInfo_full: bool = "true",
34 34
35 /// Automatically refresh project info via `cargo metadata` on 35 /// Automatically refresh project info via `cargo metadata` on
36 /// Cargo.toml changes. 36 /// `Cargo.toml` changes.
37 cargo_autoreload: bool = "true", 37 cargo_autoreload: bool = "true",
38 /// Activate all available features. 38 /// Activate all available features.
39 cargo_allFeatures: bool = "false", 39 cargo_allFeatures: bool = "false",
@@ -52,7 +52,7 @@ config_data! {
52 /// Run specified `cargo check` command for diagnostics on save. 52 /// Run specified `cargo check` command for diagnostics on save.
53 checkOnSave_enable: bool = "true", 53 checkOnSave_enable: bool = "true",
54 /// Check with all features (will be passed as `--all-features`). 54 /// Check with all features (will be passed as `--all-features`).
55 /// Defaults to `rust-analyzer.cargo.allFeatures`. 55 /// Defaults to `#rust-analyzer.cargo.allFeatures#`.
56 checkOnSave_allFeatures: Option<bool> = "null", 56 checkOnSave_allFeatures: Option<bool> = "null",
57 /// Check all targets and tests (will be passed as `--all-targets`). 57 /// Check all targets and tests (will be passed as `--all-targets`).
58 checkOnSave_allTargets: bool = "true", 58 checkOnSave_allTargets: bool = "true",
@@ -61,12 +61,12 @@ config_data! {
61 /// Do not activate the `default` feature. 61 /// Do not activate the `default` feature.
62 checkOnSave_noDefaultFeatures: Option<bool> = "null", 62 checkOnSave_noDefaultFeatures: Option<bool> = "null",
63 /// Check for a specific target. Defaults to 63 /// Check for a specific target. Defaults to
64 /// `rust-analyzer.cargo.target`. 64 /// `#rust-analyzer.cargo.target#`.
65 checkOnSave_target: Option<String> = "null", 65 checkOnSave_target: Option<String> = "null",
66 /// Extra arguments for `cargo check`. 66 /// Extra arguments for `cargo check`.
67 checkOnSave_extraArgs: Vec<String> = "[]", 67 checkOnSave_extraArgs: Vec<String> = "[]",
68 /// List of features to activate. Defaults to 68 /// List of features to activate. Defaults to
69 /// `rust-analyzer.cargo.features`. 69 /// `#rust-analyzer.cargo.features#`.
70 checkOnSave_features: Option<Vec<String>> = "null", 70 checkOnSave_features: Option<Vec<String>> = "null",
71 /// Advanced option, fully override the command rust-analyzer uses for 71 /// Advanced option, fully override the command rust-analyzer uses for
72 /// checking. The command should include `--message-format=json` or 72 /// checking. The command should include `--message-format=json` or
@@ -80,7 +80,7 @@ config_data! {
80 /// Whether to show postfix snippets like `dbg`, `if`, `not`, etc. 80 /// Whether to show postfix snippets like `dbg`, `if`, `not`, etc.
81 completion_postfix_enable: bool = "true", 81 completion_postfix_enable: bool = "true",
82 /// Toggles the additional completions that automatically add imports when completed. 82 /// Toggles the additional completions that automatically add imports when completed.
83 /// Note that your client have to specify the `additionalTextEdits` LSP client capability to truly have this feature enabled. 83 /// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
84 completion_autoimport_enable: bool = "true", 84 completion_autoimport_enable: bool = "true",
85 85
86 /// Whether to show native rust-analyzer diagnostics. 86 /// Whether to show native rust-analyzer diagnostics.
@@ -90,13 +90,13 @@ config_data! {
90 diagnostics_enableExperimental: bool = "true", 90 diagnostics_enableExperimental: bool = "true",
91 /// List of rust-analyzer diagnostics to disable. 91 /// List of rust-analyzer diagnostics to disable.
92 diagnostics_disabled: FxHashSet<String> = "[]", 92 diagnostics_disabled: FxHashSet<String> = "[]",
93 /// List of warnings that should be displayed with info severity.\nThe 93 /// List of warnings that should be displayed with info severity.\n\nThe
94 /// warnings will be indicated by a blue squiggly underline in code and 94 /// warnings will be indicated by a blue squiggly underline in code and
95 /// a blue icon in the problems panel. 95 /// a blue icon in the `Problems Panel`.
96 diagnostics_warningsAsHint: Vec<String> = "[]", 96 diagnostics_warningsAsHint: Vec<String> = "[]",
97 /// List of warnings that should be displayed with hint severity.\nThe 97 /// List of warnings that should be displayed with hint severity.\n\nThe
98 /// warnings will be indicated by faded text or three dots in code and 98 /// warnings will be indicated by faded text or three dots in code and
99 /// will not show up in the problems panel. 99 /// will not show up in the `Problems Panel`.
100 diagnostics_warningsAsInfo: Vec<String> = "[]", 100 diagnostics_warningsAsInfo: Vec<String> = "[]",
101 101
102 /// Controls file watching implementation. 102 /// Controls file watching implementation.
@@ -121,7 +121,7 @@ config_data! {
121 121
122 /// Whether to show inlay type hints for method chains. 122 /// Whether to show inlay type hints for method chains.
123 inlayHints_chainingHints: bool = "true", 123 inlayHints_chainingHints: bool = "true",
124 /// Maximum length for inlay hints. 124 /// Maximum length for inlay hints. Default is unlimited.
125 inlayHints_maxLength: Option<usize> = "null", 125 inlayHints_maxLength: Option<usize> = "null",
126 /// Whether to show function parameter name inlay hints at the call 126 /// Whether to show function parameter name inlay hints at the call
127 /// site. 127 /// site.
@@ -145,27 +145,27 @@ config_data! {
145 lens_methodReferences: bool = "false", 145 lens_methodReferences: bool = "false",
146 146
147 /// Disable project auto-discovery in favor of explicitly specified set 147 /// Disable project auto-discovery in favor of explicitly specified set
148 /// of projects. \nElements must be paths pointing to Cargo.toml, 148 /// of projects.\n\nElements must be paths pointing to `Cargo.toml`,
149 /// rust-project.json, or JSON objects in rust-project.json format. 149 /// `rust-project.json`, or JSON objects in `rust-project.json` format.
150 linkedProjects: Vec<ManifestOrProjectJson> = "[]", 150 linkedProjects: Vec<ManifestOrProjectJson> = "[]",
151 /// Number of syntax trees rust-analyzer keeps in memory. 151 /// Number of syntax trees rust-analyzer keeps in memory. Defaults to 128.
152 lruCapacity: Option<usize> = "null", 152 lruCapacity: Option<usize> = "null",
153 /// Whether to show `can't find Cargo.toml` error message. 153 /// Whether to show `can't find Cargo.toml` error message.
154 notifications_cargoTomlNotFound: bool = "true", 154 notifications_cargoTomlNotFound: bool = "true",
155 /// Enable Proc macro support, cargo.loadOutDirsFromCheck must be 155 /// Enable Proc macro support, `#rust-analyzer.cargo.loadOutDirsFromCheck#` must be
156 /// enabled. 156 /// enabled.
157 procMacro_enable: bool = "false", 157 procMacro_enable: bool = "false",
158 158
159 /// Command to be executed instead of 'cargo' for runnables. 159 /// Command to be executed instead of 'cargo' for runnables.
160 runnables_overrideCargo: Option<String> = "null", 160 runnables_overrideCargo: Option<String> = "null",
161 /// Additional arguments to be passed to cargo for runnables such as 161 /// Additional arguments to be passed to cargo for runnables such as
162 /// tests or binaries.\nFor example, it may be '--release'. 162 /// tests or binaries.\nFor example, it may be `--release`.
163 runnables_cargoExtraArgs: Vec<String> = "[]", 163 runnables_cargoExtraArgs: Vec<String> = "[]",
164 164
165 /// Path to the rust compiler sources, for usage in rustc_private projects. 165 /// Path to the rust compiler sources, for usage in rustc_private projects.
166 rustcSource : Option<String> = "null", 166 rustcSource : Option<String> = "null",
167 167
168 /// Additional arguments to rustfmt. 168 /// Additional arguments to `rustfmt`.
169 rustfmt_extraArgs: Vec<String> = "[]", 169 rustfmt_extraArgs: Vec<String> = "[]",
170 /// Advanced option, fully override the command rust-analyzer uses for 170 /// Advanced option, fully override the command rust-analyzer uses for
171 /// formatting. 171 /// formatting.
@@ -758,7 +758,7 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
758 ], 758 ],
759 "enumDescriptions": [ 759 "enumDescriptions": [
760 "Insert import paths relative to the current module, using up to one `super` prefix if the parent module contains the requested item.", 760 "Insert import paths relative to the current module, using up to one `super` prefix if the parent module contains the requested item.",
761 "Prefix all import paths with `self` if they don't begin with `self`, `super`, `crate` or a crate name", 761 "Prefix all import paths with `self` if they don't begin with `self`, `super`, `crate` or a crate name.",
762 "Force import paths to be absolute by always starting them with `crate` or the crate name they refer to." 762 "Force import paths to be absolute by always starting them with `crate` or the crate name they refer to."
763 ], 763 ],
764 }, 764 },
diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc
index cb2ae6fc1..3025dc8d6 100644
--- a/docs/user/generated_config.adoc
+++ b/docs/user/generated_config.adoc
@@ -5,7 +5,7 @@ rust-analyzer.assist.importPrefix (default: `"plain"`)::
5rust-analyzer.callInfo.full (default: `true`):: 5rust-analyzer.callInfo.full (default: `true`)::
6 Show function name and docs in parameter hints. 6 Show function name and docs in parameter hints.
7rust-analyzer.cargo.autoreload (default: `true`):: 7rust-analyzer.cargo.autoreload (default: `true`)::
8 Automatically refresh project info via `cargo metadata` on Cargo.toml changes. 8 Automatically refresh project info via `cargo metadata` on `Cargo.toml` changes.
9rust-analyzer.cargo.allFeatures (default: `false`):: 9rust-analyzer.cargo.allFeatures (default: `false`)::
10 Activate all available features. 10 Activate all available features.
11rust-analyzer.cargo.features (default: `[]`):: 11rust-analyzer.cargo.features (default: `[]`)::
@@ -21,7 +21,7 @@ rust-analyzer.cargo.noSysroot (default: `false`)::
21rust-analyzer.checkOnSave.enable (default: `true`):: 21rust-analyzer.checkOnSave.enable (default: `true`)::
22 Run specified `cargo check` command for diagnostics on save. 22 Run specified `cargo check` command for diagnostics on save.
23rust-analyzer.checkOnSave.allFeatures (default: `null`):: 23rust-analyzer.checkOnSave.allFeatures (default: `null`)::
24 Check with all features (will be passed as `--all-features`). Defaults to `rust-analyzer.cargo.allFeatures`. 24 Check with all features (will be passed as `--all-features`). Defaults to `#rust-analyzer.cargo.allFeatures#`.
25rust-analyzer.checkOnSave.allTargets (default: `true`):: 25rust-analyzer.checkOnSave.allTargets (default: `true`)::
26 Check all targets and tests (will be passed as `--all-targets`). 26 Check all targets and tests (will be passed as `--all-targets`).
27rust-analyzer.checkOnSave.command (default: `"check"`):: 27rust-analyzer.checkOnSave.command (default: `"check"`)::
@@ -29,11 +29,11 @@ rust-analyzer.checkOnSave.command (default: `"check"`)::
29rust-analyzer.checkOnSave.noDefaultFeatures (default: `null`):: 29rust-analyzer.checkOnSave.noDefaultFeatures (default: `null`)::
30 Do not activate the `default` feature. 30 Do not activate the `default` feature.
31rust-analyzer.checkOnSave.target (default: `null`):: 31rust-analyzer.checkOnSave.target (default: `null`)::
32 Check for a specific target. Defaults to `rust-analyzer.cargo.target`. 32 Check for a specific target. Defaults to `#rust-analyzer.cargo.target#`.
33rust-analyzer.checkOnSave.extraArgs (default: `[]`):: 33rust-analyzer.checkOnSave.extraArgs (default: `[]`)::
34 Extra arguments for `cargo check`. 34 Extra arguments for `cargo check`.
35rust-analyzer.checkOnSave.features (default: `null`):: 35rust-analyzer.checkOnSave.features (default: `null`)::
36 List of features to activate. Defaults to `rust-analyzer.cargo.features`. 36 List of features to activate. Defaults to `#rust-analyzer.cargo.features#`.
37rust-analyzer.checkOnSave.overrideCommand (default: `null`):: 37rust-analyzer.checkOnSave.overrideCommand (default: `null`)::
38 Advanced option, fully override the command rust-analyzer uses for checking. The command should include `--message-format=json` or similar option. 38 Advanced option, fully override the command rust-analyzer uses for checking. The command should include `--message-format=json` or similar option.
39rust-analyzer.completion.addCallArgumentSnippets (default: `true`):: 39rust-analyzer.completion.addCallArgumentSnippets (default: `true`)::
@@ -43,7 +43,7 @@ rust-analyzer.completion.addCallParenthesis (default: `true`)::
43rust-analyzer.completion.postfix.enable (default: `true`):: 43rust-analyzer.completion.postfix.enable (default: `true`)::
44 Whether to show postfix snippets like `dbg`, `if`, `not`, etc. 44 Whether to show postfix snippets like `dbg`, `if`, `not`, etc.
45rust-analyzer.completion.autoimport.enable (default: `true`):: 45rust-analyzer.completion.autoimport.enable (default: `true`)::
46 Toggles the additional completions that automatically add imports when completed. Note that your client have to specify the `additionalTextEdits` LSP client capability to truly have this feature enabled. 46 Toggles the additional completions that automatically add imports when completed. Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
47rust-analyzer.diagnostics.enable (default: `true`):: 47rust-analyzer.diagnostics.enable (default: `true`)::
48 Whether to show native rust-analyzer diagnostics. 48 Whether to show native rust-analyzer diagnostics.
49rust-analyzer.diagnostics.enableExperimental (default: `true`):: 49rust-analyzer.diagnostics.enableExperimental (default: `true`)::
@@ -51,9 +51,9 @@ rust-analyzer.diagnostics.enableExperimental (default: `true`)::
51rust-analyzer.diagnostics.disabled (default: `[]`):: 51rust-analyzer.diagnostics.disabled (default: `[]`)::
52 List of rust-analyzer diagnostics to disable. 52 List of rust-analyzer diagnostics to disable.
53rust-analyzer.diagnostics.warningsAsHint (default: `[]`):: 53rust-analyzer.diagnostics.warningsAsHint (default: `[]`)::
54 List of warnings that should be displayed with info severity.\nThe warnings will be indicated by a blue squiggly underline in code and a blue icon in the problems panel. 54 List of warnings that should be displayed with info severity.\n\nThe warnings will be indicated by a blue squiggly underline in code and a blue icon in the `Problems Panel`.
55rust-analyzer.diagnostics.warningsAsInfo (default: `[]`):: 55rust-analyzer.diagnostics.warningsAsInfo (default: `[]`)::
56 List of warnings that should be displayed with hint severity.\nThe warnings will be indicated by faded text or three dots in code and will not show up in the problems panel. 56 List of warnings that should be displayed with hint severity.\n\nThe warnings will be indicated by faded text or three dots in code and will not show up in the `Problems Panel`.
57rust-analyzer.files.watcher (default: `"client"`):: 57rust-analyzer.files.watcher (default: `"client"`)::
58 Controls file watching implementation. 58 Controls file watching implementation.
59rust-analyzer.hoverActions.debug (default: `true`):: 59rust-analyzer.hoverActions.debug (default: `true`)::
@@ -71,7 +71,7 @@ rust-analyzer.hoverActions.linksInHover (default: `true`)::
71rust-analyzer.inlayHints.chainingHints (default: `true`):: 71rust-analyzer.inlayHints.chainingHints (default: `true`)::
72 Whether to show inlay type hints for method chains. 72 Whether to show inlay type hints for method chains.
73rust-analyzer.inlayHints.maxLength (default: `null`):: 73rust-analyzer.inlayHints.maxLength (default: `null`)::
74 Maximum length for inlay hints. 74 Maximum length for inlay hints. Default is unlimited.
75rust-analyzer.inlayHints.parameterHints (default: `true`):: 75rust-analyzer.inlayHints.parameterHints (default: `true`)::
76 Whether to show function parameter name inlay hints at the call site. 76 Whether to show function parameter name inlay hints at the call site.
77rust-analyzer.inlayHints.typeHints (default: `true`):: 77rust-analyzer.inlayHints.typeHints (default: `true`)::
@@ -87,20 +87,20 @@ rust-analyzer.lens.run (default: `true`)::
87rust-analyzer.lens.methodReferences (default: `false`):: 87rust-analyzer.lens.methodReferences (default: `false`)::
88 Whether to show `Method References` lens. Only applies when `#rust-analyzer.lens.enable#` is set. 88 Whether to show `Method References` lens. Only applies when `#rust-analyzer.lens.enable#` is set.
89rust-analyzer.linkedProjects (default: `[]`):: 89rust-analyzer.linkedProjects (default: `[]`)::
90 Disable project auto-discovery in favor of explicitly specified set of projects. \nElements must be paths pointing to Cargo.toml, rust-project.json, or JSON objects in rust-project.json format. 90 Disable project auto-discovery in favor of explicitly specified set of projects.\n\nElements must be paths pointing to `Cargo.toml`, `rust-project.json`, or JSON objects in `rust-project.json` format.
91rust-analyzer.lruCapacity (default: `null`):: 91rust-analyzer.lruCapacity (default: `null`)::
92 Number of syntax trees rust-analyzer keeps in memory. 92 Number of syntax trees rust-analyzer keeps in memory. Defaults to 128.
93rust-analyzer.notifications.cargoTomlNotFound (default: `true`):: 93rust-analyzer.notifications.cargoTomlNotFound (default: `true`)::
94 Whether to show `can't find Cargo.toml` error message. 94 Whether to show `can't find Cargo.toml` error message.
95rust-analyzer.procMacro.enable (default: `false`):: 95rust-analyzer.procMacro.enable (default: `false`)::
96 Enable Proc macro support, cargo.loadOutDirsFromCheck must be enabled. 96 Enable Proc macro support, `#rust-analyzer.cargo.loadOutDirsFromCheck#` must be enabled.
97rust-analyzer.runnables.overrideCargo (default: `null`):: 97rust-analyzer.runnables.overrideCargo (default: `null`)::
98 Command to be executed instead of 'cargo' for runnables. 98 Command to be executed instead of 'cargo' for runnables.
99rust-analyzer.runnables.cargoExtraArgs (default: `[]`):: 99rust-analyzer.runnables.cargoExtraArgs (default: `[]`)::
100 Additional arguments to be passed to cargo for runnables such as tests or binaries.\nFor example, it may be '--release'. 100 Additional arguments to be passed to cargo for runnables such as tests or binaries.\nFor example, it may be `--release`.
101rust-analyzer.rustcSource (default: `null`):: 101rust-analyzer.rustcSource (default: `null`)::
102 Path to the rust compiler sources, for usage in rustc_private projects. 102 Path to the rust compiler sources, for usage in rustc_private projects.
103rust-analyzer.rustfmt.extraArgs (default: `[]`):: 103rust-analyzer.rustfmt.extraArgs (default: `[]`)::
104 Additional arguments to rustfmt. 104 Additional arguments to `rustfmt`.
105rust-analyzer.rustfmt.overrideCommand (default: `null`):: 105rust-analyzer.rustfmt.overrideCommand (default: `null`)::
106 Advanced option, fully override the command rust-analyzer uses for formatting. 106 Advanced option, fully override the command rust-analyzer uses for formatting.
diff --git a/editors/code/package.json b/editors/code/package.json
index abcc84eda..13749a084 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -250,12 +250,12 @@
250 } 250 }
251 ], 251 ],
252 "default": null, 252 "default": null,
253 "description": "Environment variables passed to the runnable launched using `Test ` or `Debug` lens or `rust-analyzer.run` command." 253 "markdownDescription": "Environment variables passed to the runnable launched using `Test` or `Debug` lens or `rust-analyzer.run` command."
254 }, 254 },
255 "rust-analyzer.inlayHints.enable": { 255 "rust-analyzer.inlayHints.enable": {
256 "type": "boolean", 256 "type": "boolean",
257 "default": true, 257 "default": true,
258 "description": "Whether to show inlay hints" 258 "description": "Whether to show inlay hints."
259 }, 259 },
260 "rust-analyzer.updates.channel": { 260 "rust-analyzer.updates.channel": {
261 "type": "string", 261 "type": "string",
@@ -265,15 +265,15 @@
265 ], 265 ],
266 "default": "stable", 266 "default": "stable",
267 "markdownEnumDescriptions": [ 267 "markdownEnumDescriptions": [
268 "`\"stable\"` updates are shipped weekly, they don't contain cutting-edge features from VSCode proposed APIs but have less bugs in general", 268 "`stable` updates are shipped weekly, they don't contain cutting-edge features from VSCode proposed APIs but have less bugs in general.",
269 "`\"nightly\"` updates are shipped daily (extension updates automatically by downloading artifacts directly from GitHub), they contain cutting-edge features and latest bug fixes. These releases help us get your feedback very quickly and speed up rust-analyzer development **drastically**" 269 "`nightly` updates are shipped daily (extension updates automatically by downloading artifacts directly from GitHub), they contain cutting-edge features and latest bug fixes. These releases help us get your feedback very quickly and speed up rust-analyzer development **drastically**."
270 ], 270 ],
271 "markdownDescription": "Choose `\"nightly\"` updates to get the latest features and bug fixes every day. While `\"stable\"` releases occur weekly and don't contain cutting-edge features from VSCode proposed APIs" 271 "markdownDescription": "Choose `nightly` updates to get the latest features and bug fixes every day. While `stable` releases occur weekly and don't contain cutting-edge features from VSCode proposed APIs."
272 }, 272 },
273 "rust-analyzer.updates.askBeforeDownload": { 273 "rust-analyzer.updates.askBeforeDownload": {
274 "type": "boolean", 274 "type": "boolean",
275 "default": true, 275 "default": true,
276 "description": "Whether to ask for permission before downloading any files from the Internet" 276 "description": "Whether to ask for permission before downloading any files from the Internet."
277 }, 277 },
278 "rust-analyzer.serverPath": { 278 "rust-analyzer.serverPath": {
279 "type": [ 279 "type": [
@@ -281,7 +281,7 @@
281 "string" 281 "string"
282 ], 282 ],
283 "default": null, 283 "default": null,
284 "description": "Path to rust-analyzer executable (points to bundled binary by default). If this is set, then \"rust-analyzer.updates.channel\" setting is not used" 284 "markdownDescription": "Path to rust-analyzer executable (points to bundled binary by default). If this is set, then `#rust-analyzer.updates.channel#` setting is not used"
285 }, 285 },
286 "rust-analyzer.trace.server": { 286 "rust-analyzer.trace.server": {
287 "type": "string", 287 "type": "string",
@@ -297,10 +297,10 @@
297 "Full log" 297 "Full log"
298 ], 298 ],
299 "default": "off", 299 "default": "off",
300 "description": "Trace requests to the rust-analyzer (this is usually overly verbose and not recommended for regular users)" 300 "description": "Trace requests to the rust-analyzer (this is usually overly verbose and not recommended for regular users)."
301 }, 301 },
302 "rust-analyzer.trace.extension": { 302 "rust-analyzer.trace.extension": {
303 "description": "Enable logging of VS Code extensions itself", 303 "description": "Enable logging of VS Code extensions itself.",
304 "type": "boolean", 304 "type": "boolean",
305 "default": false 305 "default": false
306 }, 306 },
@@ -327,14 +327,14 @@
327 } 327 }
328 }, 328 },
329 "rust-analyzer.debug.openDebugPane": { 329 "rust-analyzer.debug.openDebugPane": {
330 "description": "Whether to open up the Debug Pane on debugging start.", 330 "markdownDescription": "Whether to open up the `Debug Panel` on debugging start.",
331 "type": "boolean", 331 "type": "boolean",
332 "default": false 332 "default": false
333 }, 333 },
334 "rust-analyzer.debug.engineSettings": { 334 "rust-analyzer.debug.engineSettings": {
335 "type": "object", 335 "type": "object",
336 "default": {}, 336 "default": {},
337 "description": "Optional settings passed to the debug engine. Example:\n{ \"lldb\": { \"terminal\":\"external\"} }" 337 "markdownDescription": "Optional settings passed to the debug engine. Example: `{ \"lldb\": { \"terminal\":\"external\"} }`"
338 }, 338 },
339 "rust-analyzer.assist.importMergeBehaviour": { 339 "rust-analyzer.assist.importMergeBehaviour": {
340 "markdownDescription": "The strategy to use when inserting new imports or merging imports.", 340 "markdownDescription": "The strategy to use when inserting new imports or merging imports.",
@@ -362,7 +362,7 @@
362 ], 362 ],
363 "enumDescriptions": [ 363 "enumDescriptions": [
364 "Insert import paths relative to the current module, using up to one `super` prefix if the parent module contains the requested item.", 364 "Insert import paths relative to the current module, using up to one `super` prefix if the parent module contains the requested item.",
365 "Prefix all import paths with `self` if they don't begin with `self`, `super`, `crate` or a crate name", 365 "Prefix all import paths with `self` if they don't begin with `self`, `super`, `crate` or a crate name.",
366 "Force import paths to be absolute by always starting them with `crate` or the crate name they refer to." 366 "Force import paths to be absolute by always starting them with `crate` or the crate name they refer to."
367 ] 367 ]
368 }, 368 },
@@ -372,7 +372,7 @@
372 "type": "boolean" 372 "type": "boolean"
373 }, 373 },
374 "rust-analyzer.cargo.autoreload": { 374 "rust-analyzer.cargo.autoreload": {
375 "markdownDescription": "Automatically refresh project info via `cargo metadata` on Cargo.toml changes.", 375 "markdownDescription": "Automatically refresh project info via `cargo metadata` on `Cargo.toml` changes.",
376 "default": true, 376 "default": true,
377 "type": "boolean" 377 "type": "boolean"
378 }, 378 },
@@ -418,7 +418,7 @@
418 "type": "boolean" 418 "type": "boolean"
419 }, 419 },
420 "rust-analyzer.checkOnSave.allFeatures": { 420 "rust-analyzer.checkOnSave.allFeatures": {
421 "markdownDescription": "Check with all features (will be passed as `--all-features`). Defaults to `rust-analyzer.cargo.allFeatures`.", 421 "markdownDescription": "Check with all features (will be passed as `--all-features`). Defaults to `#rust-analyzer.cargo.allFeatures#`.",
422 "default": null, 422 "default": null,
423 "type": [ 423 "type": [
424 "null", 424 "null",
@@ -444,7 +444,7 @@
444 ] 444 ]
445 }, 445 },
446 "rust-analyzer.checkOnSave.target": { 446 "rust-analyzer.checkOnSave.target": {
447 "markdownDescription": "Check for a specific target. Defaults to `rust-analyzer.cargo.target`.", 447 "markdownDescription": "Check for a specific target. Defaults to `#rust-analyzer.cargo.target#`.",
448 "default": null, 448 "default": null,
449 "type": [ 449 "type": [
450 "null", 450 "null",
@@ -460,7 +460,7 @@
460 } 460 }
461 }, 461 },
462 "rust-analyzer.checkOnSave.features": { 462 "rust-analyzer.checkOnSave.features": {
463 "markdownDescription": "List of features to activate. Defaults to `rust-analyzer.cargo.features`.", 463 "markdownDescription": "List of features to activate. Defaults to `#rust-analyzer.cargo.features#`.",
464 "default": null, 464 "default": null,
465 "type": [ 465 "type": [
466 "null", 466 "null",
@@ -497,7 +497,7 @@
497 "type": "boolean" 497 "type": "boolean"
498 }, 498 },
499 "rust-analyzer.completion.autoimport.enable": { 499 "rust-analyzer.completion.autoimport.enable": {
500 "markdownDescription": "Toggles the additional completions that automatically add imports when completed. Note that your client have to specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.", 500 "markdownDescription": "Toggles the additional completions that automatically add imports when completed. Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.",
501 "default": true, 501 "default": true,
502 "type": "boolean" 502 "type": "boolean"
503 }, 503 },
@@ -521,7 +521,7 @@
521 "uniqueItems": true 521 "uniqueItems": true
522 }, 522 },
523 "rust-analyzer.diagnostics.warningsAsHint": { 523 "rust-analyzer.diagnostics.warningsAsHint": {
524 "markdownDescription": "List of warnings that should be displayed with info severity.\\nThe warnings will be indicated by a blue squiggly underline in code and a blue icon in the problems panel.", 524 "markdownDescription": "List of warnings that should be displayed with info severity.\\n\\nThe warnings will be indicated by a blue squiggly underline in code and a blue icon in the `Problems Panel`.",
525 "default": [], 525 "default": [],
526 "type": "array", 526 "type": "array",
527 "items": { 527 "items": {
@@ -529,7 +529,7 @@
529 } 529 }
530 }, 530 },
531 "rust-analyzer.diagnostics.warningsAsInfo": { 531 "rust-analyzer.diagnostics.warningsAsInfo": {
532 "markdownDescription": "List of warnings that should be displayed with hint severity.\\nThe warnings will be indicated by faded text or three dots in code and will not show up in the problems panel.", 532 "markdownDescription": "List of warnings that should be displayed with hint severity.\\n\\nThe warnings will be indicated by faded text or three dots in code and will not show up in the `Problems Panel`.",
533 "default": [], 533 "default": [],
534 "type": "array", 534 "type": "array",
535 "items": { 535 "items": {
@@ -577,7 +577,7 @@
577 "type": "boolean" 577 "type": "boolean"
578 }, 578 },
579 "rust-analyzer.inlayHints.maxLength": { 579 "rust-analyzer.inlayHints.maxLength": {
580 "markdownDescription": "Maximum length for inlay hints.", 580 "markdownDescription": "Maximum length for inlay hints. Default is unlimited.",
581 "default": null, 581 "default": null,
582 "type": [ 582 "type": [
583 "null", 583 "null",
@@ -621,7 +621,7 @@
621 "type": "boolean" 621 "type": "boolean"
622 }, 622 },
623 "rust-analyzer.linkedProjects": { 623 "rust-analyzer.linkedProjects": {
624 "markdownDescription": "Disable project auto-discovery in favor of explicitly specified set of projects. \\nElements must be paths pointing to Cargo.toml, rust-project.json, or JSON objects in rust-project.json format.", 624 "markdownDescription": "Disable project auto-discovery in favor of explicitly specified set of projects.\\n\\nElements must be paths pointing to `Cargo.toml`, `rust-project.json`, or JSON objects in `rust-project.json` format.",
625 "default": [], 625 "default": [],
626 "type": "array", 626 "type": "array",
627 "items": { 627 "items": {
@@ -632,7 +632,7 @@
632 } 632 }
633 }, 633 },
634 "rust-analyzer.lruCapacity": { 634 "rust-analyzer.lruCapacity": {
635 "markdownDescription": "Number of syntax trees rust-analyzer keeps in memory.", 635 "markdownDescription": "Number of syntax trees rust-analyzer keeps in memory. Defaults to 128.",
636 "default": null, 636 "default": null,
637 "type": [ 637 "type": [
638 "null", 638 "null",
@@ -646,7 +646,7 @@
646 "type": "boolean" 646 "type": "boolean"
647 }, 647 },
648 "rust-analyzer.procMacro.enable": { 648 "rust-analyzer.procMacro.enable": {
649 "markdownDescription": "Enable Proc macro support, cargo.loadOutDirsFromCheck must be enabled.", 649 "markdownDescription": "Enable Proc macro support, `#rust-analyzer.cargo.loadOutDirsFromCheck#` must be enabled.",
650 "default": false, 650 "default": false,
651 "type": "boolean" 651 "type": "boolean"
652 }, 652 },
@@ -659,7 +659,7 @@
659 ] 659 ]
660 }, 660 },
661 "rust-analyzer.runnables.cargoExtraArgs": { 661 "rust-analyzer.runnables.cargoExtraArgs": {
662 "markdownDescription": "Additional arguments to be passed to cargo for runnables such as tests or binaries.\\nFor example, it may be '--release'.", 662 "markdownDescription": "Additional arguments to be passed to cargo for runnables such as tests or binaries.\\nFor example, it may be `--release`.",
663 "default": [], 663 "default": [],
664 "type": "array", 664 "type": "array",
665 "items": { 665 "items": {
@@ -675,7 +675,7 @@
675 ] 675 ]
676 }, 676 },
677 "rust-analyzer.rustfmt.extraArgs": { 677 "rust-analyzer.rustfmt.extraArgs": {
678 "markdownDescription": "Additional arguments to rustfmt.", 678 "markdownDescription": "Additional arguments to `rustfmt`.",
679 "default": [], 679 "default": [],
680 "type": "array", 680 "type": "array",
681 "items": { 681 "items": {
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index e7d184cb3..282240d84 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -131,7 +131,7 @@ async function tryActivate(context: vscode.ExtensionContext) {
131 ctx.pushCleanup(activateTaskProvider(workspaceFolder, ctx.config)); 131 ctx.pushCleanup(activateTaskProvider(workspaceFolder, ctx.config));
132 132
133 activateInlayHints(ctx); 133 activateInlayHints(ctx);
134 warnAboutRustLangExtensionConflict(); 134 warnAboutExtensionConflicts();
135 135
136 vscode.workspace.onDidChangeConfiguration( 136 vscode.workspace.onDidChangeConfiguration(
137 _ => ctx?.client?.sendNotification('workspace/didChangeConfiguration', { settings: "" }), 137 _ => ctx?.client?.sendNotification('workspace/didChangeConfiguration', { settings: "" }),
@@ -413,11 +413,21 @@ async function queryForGithubToken(state: PersistentState): Promise<void> {
413 } 413 }
414} 414}
415 415
416function warnAboutRustLangExtensionConflict() { 416function warnAboutExtensionConflicts() {
417 const rustLangExt = vscode.extensions.getExtension("rust-lang.rust"); 417 const conflicting = [
418 if (rustLangExt !== undefined) { 418 ["rust-analyzer", "matklad.rust-analyzer"],
419 ["Rust", "rust-lang.rust"],
420 ["Rust", "kalitaalexey.vscode-rust"],
421 ];
422
423 const found = conflicting.filter(
424 nameId => vscode.extensions.getExtension(nameId[1]) !== undefined);
425
426 if (found.length > 1) {
427 const fst = found[0];
428 const sec = found[1];
419 vscode.window.showWarningMessage( 429 vscode.window.showWarningMessage(
420 "You have both rust-analyzer (matklad.rust-analyzer) and Rust (rust-lang.rust) " + 430 `You have both the ${fst[0]} (${fst[1]}) and ${sec[0]} (${sec[1]}) ` +
421 "plugins enabled. These are known to conflict and cause various functions of " + 431 "plugins enabled. These are known to conflict and cause various functions of " +
422 "both plugins to not work correctly. You should disable one of them.", "Got it"); 432 "both plugins to not work correctly. You should disable one of them.", "Got it");
423 }; 433 };