mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Properly account for editions in names
This PR touches a lot of parts. But the main changes are changing `hir_expand::Name` to be raw edition-dependently and only when necessary (unrelated to how the user originally wrote the identifier), and changing `is_keyword()` and `is_raw_identifier()` to be edition-aware (this was done in #17896, but the FIXMEs were fixed here). It is possible that I missed some cases, but most IDE parts should properly escape (or not escape) identifiers now. The rules of thumb are: - If we show the identifier to the user, its rawness should be determined by the edition of the edited crate. This is nice for IDE features, but really important for changes we insert to the source code. - For tests, I chose `Edition::CURRENT` (so we only have to (maybe) update tests when an edition becomes stable, to avoid churn). - For debugging tools (helper methods and logs), I used `Edition::LATEST`.
This commit is contained in:
parent
91aa3f46b3
commit
9d3368f2c2
179 changed files with 2485 additions and 1250 deletions
|
@ -10,6 +10,7 @@ use ide_db::{
|
|||
helpers::get_definition,
|
||||
FileId, FileRange, FxHashMap, FxHashSet, RootDatabase,
|
||||
};
|
||||
use span::Edition;
|
||||
use syntax::{AstNode, SyntaxKind::*, SyntaxNode, TextRange, T};
|
||||
|
||||
use crate::inlay_hints::InlayFieldsToResolve;
|
||||
|
@ -116,7 +117,11 @@ fn documentation_for_definition(
|
|||
_ => None,
|
||||
};
|
||||
|
||||
def.docs(sema.db, famous_defs.as_ref())
|
||||
def.docs(
|
||||
sema.db,
|
||||
famous_defs.as_ref(),
|
||||
def.krate(sema.db).map(|it| it.edition(sema.db)).unwrap_or(Edition::CURRENT),
|
||||
)
|
||||
}
|
||||
|
||||
impl StaticIndex<'_> {
|
||||
|
@ -161,6 +166,8 @@ impl StaticIndex<'_> {
|
|||
// hovers
|
||||
let sema = hir::Semantics::new(self.db);
|
||||
let tokens_or_nodes = sema.parse_guess_edition(file_id).syntax().clone();
|
||||
let edition =
|
||||
sema.attach_first_edition(file_id).map(|it| it.edition()).unwrap_or(Edition::CURRENT);
|
||||
let tokens = tokens_or_nodes.descendants_with_tokens().filter_map(|it| match it {
|
||||
syntax::NodeOrToken::Node(_) => None,
|
||||
syntax::NodeOrToken::Token(it) => Some(it),
|
||||
|
@ -201,17 +208,20 @@ impl StaticIndex<'_> {
|
|||
&node,
|
||||
None,
|
||||
&hover_config,
|
||||
edition,
|
||||
)),
|
||||
definition: def.try_to_nav(self.db).map(UpmappingResult::call_site).map(|it| {
|
||||
FileRange { file_id: it.file_id, range: it.focus_or_full_range() }
|
||||
}),
|
||||
references: vec![],
|
||||
moniker: current_crate.and_then(|cc| def_to_moniker(self.db, def, cc)),
|
||||
display_name: def.name(self.db).map(|name| name.display(self.db).to_string()),
|
||||
display_name: def
|
||||
.name(self.db)
|
||||
.map(|name| name.display(self.db, edition).to_string()),
|
||||
enclosing_moniker: current_crate
|
||||
.zip(def.enclosing_definition(self.db))
|
||||
.and_then(|(cc, enclosing_def)| def_to_moniker(self.db, enclosing_def, cc)),
|
||||
signature: Some(def.label(self.db)),
|
||||
signature: Some(def.label(self.db, edition)),
|
||||
kind: def_to_kind(self.db, def),
|
||||
});
|
||||
self.def_map.insert(def, it);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue