Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c7b0349

Browse files
committed
Auto merge of rust-lang#14834 - Veykril:ty-diag-unit, r=Veykril
internal: Less file parsing for symbol index generation
2 parents c06f088 + d6dcfa5 commit c7b0349

File tree

5 files changed

+19
-35
lines changed

5 files changed

+19
-35
lines changed

crates/hir-def/src/attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ impl<'attr> AttrQuery<'attr> {
764764
.nth(2);
765765

766766
match name {
767-
Some(tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal{ref text, ..}))) => Some(text),
767+
Some(tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal{ ref text, ..}))) => Some(text),
768768
_ => None
769769
}
770770
})

crates/hir-expand/src/ast_id_map.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ impl AstIdMap {
124124
FileAstId { raw, _ty: PhantomData }
125125
}
126126

127+
pub fn get<N: AstNode>(&self, id: FileAstId<N>) -> AstPtr<N> {
128+
AstPtr::try_from_raw(self.arena[id.raw].clone()).unwrap()
129+
}
130+
127131
fn erased_ast_id(&self, item: &SyntaxNode) -> ErasedFileAstId {
128132
let ptr = SyntaxNodePtr::new(item);
129133
let hash = hash_ptr(&ptr);
@@ -137,10 +141,6 @@ impl AstIdMap {
137141
}
138142
}
139143

140-
pub fn get<N: AstNode>(&self, id: FileAstId<N>) -> AstPtr<N> {
141-
AstPtr::try_from_raw(self.arena[id.raw].clone()).unwrap()
142-
}
143-
144144
fn alloc(&mut self, item: &SyntaxNode) -> ErasedFileAstId {
145145
self.arena.alloc(SyntaxNodePtr::new(item))
146146
}

crates/hir-expand/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,7 @@ fn ascend_node_border_tokens(
978978
let first_token = |node: &SyntaxNode| skip_trivia_token(node.first_token()?, Direction::Next);
979979
let last_token = |node: &SyntaxNode| skip_trivia_token(node.last_token()?, Direction::Prev);
980980

981+
// FIXME: Once the token map rewrite is done, this shouldnt need to rely on syntax nodes and tokens anymore
981982
let first = first_token(node)?;
982983
let last = last_token(node)?;
983984
let first = ascend_call_token(db, &expansion, InFile::new(file_id, first))?;

crates/hir/src/symbols.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,19 @@ impl DeclarationLocation {
3939
}
4040

4141
pub fn original_range(&self, db: &dyn HirDatabase) -> FileRange {
42+
if let Some(file_id) = self.hir_file_id.file_id() {
43+
// fast path to prevent parsing
44+
return FileRange { file_id, range: self.ptr.text_range() };
45+
}
4246
let node = resolve_node(db, self.hir_file_id, &self.ptr);
4347
node.as_ref().original_file_range(db.upcast())
4448
}
4549

4650
pub fn original_name_range(&self, db: &dyn HirDatabase) -> Option<FileRange> {
51+
if let Some(file_id) = self.hir_file_id.file_id() {
52+
// fast path to prevent parsing
53+
return Some(FileRange { file_id, range: self.ptr.text_range() });
54+
}
4755
let node = resolve_node(db, self.hir_file_id, &self.name_ptr);
4856
node.as_ref().original_file_range_opt(db.upcast())
4957
}

crates/rust-analyzer/src/lsp_utils.rs

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -81,39 +81,14 @@ impl GlobalState {
8181
match additional_info {
8282
Some(additional_info) => {
8383
tracing::error!("{}:\n{}", &message, &additional_info);
84-
match self.config.open_server_logs() && tracing::enabled!(tracing::Level::ERROR) {
85-
true => self.send_request::<lsp_types::request::ShowMessageRequest>(
86-
lsp_types::ShowMessageRequestParams {
87-
typ: lsp_types::MessageType::ERROR,
88-
message,
89-
actions: Some(vec![lsp_types::MessageActionItem {
90-
title: "Open server logs".to_owned(),
91-
properties: Default::default(),
92-
}]),
93-
},
94-
|this, resp| {
95-
let lsp_server::Response { error: None, result: Some(result), .. } = resp
96-
else { return };
97-
if let Ok(Some(_item)) = crate::from_json::<
98-
<lsp_types::request::ShowMessageRequest as lsp_types::request::Request>::Result,
99-
>(
100-
lsp_types::request::ShowMessageRequest::METHOD, &result
101-
) {
102-
this.send_notification::<lsp_ext::OpenServerLogs>(());
103-
}
104-
},
105-
),
106-
false => self.send_notification::<lsp_types::notification::ShowMessage>(
107-
lsp_types::ShowMessageParams {
108-
typ: lsp_types::MessageType::ERROR,
109-
message,
110-
},
111-
),
112-
}
84+
self.show_message(
85+
lsp_types::MessageType::ERROR,
86+
message,
87+
tracing::enabled!(tracing::Level::ERROR),
88+
);
11389
}
11490
None => {
11591
tracing::error!("{}", &message);
116-
11792
self.send_notification::<lsp_types::notification::ShowMessage>(
11893
lsp_types::ShowMessageParams { typ: lsp_types::MessageType::ERROR, message },
11994
);

0 commit comments

Comments
 (0)