From 61e1474ab35deb7d54cc2f5d710b901f200b6467 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 28 May 2019 18:46:11 +0300 Subject: fix typos in mbe tests --- crates/ra_ide_api/src/call_info.rs | 2 +- crates/ra_ide_api/src/change.rs | 2 +- crates/ra_ide_api/src/completion.rs | 4 +-- .../src/completion/completion_context.rs | 15 +++++---- crates/ra_ide_api/src/diagnostics.rs | 39 +++++++++++----------- crates/ra_ide_api/src/display/navigation_target.rs | 4 +-- crates/ra_ide_api/src/display/structure.rs | 4 ++- crates/ra_ide_api/src/extend_selection.rs | 4 +-- crates/ra_ide_api/src/folding_ranges.rs | 2 +- crates/ra_ide_api/src/goto_definition.rs | 2 +- crates/ra_ide_api/src/goto_type_definition.rs | 2 +- crates/ra_ide_api/src/hover.rs | 4 +-- crates/ra_ide_api/src/impls.rs | 2 +- crates/ra_ide_api/src/join_lines.rs | 2 +- crates/ra_ide_api/src/lib.rs | 12 +++---- crates/ra_ide_api/src/matching_brace.rs | 2 +- crates/ra_ide_api/src/references.rs | 4 +-- crates/ra_ide_api/src/runnables.rs | 2 +- crates/ra_ide_api/src/status.rs | 8 ++--- crates/ra_ide_api/src/symbol_index.rs | 2 +- crates/ra_ide_api/src/syntax_highlighting.rs | 4 +-- crates/ra_ide_api/src/syntax_tree.rs | 8 ++--- crates/ra_ide_api/src/test_utils.rs | 2 +- crates/ra_ide_api/src/typing.rs | 6 ++-- 24 files changed, 70 insertions(+), 68 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index 4413aec73..5d43282fd 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs @@ -10,7 +10,7 @@ use crate::{FilePosition, CallInfo, FunctionSignature, db::RootDatabase}; /// Computes parameter information for the given call expression. pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option { - let file = db.parse(position.file_id); + let file = db.parse(position.file_id).tree; let syntax = file.syntax(); // Find the calling expression and it's NameRef diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs index 0e64abdbd..4b597afc0 100644 --- a/crates/ra_ide_api/src/change.rs +++ b/crates/ra_ide_api/src/change.rs @@ -138,7 +138,7 @@ impl LibraryData { files: Vec<(FileId, RelativePathBuf, Arc)>, ) -> LibraryData { let symbol_index = SymbolIndex::for_files(files.par_iter().map(|(file_id, _, text)| { - let file = SourceFile::parse(text); + let file = SourceFile::parse(text).tree; (*file_id, file) })); let mut root_change = RootChange::default(); diff --git a/crates/ra_ide_api/src/completion.rs b/crates/ra_ide_api/src/completion.rs index deff59cd3..3a75bbf92 100644 --- a/crates/ra_ide_api/src/completion.rs +++ b/crates/ra_ide_api/src/completion.rs @@ -51,8 +51,8 @@ pub use crate::completion::completion_item::{CompletionItem, CompletionItemKind, /// identifier prefix/fuzzy match should be done higher in the stack, together /// with ordering of completions (currently this is done by the client). pub(crate) fn completions(db: &db::RootDatabase, position: FilePosition) -> Option { - let original_file = db.parse(position.file_id); - let ctx = CompletionContext::new(db, &original_file, position)?; + let original_parse = db.parse(position.file_id); + let ctx = CompletionContext::new(db, &original_parse, position)?; let mut acc = Completions::default(); diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs index a8c8cc7b0..bda7d9bb2 100644 --- a/crates/ra_ide_api/src/completion/completion_context.rs +++ b/crates/ra_ide_api/src/completion/completion_context.rs @@ -1,6 +1,6 @@ use ra_text_edit::AtomTextEdit; use ra_syntax::{ - AstNode, SyntaxNode, SourceFile, TextUnit, TextRange, SyntaxToken, + AstNode, SyntaxNode, SourceFile, TextUnit, TextRange, SyntaxToken, Parse, ast, algo::{find_token_at_offset, find_covering_element, find_node_at_offset}, SyntaxKind::*, @@ -43,11 +43,12 @@ pub(crate) struct CompletionContext<'a> { impl<'a> CompletionContext<'a> { pub(super) fn new( db: &'a db::RootDatabase, - original_file: &'a SourceFile, + original_parse: &'a Parse, position: FilePosition, ) -> Option> { let module = source_binder::module_from_position(db, position); - let token = find_token_at_offset(original_file.syntax(), position.offset).left_biased()?; + let token = + find_token_at_offset(original_parse.tree.syntax(), position.offset).left_biased()?; let analyzer = hir::SourceAnalyzer::new(db, position.file_id, token.parent(), Some(position.offset)); let mut ctx = CompletionContext { @@ -69,7 +70,7 @@ impl<'a> CompletionContext<'a> { dot_receiver: None, is_call: false, }; - ctx.fill(original_file, position.offset); + ctx.fill(&original_parse, position.offset); Some(ctx) } @@ -82,13 +83,13 @@ impl<'a> CompletionContext<'a> { } } - fn fill(&mut self, original_file: &'a SourceFile, offset: TextUnit) { + fn fill(&mut self, original_parse: &'a Parse, offset: TextUnit) { // Insert a fake ident to get a valid parse tree. We will use this file // to determine context, though the original_file will be used for // actual completion. let file = { let edit = AtomTextEdit::insert(offset, "intellijRulezz".to_string()); - original_file.reparse(&edit) + original_parse.reparse(&edit).tree }; // First, let's try to complete a reference to some declaration. @@ -99,7 +100,7 @@ impl<'a> CompletionContext<'a> { self.is_param = true; return; } - self.classify_name_ref(original_file, name_ref); + self.classify_name_ref(&original_parse.tree, name_ref); } // Otherwise, see if this is a declaration. We can use heuristics to diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs index 923008708..4cf2a0b70 100644 --- a/crates/ra_ide_api/src/diagnostics.rs +++ b/crates/ra_ide_api/src/diagnostics.rs @@ -4,7 +4,7 @@ use itertools::Itertools; use hir::{source_binder, diagnostics::{Diagnostic as _, DiagnosticSink}}; use ra_db::SourceDatabase; use ra_syntax::{ - T, Location, SourceFile, TextRange, SyntaxNode, + T, Location, TextRange, SyntaxNode, ast::{self, AstNode, NamedFieldList, NamedField}, }; use ra_assists::ast_editor::{AstEditor, AstBuilder}; @@ -21,10 +21,17 @@ pub enum Severity { pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec { let _p = profile("diagnostics"); - let source_file = db.parse(file_id); + let parse = db.parse(file_id); let mut res = Vec::new(); - syntax_errors(&mut res, &source_file); + res.extend(parse.errors.iter().map(|err| Diagnostic { + range: location_to_range(err.location()), + message: format!("Syntax Error: {}", err), + severity: Severity::Error, + fix: None, + })); + + let source_file = parse.tree; for node in source_file.syntax().descendants() { check_unnecessary_braces_in_use_statement(&mut res, file_id, node); @@ -51,8 +58,9 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec }) }) .on::(|d| { + //TODO: commment let file_id = d.file().original_file(db); - let source_file = db.parse(file_id); + let source_file = db.parse(file_id).tree; let syntax_node = d.syntax_node_ptr(); let node = NamedFieldList::cast(syntax_node.to_node(source_file.syntax())).unwrap(); let mut ast_editor = AstEditor::new(node); @@ -77,21 +85,11 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec drop(sink); res.into_inner() } - -fn syntax_errors(acc: &mut Vec, source_file: &SourceFile) { - fn location_to_range(location: Location) -> TextRange { - match location { - Location::Offset(offset) => TextRange::offset_len(offset, 1.into()), - Location::Range(range) => range, - } +fn location_to_range(location: Location) -> TextRange { + match location { + Location::Offset(offset) => TextRange::offset_len(offset, 1.into()), + Location::Range(range) => range, } - - acc.extend(source_file.errors().into_iter().map(|err| Diagnostic { - range: location_to_range(err.location()), - message: format!("Syntax Error: {}", err), - severity: Severity::Error, - fix: None, - })); } fn check_unnecessary_braces_in_use_statement( @@ -177,6 +175,7 @@ fn check_struct_shorthand_initialization( mod tests { use test_utils::assert_eq_text; use insta::assert_debug_snapshot_matches; + use ra_syntax::SourceFile; use crate::mock_analysis::single_file; @@ -185,7 +184,7 @@ mod tests { type DiagnosticChecker = fn(&mut Vec, FileId, &SyntaxNode) -> Option<()>; fn check_not_applicable(code: &str, func: DiagnosticChecker) { - let file = SourceFile::parse(code); + let file = SourceFile::parse(code).tree; let mut diagnostics = Vec::new(); for node in file.syntax().descendants() { func(&mut diagnostics, FileId(0), node); @@ -194,7 +193,7 @@ mod tests { } fn check_apply(before: &str, after: &str, func: DiagnosticChecker) { - let file = SourceFile::parse(before); + let file = SourceFile::parse(before).tree; let mut diagnostics = Vec::new(); for node in file.syntax().descendants() { func(&mut diagnostics, FileId(0), node); diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index 7f81483f7..ae729614f 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs @@ -79,7 +79,7 @@ impl NavigationTarget { file_id: FileId, pat: AstPtr, ) -> NavigationTarget { - let file = db.parse(file_id); + let file = db.parse(file_id).tree; let (name, full_range) = match pat.to_node(file.syntax()).kind() { ast::PatKind::BindPat(pat) => return NavigationTarget::from_bind_pat(file_id, &pat), _ => ("_".into(), pat.syntax_node_ptr().range()), @@ -290,7 +290,7 @@ impl NavigationTarget { } pub(crate) fn node(&self, db: &RootDatabase) -> Option> { - let source_file = db.parse(self.file_id()); + let source_file = db.parse(self.file_id()).tree; let source_file = source_file.syntax(); let node = source_file .descendants() diff --git a/crates/ra_ide_api/src/display/structure.rs b/crates/ra_ide_api/src/display/structure.rs index ec2c9bbc6..24ab7b59c 100644 --- a/crates/ra_ide_api/src/display/structure.rs +++ b/crates/ra_ide_api/src/display/structure.rs @@ -183,7 +183,9 @@ fn obsolete() {} #[deprecated(note = "for awhile")] fn very_obsolete() {} "#, - ); + ) + .ok() + .unwrap(); let structure = file_structure(&file); assert_debug_snapshot_matches!("file_structure", structure); } diff --git a/crates/ra_ide_api/src/extend_selection.rs b/crates/ra_ide_api/src/extend_selection.rs index 4553faad0..00c445310 100644 --- a/crates/ra_ide_api/src/extend_selection.rs +++ b/crates/ra_ide_api/src/extend_selection.rs @@ -11,7 +11,7 @@ use crate::{FileRange, db::RootDatabase}; // FIXME: restore macro support pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRange { - let source_file = db.parse(frange.file_id); + let source_file = db.parse(frange.file_id).tree; try_extend_selection(source_file.syntax(), frange.range).unwrap_or(frange.range) } @@ -212,7 +212,7 @@ mod tests { fn do_check(before: &str, afters: &[&str]) { let (cursor, before) = extract_offset(before); - let file = SourceFile::parse(&before); + let file = SourceFile::parse(&before).tree; let mut range = TextRange::offset_len(cursor, 0.into()); for &after in afters { range = try_extend_selection(file.syntax(), range).unwrap(); diff --git a/crates/ra_ide_api/src/folding_ranges.rs b/crates/ra_ide_api/src/folding_ranges.rs index 6987fcc9e..b50bbee38 100644 --- a/crates/ra_ide_api/src/folding_ranges.rs +++ b/crates/ra_ide_api/src/folding_ranges.rs @@ -191,7 +191,7 @@ mod tests { fn do_check(text: &str, fold_kinds: &[FoldKind]) { let (ranges, text) = extract_ranges(text, "fold"); - let file = SourceFile::parse(&text); + let file = SourceFile::parse(&text).tree; let folds = folding_ranges(&file); assert_eq!( diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 9c56f17f2..4f8554625 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs @@ -19,7 +19,7 @@ pub(crate) fn goto_definition( db: &RootDatabase, position: FilePosition, ) -> Option>> { - let file = db.parse(position.file_id); + let file = db.parse(position.file_id).tree; let syntax = file.syntax(); if let Some(name_ref) = find_node_at_offset::(syntax, position.offset) { let navs = reference_definition(db, position.file_id, name_ref).to_vec(); diff --git a/crates/ra_ide_api/src/goto_type_definition.rs b/crates/ra_ide_api/src/goto_type_definition.rs index e456ec5d6..0f638b170 100644 --- a/crates/ra_ide_api/src/goto_type_definition.rs +++ b/crates/ra_ide_api/src/goto_type_definition.rs @@ -10,7 +10,7 @@ pub(crate) fn goto_type_definition( db: &RootDatabase, position: FilePosition, ) -> Option>> { - let file = db.parse(position.file_id); + let file = db.parse(position.file_id).tree; let node = find_token_at_offset(file.syntax(), position.offset).find_map(|token| { token diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 6545a2581..a390dab65 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -68,7 +68,7 @@ impl HoverResult { } pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option> { - let file = db.parse(position.file_id); + let file = db.parse(position.file_id).tree; let mut res = HoverResult::new(); let mut range = None; @@ -120,7 +120,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option Option { - let file = db.parse(frange.file_id); + let file = db.parse(frange.file_id).tree; let syntax = file.syntax(); let leaf_node = find_covering_element(syntax, frange.range); // if we picked identifier, expand to pattern/expression diff --git a/crates/ra_ide_api/src/impls.rs b/crates/ra_ide_api/src/impls.rs index ee9220a15..b80238d9e 100644 --- a/crates/ra_ide_api/src/impls.rs +++ b/crates/ra_ide_api/src/impls.rs @@ -11,7 +11,7 @@ pub(crate) fn goto_implementation( db: &RootDatabase, position: FilePosition, ) -> Option>> { - let file = db.parse(position.file_id); + let file = db.parse(position.file_id).tree; let syntax = file.syntax(); let module = source_binder::module_from_position(db, position)?; diff --git a/crates/ra_ide_api/src/join_lines.rs b/crates/ra_ide_api/src/join_lines.rs index 4ca005466..3978e9635 100644 --- a/crates/ra_ide_api/src/join_lines.rs +++ b/crates/ra_ide_api/src/join_lines.rs @@ -506,7 +506,7 @@ fn foo() { fn check_join_lines_sel(before: &str, after: &str) { let (sel, before) = extract_range(before); - let file = SourceFile::parse(&before); + let file = SourceFile::parse(&before).tree; let result = join_lines(&file, sel); let actual = result.apply(&before); assert_eq_text!(after, &actual); diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 452407e8e..2fe46cd13 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -314,7 +314,7 @@ impl Analysis { /// Gets the syntax tree of the file. pub fn parse(&self, file_id: FileId) -> TreeArc { - self.db.parse(file_id).clone() + self.db.parse(file_id).tree } /// Gets the file's `LineIndex`: data structure to convert between absolute @@ -331,7 +331,7 @@ impl Analysis { /// Returns position of the matching brace (all types of braces are /// supported). pub fn matching_brace(&self, position: FilePosition) -> Option { - let file = self.db.parse(position.file_id); + let file = self.db.parse(position.file_id).tree; matching_brace::matching_brace(&file, position.offset) } @@ -344,7 +344,7 @@ impl Analysis { /// Returns an edit to remove all newlines in the range, cleaning up minor /// stuff like trailing commas. pub fn join_lines(&self, frange: FileRange) -> SourceChange { - let file = self.db.parse(frange.file_id); + let file = self.db.parse(frange.file_id).tree; let file_edit = SourceFileEdit { file_id: frange.file_id, edit: join_lines::join_lines(&file, frange.range), @@ -362,7 +362,7 @@ impl Analysis { /// this works when adding `let =`. // FIXME: use a snippet completion instead of this hack here. pub fn on_eq_typed(&self, position: FilePosition) -> Option { - let file = self.db.parse(position.file_id); + let file = self.db.parse(position.file_id).tree; let edit = typing::on_eq_typed(&file, position.offset)?; Some(SourceChange::source_file_edit( "add semicolon", @@ -378,13 +378,13 @@ impl Analysis { /// Returns a tree representation of symbols in the file. Useful to draw a /// file outline. pub fn file_structure(&self, file_id: FileId) -> Vec { - let file = self.db.parse(file_id); + let file = self.db.parse(file_id).tree; file_structure(&file) } /// Returns the set of folding ranges. pub fn folding_ranges(&self, file_id: FileId) -> Vec { - let file = self.db.parse(file_id); + let file = self.db.parse(file_id).tree; folding_ranges::folding_ranges(&file) } diff --git a/crates/ra_ide_api/src/matching_brace.rs b/crates/ra_ide_api/src/matching_brace.rs index eaa4b620c..7f3e65b46 100644 --- a/crates/ra_ide_api/src/matching_brace.rs +++ b/crates/ra_ide_api/src/matching_brace.rs @@ -31,7 +31,7 @@ mod tests { fn test_matching_brace() { fn do_check(before: &str, after: &str) { let (pos, before) = extract_offset(before); - let file = SourceFile::parse(&before); + let file = SourceFile::parse(&before).tree; let new_pos = match matching_brace(&file, pos) { None => pos, Some(pos) => pos, diff --git a/crates/ra_ide_api/src/references.rs b/crates/ra_ide_api/src/references.rs index d5c2b08ca..a75042b76 100644 --- a/crates/ra_ide_api/src/references.rs +++ b/crates/ra_ide_api/src/references.rs @@ -60,7 +60,7 @@ pub(crate) fn find_all_refs( db: &RootDatabase, position: FilePosition, ) -> Option { - let file = db.parse(position.file_id); + let file = db.parse(position.file_id).tree; let (binding, analyzer) = find_binding(db, &file, position)?; let declaration = NavigationTarget::from_bind_pat(position.file_id, binding); @@ -99,7 +99,7 @@ pub(crate) fn rename( position: FilePosition, new_name: &str, ) -> Option { - let source_file = db.parse(position.file_id); + let source_file = db.parse(position.file_id).tree; let syntax = source_file.syntax(); if let Some((ast_name, ast_module)) = find_name_and_module_at_offset(syntax, position) { diff --git a/crates/ra_ide_api/src/runnables.rs b/crates/ra_ide_api/src/runnables.rs index 3969076a8..afe629d50 100644 --- a/crates/ra_ide_api/src/runnables.rs +++ b/crates/ra_ide_api/src/runnables.rs @@ -22,7 +22,7 @@ pub enum RunnableKind { } pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec { - let source_file = db.parse(file_id); + let source_file = db.parse(file_id).tree; source_file.syntax().descendants().filter_map(|i| runnable(db, file_id, i)).collect() } diff --git a/crates/ra_ide_api/src/status.rs b/crates/ra_ide_api/src/status.rs index d99a4e750..821106fea 100644 --- a/crates/ra_ide_api/src/status.rs +++ b/crates/ra_ide_api/src/status.rs @@ -4,7 +4,7 @@ use std::{ sync::Arc, }; -use ra_syntax::{AstNode, TreeArc, SourceFile}; +use ra_syntax::{AstNode, Parse}; use ra_db::{ ParseQuery, FileTextQuery, SourceRootId, salsa::{Database, debug::{DebugQueryTable, TableEntry}}, @@ -72,17 +72,17 @@ impl fmt::Display for SyntaxTreeStats { } } -impl FromIterator>> for SyntaxTreeStats { +impl FromIterator> for SyntaxTreeStats { fn from_iter(iter: T) -> SyntaxTreeStats where - T: IntoIterator>>, + T: IntoIterator>, { let mut res = SyntaxTreeStats::default(); for entry in iter { res.total += 1; if let Some(value) = entry.value { res.retained += 1; - res.retained_size += value.syntax().memory_size_of_subtree(); + res.retained_size += value.tree.syntax().memory_size_of_subtree(); } } res diff --git a/crates/ra_ide_api/src/symbol_index.rs b/crates/ra_ide_api/src/symbol_index.rs index 1dcff8beb..a6cd7bf61 100644 --- a/crates/ra_ide_api/src/symbol_index.rs +++ b/crates/ra_ide_api/src/symbol_index.rs @@ -63,7 +63,7 @@ pub(crate) trait SymbolsDatabase: hir::db::HirDatabase { fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Arc { db.check_canceled(); - let source_file = db.parse(file_id); + let source_file = db.parse(file_id).tree; let symbols = source_file_to_file_symbols(&source_file, file_id); diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs index dcefb0513..416e11334 100644 --- a/crates/ra_ide_api/src/syntax_highlighting.rs +++ b/crates/ra_ide_api/src/syntax_highlighting.rs @@ -30,7 +30,7 @@ fn is_control_keyword(kind: SyntaxKind) -> bool { pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec { let _p = profile("highlight"); - let source_file = db.parse(file_id); + let source_file = db.parse(file_id).tree; fn calc_binding_hash(file_id: FileId, text: &SmolStr, shadow_count: u32) -> u64 { fn hash(x: T) -> u64 { @@ -162,7 +162,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec String { - let source_file = db.parse(file_id); + let source_file = db.parse(file_id).tree; fn rainbowify(seed: u64) -> String { use rand::prelude::*; diff --git a/crates/ra_ide_api/src/syntax_tree.rs b/crates/ra_ide_api/src/syntax_tree.rs index c7288220c..7165fa97a 100644 --- a/crates/ra_ide_api/src/syntax_tree.rs +++ b/crates/ra_ide_api/src/syntax_tree.rs @@ -14,7 +14,7 @@ pub(crate) fn syntax_tree( text_range: Option, ) -> String { if let Some(text_range) = text_range { - let file = db.parse(file_id); + let file = db.parse(file_id).tree; let node = match algo::find_covering_element(file.syntax(), text_range) { SyntaxElement::Node(node) => node, SyntaxElement::Token(token) => { @@ -27,7 +27,7 @@ pub(crate) fn syntax_tree( node.debug_dump() } else { - db.parse(file_id).syntax().debug_dump() + db.parse(file_id).tree.syntax().debug_dump() } } @@ -84,8 +84,8 @@ fn syntax_tree_for_token(node: SyntaxToken, text_range: TextRange) -> Option Option>( f: F, ) { let (before_cursor_pos, before) = extract_offset(before); - let file = SourceFile::parse(&before); + let file = SourceFile::parse(&before).ok().unwrap(); let result = f(&file, before_cursor_pos).expect("code action is not applicable"); let actual = result.apply(&before); let actual_cursor_pos = diff --git a/crates/ra_ide_api/src/typing.rs b/crates/ra_ide_api/src/typing.rs index ae53bca77..63bc0cf88 100644 --- a/crates/ra_ide_api/src/typing.rs +++ b/crates/ra_ide_api/src/typing.rs @@ -10,7 +10,7 @@ use ra_db::{FilePosition, SourceDatabase}; use crate::{db::RootDatabase, SourceChange, SourceFileEdit}; pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option { - let file = db.parse(position.file_id); + let file = db.parse(position.file_id).tree; let comment = find_token_at_offset(file.syntax(), position.offset) .left_biased() .and_then(ast::Comment::cast)?; @@ -85,7 +85,7 @@ pub fn on_eq_typed(file: &SourceFile, eq_offset: TextUnit) -> Option { } pub(crate) fn on_dot_typed(db: &RootDatabase, position: FilePosition) -> Option { - let file = db.parse(position.file_id); + let file = db.parse(position.file_id).tree; assert_eq!(file.syntax().text().char_at(position.offset), Some('.')); let whitespace = find_token_at_offset(file.syntax(), position.offset) @@ -138,7 +138,7 @@ mod tests { let mut edit = TextEditBuilder::default(); edit.insert(offset, "=".to_string()); let before = edit.finish().apply(&before); - let file = SourceFile::parse(&before); + let file = SourceFile::parse(&before).tree; if let Some(result) = on_eq_typed(&file, offset) { let actual = result.apply(&before); assert_eq_text!(after, &actual); -- cgit v1.2.3 From 80a17251473bd6213a4c8a51ea7f732394d173c5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 28 May 2019 18:50:53 +0300 Subject: fix todo --- crates/ra_ide_api/src/diagnostics.rs | 3 --- 1 file changed, 3 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs index 4cf2a0b70..a2a8c1e4f 100644 --- a/crates/ra_ide_api/src/diagnostics.rs +++ b/crates/ra_ide_api/src/diagnostics.rs @@ -58,9 +58,6 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec }) }) .on::(|d| { - //TODO: commment - let file_id = d.file().original_file(db); - let source_file = db.parse(file_id).tree; let syntax_node = d.syntax_node_ptr(); let node = NamedFieldList::cast(syntax_node.to_node(source_file.syntax())).unwrap(); let mut ast_editor = AstEditor::new(node); -- cgit v1.2.3