Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #14834 - Veykril:ty-diag-unit, r=Veykril
internal: Less file parsing for symbol index generation
bors 2023-05-18
parent c06f088 · parent d6dcfa5 · commit c7b0349
-rw-r--r--crates/hir-def/src/attr.rs2
-rw-r--r--crates/hir-expand/src/ast_id_map.rs8
-rw-r--r--crates/hir-expand/src/lib.rs1
-rw-r--r--crates/hir/src/symbols.rs8
-rw-r--r--crates/rust-analyzer/src/lsp_utils.rs35
5 files changed, 19 insertions, 35 deletions
diff --git a/crates/hir-def/src/attr.rs b/crates/hir-def/src/attr.rs
index f93d8d5c78..de515b569d 100644
--- a/crates/hir-def/src/attr.rs
+++ b/crates/hir-def/src/attr.rs
@@ -764,7 +764,7 @@ impl<'attr> AttrQuery<'attr> {
.nth(2);
match name {
- Some(tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal{ref text, ..}))) => Some(text),
+ Some(tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal{ ref text, ..}))) => Some(text),
_ => None
}
})
diff --git a/crates/hir-expand/src/ast_id_map.rs b/crates/hir-expand/src/ast_id_map.rs
index e48caca790..400442de94 100644
--- a/crates/hir-expand/src/ast_id_map.rs
+++ b/crates/hir-expand/src/ast_id_map.rs
@@ -124,6 +124,10 @@ impl AstIdMap {
FileAstId { raw, _ty: PhantomData }
}
+ pub fn get<N: AstNode>(&self, id: FileAstId<N>) -> AstPtr<N> {
+ AstPtr::try_from_raw(self.arena[id.raw].clone()).unwrap()
+ }
+
fn erased_ast_id(&self, item: &SyntaxNode) -> ErasedFileAstId {
let ptr = SyntaxNodePtr::new(item);
let hash = hash_ptr(&ptr);
@@ -137,10 +141,6 @@ impl AstIdMap {
}
}
- pub fn get<N: AstNode>(&self, id: FileAstId<N>) -> AstPtr<N> {
- AstPtr::try_from_raw(self.arena[id.raw].clone()).unwrap()
- }
-
fn alloc(&mut self, item: &SyntaxNode) -> ErasedFileAstId {
self.arena.alloc(SyntaxNodePtr::new(item))
}
diff --git a/crates/hir-expand/src/lib.rs b/crates/hir-expand/src/lib.rs
index c24887e15f..c8373778d3 100644
--- a/crates/hir-expand/src/lib.rs
+++ b/crates/hir-expand/src/lib.rs
@@ -978,6 +978,7 @@ fn ascend_node_border_tokens(
let first_token = |node: &SyntaxNode| skip_trivia_token(node.first_token()?, Direction::Next);
let last_token = |node: &SyntaxNode| skip_trivia_token(node.last_token()?, Direction::Prev);
+ // FIXME: Once the token map rewrite is done, this shouldnt need to rely on syntax nodes and tokens anymore
let first = first_token(node)?;
let last = last_token(node)?;
let first = ascend_call_token(db, &expansion, InFile::new(file_id, first))?;
diff --git a/crates/hir/src/symbols.rs b/crates/hir/src/symbols.rs
index 5d68aa52e6..4eaf99e3e7 100644
--- a/crates/hir/src/symbols.rs
+++ b/crates/hir/src/symbols.rs
@@ -39,11 +39,19 @@ impl DeclarationLocation {
}
pub fn original_range(&self, db: &dyn HirDatabase) -> FileRange {
+ if let Some(file_id) = self.hir_file_id.file_id() {
+ // fast path to prevent parsing
+ return FileRange { file_id, range: self.ptr.text_range() };
+ }
let node = resolve_node(db, self.hir_file_id, &self.ptr);
node.as_ref().original_file_range(db.upcast())
}
pub fn original_name_range(&self, db: &dyn HirDatabase) -> Option<FileRange> {
+ if let Some(file_id) = self.hir_file_id.file_id() {
+ // fast path to prevent parsing
+ return Some(FileRange { file_id, range: self.ptr.text_range() });
+ }
let node = resolve_node(db, self.hir_file_id, &self.name_ptr);
node.as_ref().original_file_range_opt(db.upcast())
}
diff --git a/crates/rust-analyzer/src/lsp_utils.rs b/crates/rust-analyzer/src/lsp_utils.rs
index 9a73da1539..74e79e8e60 100644
--- a/crates/rust-analyzer/src/lsp_utils.rs
+++ b/crates/rust-analyzer/src/lsp_utils.rs
@@ -81,39 +81,14 @@ impl GlobalState {
match additional_info {
Some(additional_info) => {
tracing::error!("{}:\n{}", &message, &additional_info);
- match self.config.open_server_logs() && tracing::enabled!(tracing::Level::ERROR) {
- true => self.send_request::<lsp_types::request::ShowMessageRequest>(
- lsp_types::ShowMessageRequestParams {
- typ: lsp_types::MessageType::ERROR,
- message,
- actions: Some(vec![lsp_types::MessageActionItem {
- title: "Open server logs".to_owned(),
- properties: Default::default(),
- }]),
- },
- |this, resp| {
- let lsp_server::Response { error: None, result: Some(result), .. } = resp
- else { return };
- if let Ok(Some(_item)) = crate::from_json::<
- <lsp_types::request::ShowMessageRequest as lsp_types::request::Request>::Result,
- >(
- lsp_types::request::ShowMessageRequest::METHOD, &result
- ) {
- this.send_notification::<lsp_ext::OpenServerLogs>(());
- }
- },
- ),
- false => self.send_notification::<lsp_types::notification::ShowMessage>(
- lsp_types::ShowMessageParams {
- typ: lsp_types::MessageType::ERROR,
- message,
- },
- ),
- }
+ self.show_message(
+ lsp_types::MessageType::ERROR,
+ message,
+ tracing::enabled!(tracing::Level::ERROR),
+ );
}
None => {
tracing::error!("{}", &message);
-
self.send_notification::<lsp_types::notification::ShowMessage>(
lsp_types::ShowMessageParams { typ: lsp_types::MessageType::ERROR, message },
);