diff options
Diffstat (limited to 'crates')
39 files changed, 814 insertions, 232 deletions
diff --git a/crates/arena/Cargo.toml b/crates/arena/Cargo.toml index f2bb5cc45..863eedf76 100644 --- a/crates/arena/Cargo.toml +++ b/crates/arena/Cargo.toml | |||
@@ -1,6 +1,7 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "arena" | 2 | name = "arena" |
3 | version = "0.0.0" | 3 | version = "0.0.0" |
4 | description = "TBD" | ||
4 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 6 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 7 | edition = "2018" |
diff --git a/crates/assists/Cargo.toml b/crates/assists/Cargo.toml index a560a35c7..264125651 100644 --- a/crates/assists/Cargo.toml +++ b/crates/assists/Cargo.toml | |||
@@ -1,6 +1,7 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "assists" | 2 | name = "assists" |
3 | version = "0.0.0" | 3 | version = "0.0.0" |
4 | description = "TBD" | ||
4 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 6 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 7 | edition = "2018" |
@@ -13,11 +14,11 @@ rustc-hash = "1.1.0" | |||
13 | itertools = "0.9.0" | 14 | itertools = "0.9.0" |
14 | either = "1.5.3" | 15 | either = "1.5.3" |
15 | 16 | ||
16 | stdx = { path = "../stdx" } | 17 | stdx = { path = "../stdx", version = "0.0.0" } |
17 | syntax = { path = "../syntax" } | 18 | syntax = { path = "../syntax", version = "0.0.0" } |
18 | text_edit = { path = "../text_edit" } | 19 | text_edit = { path = "../text_edit", version = "0.0.0" } |
19 | profile = { path = "../profile" } | 20 | profile = { path = "../profile", version = "0.0.0" } |
20 | base_db = { path = "../base_db" } | 21 | base_db = { path = "../base_db", version = "0.0.0" } |
21 | ide_db = { path = "../ide_db" } | 22 | ide_db = { path = "../ide_db", version = "0.0.0" } |
22 | hir = { path = "../hir" } | 23 | hir = { path = "../hir", version = "0.0.0" } |
23 | test_utils = { path = "../test_utils" } | 24 | test_utils = { path = "../test_utils", version = "0.0.0" } |
diff --git a/crates/assists/src/assist_context.rs b/crates/assists/src/assist_context.rs index 11c171fc2..bf520069e 100644 --- a/crates/assists/src/assist_context.rs +++ b/crates/assists/src/assist_context.rs | |||
@@ -73,10 +73,6 @@ impl<'a> AssistContext<'a> { | |||
73 | self.sema.db | 73 | self.sema.db |
74 | } | 74 | } |
75 | 75 | ||
76 | pub(crate) fn source_file(&self) -> &SourceFile { | ||
77 | &self.source_file | ||
78 | } | ||
79 | |||
80 | // NB, this ignores active selection. | 76 | // NB, this ignores active selection. |
81 | pub(crate) fn offset(&self) -> TextSize { | 77 | pub(crate) fn offset(&self) -> TextSize { |
82 | self.frange.range.start() | 78 | self.frange.range.start() |
diff --git a/crates/assists/src/handlers/expand_glob_import.rs b/crates/assists/src/handlers/expand_glob_import.rs index 81d0af2f3..b39d040f6 100644 --- a/crates/assists/src/handlers/expand_glob_import.rs +++ b/crates/assists/src/handlers/expand_glob_import.rs | |||
@@ -1,10 +1,10 @@ | |||
1 | use either::Either; | 1 | use either::Either; |
2 | use hir::{AssocItem, MacroDef, ModuleDef, Name, PathResolution, ScopeDef, SemanticsScope}; | 2 | use hir::{AssocItem, MacroDef, Module, ModuleDef, Name, PathResolution, ScopeDef}; |
3 | use ide_db::{ | 3 | use ide_db::{ |
4 | defs::{classify_name_ref, Definition, NameRefClass}, | 4 | defs::{classify_name_ref, Definition, NameRefClass}, |
5 | RootDatabase, | 5 | search::SearchScope, |
6 | }; | 6 | }; |
7 | use syntax::{algo, ast, match_ast, AstNode, SyntaxNode, SyntaxToken, T}; | 7 | use syntax::{algo, ast, AstNode, Direction, SyntaxNode, SyntaxToken, T}; |
8 | 8 | ||
9 | use crate::{ | 9 | use crate::{ |
10 | assist_context::{AssistBuilder, AssistContext, Assists}, | 10 | assist_context::{AssistBuilder, AssistContext, Assists}, |
@@ -38,140 +38,259 @@ use crate::{ | |||
38 | // ``` | 38 | // ``` |
39 | pub(crate) fn expand_glob_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { | 39 | pub(crate) fn expand_glob_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { |
40 | let star = ctx.find_token_at_offset(T![*])?; | 40 | let star = ctx.find_token_at_offset(T![*])?; |
41 | let mod_path = find_mod_path(&star)?; | 41 | let (parent, mod_path) = find_parent_and_path(&star)?; |
42 | let module = match ctx.sema.resolve_path(&mod_path)? { | 42 | let target_module = match ctx.sema.resolve_path(&mod_path)? { |
43 | PathResolution::Def(ModuleDef::Module(it)) => it, | 43 | PathResolution::Def(ModuleDef::Module(it)) => it, |
44 | _ => return None, | 44 | _ => return None, |
45 | }; | 45 | }; |
46 | 46 | ||
47 | let source_file = ctx.source_file(); | 47 | let current_scope = ctx.sema.scope(&star.parent()); |
48 | let scope = ctx.sema.scope_at_offset(source_file.syntax(), ctx.offset()); | 48 | let current_module = current_scope.module()?; |
49 | 49 | ||
50 | let defs_in_mod = find_defs_in_mod(ctx, scope, module)?; | 50 | let refs_in_target = find_refs_in_mod(ctx, target_module, Some(current_module))?; |
51 | let name_refs_in_source_file = | 51 | let imported_defs = find_imported_defs(ctx, star)?; |
52 | source_file.syntax().descendants().filter_map(ast::NameRef::cast).collect(); | 52 | let names_to_import = find_names_to_import(ctx, refs_in_target, imported_defs); |
53 | let used_names = find_used_names(ctx, defs_in_mod, name_refs_in_source_file); | ||
54 | 53 | ||
55 | let parent = star.parent().parent()?; | 54 | let target = parent.clone().either(|n| n.syntax().clone(), |n| n.syntax().clone()); |
56 | acc.add( | 55 | acc.add( |
57 | AssistId("expand_glob_import", AssistKind::RefactorRewrite), | 56 | AssistId("expand_glob_import", AssistKind::RefactorRewrite), |
58 | "Expand glob import", | 57 | "Expand glob import", |
59 | parent.text_range(), | 58 | target.text_range(), |
60 | |builder| { | 59 | |builder| { |
61 | replace_ast(builder, &parent, mod_path, used_names); | 60 | replace_ast(builder, parent, mod_path, names_to_import); |
62 | }, | 61 | }, |
63 | ) | 62 | ) |
64 | } | 63 | } |
65 | 64 | ||
66 | fn find_mod_path(star: &SyntaxToken) -> Option<ast::Path> { | 65 | fn find_parent_and_path( |
67 | star.ancestors().find_map(|n| ast::UseTree::cast(n).and_then(|u| u.path())) | 66 | star: &SyntaxToken, |
67 | ) -> Option<(Either<ast::UseTree, ast::UseTreeList>, ast::Path)> { | ||
68 | return star.ancestors().find_map(|n| { | ||
69 | find_use_tree_list(n.clone()) | ||
70 | .and_then(|(u, p)| Some((Either::Right(u), p))) | ||
71 | .or_else(|| find_use_tree(n).and_then(|(u, p)| Some((Either::Left(u), p)))) | ||
72 | }); | ||
73 | |||
74 | fn find_use_tree_list(n: SyntaxNode) -> Option<(ast::UseTreeList, ast::Path)> { | ||
75 | let use_tree_list = ast::UseTreeList::cast(n)?; | ||
76 | let path = use_tree_list.parent_use_tree().path()?; | ||
77 | Some((use_tree_list, path)) | ||
78 | } | ||
79 | |||
80 | fn find_use_tree(n: SyntaxNode) -> Option<(ast::UseTree, ast::Path)> { | ||
81 | let use_tree = ast::UseTree::cast(n)?; | ||
82 | let path = use_tree.path()?; | ||
83 | Some((use_tree, path)) | ||
84 | } | ||
68 | } | 85 | } |
69 | 86 | ||
70 | #[derive(PartialEq)] | 87 | #[derive(Debug, PartialEq, Clone)] |
71 | enum Def { | 88 | enum Def { |
72 | ModuleDef(ModuleDef), | 89 | ModuleDef(ModuleDef), |
73 | MacroDef(MacroDef), | 90 | MacroDef(MacroDef), |
74 | } | 91 | } |
75 | 92 | ||
76 | impl Def { | 93 | impl Def { |
77 | fn name(&self, db: &RootDatabase) -> Option<Name> { | 94 | fn is_referenced_in(&self, ctx: &AssistContext) -> bool { |
78 | match self { | 95 | let def = match self { |
79 | Def::ModuleDef(def) => def.name(db), | 96 | Def::ModuleDef(def) => Definition::ModuleDef(*def), |
80 | Def::MacroDef(def) => def.name(db), | 97 | Def::MacroDef(def) => Definition::Macro(*def), |
98 | }; | ||
99 | |||
100 | let search_scope = SearchScope::single_file(ctx.frange.file_id); | ||
101 | def.usages(&ctx.sema).in_scope(search_scope).at_least_one() | ||
102 | } | ||
103 | } | ||
104 | |||
105 | #[derive(Debug, Clone)] | ||
106 | struct Ref { | ||
107 | // could be alias | ||
108 | visible_name: Name, | ||
109 | def: Def, | ||
110 | } | ||
111 | |||
112 | impl Ref { | ||
113 | fn from_scope_def(name: Name, scope_def: ScopeDef) -> Option<Self> { | ||
114 | match scope_def { | ||
115 | ScopeDef::ModuleDef(def) => Some(Ref { visible_name: name, def: Def::ModuleDef(def) }), | ||
116 | ScopeDef::MacroDef(def) => Some(Ref { visible_name: name, def: Def::MacroDef(def) }), | ||
117 | _ => None, | ||
81 | } | 118 | } |
82 | } | 119 | } |
83 | } | 120 | } |
84 | 121 | ||
85 | fn find_defs_in_mod( | 122 | #[derive(Debug, Clone)] |
123 | struct Refs(Vec<Ref>); | ||
124 | |||
125 | impl Refs { | ||
126 | fn used_refs(&self, ctx: &AssistContext) -> Refs { | ||
127 | Refs( | ||
128 | self.0 | ||
129 | .clone() | ||
130 | .into_iter() | ||
131 | .filter(|r| { | ||
132 | if let Def::ModuleDef(ModuleDef::Trait(tr)) = r.def { | ||
133 | if tr | ||
134 | .items(ctx.db()) | ||
135 | .into_iter() | ||
136 | .find(|ai| { | ||
137 | if let AssocItem::Function(f) = *ai { | ||
138 | Def::ModuleDef(ModuleDef::Function(f)).is_referenced_in(ctx) | ||
139 | } else { | ||
140 | false | ||
141 | } | ||
142 | }) | ||
143 | .is_some() | ||
144 | { | ||
145 | return true; | ||
146 | } | ||
147 | } | ||
148 | |||
149 | r.def.is_referenced_in(ctx) | ||
150 | }) | ||
151 | .collect(), | ||
152 | ) | ||
153 | } | ||
154 | |||
155 | fn filter_out_by_defs(&self, defs: Vec<Def>) -> Refs { | ||
156 | Refs(self.0.clone().into_iter().filter(|r| !defs.contains(&r.def)).collect()) | ||
157 | } | ||
158 | } | ||
159 | |||
160 | fn find_refs_in_mod( | ||
86 | ctx: &AssistContext, | 161 | ctx: &AssistContext, |
87 | from: SemanticsScope<'_>, | 162 | module: Module, |
88 | module: hir::Module, | 163 | visible_from: Option<Module>, |
89 | ) -> Option<Vec<Def>> { | 164 | ) -> Option<Refs> { |
90 | let module_scope = module.scope(ctx.db(), from.module()); | 165 | if let Some(from) = visible_from { |
91 | 166 | if !is_mod_visible_from(ctx, module, from) { | |
92 | let mut defs = vec![]; | 167 | return None; |
93 | for (_, def) in module_scope { | ||
94 | match def { | ||
95 | ScopeDef::ModuleDef(def) => defs.push(Def::ModuleDef(def)), | ||
96 | ScopeDef::MacroDef(def) => defs.push(Def::MacroDef(def)), | ||
97 | _ => continue, | ||
98 | } | 168 | } |
99 | } | 169 | } |
100 | 170 | ||
101 | Some(defs) | 171 | let module_scope = module.scope(ctx.db(), visible_from); |
172 | let refs = module_scope.into_iter().filter_map(|(n, d)| Ref::from_scope_def(n, d)).collect(); | ||
173 | Some(Refs(refs)) | ||
102 | } | 174 | } |
103 | 175 | ||
104 | fn find_used_names( | 176 | fn is_mod_visible_from(ctx: &AssistContext, module: Module, from: Module) -> bool { |
105 | ctx: &AssistContext, | 177 | match module.parent(ctx.db()) { |
106 | defs_in_mod: Vec<Def>, | 178 | Some(parent) => { |
107 | name_refs_in_source_file: Vec<ast::NameRef>, | 179 | parent.visibility_of(ctx.db(), &ModuleDef::Module(module)).map_or(true, |vis| { |
108 | ) -> Vec<Name> { | 180 | vis.is_visible_from(ctx.db(), from.into()) && is_mod_visible_from(ctx, parent, from) |
109 | let defs_in_source_file = name_refs_in_source_file | 181 | }) |
110 | .iter() | 182 | } |
111 | .filter_map(|r| classify_name_ref(&ctx.sema, r)) | 183 | None => true, |
112 | .filter_map(|rc| match rc { | 184 | } |
113 | NameRefClass::Definition(Definition::ModuleDef(def)) => Some(Def::ModuleDef(def)), | 185 | } |
114 | NameRefClass::Definition(Definition::Macro(def)) => Some(Def::MacroDef(def)), | ||
115 | _ => None, | ||
116 | }) | ||
117 | .collect::<Vec<Def>>(); | ||
118 | 186 | ||
119 | defs_in_mod | 187 | // looks for name refs in parent use block's siblings |
120 | .iter() | 188 | // |
121 | .filter(|def| { | 189 | // mod bar { |
122 | if let Def::ModuleDef(ModuleDef::Trait(tr)) = def { | 190 | // mod qux { |
123 | for item in tr.items(ctx.db()) { | 191 | // struct Qux; |
124 | if let AssocItem::Function(f) = item { | 192 | // } |
125 | if defs_in_source_file.contains(&Def::ModuleDef(ModuleDef::Function(f))) { | 193 | // |
126 | return true; | 194 | // pub use qux::Qux; |
127 | } | 195 | // } |
128 | } | 196 | // |
129 | } | 197 | // ↓ --------------- |
130 | } | 198 | // use foo::*<|>; |
199 | // use baz::Baz; | ||
200 | // ↑ --------------- | ||
201 | fn find_imported_defs(ctx: &AssistContext, star: SyntaxToken) -> Option<Vec<Def>> { | ||
202 | let parent_use_item_syntax = | ||
203 | star.ancestors().find_map(|n| if ast::Use::can_cast(n.kind()) { Some(n) } else { None })?; | ||
204 | |||
205 | Some( | ||
206 | [Direction::Prev, Direction::Next] | ||
207 | .iter() | ||
208 | .map(|dir| { | ||
209 | parent_use_item_syntax | ||
210 | .siblings(dir.to_owned()) | ||
211 | .filter(|n| ast::Use::can_cast(n.kind())) | ||
212 | }) | ||
213 | .flatten() | ||
214 | .filter_map(|n| Some(n.descendants().filter_map(ast::NameRef::cast))) | ||
215 | .flatten() | ||
216 | .filter_map(|r| match classify_name_ref(&ctx.sema, &r)? { | ||
217 | NameRefClass::Definition(Definition::ModuleDef(def)) => Some(Def::ModuleDef(def)), | ||
218 | NameRefClass::Definition(Definition::Macro(def)) => Some(Def::MacroDef(def)), | ||
219 | _ => None, | ||
220 | }) | ||
221 | .collect(), | ||
222 | ) | ||
223 | } | ||
131 | 224 | ||
132 | defs_in_source_file.contains(def) | 225 | fn find_names_to_import( |
133 | }) | 226 | ctx: &AssistContext, |
134 | .filter_map(|d| d.name(ctx.db())) | 227 | refs_in_target: Refs, |
135 | .collect() | 228 | imported_defs: Vec<Def>, |
229 | ) -> Vec<Name> { | ||
230 | let used_refs = refs_in_target.used_refs(ctx).filter_out_by_defs(imported_defs); | ||
231 | used_refs.0.iter().map(|r| r.visible_name.clone()).collect() | ||
136 | } | 232 | } |
137 | 233 | ||
138 | fn replace_ast( | 234 | fn replace_ast( |
139 | builder: &mut AssistBuilder, | 235 | builder: &mut AssistBuilder, |
140 | node: &SyntaxNode, | 236 | parent: Either<ast::UseTree, ast::UseTreeList>, |
141 | path: ast::Path, | 237 | path: ast::Path, |
142 | used_names: Vec<Name>, | 238 | names_to_import: Vec<Name>, |
143 | ) { | 239 | ) { |
144 | let replacement: Either<ast::UseTree, ast::UseTreeList> = match used_names.as_slice() { | 240 | let existing_use_trees = match parent.clone() { |
145 | [name] => Either::Left(ast::make::use_tree( | 241 | Either::Left(_) => vec![], |
146 | ast::make::path_from_text(&format!("{}::{}", path, name)), | 242 | Either::Right(u) => u |
147 | None, | 243 | .use_trees() |
148 | None, | 244 | .filter(|n| |
149 | false, | 245 | // filter out star |
150 | )), | 246 | n.star_token().is_none()) |
151 | names => Either::Right(ast::make::use_tree_list(names.iter().map(|n| { | 247 | .collect(), |
152 | ast::make::use_tree(ast::make::path_from_text(&n.to_string()), None, None, false) | ||
153 | }))), | ||
154 | }; | 248 | }; |
155 | 249 | ||
156 | let mut replace_node = |replacement: Either<ast::UseTree, ast::UseTreeList>| { | 250 | let new_use_trees: Vec<ast::UseTree> = names_to_import |
157 | algo::diff(node, &replacement.either(|u| u.syntax().clone(), |ut| ut.syntax().clone())) | 251 | .iter() |
252 | .map(|n| ast::make::use_tree(ast::make::path_from_text(&n.to_string()), None, None, false)) | ||
253 | .collect(); | ||
254 | |||
255 | let use_trees = [&existing_use_trees[..], &new_use_trees[..]].concat(); | ||
256 | |||
257 | match use_trees.as_slice() { | ||
258 | [name] => { | ||
259 | if let Some(end_path) = name.path() { | ||
260 | let replacement = ast::make::use_tree( | ||
261 | ast::make::path_from_text(&format!("{}::{}", path, end_path)), | ||
262 | None, | ||
263 | None, | ||
264 | false, | ||
265 | ); | ||
266 | |||
267 | algo::diff( | ||
268 | &parent.either(|n| n.syntax().clone(), |n| n.syntax().clone()), | ||
269 | replacement.syntax(), | ||
270 | ) | ||
271 | .into_text_edit(builder.text_edit_builder()); | ||
272 | } | ||
273 | } | ||
274 | names => { | ||
275 | let replacement = match parent { | ||
276 | Either::Left(_) => ast::make::use_tree( | ||
277 | path, | ||
278 | Some(ast::make::use_tree_list(names.to_owned())), | ||
279 | None, | ||
280 | false, | ||
281 | ) | ||
282 | .syntax() | ||
283 | .clone(), | ||
284 | Either::Right(_) => ast::make::use_tree_list(names.to_owned()).syntax().clone(), | ||
285 | }; | ||
286 | |||
287 | algo::diff( | ||
288 | &parent.either(|n| n.syntax().clone(), |n| n.syntax().clone()), | ||
289 | &replacement, | ||
290 | ) | ||
158 | .into_text_edit(builder.text_edit_builder()); | 291 | .into_text_edit(builder.text_edit_builder()); |
159 | }; | ||
160 | |||
161 | match_ast! { | ||
162 | match node { | ||
163 | ast::UseTree(use_tree) => { | ||
164 | replace_node(replacement); | ||
165 | }, | ||
166 | ast::UseTreeList(use_tree_list) => { | ||
167 | replace_node(replacement); | ||
168 | }, | ||
169 | ast::Use(use_item) => { | ||
170 | builder.replace_ast(use_item, ast::make::use_(replacement.left_or_else(|ut| ast::make::use_tree(path, Some(ut), None, false)))); | ||
171 | }, | ||
172 | _ => {}, | ||
173 | } | 292 | } |
174 | } | 293 | }; |
175 | } | 294 | } |
176 | 295 | ||
177 | #[cfg(test)] | 296 | #[cfg(test)] |
@@ -245,7 +364,46 @@ mod foo { | |||
245 | pub fn f() {} | 364 | pub fn f() {} |
246 | } | 365 | } |
247 | 366 | ||
248 | use foo::{Baz, Bar, f}; | 367 | use foo::{f, Baz, Bar}; |
368 | |||
369 | fn qux(bar: Bar, baz: Baz) { | ||
370 | f(); | ||
371 | } | ||
372 | ", | ||
373 | ) | ||
374 | } | ||
375 | |||
376 | #[test] | ||
377 | fn expanding_glob_import_with_existing_uses_in_same_module() { | ||
378 | check_assist( | ||
379 | expand_glob_import, | ||
380 | r" | ||
381 | mod foo { | ||
382 | pub struct Bar; | ||
383 | pub struct Baz; | ||
384 | pub struct Qux; | ||
385 | |||
386 | pub fn f() {} | ||
387 | } | ||
388 | |||
389 | use foo::Bar; | ||
390 | use foo::{*<|>, f}; | ||
391 | |||
392 | fn qux(bar: Bar, baz: Baz) { | ||
393 | f(); | ||
394 | } | ||
395 | ", | ||
396 | r" | ||
397 | mod foo { | ||
398 | pub struct Bar; | ||
399 | pub struct Baz; | ||
400 | pub struct Qux; | ||
401 | |||
402 | pub fn f() {} | ||
403 | } | ||
404 | |||
405 | use foo::Bar; | ||
406 | use foo::{f, Baz}; | ||
249 | 407 | ||
250 | fn qux(bar: Bar, baz: Baz) { | 408 | fn qux(bar: Bar, baz: Baz) { |
251 | f(); | 409 | f(); |
@@ -260,7 +418,7 @@ fn qux(bar: Bar, baz: Baz) { | |||
260 | expand_glob_import, | 418 | expand_glob_import, |
261 | r" | 419 | r" |
262 | mod foo { | 420 | mod foo { |
263 | mod bar { | 421 | pub mod bar { |
264 | pub struct Bar; | 422 | pub struct Bar; |
265 | pub struct Baz; | 423 | pub struct Baz; |
266 | pub struct Qux; | 424 | pub struct Qux; |
@@ -268,7 +426,7 @@ mod foo { | |||
268 | pub fn f() {} | 426 | pub fn f() {} |
269 | } | 427 | } |
270 | 428 | ||
271 | mod baz { | 429 | pub mod baz { |
272 | pub fn g() {} | 430 | pub fn g() {} |
273 | } | 431 | } |
274 | } | 432 | } |
@@ -282,7 +440,7 @@ fn qux(bar: Bar, baz: Baz) { | |||
282 | ", | 440 | ", |
283 | r" | 441 | r" |
284 | mod foo { | 442 | mod foo { |
285 | mod bar { | 443 | pub mod bar { |
286 | pub struct Bar; | 444 | pub struct Bar; |
287 | pub struct Baz; | 445 | pub struct Baz; |
288 | pub struct Qux; | 446 | pub struct Qux; |
@@ -290,55 +448,359 @@ mod foo { | |||
290 | pub fn f() {} | 448 | pub fn f() {} |
291 | } | 449 | } |
292 | 450 | ||
293 | mod baz { | 451 | pub mod baz { |
294 | pub fn g() {} | 452 | pub fn g() {} |
295 | } | 453 | } |
296 | } | 454 | } |
297 | 455 | ||
298 | use foo::{bar::{Baz, Bar, f}, baz::*}; | 456 | use foo::{bar::{f, Baz, Bar}, baz::*}; |
299 | 457 | ||
300 | fn qux(bar: Bar, baz: Baz) { | 458 | fn qux(bar: Bar, baz: Baz) { |
301 | f(); | 459 | f(); |
302 | g(); | 460 | g(); |
303 | } | 461 | } |
304 | ", | 462 | ", |
305 | ) | 463 | ); |
464 | |||
465 | check_assist( | ||
466 | expand_glob_import, | ||
467 | r" | ||
468 | mod foo { | ||
469 | pub mod bar { | ||
470 | pub struct Bar; | ||
471 | pub struct Baz; | ||
472 | pub struct Qux; | ||
473 | |||
474 | pub fn f() {} | ||
475 | } | ||
476 | |||
477 | pub mod baz { | ||
478 | pub fn g() {} | ||
479 | } | ||
480 | } | ||
481 | |||
482 | use foo::{bar::{Bar, Baz, f}, baz::*<|>}; | ||
483 | |||
484 | fn qux(bar: Bar, baz: Baz) { | ||
485 | f(); | ||
486 | g(); | ||
487 | } | ||
488 | ", | ||
489 | r" | ||
490 | mod foo { | ||
491 | pub mod bar { | ||
492 | pub struct Bar; | ||
493 | pub struct Baz; | ||
494 | pub struct Qux; | ||
495 | |||
496 | pub fn f() {} | ||
497 | } | ||
498 | |||
499 | pub mod baz { | ||
500 | pub fn g() {} | ||
501 | } | ||
502 | } | ||
503 | |||
504 | use foo::{bar::{Bar, Baz, f}, baz::g}; | ||
505 | |||
506 | fn qux(bar: Bar, baz: Baz) { | ||
507 | f(); | ||
508 | g(); | ||
509 | } | ||
510 | ", | ||
511 | ); | ||
512 | |||
513 | check_assist( | ||
514 | expand_glob_import, | ||
515 | r" | ||
516 | mod foo { | ||
517 | pub mod bar { | ||
518 | pub struct Bar; | ||
519 | pub struct Baz; | ||
520 | pub struct Qux; | ||
521 | |||
522 | pub fn f() {} | ||
523 | } | ||
524 | |||
525 | pub mod baz { | ||
526 | pub fn g() {} | ||
527 | |||
528 | pub mod qux { | ||
529 | pub fn h() {} | ||
530 | pub fn m() {} | ||
531 | |||
532 | pub mod q { | ||
533 | pub fn j() {} | ||
534 | } | ||
535 | } | ||
536 | } | ||
537 | } | ||
538 | |||
539 | use foo::{ | ||
540 | bar::{*, f}, | ||
541 | baz::{g, qux::*<|>} | ||
542 | }; | ||
543 | |||
544 | fn qux(bar: Bar, baz: Baz) { | ||
545 | f(); | ||
546 | g(); | ||
547 | h(); | ||
548 | q::j(); | ||
549 | } | ||
550 | ", | ||
551 | r" | ||
552 | mod foo { | ||
553 | pub mod bar { | ||
554 | pub struct Bar; | ||
555 | pub struct Baz; | ||
556 | pub struct Qux; | ||
557 | |||
558 | pub fn f() {} | ||
559 | } | ||
560 | |||
561 | pub mod baz { | ||
562 | pub fn g() {} | ||
563 | |||
564 | pub mod qux { | ||
565 | pub fn h() {} | ||
566 | pub fn m() {} | ||
567 | |||
568 | pub mod q { | ||
569 | pub fn j() {} | ||
570 | } | ||
571 | } | ||
572 | } | ||
573 | } | ||
574 | |||
575 | use foo::{ | ||
576 | bar::{*, f}, | ||
577 | baz::{g, qux::{q, h}} | ||
578 | }; | ||
579 | |||
580 | fn qux(bar: Bar, baz: Baz) { | ||
581 | f(); | ||
582 | g(); | ||
583 | h(); | ||
584 | q::j(); | ||
585 | } | ||
586 | ", | ||
587 | ); | ||
588 | |||
589 | check_assist( | ||
590 | expand_glob_import, | ||
591 | r" | ||
592 | mod foo { | ||
593 | pub mod bar { | ||
594 | pub struct Bar; | ||
595 | pub struct Baz; | ||
596 | pub struct Qux; | ||
597 | |||
598 | pub fn f() {} | ||
599 | } | ||
600 | |||
601 | pub mod baz { | ||
602 | pub fn g() {} | ||
603 | |||
604 | pub mod qux { | ||
605 | pub fn h() {} | ||
606 | pub fn m() {} | ||
607 | |||
608 | pub mod q { | ||
609 | pub fn j() {} | ||
610 | } | ||
611 | } | ||
612 | } | ||
613 | } | ||
614 | |||
615 | use foo::{ | ||
616 | bar::{*, f}, | ||
617 | baz::{g, qux::{h, q::*<|>}} | ||
618 | }; | ||
619 | |||
620 | fn qux(bar: Bar, baz: Baz) { | ||
621 | f(); | ||
622 | g(); | ||
623 | h(); | ||
624 | j(); | ||
625 | } | ||
626 | ", | ||
627 | r" | ||
628 | mod foo { | ||
629 | pub mod bar { | ||
630 | pub struct Bar; | ||
631 | pub struct Baz; | ||
632 | pub struct Qux; | ||
633 | |||
634 | pub fn f() {} | ||
635 | } | ||
636 | |||
637 | pub mod baz { | ||
638 | pub fn g() {} | ||
639 | |||
640 | pub mod qux { | ||
641 | pub fn h() {} | ||
642 | pub fn m() {} | ||
643 | |||
644 | pub mod q { | ||
645 | pub fn j() {} | ||
646 | } | ||
647 | } | ||
648 | } | ||
649 | } | ||
650 | |||
651 | use foo::{ | ||
652 | bar::{*, f}, | ||
653 | baz::{g, qux::{h, q::j}} | ||
654 | }; | ||
655 | |||
656 | fn qux(bar: Bar, baz: Baz) { | ||
657 | f(); | ||
658 | g(); | ||
659 | h(); | ||
660 | j(); | ||
661 | } | ||
662 | ", | ||
663 | ); | ||
664 | |||
665 | check_assist( | ||
666 | expand_glob_import, | ||
667 | r" | ||
668 | mod foo { | ||
669 | pub mod bar { | ||
670 | pub struct Bar; | ||
671 | pub struct Baz; | ||
672 | pub struct Qux; | ||
673 | |||
674 | pub fn f() {} | ||
675 | } | ||
676 | |||
677 | pub mod baz { | ||
678 | pub fn g() {} | ||
679 | |||
680 | pub mod qux { | ||
681 | pub fn h() {} | ||
682 | pub fn m() {} | ||
683 | |||
684 | pub mod q { | ||
685 | pub fn j() {} | ||
686 | } | ||
687 | } | ||
688 | } | ||
689 | } | ||
690 | |||
691 | use foo::{ | ||
692 | bar::{*, f}, | ||
693 | baz::{g, qux::{q::j, *<|>}} | ||
694 | }; | ||
695 | |||
696 | fn qux(bar: Bar, baz: Baz) { | ||
697 | f(); | ||
698 | g(); | ||
699 | h(); | ||
700 | j(); | ||
701 | } | ||
702 | ", | ||
703 | r" | ||
704 | mod foo { | ||
705 | pub mod bar { | ||
706 | pub struct Bar; | ||
707 | pub struct Baz; | ||
708 | pub struct Qux; | ||
709 | |||
710 | pub fn f() {} | ||
711 | } | ||
712 | |||
713 | pub mod baz { | ||
714 | pub fn g() {} | ||
715 | |||
716 | pub mod qux { | ||
717 | pub fn h() {} | ||
718 | pub fn m() {} | ||
719 | |||
720 | pub mod q { | ||
721 | pub fn j() {} | ||
722 | } | ||
723 | } | ||
724 | } | ||
725 | } | ||
726 | |||
727 | use foo::{ | ||
728 | bar::{*, f}, | ||
729 | baz::{g, qux::{q::j, h}} | ||
730 | }; | ||
731 | |||
732 | fn qux(bar: Bar, baz: Baz) { | ||
733 | f(); | ||
734 | g(); | ||
735 | h(); | ||
736 | j(); | ||
737 | } | ||
738 | ", | ||
739 | ); | ||
306 | } | 740 | } |
307 | 741 | ||
308 | #[test] | 742 | #[test] |
309 | fn expanding_glob_import_with_macro_defs() { | 743 | fn expanding_glob_import_with_macro_defs() { |
744 | // FIXME: this is currently fails because `Definition::find_usages` ignores macros | ||
745 | // https://github.com/rust-analyzer/rust-analyzer/issues/3484 | ||
746 | // | ||
747 | // check_assist( | ||
748 | // expand_glob_import, | ||
749 | // r" | ||
750 | // //- /lib.rs crate:foo | ||
751 | // #[macro_export] | ||
752 | // macro_rules! bar { | ||
753 | // () => () | ||
754 | // } | ||
755 | |||
756 | // pub fn baz() {} | ||
757 | |||
758 | // //- /main.rs crate:main deps:foo | ||
759 | // use foo::*<|>; | ||
760 | |||
761 | // fn main() { | ||
762 | // bar!(); | ||
763 | // baz(); | ||
764 | // } | ||
765 | // ", | ||
766 | // r" | ||
767 | // use foo::{bar, baz}; | ||
768 | |||
769 | // fn main() { | ||
770 | // bar!(); | ||
771 | // baz(); | ||
772 | // } | ||
773 | // ", | ||
774 | // ) | ||
775 | } | ||
776 | |||
777 | #[test] | ||
778 | fn expanding_glob_import_with_trait_method_uses() { | ||
310 | check_assist( | 779 | check_assist( |
311 | expand_glob_import, | 780 | expand_glob_import, |
312 | r" | 781 | r" |
313 | //- /lib.rs crate:foo | 782 | //- /lib.rs crate:foo |
314 | #[macro_export] | 783 | pub trait Tr { |
315 | macro_rules! bar { | 784 | fn method(&self) {} |
316 | () => () | ||
317 | } | 785 | } |
318 | 786 | impl Tr for () {} | |
319 | pub fn baz() {} | ||
320 | 787 | ||
321 | //- /main.rs crate:main deps:foo | 788 | //- /main.rs crate:main deps:foo |
322 | use foo::*<|>; | 789 | use foo::*<|>; |
323 | 790 | ||
324 | fn main() { | 791 | fn main() { |
325 | bar!(); | 792 | ().method(); |
326 | baz(); | ||
327 | } | 793 | } |
328 | ", | 794 | ", |
329 | r" | 795 | r" |
330 | use foo::{bar, baz}; | 796 | use foo::Tr; |
331 | 797 | ||
332 | fn main() { | 798 | fn main() { |
333 | bar!(); | 799 | ().method(); |
334 | baz(); | ||
335 | } | 800 | } |
336 | ", | 801 | ", |
337 | ) | 802 | ); |
338 | } | ||
339 | 803 | ||
340 | #[test] | ||
341 | fn expanding_glob_import_with_trait_method_uses() { | ||
342 | check_assist( | 804 | check_assist( |
343 | expand_glob_import, | 805 | expand_glob_import, |
344 | r" | 806 | r" |
@@ -348,6 +810,11 @@ pub trait Tr { | |||
348 | } | 810 | } |
349 | impl Tr for () {} | 811 | impl Tr for () {} |
350 | 812 | ||
813 | pub trait Tr2 { | ||
814 | fn method2(&self) {} | ||
815 | } | ||
816 | impl Tr2 for () {} | ||
817 | |||
351 | //- /main.rs crate:main deps:foo | 818 | //- /main.rs crate:main deps:foo |
352 | use foo::*<|>; | 819 | use foo::*<|>; |
353 | 820 | ||
@@ -362,7 +829,42 @@ fn main() { | |||
362 | ().method(); | 829 | ().method(); |
363 | } | 830 | } |
364 | ", | 831 | ", |
365 | ) | 832 | ); |
833 | } | ||
834 | |||
835 | #[test] | ||
836 | fn expanding_is_not_applicable_if_target_module_is_not_accessible_from_current_scope() { | ||
837 | check_assist_not_applicable( | ||
838 | expand_glob_import, | ||
839 | r" | ||
840 | mod foo { | ||
841 | mod bar { | ||
842 | pub struct Bar; | ||
843 | } | ||
844 | } | ||
845 | |||
846 | use foo::bar::*<|>; | ||
847 | |||
848 | fn baz(bar: Bar) {} | ||
849 | ", | ||
850 | ); | ||
851 | |||
852 | check_assist_not_applicable( | ||
853 | expand_glob_import, | ||
854 | r" | ||
855 | mod foo { | ||
856 | mod bar { | ||
857 | pub mod baz { | ||
858 | pub struct Baz; | ||
859 | } | ||
860 | } | ||
861 | } | ||
862 | |||
863 | use foo::bar::baz::*<|>; | ||
864 | |||
865 | fn qux(baz: Baz) {} | ||
866 | ", | ||
867 | ); | ||
366 | } | 868 | } |
367 | 869 | ||
368 | #[test] | 870 | #[test] |
diff --git a/crates/assists/src/handlers/invert_if.rs b/crates/assists/src/handlers/invert_if.rs index f0e047538..294256297 100644 --- a/crates/assists/src/handlers/invert_if.rs +++ b/crates/assists/src/handlers/invert_if.rs | |||
@@ -106,4 +106,22 @@ mod tests { | |||
106 | "fn f() { i<|>f let Some(_) = Some(1) { 1 } else { 0 } }", | 106 | "fn f() { i<|>f let Some(_) = Some(1) { 1 } else { 0 } }", |
107 | ) | 107 | ) |
108 | } | 108 | } |
109 | |||
110 | #[test] | ||
111 | fn invert_if_option_case() { | ||
112 | check_assist( | ||
113 | invert_if, | ||
114 | "fn f() { if<|> doc_style.is_some() { Class::DocComment } else { Class::Comment } }", | ||
115 | "fn f() { if doc_style.is_none() { Class::Comment } else { Class::DocComment } }", | ||
116 | ) | ||
117 | } | ||
118 | |||
119 | #[test] | ||
120 | fn invert_if_result_case() { | ||
121 | check_assist( | ||
122 | invert_if, | ||
123 | "fn f() { i<|>f doc_style.is_err() { Class::Err } else { Class::Ok } }", | ||
124 | "fn f() { if doc_style.is_ok() { Class::Ok } else { Class::Err } }", | ||
125 | ) | ||
126 | } | ||
109 | } | 127 | } |
diff --git a/crates/assists/src/utils.rs b/crates/assists/src/utils.rs index d071d6502..e15c982e7 100644 --- a/crates/assists/src/utils.rs +++ b/crates/assists/src/utils.rs | |||
@@ -11,7 +11,7 @@ use syntax::{ | |||
11 | ast::{self, make, NameOwner}, | 11 | ast::{self, make, NameOwner}, |
12 | AstNode, Direction, | 12 | AstNode, Direction, |
13 | SyntaxKind::*, | 13 | SyntaxKind::*, |
14 | SyntaxNode, TextSize, T, | 14 | SyntaxNode, SyntaxText, TextSize, T, |
15 | }; | 15 | }; |
16 | 16 | ||
17 | use crate::assist_config::SnippetCap; | 17 | use crate::assist_config::SnippetCap; |
@@ -179,6 +179,25 @@ fn invert_special_case(expr: &ast::Expr) -> Option<ast::Expr> { | |||
179 | ast::BinOp::EqualityTest => bin.replace_op(T![!=]).map(|it| it.into()), | 179 | ast::BinOp::EqualityTest => bin.replace_op(T![!=]).map(|it| it.into()), |
180 | _ => None, | 180 | _ => None, |
181 | }, | 181 | }, |
182 | ast::Expr::MethodCallExpr(mce) => { | ||
183 | const IS_SOME_TEXT: &str = "is_some"; | ||
184 | const IS_NONE_TEXT: &str = "is_none"; | ||
185 | const IS_OK_TEXT: &str = "is_ok"; | ||
186 | const IS_ERR_TEXT: &str = "is_err"; | ||
187 | |||
188 | let name = mce.name_ref()?; | ||
189 | let name_text = name.text(); | ||
190 | |||
191 | let caller = || -> Option<SyntaxText> { Some(mce.receiver()?.syntax().text()) }; | ||
192 | |||
193 | match name_text { | ||
194 | x if x == IS_SOME_TEXT => make::expr_method_call(IS_NONE_TEXT, caller), | ||
195 | x if x == IS_NONE_TEXT => make::expr_method_call(IS_SOME_TEXT, caller), | ||
196 | x if x == IS_OK_TEXT => make::expr_method_call(IS_ERR_TEXT, caller), | ||
197 | x if x == IS_ERR_TEXT => make::expr_method_call(IS_OK_TEXT, caller), | ||
198 | _ => None, | ||
199 | } | ||
200 | } | ||
182 | ast::Expr::PrefixExpr(pe) if pe.op_kind()? == ast::PrefixOp::Not => pe.expr(), | 201 | ast::Expr::PrefixExpr(pe) if pe.op_kind()? == ast::PrefixOp::Not => pe.expr(), |
183 | // FIXME: | 202 | // FIXME: |
184 | // ast::Expr::Literal(true | false ) | 203 | // ast::Expr::Literal(true | false ) |
diff --git a/crates/base_db/Cargo.toml b/crates/base_db/Cargo.toml index 7347d7528..f7bfcb0d7 100644 --- a/crates/base_db/Cargo.toml +++ b/crates/base_db/Cargo.toml | |||
@@ -1,6 +1,7 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "base_db" | 2 | name = "base_db" |
3 | version = "0.0.0" | 3 | version = "0.0.0" |
4 | description = "TBD" | ||
4 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 6 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 7 | edition = "2018" |
@@ -12,10 +13,10 @@ doctest = false | |||
12 | salsa = "0.15.2" | 13 | salsa = "0.15.2" |
13 | rustc-hash = "1.1.0" | 14 | rustc-hash = "1.1.0" |
14 | 15 | ||
15 | syntax = { path = "../syntax" } | 16 | syntax = { path = "../syntax", version = "0.0.0" } |
16 | cfg = { path = "../cfg" } | 17 | cfg = { path = "../cfg", version = "0.0.0" } |
17 | profile = { path = "../profile" } | 18 | profile = { path = "../profile", version = "0.0.0" } |
18 | tt = { path = "../tt" } | 19 | tt = { path = "../tt", version = "0.0.0" } |
19 | test_utils = { path = "../test_utils" } | 20 | test_utils = { path = "../test_utils", version = "0.0.0" } |
20 | vfs = { path = "../vfs" } | 21 | vfs = { path = "../vfs", version = "0.0.0" } |
21 | stdx = { path = "../stdx" } | 22 | stdx = { path = "../stdx", version = "0.0.0" } |
diff --git a/crates/cfg/Cargo.toml b/crates/cfg/Cargo.toml index d2ea551d1..a6785ee8e 100644 --- a/crates/cfg/Cargo.toml +++ b/crates/cfg/Cargo.toml | |||
@@ -1,6 +1,7 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "cfg" | 2 | name = "cfg" |
3 | version = "0.0.0" | 3 | version = "0.0.0" |
4 | description = "TBD" | ||
4 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 6 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 7 | edition = "2018" |
@@ -11,7 +12,7 @@ doctest = false | |||
11 | [dependencies] | 12 | [dependencies] |
12 | rustc-hash = "1.1.0" | 13 | rustc-hash = "1.1.0" |
13 | 14 | ||
14 | tt = { path = "../tt" } | 15 | tt = { path = "../tt", version = "0.0.0" } |
15 | 16 | ||
16 | [dev-dependencies] | 17 | [dev-dependencies] |
17 | mbe = { path = "../mbe" } | 18 | mbe = { path = "../mbe" } |
diff --git a/crates/flycheck/Cargo.toml b/crates/flycheck/Cargo.toml index 262a66e4e..c230fc1e2 100644 --- a/crates/flycheck/Cargo.toml +++ b/crates/flycheck/Cargo.toml | |||
@@ -1,6 +1,7 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "flycheck" | 2 | name = "flycheck" |
3 | version = "0.0.0" | 3 | version = "0.0.0" |
4 | description = "TBD" | ||
4 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 6 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 7 | edition = "2018" |
@@ -15,4 +16,4 @@ cargo_metadata = "0.11.1" | |||
15 | serde_json = "1.0.48" | 16 | serde_json = "1.0.48" |
16 | jod-thread = "0.1.1" | 17 | jod-thread = "0.1.1" |
17 | 18 | ||
18 | toolchain = { path = "../toolchain" } | 19 | toolchain = { path = "../toolchain", version = "0.0.0" } |
diff --git a/crates/hir/Cargo.toml b/crates/hir/Cargo.toml index dbb2986b6..60a48170e 100644 --- a/crates/hir/Cargo.toml +++ b/crates/hir/Cargo.toml | |||
@@ -1,6 +1,7 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "hir" | 2 | name = "hir" |
3 | version = "0.0.0" | 3 | version = "0.0.0" |
4 | description = "TBD" | ||
4 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 6 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 7 | edition = "2018" |
@@ -15,10 +16,10 @@ either = "1.5.3" | |||
15 | arrayvec = "0.5.1" | 16 | arrayvec = "0.5.1" |
16 | itertools = "0.9.0" | 17 | itertools = "0.9.0" |
17 | 18 | ||
18 | stdx = { path = "../stdx" } | 19 | stdx = { path = "../stdx", version = "0.0.0" } |
19 | syntax = { path = "../syntax" } | 20 | syntax = { path = "../syntax", version = "0.0.0" } |
20 | base_db = { path = "../base_db" } | 21 | base_db = { path = "../base_db", version = "0.0.0" } |
21 | profile = { path = "../profile" } | 22 | profile = { path = "../profile", version = "0.0.0" } |
22 | hir_expand = { path = "../hir_expand" } | 23 | hir_expand = { path = "../hir_expand", version = "0.0.0" } |
23 | hir_def = { path = "../hir_def" } | 24 | hir_def = { path = "../hir_def", version = "0.0.0" } |
24 | hir_ty = { path = "../hir_ty" } | 25 | hir_ty = { path = "../hir_ty", version = "0.0.0" } |
diff --git a/crates/hir_def/Cargo.toml b/crates/hir_def/Cargo.toml index 57745322f..011e4612c 100644 --- a/crates/hir_def/Cargo.toml +++ b/crates/hir_def/Cargo.toml | |||
@@ -1,6 +1,7 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "hir_def" | 2 | name = "hir_def" |
3 | version = "0.0.0" | 3 | version = "0.0.0" |
4 | description = "TBD" | ||
4 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 6 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 7 | edition = "2018" |
@@ -20,16 +21,16 @@ itertools = "0.9.0" | |||
20 | indexmap = "1.4.0" | 21 | indexmap = "1.4.0" |
21 | smallvec = "1.4.0" | 22 | smallvec = "1.4.0" |
22 | 23 | ||
23 | stdx = { path = "../stdx" } | 24 | stdx = { path = "../stdx", version = "0.0.0" } |
24 | arena = { path = "../arena" } | 25 | arena = { path = "../arena", version = "0.0.0" } |
25 | base_db = { path = "../base_db" } | 26 | base_db = { path = "../base_db", version = "0.0.0" } |
26 | syntax = { path = "../syntax" } | 27 | syntax = { path = "../syntax", version = "0.0.0" } |
27 | profile = { path = "../profile" } | 28 | profile = { path = "../profile", version = "0.0.0" } |
28 | hir_expand = { path = "../hir_expand" } | 29 | hir_expand = { path = "../hir_expand", version = "0.0.0" } |
29 | test_utils = { path = "../test_utils" } | 30 | test_utils = { path = "../test_utils", version = "0.0.0" } |
30 | mbe = { path = "../mbe" } | 31 | mbe = { path = "../mbe", version = "0.0.0" } |
31 | cfg = { path = "../cfg" } | 32 | cfg = { path = "../cfg", version = "0.0.0" } |
32 | tt = { path = "../tt" } | 33 | tt = { path = "../tt", version = "0.0.0" } |
33 | 34 | ||
34 | [dev-dependencies] | 35 | [dev-dependencies] |
35 | expect-test = "0.1" | 36 | expect-test = "0.1" |
diff --git a/crates/hir_expand/Cargo.toml b/crates/hir_expand/Cargo.toml index 1c4699291..9fad2ab94 100644 --- a/crates/hir_expand/Cargo.toml +++ b/crates/hir_expand/Cargo.toml | |||
@@ -1,6 +1,7 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "hir_expand" | 2 | name = "hir_expand" |
3 | version = "0.0.0" | 3 | version = "0.0.0" |
4 | description = "TBD" | ||
4 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 6 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 7 | edition = "2018" |
@@ -13,11 +14,11 @@ log = "0.4.8" | |||
13 | either = "1.5.3" | 14 | either = "1.5.3" |
14 | rustc-hash = "1.0.0" | 15 | rustc-hash = "1.0.0" |
15 | 16 | ||
16 | arena = { path = "../arena" } | 17 | arena = { path = "../arena", version = "0.0.0" } |
17 | base_db = { path = "../base_db" } | 18 | base_db = { path = "../base_db", version = "0.0.0" } |
18 | syntax = { path = "../syntax" } | 19 | syntax = { path = "../syntax", version = "0.0.0" } |
19 | parser = { path = "../parser" } | 20 | parser = { path = "../parser", version = "0.0.0" } |
20 | profile = { path = "../profile" } | 21 | profile = { path = "../profile", version = "0.0.0" } |
21 | tt = { path = "../tt" } | 22 | tt = { path = "../tt", version = "0.0.0" } |
22 | mbe = { path = "../mbe" } | 23 | mbe = { path = "../mbe", version = "0.0.0" } |
23 | test_utils = { path = "../test_utils"} | 24 | test_utils = { path = "../test_utils", version = "0.0.0" } |
diff --git a/crates/hir_ty/Cargo.toml b/crates/hir_ty/Cargo.toml index 06da0d0ec..33e155a70 100644 --- a/crates/hir_ty/Cargo.toml +++ b/crates/hir_ty/Cargo.toml | |||
@@ -1,6 +1,7 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "hir_ty" | 2 | name = "hir_ty" |
3 | version = "0.0.0" | 3 | version = "0.0.0" |
4 | description = "TBD" | ||
4 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 6 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 7 | edition = "2018" |
@@ -20,14 +21,14 @@ chalk-solve = { version = "0.23.0" } | |||
20 | chalk-ir = { version = "0.23.0" } | 21 | chalk-ir = { version = "0.23.0" } |
21 | chalk-recursive = { version = "0.23.0" } | 22 | chalk-recursive = { version = "0.23.0" } |
22 | 23 | ||
23 | stdx = { path = "../stdx" } | 24 | stdx = { path = "../stdx", version = "0.0.0" } |
24 | hir_def = { path = "../hir_def" } | 25 | hir_def = { path = "../hir_def", version = "0.0.0" } |
25 | hir_expand = { path = "../hir_expand" } | 26 | hir_expand = { path = "../hir_expand", version = "0.0.0" } |
26 | arena = { path = "../arena" } | 27 | arena = { path = "../arena", version = "0.0.0" } |
27 | base_db = { path = "../base_db" } | 28 | base_db = { path = "../base_db", version = "0.0.0" } |
28 | profile = { path = "../profile" } | 29 | profile = { path = "../profile", version = "0.0.0" } |
29 | syntax = { path = "../syntax" } | 30 | syntax = { path = "../syntax", version = "0.0.0" } |
30 | test_utils = { path = "../test_utils" } | 31 | test_utils = { path = "../test_utils", version = "0.0.0" } |
31 | 32 | ||
32 | [dev-dependencies] | 33 | [dev-dependencies] |
33 | expect-test = "0.1" | 34 | expect-test = "0.1" |
diff --git a/crates/ide/Cargo.toml b/crates/ide/Cargo.toml index 700944430..336e9d2aa 100644 --- a/crates/ide/Cargo.toml +++ b/crates/ide/Cargo.toml | |||
@@ -1,6 +1,7 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "ide" | 2 | name = "ide" |
3 | version = "0.0.0" | 3 | version = "0.0.0" |
4 | description = "TBD" | ||
4 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 6 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 7 | edition = "2018" |
@@ -16,20 +17,20 @@ log = "0.4.8" | |||
16 | rustc-hash = "1.1.0" | 17 | rustc-hash = "1.1.0" |
17 | oorandom = "11.1.2" | 18 | oorandom = "11.1.2" |
18 | 19 | ||
19 | stdx = { path = "../stdx" } | 20 | stdx = { path = "../stdx", version = "0.0.0" } |
20 | syntax = { path = "../syntax" } | 21 | syntax = { path = "../syntax", version = "0.0.0" } |
21 | text_edit = { path = "../text_edit" } | 22 | text_edit = { path = "../text_edit", version = "0.0.0" } |
22 | base_db = { path = "../base_db" } | 23 | base_db = { path = "../base_db", version = "0.0.0" } |
23 | ide_db = { path = "../ide_db" } | 24 | ide_db = { path = "../ide_db", version = "0.0.0" } |
24 | cfg = { path = "../cfg" } | 25 | cfg = { path = "../cfg", version = "0.0.0" } |
25 | profile = { path = "../profile" } | 26 | profile = { path = "../profile", version = "0.0.0" } |
26 | test_utils = { path = "../test_utils" } | 27 | test_utils = { path = "../test_utils", version = "0.0.0" } |
27 | assists = { path = "../assists" } | 28 | assists = { path = "../assists", version = "0.0.0" } |
28 | ssr = { path = "../ssr" } | 29 | ssr = { path = "../ssr", version = "0.0.0" } |
29 | 30 | ||
30 | # ide should depend only on the top-level `hir` package. if you need | 31 | # ide should depend only on the top-level `hir` package. if you need |
31 | # something from some `hir_xxx` subpackage, reexport the API via `hir`. | 32 | # something from some `hir_xxx` subpackage, reexport the API via `hir`. |
32 | hir = { path = "../hir" } | 33 | hir = { path = "../hir", version = "0.0.0" } |
33 | 34 | ||
34 | [dev-dependencies] | 35 | [dev-dependencies] |
35 | expect-test = "0.1" | 36 | expect-test = "0.1" |
diff --git a/crates/ide/src/completion.rs b/crates/ide/src/completion.rs index 25e580d80..33bed6991 100644 --- a/crates/ide/src/completion.rs +++ b/crates/ide/src/completion.rs | |||
@@ -92,7 +92,7 @@ pub use crate::completion::{ | |||
92 | /// already present, it should give all possible variants for the identifier at | 92 | /// already present, it should give all possible variants for the identifier at |
93 | /// the caret. In other words, for | 93 | /// the caret. In other words, for |
94 | /// | 94 | /// |
95 | /// ```no-run | 95 | /// ```no_run |
96 | /// fn f() { | 96 | /// fn f() { |
97 | /// let foo = 92; | 97 | /// let foo = 92; |
98 | /// let _ = bar<|> | 98 | /// let _ = bar<|> |
diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index 4139f329e..dd59d9e70 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs | |||
@@ -160,7 +160,7 @@ fn runnable_fn( | |||
160 | RunnableKind::Test { test_id, attr } | 160 | RunnableKind::Test { test_id, attr } |
161 | } else if fn_def.has_atom_attr("bench") { | 161 | } else if fn_def.has_atom_attr("bench") { |
162 | RunnableKind::Bench { test_id } | 162 | RunnableKind::Bench { test_id } |
163 | } else if has_doc_test(&fn_def) { | 163 | } else if has_runnable_doc_test(&fn_def) { |
164 | RunnableKind::DocTest { test_id } | 164 | RunnableKind::DocTest { test_id } |
165 | } else { | 165 | } else { |
166 | return None; | 166 | return None; |
@@ -211,8 +211,13 @@ fn has_test_related_attribute(fn_def: &ast::Fn) -> bool { | |||
211 | .any(|attribute_text| attribute_text.contains("test")) | 211 | .any(|attribute_text| attribute_text.contains("test")) |
212 | } | 212 | } |
213 | 213 | ||
214 | fn has_doc_test(fn_def: &ast::Fn) -> bool { | 214 | fn has_runnable_doc_test(fn_def: &ast::Fn) -> bool { |
215 | fn_def.doc_comment_text().map_or(false, |comment| comment.contains("```")) | 215 | fn_def.doc_comment_text().map_or(false, |comments_text| { |
216 | comments_text.contains("```") | ||
217 | && !comments_text.contains("```ignore") | ||
218 | && !comments_text.contains("```no_run") | ||
219 | && !comments_text.contains("```compile_fail") | ||
220 | }) | ||
216 | } | 221 | } |
217 | 222 | ||
218 | fn runnable_mod( | 223 | fn runnable_mod( |
@@ -417,6 +422,21 @@ fn main() {} | |||
417 | /// let x = 5; | 422 | /// let x = 5; |
418 | /// ``` | 423 | /// ``` |
419 | fn foo() {} | 424 | fn foo() {} |
425 | |||
426 | /// ```no_run | ||
427 | /// let z = 55; | ||
428 | /// ``` | ||
429 | fn should_have_no_runnable() {} | ||
430 | |||
431 | /// ```ignore | ||
432 | /// let z = 55; | ||
433 | /// ``` | ||
434 | fn should_have_no_runnable_2() {} | ||
435 | |||
436 | /// ```compile_fail | ||
437 | /// let z = 55; | ||
438 | /// ``` | ||
439 | fn should_have_no_runnable_3() {} | ||
420 | "#, | 440 | "#, |
421 | &[&BIN, &DOCTEST], | 441 | &[&BIN, &DOCTEST], |
422 | expect![[r#" | 442 | expect![[r#" |
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index aefc86949..25d6f7abd 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs | |||
@@ -748,12 +748,6 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight { | |||
748 | if func.is_unsafe(db) { | 748 | if func.is_unsafe(db) { |
749 | h |= HighlightModifier::Unsafe; | 749 | h |= HighlightModifier::Unsafe; |
750 | } | 750 | } |
751 | if let Some(self_param) = func.self_param(db) { | ||
752 | match self_param.access(db) { | ||
753 | hir::Access::Exclusive => h |= HighlightModifier::Mutable, | ||
754 | hir::Access::Shared | hir::Access::Owned => (), | ||
755 | } | ||
756 | } | ||
757 | return h; | 751 | return h; |
758 | } | 752 | } |
759 | hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Struct, | 753 | hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Struct, |
diff --git a/crates/ide/test_data/highlighting.html b/crates/ide/test_data/highlighting.html index a6b79589b..d0df2e0ec 100644 --- a/crates/ide/test_data/highlighting.html +++ b/crates/ide/test_data/highlighting.html | |||
@@ -65,7 +65,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
65 | <span class="self_keyword">self</span><span class="punctuation">.</span><span class="field">x</span> | 65 | <span class="self_keyword">self</span><span class="punctuation">.</span><span class="field">x</span> |
66 | <span class="punctuation">}</span> | 66 | <span class="punctuation">}</span> |
67 | 67 | ||
68 | <span class="keyword">fn</span> <span class="function declaration mutable">qux</span><span class="punctuation">(</span><span class="operator">&</span><span class="keyword">mut</span> <span class="self_keyword mutable">self</span><span class="punctuation">)</span> <span class="punctuation">{</span> | 68 | <span class="keyword">fn</span> <span class="function declaration">qux</span><span class="punctuation">(</span><span class="operator">&</span><span class="keyword">mut</span> <span class="self_keyword mutable">self</span><span class="punctuation">)</span> <span class="punctuation">{</span> |
69 | <span class="self_keyword mutable">self</span><span class="punctuation">.</span><span class="field">x</span> <span class="operator">=</span> <span class="numeric_literal">0</span><span class="punctuation">;</span> | 69 | <span class="self_keyword mutable">self</span><span class="punctuation">.</span><span class="field">x</span> <span class="operator">=</span> <span class="numeric_literal">0</span><span class="punctuation">;</span> |
70 | <span class="punctuation">}</span> | 70 | <span class="punctuation">}</span> |
71 | 71 | ||
@@ -84,7 +84,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
84 | <span class="self_keyword">self</span><span class="punctuation">.</span><span class="field">x</span> | 84 | <span class="self_keyword">self</span><span class="punctuation">.</span><span class="field">x</span> |
85 | <span class="punctuation">}</span> | 85 | <span class="punctuation">}</span> |
86 | 86 | ||
87 | <span class="keyword">fn</span> <span class="function declaration mutable">qux</span><span class="punctuation">(</span><span class="operator">&</span><span class="keyword">mut</span> <span class="self_keyword mutable">self</span><span class="punctuation">)</span> <span class="punctuation">{</span> | 87 | <span class="keyword">fn</span> <span class="function declaration">qux</span><span class="punctuation">(</span><span class="operator">&</span><span class="keyword">mut</span> <span class="self_keyword mutable">self</span><span class="punctuation">)</span> <span class="punctuation">{</span> |
88 | <span class="self_keyword mutable">self</span><span class="punctuation">.</span><span class="field">x</span> <span class="operator">=</span> <span class="numeric_literal">0</span><span class="punctuation">;</span> | 88 | <span class="self_keyword mutable">self</span><span class="punctuation">.</span><span class="field">x</span> <span class="operator">=</span> <span class="numeric_literal">0</span><span class="punctuation">;</span> |
89 | <span class="punctuation">}</span> | 89 | <span class="punctuation">}</span> |
90 | 90 | ||
diff --git a/crates/ide_db/Cargo.toml b/crates/ide_db/Cargo.toml index 692fb6415..320fb15e5 100644 --- a/crates/ide_db/Cargo.toml +++ b/crates/ide_db/Cargo.toml | |||
@@ -1,6 +1,7 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "ide_db" | 2 | name = "ide_db" |
3 | version = "0.0.0" | 3 | version = "0.0.0" |
4 | description = "TBD" | ||
4 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 6 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 7 | edition = "2018" |
@@ -19,12 +20,12 @@ rustc-hash = "1.1.0" | |||
19 | once_cell = "1.3.1" | 20 | once_cell = "1.3.1" |
20 | either = "1.5.3" | 21 | either = "1.5.3" |
21 | 22 | ||
22 | stdx = { path = "../stdx" } | 23 | stdx = { path = "../stdx", version = "0.0.0" } |
23 | syntax = { path = "../syntax" } | 24 | syntax = { path = "../syntax", version = "0.0.0" } |
24 | text_edit = { path = "../text_edit" } | 25 | text_edit = { path = "../text_edit", version = "0.0.0" } |
25 | base_db = { path = "../base_db" } | 26 | base_db = { path = "../base_db", version = "0.0.0" } |
26 | profile = { path = "../profile" } | 27 | profile = { path = "../profile", version = "0.0.0" } |
27 | test_utils = { path = "../test_utils" } | 28 | test_utils = { path = "../test_utils", version = "0.0.0" } |
28 | # ide should depend only on the top-level `hir` package. if you need | 29 | # ide should depend only on the top-level `hir` package. if you need |
29 | # something from some `hir_xxx` subpackage, reexport the API via `hir`. | 30 | # something from some `hir_xxx` subpackage, reexport the API via `hir`. |
30 | hir = { path = "../hir" } | 31 | hir = { path = "../hir", version = "0.0.0" } |
diff --git a/crates/mbe/Cargo.toml b/crates/mbe/Cargo.toml index 1aba8b7c4..af80e2be3 100644 --- a/crates/mbe/Cargo.toml +++ b/crates/mbe/Cargo.toml | |||
@@ -1,6 +1,7 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "mbe" | 2 | name = "mbe" |
3 | version = "0.0.0" | 3 | version = "0.0.0" |
4 | description = "TBD" | ||
4 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 6 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 7 | edition = "2018" |
@@ -13,9 +14,9 @@ rustc-hash = "1.1.0" | |||
13 | smallvec = "1.2.0" | 14 | smallvec = "1.2.0" |
14 | log = "0.4.8" | 15 | log = "0.4.8" |
15 | 16 | ||
16 | syntax = { path = "../syntax" } | 17 | syntax = { path = "../syntax", version = "0.0.0" } |
17 | parser = { path = "../parser" } | 18 | parser = { path = "../parser", version = "0.0.0" } |
18 | tt = { path = "../tt" } | 19 | tt = { path = "../tt", version = "0.0.0" } |
19 | 20 | ||
20 | [dev-dependencies] | 21 | [dev-dependencies] |
21 | test_utils = { path = "../test_utils" } | 22 | test_utils = { path = "../test_utils" } |
diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml index 358be92d1..1610e0d23 100644 --- a/crates/parser/Cargo.toml +++ b/crates/parser/Cargo.toml | |||
@@ -1,6 +1,7 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "parser" | 2 | name = "parser" |
3 | version = "0.0.0" | 3 | version = "0.0.0" |
4 | description = "TBD" | ||
4 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 6 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 7 | edition = "2018" |
diff --git a/crates/paths/Cargo.toml b/crates/paths/Cargo.toml index 5ac18d63b..da26938c1 100644 --- a/crates/paths/Cargo.toml +++ b/crates/paths/Cargo.toml | |||
@@ -1,6 +1,7 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "paths" | 2 | name = "paths" |
3 | version = "0.0.0" | 3 | version = "0.0.0" |
4 | description = "TBD" | ||
4 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 6 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 7 | edition = "2018" |
diff --git a/crates/proc_macro_api/Cargo.toml b/crates/proc_macro_api/Cargo.toml index a3a4c1103..75f67a22e 100644 --- a/crates/proc_macro_api/Cargo.toml +++ b/crates/proc_macro_api/Cargo.toml | |||
@@ -1,6 +1,7 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "proc_macro_api" | 2 | name = "proc_macro_api" |
3 | version = "0.0.0" | 3 | version = "0.0.0" |
4 | description = "TBD" | ||
4 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 6 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 7 | edition = "2018" |
@@ -15,4 +16,4 @@ log = "0.4.8" | |||
15 | crossbeam-channel = "0.4.0" | 16 | crossbeam-channel = "0.4.0" |
16 | jod-thread = "0.1.1" | 17 | jod-thread = "0.1.1" |
17 | 18 | ||
18 | tt = { path = "../tt" } | 19 | tt = { path = "../tt", version = "0.0.0" } |
diff --git a/crates/proc_macro_srv/Cargo.toml b/crates/proc_macro_srv/Cargo.toml index a468b5560..fb84e04ae 100644 --- a/crates/proc_macro_srv/Cargo.toml +++ b/crates/proc_macro_srv/Cargo.toml | |||
@@ -1,6 +1,7 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "proc_macro_srv" | 2 | name = "proc_macro_srv" |
3 | version = "0.0.0" | 3 | version = "0.0.0" |
4 | description = "TBD" | ||
4 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 6 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 7 | edition = "2018" |
@@ -13,10 +14,10 @@ goblin = "0.2.1" | |||
13 | libloading = "0.6.0" | 14 | libloading = "0.6.0" |
14 | memmap = "0.7" | 15 | memmap = "0.7" |
15 | 16 | ||
16 | tt = { path = "../tt" } | 17 | tt = { path = "../tt", version = "0.0.0" } |
17 | mbe = { path = "../mbe" } | 18 | mbe = { path = "../mbe", version = "0.0.0" } |
18 | proc_macro_api = { path = "../proc_macro_api" } | 19 | proc_macro_api = { path = "../proc_macro_api", version = "0.0.0" } |
19 | test_utils = { path = "../test_utils" } | 20 | test_utils = { path = "../test_utils", version = "0.0.0" } |
20 | 21 | ||
21 | [dev-dependencies] | 22 | [dev-dependencies] |
22 | cargo_metadata = "0.11.1" | 23 | cargo_metadata = "0.11.1" |
diff --git a/crates/proc_macro_test/Cargo.toml b/crates/proc_macro_test/Cargo.toml index 7b0f64f31..753443be2 100644 --- a/crates/proc_macro_test/Cargo.toml +++ b/crates/proc_macro_test/Cargo.toml | |||
@@ -4,6 +4,7 @@ version = "0.0.0" | |||
4 | license = "MIT OR Apache-2.0" | 4 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 5 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 6 | edition = "2018" |
7 | publish = false | ||
7 | 8 | ||
8 | [lib] | 9 | [lib] |
9 | doctest = false | 10 | doctest = false |
diff --git a/crates/profile/Cargo.toml b/crates/profile/Cargo.toml index e271e3a56..261172d61 100644 --- a/crates/profile/Cargo.toml +++ b/crates/profile/Cargo.toml | |||
@@ -1,6 +1,7 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "profile" | 2 | name = "profile" |
3 | version = "0.0.0" | 3 | version = "0.0.0" |
4 | description = "TBD" | ||
4 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 6 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 7 | edition = "2018" |
@@ -14,7 +15,7 @@ cfg-if = "0.1.10" | |||
14 | libc = "0.2.73" | 15 | libc = "0.2.73" |
15 | backtrace = { version = "0.3.44", optional = true } | 16 | backtrace = { version = "0.3.44", optional = true } |
16 | 17 | ||
17 | arena = { path = "../arena" } | 18 | arena = { path = "../arena", version = "0.0.0" } |
18 | 19 | ||
19 | [target.'cfg(target_os = "linux")'.dependencies] | 20 | [target.'cfg(target_os = "linux")'.dependencies] |
20 | perf-event = "0.4" | 21 | perf-event = "0.4" |
diff --git a/crates/project_model/Cargo.toml b/crates/project_model/Cargo.toml index 386f72f41..8bee398d9 100644 --- a/crates/project_model/Cargo.toml +++ b/crates/project_model/Cargo.toml | |||
@@ -1,6 +1,7 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "project_model" | 2 | name = "project_model" |
3 | version = "0.0.0" | 3 | version = "0.0.0" |
4 | description = "TBD" | ||
4 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 6 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 7 | edition = "2018" |
@@ -16,10 +17,10 @@ serde = { version = "1.0.106", features = ["derive"] } | |||
16 | serde_json = "1.0.48" | 17 | serde_json = "1.0.48" |
17 | anyhow = "1.0.26" | 18 | anyhow = "1.0.26" |
18 | 19 | ||
19 | arena = { path = "../arena" } | 20 | arena = { path = "../arena", version = "0.0.0" } |
20 | cfg = { path = "../cfg" } | 21 | cfg = { path = "../cfg", version = "0.0.0" } |
21 | base_db = { path = "../base_db" } | 22 | base_db = { path = "../base_db", version = "0.0.0" } |
22 | toolchain = { path = "../toolchain" } | 23 | toolchain = { path = "../toolchain", version = "0.0.0" } |
23 | proc_macro_api = { path = "../proc_macro_api" } | 24 | proc_macro_api = { path = "../proc_macro_api", version = "0.0.0" } |
24 | paths = { path = "../paths" } | 25 | paths = { path = "../paths", version = "0.0.0" } |
25 | stdx = { path = "../stdx" } | 26 | stdx = { path = "../stdx", version = "0.0.0" } |
diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml index 068a961dc..7e280b1f7 100644 --- a/crates/rust-analyzer/Cargo.toml +++ b/crates/rust-analyzer/Cargo.toml | |||
@@ -5,6 +5,7 @@ license = "MIT OR Apache-2.0" | |||
5 | authors = ["rust-analyzer developers"] | 5 | authors = ["rust-analyzer developers"] |
6 | autobins = false | 6 | autobins = false |
7 | edition = "2018" | 7 | edition = "2018" |
8 | publish = false | ||
8 | 9 | ||
9 | [lib] | 10 | [lib] |
10 | doctest = false | 11 | doctest = false |
diff --git a/crates/ssr/Cargo.toml b/crates/ssr/Cargo.toml index 22b6af0fa..6f0f53d70 100644 --- a/crates/ssr/Cargo.toml +++ b/crates/ssr/Cargo.toml | |||
@@ -14,12 +14,12 @@ doctest = false | |||
14 | rustc-hash = "1.1.0" | 14 | rustc-hash = "1.1.0" |
15 | itertools = "0.9.0" | 15 | itertools = "0.9.0" |
16 | 16 | ||
17 | text_edit = { path = "../text_edit" } | 17 | text_edit = { path = "../text_edit", version = "0.0.0" } |
18 | syntax = { path = "../syntax" } | 18 | syntax = { path = "../syntax", version = "0.0.0" } |
19 | base_db = { path = "../base_db" } | 19 | base_db = { path = "../base_db", version = "0.0.0" } |
20 | ide_db = { path = "../ide_db" } | 20 | ide_db = { path = "../ide_db", version = "0.0.0" } |
21 | hir = { path = "../hir" } | 21 | hir = { path = "../hir", version = "0.0.0" } |
22 | test_utils = { path = "../test_utils" } | 22 | test_utils = { path = "../test_utils", version = "0.0.0" } |
23 | 23 | ||
24 | [dev-dependencies] | 24 | [dev-dependencies] |
25 | expect-test = "0.1" | 25 | expect-test = "0.1" |
diff --git a/crates/stdx/Cargo.toml b/crates/stdx/Cargo.toml index b186b46f2..8d7a51156 100644 --- a/crates/stdx/Cargo.toml +++ b/crates/stdx/Cargo.toml | |||
@@ -1,6 +1,7 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "stdx" | 2 | name = "stdx" |
3 | version = "0.0.0" | 3 | version = "0.0.0" |
4 | description = "TBD" | ||
4 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 6 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 7 | edition = "2018" |
diff --git a/crates/syntax/Cargo.toml b/crates/syntax/Cargo.toml index 6818f3ad8..2c1bdb295 100644 --- a/crates/syntax/Cargo.toml +++ b/crates/syntax/Cargo.toml | |||
@@ -23,9 +23,9 @@ once_cell = "1.3.1" | |||
23 | smol_str = { version = "0.1.15", features = ["serde"] } | 23 | smol_str = { version = "0.1.15", features = ["serde"] } |
24 | serde = { version = "1.0.106", features = ["derive"] } | 24 | serde = { version = "1.0.106", features = ["derive"] } |
25 | 25 | ||
26 | stdx = { path = "../stdx" } | 26 | stdx = { path = "../stdx", version = "0.0.0" } |
27 | text_edit = { path = "../text_edit" } | 27 | text_edit = { path = "../text_edit", version = "0.0.0" } |
28 | parser = { path = "../parser" } | 28 | parser = { path = "../parser", version = "0.0.0" } |
29 | 29 | ||
30 | [dev-dependencies] | 30 | [dev-dependencies] |
31 | walkdir = "2.3.1" | 31 | walkdir = "2.3.1" |
diff --git a/crates/syntax/src/algo.rs b/crates/syntax/src/algo.rs index 6254b38ba..ea199f9b8 100644 --- a/crates/syntax/src/algo.rs +++ b/crates/syntax/src/algo.rs | |||
@@ -32,7 +32,7 @@ pub fn ancestors_at_offset( | |||
32 | /// imprecise: if the cursor is strictly between two nodes of the desired type, | 32 | /// imprecise: if the cursor is strictly between two nodes of the desired type, |
33 | /// as in | 33 | /// as in |
34 | /// | 34 | /// |
35 | /// ```no-run | 35 | /// ```no_run |
36 | /// struct Foo {}|struct Bar; | 36 | /// struct Foo {}|struct Bar; |
37 | /// ``` | 37 | /// ``` |
38 | /// | 38 | /// |
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs index d20c085aa..7958721e2 100644 --- a/crates/syntax/src/ast/make.rs +++ b/crates/syntax/src/ast/make.rs | |||
@@ -7,7 +7,7 @@ | |||
7 | use itertools::Itertools; | 7 | use itertools::Itertools; |
8 | use stdx::format_to; | 8 | use stdx::format_to; |
9 | 9 | ||
10 | use crate::{ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, SyntaxToken}; | 10 | use crate::{ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, SyntaxText, SyntaxToken}; |
11 | 11 | ||
12 | pub fn name(text: &str) -> ast::Name { | 12 | pub fn name(text: &str) -> ast::Name { |
13 | ast_from_text(&format!("mod {};", text)) | 13 | ast_from_text(&format!("mod {};", text)) |
@@ -137,6 +137,12 @@ pub fn expr_prefix(op: SyntaxKind, expr: ast::Expr) -> ast::Expr { | |||
137 | pub fn expr_call(f: ast::Expr, arg_list: ast::ArgList) -> ast::Expr { | 137 | pub fn expr_call(f: ast::Expr, arg_list: ast::ArgList) -> ast::Expr { |
138 | expr_from_text(&format!("{}{}", f, arg_list)) | 138 | expr_from_text(&format!("{}{}", f, arg_list)) |
139 | } | 139 | } |
140 | pub fn expr_method_call<F>(text: &str, caller: F) -> Option<ast::Expr> | ||
141 | where | ||
142 | F: FnOnce() -> Option<SyntaxText>, | ||
143 | { | ||
144 | try_expr_from_text(&format!("{}.{}()", caller()?, text)) | ||
145 | } | ||
140 | fn expr_from_text(text: &str) -> ast::Expr { | 146 | fn expr_from_text(text: &str) -> ast::Expr { |
141 | ast_from_text(&format!("const C: () = {};", text)) | 147 | ast_from_text(&format!("const C: () = {};", text)) |
142 | } | 148 | } |
diff --git a/crates/test_utils/Cargo.toml b/crates/test_utils/Cargo.toml index 45e5fb97f..93eecc678 100644 --- a/crates/test_utils/Cargo.toml +++ b/crates/test_utils/Cargo.toml | |||
@@ -1,6 +1,7 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "test_utils" | 2 | name = "test_utils" |
3 | version = "0.0.0" | 3 | version = "0.0.0" |
4 | description = "TBD" | ||
4 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 6 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 7 | edition = "2018" |
@@ -15,4 +16,4 @@ text-size = "1.0.0" | |||
15 | serde_json = "1.0.48" | 16 | serde_json = "1.0.48" |
16 | rustc-hash = "1.1.0" | 17 | rustc-hash = "1.1.0" |
17 | 18 | ||
18 | stdx = { path = "../stdx" } | 19 | stdx = { path = "../stdx", version = "0.0.0" } |
diff --git a/crates/text_edit/Cargo.toml b/crates/text_edit/Cargo.toml index a69b1ef2b..8aadc1875 100644 --- a/crates/text_edit/Cargo.toml +++ b/crates/text_edit/Cargo.toml | |||
@@ -1,6 +1,7 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "text_edit" | 2 | name = "text_edit" |
3 | version = "0.0.0" | 3 | version = "0.0.0" |
4 | description = "TBD" | ||
4 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 6 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 7 | edition = "2018" |
diff --git a/crates/toolchain/Cargo.toml b/crates/toolchain/Cargo.toml index 4856668f8..dcf0bfca0 100644 --- a/crates/toolchain/Cargo.toml +++ b/crates/toolchain/Cargo.toml | |||
@@ -1,6 +1,7 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "toolchain" | 2 | name = "toolchain" |
3 | version = "0.0.0" | 3 | version = "0.0.0" |
4 | description = "TBD" | ||
4 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 6 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 7 | edition = "2018" |
diff --git a/crates/tt/Cargo.toml b/crates/tt/Cargo.toml index dfcdcf03e..5b8972ea3 100644 --- a/crates/tt/Cargo.toml +++ b/crates/tt/Cargo.toml | |||
@@ -1,6 +1,7 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "tt" | 2 | name = "tt" |
3 | version = "0.0.0" | 3 | version = "0.0.0" |
4 | description = "TBD" | ||
4 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 6 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 7 | edition = "2018" |
@@ -13,4 +14,4 @@ doctest = false | |||
13 | # to reduce number of compilations | 14 | # to reduce number of compilations |
14 | smol_str = { version = "0.1.15", features = ["serde"] } | 15 | smol_str = { version = "0.1.15", features = ["serde"] } |
15 | 16 | ||
16 | stdx = { path = "../stdx" } | 17 | stdx = { path = "../stdx", version = "0.0.0" } |
diff --git a/crates/vfs-notify/Cargo.toml b/crates/vfs-notify/Cargo.toml index c1e53f4b1..54b51faab 100644 --- a/crates/vfs-notify/Cargo.toml +++ b/crates/vfs-notify/Cargo.toml | |||
@@ -1,6 +1,7 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "vfs-notify" | 2 | name = "vfs-notify" |
3 | version = "0.0.0" | 3 | version = "0.0.0" |
4 | description = "TBD" | ||
4 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 6 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 7 | edition = "2018" |
@@ -16,5 +17,5 @@ walkdir = "2.3.1" | |||
16 | crossbeam-channel = "0.4.0" | 17 | crossbeam-channel = "0.4.0" |
17 | notify = "5.0.0-pre.3" | 18 | notify = "5.0.0-pre.3" |
18 | 19 | ||
19 | vfs = { path = "../vfs" } | 20 | vfs = { path = "../vfs", version = "0.0.0" } |
20 | paths = { path = "../paths" } | 21 | paths = { path = "../paths", version = "0.0.0" } |
diff --git a/crates/vfs/Cargo.toml b/crates/vfs/Cargo.toml index 9ae8f19b6..c318a68f7 100644 --- a/crates/vfs/Cargo.toml +++ b/crates/vfs/Cargo.toml | |||
@@ -1,6 +1,7 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "vfs" | 2 | name = "vfs" |
3 | version = "0.0.0" | 3 | version = "0.0.0" |
4 | description = "TBD" | ||
4 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
5 | authors = ["rust-analyzer developers"] | 6 | authors = ["rust-analyzer developers"] |
6 | edition = "2018" | 7 | edition = "2018" |
@@ -12,4 +13,4 @@ doctest = false | |||
12 | rustc-hash = "1.0" | 13 | rustc-hash = "1.0" |
13 | fst = "0.4" | 14 | fst = "0.4" |
14 | 15 | ||
15 | paths = { path = "../paths" } | 16 | paths = { path = "../paths", version = "0.0.0" } |