about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-05-18 06:25:40 +0000
committerbors <bors@rust-lang.org>2023-05-18 06:25:40 +0000
commitc7b03491cdb40a3b900c7db3c4193d5cc704a7d7 (patch)
treec9961ed791ca0af4043422966b93d8cbb1645038
parentc06f08896835d0162a1b328726578dbf886d888f (diff)
parentd6dcfa5744034c178ea4174342618b915112e431 (diff)
downloadrust-c7b03491cdb40a3b900c7db3c4193d5cc704a7d7.tar.gz
rust-c7b03491cdb40a3b900c7db3c4193d5cc704a7d7.zip
Auto merge of #14834 - Veykril:ty-diag-unit, r=Veykril
internal: Less file parsing for symbol index generation
-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 f93d8d5c78e..de515b569df 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 e48caca790c..400442de94b 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 c24887e15ff..c8373778d32 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 5d68aa52e62..4eaf99e3e73 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 9a73da15398..74e79e8e605 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 },
                 );