From f8261d611a60e99bc188022773f84912972208d2 Mon Sep 17 00:00:00 2001 From: Marcus Klaas de Vries Date: Tue, 8 Jan 2019 23:38:51 +0100 Subject: Fix typo defenition -> definition --- crates/ra_hir/src/code_model_api.rs | 4 +- crates/ra_hir/src/code_model_impl/module.rs | 2 +- crates/ra_hir/src/impl_block.rs | 2 +- crates/ra_ide_api/src/completion/complete_scope.rs | 2 +- crates/ra_ide_api/src/goto_defenition.rs | 139 --------------------- crates/ra_ide_api/src/goto_definition.rs | 139 +++++++++++++++++++++ crates/ra_ide_api/src/hover.rs | 2 +- crates/ra_ide_api/src/lib.rs | 6 +- crates/ra_lsp_server/src/main_loop/handlers.rs | 2 +- 9 files changed, 149 insertions(+), 149 deletions(-) delete mode 100644 crates/ra_ide_api/src/goto_defenition.rs create mode 100644 crates/ra_ide_api/src/goto_definition.rs (limited to 'crates') diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 902032e14..343d06a5b 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs @@ -75,8 +75,8 @@ impl Module { } /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. - pub fn defenition_source(&self, db: &impl HirDatabase) -> Cancelable<(FileId, ModuleSource)> { - self.defenition_source_impl(db) + pub fn definition_source(&self, db: &impl HirDatabase) -> Cancelable<(FileId, ModuleSource)> { + self.definition_source_impl(db) } /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. /// `None` for the crate root. diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index 56e14fac1..1cb408cff 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs @@ -37,7 +37,7 @@ impl Module { Ok(Some(link.name(&module_tree).clone())) } - pub fn defenition_source_impl( + pub fn definition_source_impl( &self, db: &impl HirDatabase, ) -> Cancelable<(FileId, ModuleSource)> { diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index bb0ad84e4..0fbbdc8eb 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs @@ -150,7 +150,7 @@ impl ModuleImplBlocks { } fn collect(&mut self, db: &impl HirDatabase, module: Module) -> Cancelable<()> { - let (file_id, module_source) = module.defenition_source(db)?; + let (file_id, module_source) = module.definition_source(db)?; let node = match &module_source { ModuleSource::SourceFile(node) => node.syntax(), ModuleSource::Module(node) => node.syntax(), diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs index ee9052d3d..770a0fdf2 100644 --- a/crates/ra_ide_api/src/completion/complete_scope.rs +++ b/crates/ra_ide_api/src/completion/complete_scope.rs @@ -20,7 +20,7 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) -> } let module_scope = module.scope(ctx.db)?; - let (file_id, _) = module.defenition_source(ctx.db)?; + let (file_id, _) = module.definition_source(ctx.db)?; module_scope .entries() .filter(|(_name, res)| { diff --git a/crates/ra_ide_api/src/goto_defenition.rs b/crates/ra_ide_api/src/goto_defenition.rs deleted file mode 100644 index fcd8d315e..000000000 --- a/crates/ra_ide_api/src/goto_defenition.rs +++ /dev/null @@ -1,139 +0,0 @@ -use ra_db::{FileId, Cancelable, SyntaxDatabase}; -use ra_syntax::{ - TextRange, AstNode, ast, SyntaxKind::{NAME, MODULE}, - algo::find_node_at_offset, -}; - -use crate::{FilePosition, NavigationTarget, db::RootDatabase}; - -pub(crate) fn goto_defenition( - db: &RootDatabase, - position: FilePosition, -) -> Cancelable>> { - let file = db.source_file(position.file_id); - let syntax = file.syntax(); - if let Some(name_ref) = find_node_at_offset::(syntax, position.offset) { - return Ok(Some(reference_defenition(db, position.file_id, name_ref)?)); - } - if let Some(name) = find_node_at_offset::(syntax, position.offset) { - return name_defenition(db, position.file_id, name); - } - Ok(None) -} - -pub(crate) fn reference_defenition( - db: &RootDatabase, - file_id: FileId, - name_ref: &ast::NameRef, -) -> Cancelable> { - if let Some(fn_descr) = - hir::source_binder::function_from_child_node(db, file_id, name_ref.syntax())? - { - let scope = fn_descr.scopes(db)?; - // First try to resolve the symbol locally - if let Some(entry) = scope.resolve_local_name(name_ref) { - let nav = NavigationTarget { - file_id, - name: entry.name().to_string().into(), - range: entry.ptr().range(), - kind: NAME, - ptr: None, - }; - return Ok(vec![nav]); - }; - } - // If that fails try the index based approach. - let navs = db - .index_resolve(name_ref)? - .into_iter() - .map(NavigationTarget::from_symbol) - .collect(); - Ok(navs) -} - -fn name_defenition( - db: &RootDatabase, - file_id: FileId, - name: &ast::Name, -) -> Cancelable>> { - if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { - if module.has_semi() { - if let Some(child_module) = - hir::source_binder::module_from_declaration(db, file_id, module)? - { - let (file_id, _) = child_module.defenition_source(db)?; - let name = match child_module.name(db)? { - Some(name) => name.to_string().into(), - None => "".into(), - }; - let nav = NavigationTarget { - file_id, - name, - range: TextRange::offset_len(0.into(), 0.into()), - kind: MODULE, - ptr: None, - }; - return Ok(Some(vec![nav])); - } - } - } - Ok(None) -} - -#[cfg(test)] -mod tests { - use test_utils::assert_eq_dbg; - use crate::mock_analysis::analysis_and_position; - - #[test] - fn goto_defenition_works_in_items() { - let (analysis, pos) = analysis_and_position( - " - //- /lib.rs - struct Foo; - enum E { X(Foo<|>) } - ", - ); - - let symbols = analysis.goto_defenition(pos).unwrap().unwrap(); - assert_eq_dbg( - r#"[NavigationTarget { file_id: FileId(1), name: "Foo", - kind: STRUCT_DEF, range: [0; 11), - ptr: Some(LocalSyntaxPtr { range: [0; 11), kind: STRUCT_DEF }) }]"#, - &symbols, - ); - } - - #[test] - fn goto_defenition_works_for_module_declaration() { - let (analysis, pos) = analysis_and_position( - " - //- /lib.rs - mod <|>foo; - //- /foo.rs - // empty - ", - ); - - let symbols = analysis.goto_defenition(pos).unwrap().unwrap(); - assert_eq_dbg( - r#"[NavigationTarget { file_id: FileId(2), name: "foo", kind: MODULE, range: [0; 0), ptr: None }]"#, - &symbols, - ); - - let (analysis, pos) = analysis_and_position( - " - //- /lib.rs - mod <|>foo; - //- /foo/mod.rs - // empty - ", - ); - - let symbols = analysis.goto_defenition(pos).unwrap().unwrap(); - assert_eq_dbg( - r#"[NavigationTarget { file_id: FileId(2), name: "foo", kind: MODULE, range: [0; 0), ptr: None }]"#, - &symbols, - ); - } -} diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs new file mode 100644 index 000000000..0d524b6f1 --- /dev/null +++ b/crates/ra_ide_api/src/goto_definition.rs @@ -0,0 +1,139 @@ +use ra_db::{FileId, Cancelable, SyntaxDatabase}; +use ra_syntax::{ + TextRange, AstNode, ast, SyntaxKind::{NAME, MODULE}, + algo::find_node_at_offset, +}; + +use crate::{FilePosition, NavigationTarget, db::RootDatabase}; + +pub(crate) fn goto_definition( + db: &RootDatabase, + position: FilePosition, +) -> Cancelable>> { + let file = db.source_file(position.file_id); + let syntax = file.syntax(); + if let Some(name_ref) = find_node_at_offset::(syntax, position.offset) { + return Ok(Some(reference_definition(db, position.file_id, name_ref)?)); + } + if let Some(name) = find_node_at_offset::(syntax, position.offset) { + return name_definition(db, position.file_id, name); + } + Ok(None) +} + +pub(crate) fn reference_definition( + db: &RootDatabase, + file_id: FileId, + name_ref: &ast::NameRef, +) -> Cancelable> { + if let Some(fn_descr) = + hir::source_binder::function_from_child_node(db, file_id, name_ref.syntax())? + { + let scope = fn_descr.scopes(db)?; + // First try to resolve the symbol locally + if let Some(entry) = scope.resolve_local_name(name_ref) { + let nav = NavigationTarget { + file_id, + name: entry.name().to_string().into(), + range: entry.ptr().range(), + kind: NAME, + ptr: None, + }; + return Ok(vec![nav]); + }; + } + // If that fails try the index based approach. + let navs = db + .index_resolve(name_ref)? + .into_iter() + .map(NavigationTarget::from_symbol) + .collect(); + Ok(navs) +} + +fn name_definition( + db: &RootDatabase, + file_id: FileId, + name: &ast::Name, +) -> Cancelable>> { + if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { + if module.has_semi() { + if let Some(child_module) = + hir::source_binder::module_from_declaration(db, file_id, module)? + { + let (file_id, _) = child_module.definition_source(db)?; + let name = match child_module.name(db)? { + Some(name) => name.to_string().into(), + None => "".into(), + }; + let nav = NavigationTarget { + file_id, + name, + range: TextRange::offset_len(0.into(), 0.into()), + kind: MODULE, + ptr: None, + }; + return Ok(Some(vec![nav])); + } + } + } + Ok(None) +} + +#[cfg(test)] +mod tests { + use test_utils::assert_eq_dbg; + use crate::mock_analysis::analysis_and_position; + + #[test] + fn goto_definition_works_in_items() { + let (analysis, pos) = analysis_and_position( + " + //- /lib.rs + struct Foo; + enum E { X(Foo<|>) } + ", + ); + + let symbols = analysis.goto_definition(pos).unwrap().unwrap(); + assert_eq_dbg( + r#"[NavigationTarget { file_id: FileId(1), name: "Foo", + kind: STRUCT_DEF, range: [0; 11), + ptr: Some(LocalSyntaxPtr { range: [0; 11), kind: STRUCT_DEF }) }]"#, + &symbols, + ); + } + + #[test] + fn goto_definition_works_for_module_declaration() { + let (analysis, pos) = analysis_and_position( + " + //- /lib.rs + mod <|>foo; + //- /foo.rs + // empty + ", + ); + + let symbols = analysis.goto_definition(pos).unwrap().unwrap(); + assert_eq_dbg( + r#"[NavigationTarget { file_id: FileId(2), name: "foo", kind: MODULE, range: [0; 0), ptr: None }]"#, + &symbols, + ); + + let (analysis, pos) = analysis_and_position( + " + //- /lib.rs + mod <|>foo; + //- /foo/mod.rs + // empty + ", + ); + + let symbols = analysis.goto_definition(pos).unwrap().unwrap(); + assert_eq_dbg( + r#"[NavigationTarget { file_id: FileId(2), name: "foo", kind: MODULE, range: [0; 0), ptr: None }]"#, + &symbols, + ); + } +} diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 475524ee1..41309e756 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -16,7 +16,7 @@ pub(crate) fn hover( let mut range = None; if let Some(name_ref) = find_node_at_offset::(file.syntax(), position.offset) { - let navs = crate::goto_defenition::reference_defenition(db, position.file_id, name_ref)?; + let navs = crate::goto_definition::reference_definition(db, position.file_id, name_ref)?; for nav in navs { res.extend(doc_text_for(db, nav)?) } diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 7e9ca2034..762731268 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -20,7 +20,7 @@ macro_rules! ctry { mod completion; mod db; -mod goto_defenition; +mod goto_definition; mod imp; pub mod mock_analysis; mod runnables; @@ -399,11 +399,11 @@ impl Analysis { .collect(); Ok(res) } - pub fn goto_defenition( + pub fn goto_definition( &self, position: FilePosition, ) -> Cancelable>> { - goto_defenition::goto_defenition(&*self.db, position) + goto_definition::goto_definition(&*self.db, position) } /// Finds all usages of the reference at point. pub fn find_all_refs(&self, position: FilePosition) -> Cancelable> { diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index a653c5ada..069e7f932 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -213,7 +213,7 @@ pub fn handle_goto_definition( params: req::TextDocumentPositionParams, ) -> Result> { let position = params.try_conv_with(&world)?; - let navs = match world.analysis().goto_defenition(position)? { + let navs = match world.analysis().goto_definition(position)? { None => return Ok(None), Some(it) => it, }; -- cgit v1.2.3 From 0b8fbb4fad97d2980f0070a23f5365a5ed887e2a Mon Sep 17 00:00:00 2001 From: Marcus Klaas de Vries Date: Wed, 9 Jan 2019 00:47:12 +0100 Subject: Fix typos in ARCHITECTURE.md and a number of crates specifically: gen_lsp_server, ra_arena, ra_cli, ra_db, ra_hir --- crates/gen_lsp_server/src/lib.rs | 6 ++--- crates/gen_lsp_server/src/msg.rs | 2 +- crates/ra_db/src/cancelation.rs | 44 ----------------------------------- crates/ra_db/src/cancellation.rs | 44 +++++++++++++++++++++++++++++++++++ crates/ra_db/src/input.rs | 22 +++++++++--------- crates/ra_db/src/lib.rs | 6 ++--- crates/ra_db/src/loc2id.rs | 4 ++-- crates/ra_hir/src/code_model_api.rs | 20 ++++++++++++---- crates/ra_hir/src/db.rs | 3 +++ crates/ra_hir/src/expr.rs | 8 +++++-- crates/ra_hir/src/ids.rs | 12 +++++----- crates/ra_hir/src/impl_block.rs | 12 +++++----- crates/ra_hir/src/lib.rs | 6 ++--- crates/ra_hir/src/macros.rs | 6 ++--- crates/ra_hir/src/module_tree.rs | 4 ++-- crates/ra_hir/src/name.rs | 2 +- crates/ra_hir/src/nameres.rs | 24 +++++++++---------- crates/ra_hir/src/source_binder.rs | 2 +- crates/ra_hir/src/ty.rs | 4 ++-- crates/ra_hir/src/ty/autoderef.rs | 2 +- crates/ra_hir/src/ty/tests.rs | 2 +- crates/ra_ide_api/src/lib.rs | 41 ++++++++++++++++++++++++++++++++ crates/ra_lsp_server/src/main_loop.rs | 2 +- 23 files changed, 169 insertions(+), 109 deletions(-) delete mode 100644 crates/ra_db/src/cancelation.rs create mode 100644 crates/ra_db/src/cancellation.rs (limited to 'crates') diff --git a/crates/gen_lsp_server/src/lib.rs b/crates/gen_lsp_server/src/lib.rs index b20652928..16ac799ac 100644 --- a/crates/gen_lsp_server/src/lib.rs +++ b/crates/gen_lsp_server/src/lib.rs @@ -78,10 +78,10 @@ pub use crate::{ }; /// Main entry point: runs the server from initialization to shutdown. -/// To attach server to standard input/output streams, use `stdio_transport` +/// To attach server to standard input/output streams, use the `stdio_transport` /// function to create corresponding `sender` and `receiver` pair. /// -///`server` should use `handle_shutdown` function to handle the `Shutdown` +/// `server` should use the `handle_shutdown` function to handle the `Shutdown` /// request. pub fn run_server( caps: ServerCapabilities, @@ -104,7 +104,7 @@ pub fn run_server( Ok(()) } -/// if `req` is `Shutdown`, respond to it and return `None`, otherwise return `Some(req)` +/// If `req` is `Shutdown`, respond to it and return `None`, otherwise return `Some(req)` pub fn handle_shutdown(req: RawRequest, sender: &Sender) -> Option { match req.cast::() { Ok((id, ())) => { diff --git a/crates/gen_lsp_server/src/msg.rs b/crates/gen_lsp_server/src/msg.rs index f68cbc541..94bef374c 100644 --- a/crates/gen_lsp_server/src/msg.rs +++ b/crates/gen_lsp_server/src/msg.rs @@ -54,7 +54,7 @@ pub enum ErrorCode { ServerErrorEnd = -32000, ServerNotInitialized = -32002, UnknownErrorCode = -32001, - RequestCancelled = -32800, + RequestCanceled = -32800, ContentModified = -32801, } diff --git a/crates/ra_db/src/cancelation.rs b/crates/ra_db/src/cancelation.rs deleted file mode 100644 index 56ce27bff..000000000 --- a/crates/ra_db/src/cancelation.rs +++ /dev/null @@ -1,44 +0,0 @@ -//! Utility types to support cancellation. -//! -//! In a typical IDE use-case, requests and modification happen concurrently, as -//! in the following scenario: -//! -//! * user types a character, -//! * a syntax highlighting process is started -//! * user types next character, while syntax highlighting *is still in -//! progress*. -//! -//! In this situation, we want to react to modification as quckly as possible. -//! At the same time, in-progress results are not very interesting, because they -//! are invalidated by the edit anyway. So, we first cancel all in-flight -//! requests, and then apply modification knowing that it won't intrfere with -//! any background processing (this bit is handled by salsa, see -//! `BaseDatabase::check_canceled` method). - -/// An "error" signifing that the operation was canceled. -#[derive(Clone, PartialEq, Eq, Hash)] -pub struct Canceled { - _private: (), -} - -pub type Cancelable = Result; - -impl Canceled { - pub(crate) fn new() -> Canceled { - Canceled { _private: () } - } -} - -impl std::fmt::Display for Canceled { - fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - fmt.write_str("canceled") - } -} - -impl std::fmt::Debug for Canceled { - fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(fmt, "Canceled") - } -} - -impl std::error::Error for Canceled {} diff --git a/crates/ra_db/src/cancellation.rs b/crates/ra_db/src/cancellation.rs new file mode 100644 index 000000000..8d38eebfb --- /dev/null +++ b/crates/ra_db/src/cancellation.rs @@ -0,0 +1,44 @@ +//! Utility types to support cancellation. +//! +//! In a typical IDE use-case, requests and modification happen concurrently, as +//! in the following scenario: +//! +//! * user types a character, +//! * a syntax highlighting process is started +//! * user types next character, while syntax highlighting *is still in +//! progress*. +//! +//! In this situation, we want to react to modification as quickly as possible. +//! At the same time, in-progress results are not very interesting, because they +//! are invalidated by the edit anyway. So, we first cancel all in-flight +//! requests, and then apply modification knowing that it won't interfere with +//! any background processing (this bit is handled by salsa, see the +//! `BaseDatabase::check_canceled` method). + +/// An "error" signifing that the operation was canceled. +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct Canceled { + _private: (), +} + +pub type Cancelable = Result; + +impl Canceled { + pub(crate) fn new() -> Canceled { + Canceled { _private: () } + } +} + +impl std::fmt::Display for Canceled { + fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fmt.write_str("canceled") + } +} + +impl std::fmt::Debug for Canceled { + fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(fmt, "Canceled") + } +} + +impl std::error::Error for Canceled {} diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index 7c3dd9296..023183e29 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs @@ -1,9 +1,9 @@ -/// This modules specifies the input to rust-analyzer. In some sense, this is +/// This module specifies the input to rust-analyzer. In some sense, this is /// **the** most important module, because all other fancy stuff is strictly /// derived from this input. /// /// Note that neither this module, nor any other part of the analyzer's core do -/// actual IO. See `vfs` and `project_model` in `ra_lsp_server` crate for how +/// actual IO. See `vfs` and `project_model` in the `ra_lsp_server` crate for how /// actual IO is done and lowered to input. use std::sync::Arc; @@ -17,17 +17,17 @@ use rustc_hash::FxHashSet; /// `FileId` is an integer which uniquely identifies a file. File paths are /// messy and system-dependent, so most of the code should work directly with /// `FileId`, without inspecting the path. The mapping between `FileId` and path -/// and `SourceRoot` is constant. File rename is represented as a pair of +/// and `SourceRoot` is constant. A file rename is represented as a pair of /// deletion/creation. #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct FileId(pub u32); /// Files are grouped into source roots. A source root is a directory on the /// file systems which is watched for changes. Typically it corresponds to a -/// Cargo package. Source roots *might* be nested: in this case, file belongs to -/// the nearest enclosing source root. Path to files are always relative to a -/// source root, and analyzer does not know the root path of the source root at -/// all. So, a file from one source root can't refere a file in another source +/// Rust crate. Source roots *might* be nested: in this case, a file belongs to +/// the nearest enclosing source root. Paths to files are always relative to a +/// source root, and the analyzer does not know the root path of the source root at +/// all. So, a file from one source root can't refer to a file in another source /// root by path. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct SourceRootId(pub u32); @@ -38,15 +38,15 @@ pub struct SourceRoot { } /// `CrateGraph` is a bit of information which turns a set of text files into a -/// number of Rust crates. Each Crate is the `FileId` of it's root module, the -/// set of cfg flags (not yet implemented) and the set of dependencies. Note +/// number of Rust crates. Each crate is defined by the `FileId` of its root module, +/// the set of cfg flags (not yet implemented) and the set of dependencies. Note /// that, due to cfg's, there might be several crates for a single `FileId`! As /// in the rust-lang proper, a crate does not have a name. Instead, names are /// specified on dependency edges. That is, a crate might be known under -/// different names in different dependant crates. +/// different names in different dependent crates. /// /// Note that `CrateGraph` is build-system agnostic: it's a concept of the Rust -/// langauge proper, not a concept of the build system. In practice, we get +/// language proper, not a concept of the build system. In practice, we get /// `CrateGraph` by lowering `cargo metadata` output. #[derive(Debug, Clone, Default, PartialEq, Eq)] pub struct CrateGraph { diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index e680d9fc3..fb8ea2496 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs @@ -1,5 +1,5 @@ -//! ra_db defines basic database traits. Concrete DB is defined by ra_ide_api. -mod cancelation; +//! ra_db defines basic database traits. The concrete DB is defined by ra_ide_api. +mod cancellation; mod syntax_ptr; mod input; mod loc2id; @@ -8,7 +8,7 @@ pub mod mock; use ra_syntax::{TextUnit, TextRange, SourceFile, TreePtr}; pub use crate::{ - cancelation::{Canceled, Cancelable}, + cancellation::{Canceled, Cancelable}, syntax_ptr::LocalSyntaxPtr, input::{ FilesDatabase, FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, Dependency, diff --git a/crates/ra_db/src/loc2id.rs b/crates/ra_db/src/loc2id.rs index 1d6761897..254c52629 100644 --- a/crates/ra_db/src/loc2id.rs +++ b/crates/ra_db/src/loc2id.rs @@ -5,7 +5,7 @@ use rustc_hash::FxHashMap; use ra_arena::{Arena, ArenaId}; /// There are two principle ways to refer to things: -/// - by their locatinon (module in foo/bar/baz.rs at line 42) +/// - by their location (module in foo/bar/baz.rs at line 42) /// - by their numeric id (module `ModuleId(42)`) /// /// The first one is more powerful (you can actually find the thing in question @@ -13,7 +13,7 @@ use ra_arena::{Arena, ArenaId}; /// /// `Loc2IdMap` allows us to have a cake an eat it as well: by maintaining a /// bidirectional mapping between positional and numeric ids, we can use compact -/// representation wich still allows us to get the actual item +/// representation which still allows us to get the actual item. #[derive(Debug)] struct Loc2IdMap where diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 343d06a5b..66c016180 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs @@ -13,8 +13,8 @@ use crate::{ ty::InferenceResult, }; -/// hir::Crate describes a single crate. It's the main inteface with which -/// crate's dependencies interact. Mostly, it should be just a proxy for the +/// hir::Crate describes a single crate. It's the main interface with which +/// a crate's dependencies interact. Mostly, it should be just a proxy for the /// root module. #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Crate { @@ -78,6 +78,7 @@ impl Module { pub fn definition_source(&self, db: &impl HirDatabase) -> Cancelable<(FileId, ModuleSource)> { self.definition_source_impl(db) } + /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. /// `None` for the crate root. pub fn declaration_source( @@ -91,20 +92,24 @@ impl Module { pub fn krate(&self, db: &impl HirDatabase) -> Cancelable> { self.krate_impl(db) } + /// Topmost parent of this module. Every module has a `crate_root`, but some - /// might miss `krate`. This can happen if a module's file is not included - /// into any module tree of any target from Cargo.toml. + /// might be missing `krate`. This can happen if a module's file is not included + /// in the module tree of any target in Cargo.toml. pub fn crate_root(&self, db: &impl HirDatabase) -> Cancelable { self.crate_root_impl(db) } + /// Finds a child module with the specified name. pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable> { self.child_impl(db, name) } + /// Finds a parent module. pub fn parent(&self, db: &impl HirDatabase) -> Cancelable> { self.parent_impl(db) } + pub fn path_to_root(&self, db: &impl HirDatabase) -> Cancelable> { let mut res = vec![self.clone()]; let mut curr = self.clone(); @@ -114,13 +119,16 @@ impl Module { } Ok(res) } + /// Returns a `ModuleScope`: a set of items, visible in this module. pub fn scope(&self, db: &impl HirDatabase) -> Cancelable { self.scope_impl(db) } + pub fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> Cancelable> { self.resolve_path_impl(db, path) } + pub fn problems( &self, db: &impl HirDatabase, @@ -140,6 +148,7 @@ impl StructField { pub fn name(&self) -> &Name { &self.name } + pub fn type_ref(&self) -> &TypeRef { &self.type_ref } @@ -160,18 +169,21 @@ impl VariantData { _ => &[], } } + pub fn is_struct(&self) -> bool { match self { VariantData::Struct(..) => true, _ => false, } } + pub fn is_tuple(&self) -> bool { match self { VariantData::Tuple(..) => true, _ => false, } } + pub fn is_unit(&self) -> bool { match self { VariantData::Unit => true, diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 07cf0d10a..7dbe93f2b 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -26,6 +26,7 @@ pub trait HirDatabase: SyntaxDatabase type HirSourceFileQuery; use fn HirFileId::hir_source_file; } + fn expand_macro_invocation(invoc: MacroCallId) -> Option> { type ExpandMacroCallQuery; use fn crate::macros::expand_macro_invocation; @@ -80,10 +81,12 @@ pub trait HirDatabase: SyntaxDatabase type InputModuleItemsQuery; use fn query_definitions::input_module_items; } + fn item_map(source_root_id: SourceRootId) -> Cancelable> { type ItemMapQuery; use fn query_definitions::item_map; } + fn module_tree(source_root_id: SourceRootId) -> Cancelable> { type ModuleTreeQuery; use fn crate::module_tree::ModuleTree::module_tree_query; diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index a31f086f7..ebb83d084 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs @@ -33,8 +33,7 @@ pub struct Body { /// IDs. This is needed to go from e.g. a position in a file to the HIR /// expression containing it; but for type inference etc., we want to operate on /// a structure that is agnostic to the actual positions of expressions in the -/// file, so that we don't recompute the type inference whenever some whitespace -/// is typed. +/// file, so that we don't recompute types whenever some whitespace is typed. #[derive(Debug, Eq, PartialEq)] pub struct BodySyntaxMapping { body: Arc, @@ -74,20 +73,25 @@ impl BodySyntaxMapping { pub fn expr_syntax(&self, expr: ExprId) -> Option { self.expr_syntax_mapping_back.get(expr).cloned() } + pub fn syntax_expr(&self, ptr: LocalSyntaxPtr) -> Option { self.expr_syntax_mapping.get(&ptr).cloned() } + pub fn node_expr(&self, node: &ast::Expr) -> Option { self.expr_syntax_mapping .get(&LocalSyntaxPtr::new(node.syntax())) .cloned() } + pub fn pat_syntax(&self, pat: PatId) -> Option { self.pat_syntax_mapping_back.get(pat).cloned() } + pub fn syntax_pat(&self, ptr: LocalSyntaxPtr) -> Option { self.pat_syntax_mapping.get(&ptr).cloned() } + pub fn node_pat(&self, node: &ast::Pat) -> Option { self.pat_syntax_mapping .get(&LocalSyntaxPtr::new(node.syntax())) diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 3db757778..2e10e5516 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs @@ -9,25 +9,25 @@ use crate::{ use crate::code_model_api::Module; -/// hir makes a heavy use of ids: integer (u32) handlers to various things. You +/// hir makes heavy use of ids: integer (u32) handlers to various things. You /// can think of id as a pointer (but without a lifetime) or a file descriptor /// (but for hir objects). /// /// This module defines a bunch of ids we are using. The most important ones are /// probably `HirFileId` and `DefId`. -/// Input to the analyzer is a set of file, where each file is indetified by +/// Input to the analyzer is a set of files, where each file is indentified by /// `FileId` and contains source code. However, another source of source code in /// Rust are macros: each macro can be thought of as producing a "temporary -/// file". To assign id to such file, we use the id of a macro call that +/// file". To assign an id to such a file, we use the id of the macro call that /// produced the file. So, a `HirFileId` is either a `FileId` (source code /// written by user), or a `MacroCallId` (source code produced by macro). /// /// What is a `MacroCallId`? Simplifying, it's a `HirFileId` of a file containin /// the call plus the offset of the macro call in the file. Note that this is a -/// recursive definition! Nethetheless, size_of of `HirFileId` is finite +/// recursive definition! However, the size_of of `HirFileId` is finite /// (because everything bottoms out at the real `FileId`) and small -/// (`MacroCallId` uses location interner). +/// (`MacroCallId` uses the location interner). #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct HirFileId(HirFileIdRepr); @@ -235,7 +235,7 @@ pub struct SourceItemId { pub(crate) item_id: Option, } -/// Maps item's `SyntaxNode`s to `SourceFileItemId` and back. +/// Maps items' `SyntaxNode`s to `SourceFileItemId`s and back. #[derive(Debug, PartialEq, Eq)] pub struct SourceFileItems { file_id: HirFileId, diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index 0fbbdc8eb..4acda9af3 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs @@ -128,13 +128,13 @@ impl ImplItem { pub struct ImplId(pub RawId); impl_arena_id!(ImplId); -/// Collection of impl blocks is a two-step process: First we collect the blocks -/// per-module; then we build an index of all impl blocks in the crate. This -/// way, we avoid having to do this process for the whole crate whenever someone -/// types in any file; as long as the impl blocks in the file don't change, we -/// don't need to do the second step again. +/// The collection of impl blocks is a two-step process: first we collect the +/// blocks per-module; then we build an index of all impl blocks in the crate. +/// This way, we avoid having to do this process for the whole crate whenever +/// a file is changed; as long as the impl blocks in the file don't change, +/// we don't need to do the second step again. /// -/// (The second step does not yet exist currently.) +/// (The second step does not yet exist.) #[derive(Debug, PartialEq, Eq)] pub struct ModuleImplBlocks { impls: Arena, diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index eb19d8be1..ca7f395a8 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -1,9 +1,9 @@ -//! HIR (previsouly known as descriptors) provides a high-level OO acess to Rust -//! code. +//! HIR (previously known as descriptors) provides a high-level object oriented +//! access to Rust code. //! //! The principal difference between HIR and syntax trees is that HIR is bound //! to a particular crate instance. That is, it has cfg flags and features -//! applied. So, there relation between syntax and HIR is many-to-one. +//! applied. So, the relation between syntax and HIR is many-to-one. macro_rules! ctry { ($expr:expr) => { diff --git a/crates/ra_hir/src/macros.rs b/crates/ra_hir/src/macros.rs index eb1c86091..e455b2ad5 100644 --- a/crates/ra_hir/src/macros.rs +++ b/crates/ra_hir/src/macros.rs @@ -4,9 +4,9 @@ /// that is produced after expansion. See `HirFileId` and `MacroCallId` for how /// do we do that. /// -/// When file-management question is resolved, all that is left is a token tree -/// to token tree transformation plus hygent. We don't have either of thouse -/// yet, so all macros are string based at the moment! +/// When the file-management question is resolved, all that is left is a +/// token-tree-to-token-tree transformation plus hygiene. We don't have either of +/// those yet, so all macros are string based at the moment! use std::sync::Arc; use ra_db::LocalSyntaxPtr; diff --git a/crates/ra_hir/src/module_tree.rs b/crates/ra_hir/src/module_tree.rs index 91aab5c74..d2c92f150 100644 --- a/crates/ra_hir/src/module_tree.rs +++ b/crates/ra_hir/src/module_tree.rs @@ -85,9 +85,9 @@ impl_arena_id!(LinkId); /// Physically, rust source is organized as a set of files, but logically it is /// organized as a tree of modules. Usually, a single file corresponds to a -/// single module, but it is not nessary the case. +/// single module, but it is not neccessarily always the case. /// -/// Module encapsulate the logic of transitioning from the fuzzy world of files +/// `ModuleTree` encapsulates the logic of transitioning from the fuzzy world of files /// (which can have multiple parents) to the precise world of modules (which /// always have one parent). #[derive(Default, Debug, PartialEq, Eq)] diff --git a/crates/ra_hir/src/name.rs b/crates/ra_hir/src/name.rs index 3e6ce8b95..d9683549c 100644 --- a/crates/ra_hir/src/name.rs +++ b/crates/ra_hir/src/name.rs @@ -3,7 +3,7 @@ use std::fmt; use ra_syntax::{ast, SmolStr}; /// `Name` is a wrapper around string, which is used in hir for both references -/// and declarations. In theory, names should also carry hygene info, but we are +/// and declarations. In theory, names should also carry hygiene info, but we are /// not there yet! #[derive(Clone, PartialEq, Eq, Hash)] pub struct Name { diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index 20adc9ec4..6bf949654 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -1,18 +1,18 @@ -//! Name resolution algorithm. The end result of the algorithm is `ItemMap`: a -//! map with maps each module to it's scope: the set of items, visible in the +//! Name resolution algorithm. The end result of the algorithm is an `ItemMap`: +//! a map which maps each module to its scope: the set of items visible in the //! module. That is, we only resolve imports here, name resolution of item //! bodies will be done in a separate step. //! -//! Like Rustc, we use an interative per-crate algorithm: we start with scopes +//! Like Rustc, we use an interactive per-crate algorithm: we start with scopes //! containing only directly defined items, and then iteratively resolve //! imports. //! -//! To make this work nicely in the IDE scenarios, we place `InputModuleItems` +//! To make this work nicely in the IDE scenario, we place `InputModuleItems` //! in between raw syntax and name resolution. `InputModuleItems` are computed //! using only the module's syntax, and it is all directly defined items plus -//! imports. The plain is to make `InputModuleItems` independent of local -//! modifications (that is, typing inside a function shold not change IMIs), -//! such that the results of name resolution can be preserved unless the module +//! imports. The plan is to make `InputModuleItems` independent of local +//! modifications (that is, typing inside a function should not change IMIs), +//! so that the results of name resolution can be preserved unless the module //! structure itself is modified. use std::sync::Arc; @@ -34,7 +34,7 @@ use crate::{ module_tree::{ModuleId, ModuleTree}, }; -/// Item map is the result of the name resolution. Item map contains, for each +/// `ItemMap` is the result of name resolution. It contains, for each /// module, the set of visible items. // FIXME: currenty we compute item map per source-root. We should do it per crate instead. #[derive(Default, Debug, PartialEq, Eq)] @@ -59,9 +59,9 @@ impl ModuleScope { /// A set of items and imports declared inside a module, without relation to /// other modules. /// -/// This stands in-between raw syntax and name resolution and alow us to avoid -/// recomputing name res: if `InputModuleItems` are the same, we can avoid -/// running name resolution. +/// This sits in-between raw syntax and name resolution and allows us to avoid +/// recomputing name res: if two instance of `InputModuleItems` are the same, we +/// can avoid redoing name resolution. #[derive(Debug, Default, PartialEq, Eq)] pub struct InputModuleItems { pub(crate) items: Vec, @@ -114,7 +114,7 @@ enum ImportKind { Named(NamedImport), } -/// Resolution is basically `DefId` atm, but it should account for stuff like +/// `Resolution` is basically `DefId` atm, but it should account for stuff like /// multiple namespaces, ambiguity and errors. #[derive(Debug, Clone, PartialEq, Eq)] pub struct Resolution { diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 4b0400cd0..1f149a366 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -1,4 +1,4 @@ -/// Lookup hir elements using position in the source code. This is a lossy +/// Lookup hir elements using positions in the source code. This is a lossy /// transformation: in general, a single source might correspond to several /// modules, functions, etc, due to macros, cfgs and `#[path=]` attributes on /// modules. diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 90ba393ce..3b2bfd67a 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -144,7 +144,7 @@ pub enum Ty { Bool, /// The primitive character type; holds a Unicode scalar value - /// (a non-surrogate code point). Written as `char`. + /// (a non-surrogate code point). Written as `char`. Char, /// A primitive signed integer type. For example, `i32`. @@ -204,7 +204,7 @@ pub enum Ty { // `|a| yield a`. // Generator(DefId, GeneratorSubsts<'tcx>, hir::GeneratorMovability), - // A type representin the types stored inside a generator. + // A type representing the types stored inside a generator. // This should only appear in GeneratorInteriors. // GeneratorWitness(Binder<&'tcx List>>), /// The never type `!`. diff --git a/crates/ra_hir/src/ty/autoderef.rs b/crates/ra_hir/src/ty/autoderef.rs index 24a386558..d95879e46 100644 --- a/crates/ra_hir/src/ty/autoderef.rs +++ b/crates/ra_hir/src/ty/autoderef.rs @@ -1,4 +1,4 @@ -//! In certain situations, rust automatically inserts derefs as necessary: For +//! In certain situations, rust automatically inserts derefs as necessary: for //! example, field accesses `foo.bar` still work when `foo` is actually a //! reference to a type with the field `bar`. This is an approximation of the //! logic in rustc (which lives in librustc_typeck/check/autoderef.rs). diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 2749d740c..ba2a44474 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -15,7 +15,7 @@ use crate::{ }; // These tests compare the inference results for all expressions in a file -// against snapshots of the current results. If you change something and these +// against snapshots of the expected results. If you change something and these // tests fail expectedly, you can update the comparison files by deleting them // and running the tests again. Similarly, to add a new test, just write the // test here in the same pattern and it will automatically write the snapshot. diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 762731268..fbe1421a4 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -121,9 +121,11 @@ impl AnalysisChange { pub fn new() -> AnalysisChange { AnalysisChange::default() } + pub fn add_root(&mut self, root_id: SourceRootId, is_local: bool) { self.new_roots.push((root_id, is_local)); } + pub fn add_file( &mut self, root_id: SourceRootId, @@ -142,9 +144,11 @@ impl AnalysisChange { .added .push(file); } + pub fn change_file(&mut self, file_id: FileId, new_text: Arc) { self.files_changed.push((file_id, new_text)) } + pub fn remove_file(&mut self, root_id: SourceRootId, file_id: FileId, path: RelativePathBuf) { let file = RemoveFile { file_id, path }; self.roots_changed @@ -153,9 +157,11 @@ impl AnalysisChange { .removed .push(file); } + pub fn add_library(&mut self, data: LibraryData) { self.libraries_added.push(data) } + pub fn set_crate_graph(&mut self, graph: CrateGraph) { self.crate_graph = Some(graph); } @@ -218,15 +224,19 @@ impl Query { limit: usize::max_value(), } } + pub fn only_types(&mut self) { self.only_types = true; } + pub fn libs(&mut self) { self.libs = true; } + pub fn exact(&mut self) { self.exact = true; } + pub fn limit(&mut self, limit: usize) { self.limit = limit } @@ -257,15 +267,19 @@ impl NavigationTarget { ptr: Some(symbol.ptr.clone()), } } + pub fn name(&self) -> &SmolStr { &self.name } + pub fn kind(&self) -> SyntaxKind { self.kind } + pub fn file_id(&self) -> FileId { self.file_id } + pub fn range(&self) -> TextRange { self.range } @@ -305,6 +319,7 @@ impl AnalysisHost { db: self.db.snapshot(), } } + /// Applies changes to the current state of the world. If there are /// outstanding snapshots, they will be canceled. pub fn apply_change(&mut self, change: AnalysisChange) { @@ -326,30 +341,36 @@ impl Analysis { pub fn file_text(&self, file_id: FileId) -> Arc { self.db.file_text(file_id) } + /// Gets the syntax tree of the file. pub fn file_syntax(&self, file_id: FileId) -> TreePtr { self.db.source_file(file_id).clone() } + /// Gets the file's `LineIndex`: data structure to convert between absolute /// offsets and line/column representation. pub fn file_line_index(&self, file_id: FileId) -> Arc { self.db.line_index(file_id) } + /// Selects the next syntactic nodes encopasing the range. pub fn extend_selection(&self, frange: FileRange) -> TextRange { extend_selection::extend_selection(&self.db, frange) } + /// Returns position of the mathcing brace (all types of braces are /// supported). pub fn matching_brace(&self, file: &SourceFile, offset: TextUnit) -> Option { ra_ide_api_light::matching_brace(file, offset) } + /// Returns a syntax tree represented as `String`, for debug purposes. // FIXME: use a better name here. pub fn syntax_tree(&self, file_id: FileId) -> String { let file = self.db.source_file(file_id); ra_ide_api_light::syntax_tree(&file) } + /// 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 { @@ -359,6 +380,7 @@ impl Analysis { ra_ide_api_light::join_lines(&file, frange.range), ) } + /// Returns an edit which should be applied when opening a new line, fixing /// up minor stuff like continuing the comment. pub fn on_enter(&self, position: FilePosition) -> Option { @@ -366,6 +388,7 @@ impl Analysis { let edit = ra_ide_api_light::on_enter(&file, position.offset)?; Some(SourceChange::from_local_edit(position.file_id, edit)) } + /// Returns an edit which should be applied after `=` was typed. Primarily, /// this works when adding `let =`. // FIXME: use a snippet completion instead of this hack here. @@ -374,23 +397,27 @@ impl Analysis { let edit = ra_ide_api_light::on_eq_typed(&file, position.offset)?; Some(SourceChange::from_local_edit(position.file_id, edit)) } + /// Returns an edit which should be applied when a dot ('.') is typed on a blank line, indenting the line appropriately. pub fn on_dot_typed(&self, position: FilePosition) -> Option { let file = self.db.source_file(position.file_id); let edit = ra_ide_api_light::on_dot_typed(&file, position.offset)?; Some(SourceChange::from_local_edit(position.file_id, edit)) } + /// 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.source_file(file_id); ra_ide_api_light::file_structure(&file) } + /// Returns the set of folding ranges. pub fn folding_ranges(&self, file_id: FileId) -> Vec { let file = self.db.source_file(file_id); ra_ide_api_light::folding_ranges(&file) } + /// Fuzzy searches for a symbol. pub fn symbol_search(&self, query: Query) -> Cancelable> { let res = symbol_index::world_symbols(&*self.db, query)? @@ -399,62 +426,76 @@ impl Analysis { .collect(); Ok(res) } + pub fn goto_definition( &self, position: FilePosition, ) -> Cancelable>> { goto_definition::goto_definition(&*self.db, position) } + /// Finds all usages of the reference at point. pub fn find_all_refs(&self, position: FilePosition) -> Cancelable> { self.db.find_all_refs(position) } + /// Returns a short text descrbing element at position. pub fn hover(&self, position: FilePosition) -> Cancelable>> { hover::hover(&*self.db, position) } + /// Computes parameter information for the given call expression. pub fn call_info(&self, position: FilePosition) -> Cancelable> { call_info::call_info(&*self.db, position) } + /// Returns a `mod name;` declaration which created the current module. pub fn parent_module(&self, position: FilePosition) -> Cancelable> { self.db.parent_module(position) } + /// Returns crates this file belongs too. pub fn crate_for(&self, file_id: FileId) -> Cancelable> { self.db.crate_for(file_id) } + /// Returns the root file of the given crate. pub fn crate_root(&self, crate_id: CrateId) -> Cancelable { Ok(self.db.crate_graph().crate_root(crate_id)) } + /// Returns the set of possible targets to run for the current file. pub fn runnables(&self, file_id: FileId) -> Cancelable> { runnables::runnables(&*self.db, file_id) } + /// Computes syntax highlighting for the given file. pub fn highlight(&self, file_id: FileId) -> Cancelable> { syntax_highlighting::highlight(&*self.db, file_id) } + /// Computes completions at the given position. pub fn completions(&self, position: FilePosition) -> Cancelable>> { let completions = completion::completions(&self.db, position)?; Ok(completions.map(|it| it.into())) } + /// Computes assists (aks code actons aka intentions) for the given /// position. pub fn assists(&self, frange: FileRange) -> Cancelable> { Ok(self.db.assists(frange)) } + /// Computes the set of diagnostics for the given file. pub fn diagnostics(&self, file_id: FileId) -> Cancelable> { self.db.diagnostics(file_id) } + /// Computes the type of the expression at the given position. pub fn type_of(&self, frange: FileRange) -> Cancelable> { hover::type_of(&*self.db, frange) } + /// Returns the edit required to rename reference at the position to the new /// name. pub fn rename( diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 96923fac7..7fc0b8f50 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -326,7 +326,7 @@ fn on_notification( if pending_requests.remove(&id) { let response = RawResponse::err( id, - ErrorCode::RequestCancelled as i32, + ErrorCode::RequestCanceled as i32, "canceled by client".to_string(), ); msg_sender.send(RawMessage::Response(response)).unwrap() -- cgit v1.2.3