mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
refactor
This commit is contained in:
parent
a5eeef0eee
commit
4d8be26584
5 changed files with 20 additions and 16 deletions
|
@ -26,7 +26,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use libsyntax2::{
|
use libsyntax2::{
|
||||||
TextUnit, TextRange,
|
TextUnit, TextRange, SmolStr,
|
||||||
ast::{self, AstNode, NameOwner, ParsedFile},
|
ast::{self, AstNode, NameOwner, ParsedFile},
|
||||||
SyntaxKind::*,
|
SyntaxKind::*,
|
||||||
};
|
};
|
||||||
|
@ -144,7 +144,21 @@ impl World {
|
||||||
if let Some(name) = find_node::<ast::Name>(syntax, offset) {
|
if let Some(name) = find_node::<ast::Name>(syntax, offset) {
|
||||||
if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) {
|
if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) {
|
||||||
if module.has_semi() {
|
if module.has_semi() {
|
||||||
return Ok(self.resolve_module(id, module));
|
let file_ids = self.resolve_module(id, module);
|
||||||
|
|
||||||
|
let res = file_ids.into_iter().map(|id| {
|
||||||
|
let name = module.name()
|
||||||
|
.map(|n| n.text())
|
||||||
|
.unwrap_or_else(|| SmolStr::new(""));
|
||||||
|
let symbol = FileSymbol {
|
||||||
|
name,
|
||||||
|
node_range: TextRange::offset_len(0.into(), 0.into()),
|
||||||
|
kind: MODULE,
|
||||||
|
};
|
||||||
|
(id, symbol)
|
||||||
|
}).collect();
|
||||||
|
|
||||||
|
return Ok(res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,7 +173,7 @@ impl World {
|
||||||
self.world_symbols(query)
|
self.world_symbols(query)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_module(&self, id: FileId, module: ast::Module) -> Vec<(FileId, FileSymbol)> {
|
fn resolve_module(&self, id: FileId, module: ast::Module) -> Vec<FileId> {
|
||||||
let name = match module.name() {
|
let name = match module.name() {
|
||||||
Some(name) => name.text(),
|
Some(name) => name.text(),
|
||||||
None => return Vec::new(),
|
None => return Vec::new(),
|
||||||
|
@ -170,14 +184,6 @@ impl World {
|
||||||
];
|
];
|
||||||
paths.iter()
|
paths.iter()
|
||||||
.filter_map(|path| self.resolve_relative_path(id, path))
|
.filter_map(|path| self.resolve_relative_path(id, path))
|
||||||
.map(|id| {
|
|
||||||
let symbol = FileSymbol {
|
|
||||||
name: name.clone(),
|
|
||||||
node_range: TextRange::offset_len(0.into(), 0.into()),
|
|
||||||
kind: MODULE,
|
|
||||||
};
|
|
||||||
(id, symbol)
|
|
||||||
})
|
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ itertools = "0.7.8"
|
||||||
superslice = "0.1.0"
|
superslice = "0.1.0"
|
||||||
|
|
||||||
libsyntax2 = { path = "../libsyntax2" }
|
libsyntax2 = { path = "../libsyntax2" }
|
||||||
smol_str = "0.1.0"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
assert_eq_text = { path = "../assert_eq_text" }
|
assert_eq_text = { path = "../assert_eq_text" }
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
extern crate libsyntax2;
|
extern crate libsyntax2;
|
||||||
extern crate superslice;
|
extern crate superslice;
|
||||||
extern crate itertools;
|
extern crate itertools;
|
||||||
extern crate smol_str;
|
|
||||||
|
|
||||||
mod extend_selection;
|
mod extend_selection;
|
||||||
mod symbols;
|
mod symbols;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use smol_str::SmolStr;
|
|
||||||
use libsyntax2::{
|
use libsyntax2::{
|
||||||
SyntaxKind, SyntaxNodeRef, AstNode, ParsedFile,
|
SyntaxKind, SyntaxNodeRef, AstNode, ParsedFile, SmolStr,
|
||||||
ast::{self, NameOwner},
|
ast::{self, NameOwner},
|
||||||
algo::{
|
algo::{
|
||||||
visit::{visitor, Visitor},
|
visit::{visitor, Visitor},
|
||||||
|
|
|
@ -41,10 +41,11 @@ mod yellow;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
|
||||||
pub use {
|
pub use {
|
||||||
|
text_unit::{TextRange, TextUnit},
|
||||||
|
smol_str::SmolStr,
|
||||||
ast::{AstNode, ParsedFile},
|
ast::{AstNode, ParsedFile},
|
||||||
lexer::{tokenize, Token},
|
lexer::{tokenize, Token},
|
||||||
syntax_kinds::SyntaxKind,
|
syntax_kinds::SyntaxKind,
|
||||||
text_unit::{TextRange, TextUnit},
|
|
||||||
yellow::{SyntaxNode, SyntaxNodeRef, OwnedRoot, RefRoot, TreeRoot, SyntaxError},
|
yellow::{SyntaxNode, SyntaxNodeRef, OwnedRoot, RefRoot, TreeRoot, SyntaxError},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue