mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +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
|
@ -3,6 +3,8 @@
|
|||
|
||||
mod generated;
|
||||
|
||||
use crate::Edition;
|
||||
|
||||
#[allow(unreachable_pub)]
|
||||
pub use self::generated::SyntaxKind;
|
||||
|
||||
|
@ -26,4 +28,11 @@ impl SyntaxKind {
|
|||
pub fn is_trivia(self) -> bool {
|
||||
matches!(self, SyntaxKind::WHITESPACE | SyntaxKind::COMMENT)
|
||||
}
|
||||
|
||||
/// Returns true if this is an identifier or a keyword.
|
||||
#[inline]
|
||||
pub fn is_any_identifier(self) -> bool {
|
||||
// Assuming no edition removed keywords...
|
||||
self == SyntaxKind::IDENT || self.is_keyword(Edition::LATEST)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue