mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
minor
This commit is contained in:
parent
4dd4571bfe
commit
0f968ee430
2 changed files with 21 additions and 24 deletions
|
@ -55,11 +55,9 @@ pub struct Analysis {
|
||||||
impl Analysis {
|
impl Analysis {
|
||||||
pub fn file_syntax(&self, file_id: FileId) -> File {
|
pub fn file_syntax(&self, file_id: FileId) -> File {
|
||||||
self.imp.file_syntax(file_id)
|
self.imp.file_syntax(file_id)
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
pub fn file_line_index(&self, file_id: FileId) -> LineIndex {
|
pub fn file_line_index(&self, file_id: FileId) -> LineIndex {
|
||||||
self.imp.file_line_index(file_id)
|
self.imp.file_line_index(file_id)
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
pub fn extend_selection(&self, file: &File, range: TextRange) -> TextRange {
|
pub fn extend_selection(&self, file: &File, range: TextRange) -> TextRange {
|
||||||
libeditor::extend_selection(file, range).unwrap_or(range)
|
libeditor::extend_selection(file, range).unwrap_or(range)
|
||||||
|
@ -88,7 +86,6 @@ impl Analysis {
|
||||||
}
|
}
|
||||||
pub fn approximately_resolve_symbol(&self, file_id: FileId, offset: TextUnit) -> Vec<(FileId, FileSymbol)> {
|
pub fn approximately_resolve_symbol(&self, file_id: FileId, offset: TextUnit) -> Vec<(FileId, FileSymbol)> {
|
||||||
self.imp.approximately_resolve_symbol(file_id, offset)
|
self.imp.approximately_resolve_symbol(file_id, offset)
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
pub fn parent_module(&self, file_id: FileId) -> Vec<(FileId, FileSymbol)> {
|
pub fn parent_module(&self, file_id: FileId) -> Vec<(FileId, FileSymbol)> {
|
||||||
self.imp.parent_module(file_id)
|
self.imp.parent_module(file_id)
|
||||||
|
|
|
@ -141,16 +141,16 @@ impl WorldState {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl World {
|
impl World {
|
||||||
pub fn file_syntax(&self, file_id: FileId) -> Result<File> {
|
pub fn file_syntax(&self, file_id: FileId) -> File {
|
||||||
let data = self.file_data(file_id)?;
|
self.file_data(file_id).syntax().clone()
|
||||||
Ok(data.syntax().clone())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn file_line_index(&self, id: FileId) -> Result<LineIndex> {
|
pub fn file_line_index(&self, id: FileId) -> LineIndex {
|
||||||
let data = self.file_data(id)?;
|
let data = self.file_data(id);
|
||||||
let index = data.lines
|
data
|
||||||
.get_or_init(|| LineIndex::new(&data.text));
|
.lines
|
||||||
Ok(index.clone())
|
.get_or_init(|| LineIndex::new(&data.text))
|
||||||
|
.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn world_symbols(&self, mut query: Query) -> Vec<(FileId, FileSymbol)> {
|
pub fn world_symbols(&self, mut query: Query) -> Vec<(FileId, FileSymbol)> {
|
||||||
|
@ -170,7 +170,7 @@ impl World {
|
||||||
.parent_modules(
|
.parent_modules(
|
||||||
id,
|
id,
|
||||||
&*self.file_resolver,
|
&*self.file_resolver,
|
||||||
&|file_id| self.file_syntax(file_id).unwrap(),
|
&|file_id| self.file_syntax(file_id),
|
||||||
)
|
)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(id, name, node)| {
|
.map(|(id, name, node)| {
|
||||||
|
@ -189,11 +189,11 @@ impl World {
|
||||||
&self,
|
&self,
|
||||||
id: FileId,
|
id: FileId,
|
||||||
offset: TextUnit,
|
offset: TextUnit,
|
||||||
) -> Result<Vec<(FileId, FileSymbol)>> {
|
) -> Vec<(FileId, FileSymbol)> {
|
||||||
let file = self.file_syntax(id)?;
|
let file = self.file_syntax(id);
|
||||||
let syntax = file.syntax();
|
let syntax = file.syntax();
|
||||||
if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, offset) {
|
if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, offset) {
|
||||||
return Ok(self.index_resolve(name_ref));
|
return self.index_resolve(name_ref);
|
||||||
}
|
}
|
||||||
if let Some(name) = find_node_at_offset::<ast::Name>(syntax, offset) {
|
if let Some(name) = find_node_at_offset::<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) {
|
||||||
|
@ -212,15 +212,15 @@ impl World {
|
||||||
(id, symbol)
|
(id, symbol)
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
return Ok(res);
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(vec![])
|
vec![]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn diagnostics(&self, file_id: FileId) -> Vec<Diagnostic> {
|
pub fn diagnostics(&self, file_id: FileId) -> Vec<Diagnostic> {
|
||||||
let syntax = self.file_syntax(file_id).unwrap();
|
let syntax = self.file_syntax(file_id);
|
||||||
let mut res = libeditor::diagnostics(&syntax)
|
let mut res = libeditor::diagnostics(&syntax)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|d| Diagnostic { range: d.range, message: d.msg, fix: None })
|
.map(|d| Diagnostic { range: d.range, message: d.msg, fix: None })
|
||||||
|
@ -229,7 +229,7 @@ impl World {
|
||||||
self.data.module_map.problems(
|
self.data.module_map.problems(
|
||||||
file_id,
|
file_id,
|
||||||
&*self.file_resolver,
|
&*self.file_resolver,
|
||||||
&|file_id| self.file_syntax(file_id).unwrap(),
|
&|file_id| self.file_syntax(file_id),
|
||||||
|name_node, problem| {
|
|name_node, problem| {
|
||||||
let diag = match problem {
|
let diag = match problem {
|
||||||
Problem::UnresolvedModule { candidate } => {
|
Problem::UnresolvedModule { candidate } => {
|
||||||
|
@ -272,7 +272,7 @@ impl World {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn assists(&self, file_id: FileId, offset: TextUnit) -> Vec<SourceChange> {
|
pub fn assists(&self, file_id: FileId, offset: TextUnit) -> Vec<SourceChange> {
|
||||||
let file = self.file_syntax(file_id).unwrap();
|
let file = self.file_syntax(file_id);
|
||||||
let actions = vec![
|
let actions = vec![
|
||||||
("flip comma", libeditor::flip_comma(&file, offset).map(|f| f())),
|
("flip comma", libeditor::flip_comma(&file, offset).map(|f| f())),
|
||||||
("add `#[derive]`", libeditor::add_derive(&file, offset).map(|f| f())),
|
("add `#[derive]`", libeditor::add_derive(&file, offset).map(|f| f())),
|
||||||
|
@ -308,7 +308,7 @@ impl World {
|
||||||
.child_module_by_name(
|
.child_module_by_name(
|
||||||
id, name.as_str(),
|
id, name.as_str(),
|
||||||
&*self.file_resolver,
|
&*self.file_resolver,
|
||||||
&|file_id| self.file_syntax(file_id).unwrap(),
|
&|file_id| self.file_syntax(file_id),
|
||||||
)
|
)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|id| module_map.module2file(id))
|
.map(|id| module_map.module2file(id))
|
||||||
|
@ -326,10 +326,10 @@ impl World {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn file_data(&self, file_id: FileId) -> Result<Arc<FileData>> {
|
fn file_data(&self, file_id: FileId) -> Arc<FileData> {
|
||||||
match self.data.file_map.get(&file_id) {
|
match self.data.file_map.get(&file_id) {
|
||||||
Some(data) => Ok(data.clone()),
|
Some(data) => data.clone(),
|
||||||
None => bail!("unknown file: {:?}", file_id),
|
None => panic!("unknown file: {:?}", file_id),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue