From 4d8be265849c55912467961e09af657176472dcb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 18 Aug 2018 12:42:28 +0300 Subject: refactor --- crates/libanalysis/src/lib.rs | 28 +++++++++++++++++----------- crates/libeditor/Cargo.toml | 1 - crates/libeditor/src/lib.rs | 1 - crates/libeditor/src/symbols.rs | 3 +-- crates/libsyntax2/src/lib.rs | 3 ++- 5 files changed, 20 insertions(+), 16 deletions(-) (limited to 'crates') diff --git a/crates/libanalysis/src/lib.rs b/crates/libanalysis/src/lib.rs index 15a433afc..63c4c77cf 100644 --- a/crates/libanalysis/src/lib.rs +++ b/crates/libanalysis/src/lib.rs @@ -26,7 +26,7 @@ use std::{ }; use libsyntax2::{ - TextUnit, TextRange, + TextUnit, TextRange, SmolStr, ast::{self, AstNode, NameOwner, ParsedFile}, SyntaxKind::*, }; @@ -144,7 +144,21 @@ impl World { if let Some(name) = find_node::(syntax, offset) { if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { 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) } - fn resolve_module(&self, id: FileId, module: ast::Module) -> Vec<(FileId, FileSymbol)> { + fn resolve_module(&self, id: FileId, module: ast::Module) -> Vec { let name = match module.name() { Some(name) => name.text(), None => return Vec::new(), @@ -170,14 +184,6 @@ impl World { ]; paths.iter() .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() } diff --git a/crates/libeditor/Cargo.toml b/crates/libeditor/Cargo.toml index 7b39870cd..55f41c2c5 100644 --- a/crates/libeditor/Cargo.toml +++ b/crates/libeditor/Cargo.toml @@ -9,7 +9,6 @@ itertools = "0.7.8" superslice = "0.1.0" libsyntax2 = { path = "../libsyntax2" } -smol_str = "0.1.0" [dev-dependencies] assert_eq_text = { path = "../assert_eq_text" } diff --git a/crates/libeditor/src/lib.rs b/crates/libeditor/src/lib.rs index d9d0369f6..abd104af2 100644 --- a/crates/libeditor/src/lib.rs +++ b/crates/libeditor/src/lib.rs @@ -1,7 +1,6 @@ extern crate libsyntax2; extern crate superslice; extern crate itertools; -extern crate smol_str; mod extend_selection; mod symbols; diff --git a/crates/libeditor/src/symbols.rs b/crates/libeditor/src/symbols.rs index d7bd111e6..b2b05bc6a 100644 --- a/crates/libeditor/src/symbols.rs +++ b/crates/libeditor/src/symbols.rs @@ -1,6 +1,5 @@ -use smol_str::SmolStr; use libsyntax2::{ - SyntaxKind, SyntaxNodeRef, AstNode, ParsedFile, + SyntaxKind, SyntaxNodeRef, AstNode, ParsedFile, SmolStr, ast::{self, NameOwner}, algo::{ visit::{visitor, Visitor}, diff --git a/crates/libsyntax2/src/lib.rs b/crates/libsyntax2/src/lib.rs index e837a8d2d..c078baa3a 100644 --- a/crates/libsyntax2/src/lib.rs +++ b/crates/libsyntax2/src/lib.rs @@ -41,10 +41,11 @@ mod yellow; pub mod utils; pub use { + text_unit::{TextRange, TextUnit}, + smol_str::SmolStr, ast::{AstNode, ParsedFile}, lexer::{tokenize, Token}, syntax_kinds::SyntaxKind, - text_unit::{TextRange, TextUnit}, yellow::{SyntaxNode, SyntaxNodeRef, OwnedRoot, RefRoot, TreeRoot, SyntaxError}, }; -- cgit v1.2.3