fix: Fix proc-macro server not using the supplied span in Ident::new

This commit is contained in:
Lukas Wirth 2022-01-31 16:56:33 +01:00
parent 45ff51ba22
commit f6def3ccdf
5 changed files with 8 additions and 48 deletions

View File

@ -234,15 +234,6 @@ fn highlight_name_ref(
None if syntactic_name_ref_highlighting => {
return highlight_name_ref_by_syntax(name_ref, sema, krate)
}
// FIXME: Workaround for https://github.com/rust-analyzer/rust-analyzer/issues/10708
//
// Some popular proc macros (namely async_trait) will rewrite `self` in such a way that it no
// longer resolves via NameRefClass. If we can't be resolved, but we know we're a self token,
// within a function with a self param, pretend to still be `self`, rather than
// an unresolved reference.
None if name_ref.self_token().is_some() && is_in_fn_with_self_param(&name_ref) => {
return SymbolKind::SelfParam.into()
}
// FIXME: This is required for helper attributes used by proc-macros, as those do not map down
// to anything when used.
// We can fix this for derive attributes since derive helpers are recorded, but not for
@ -712,14 +703,3 @@ fn parents_match(mut node: NodeOrToken<SyntaxNode, SyntaxToken>, mut kinds: &[Sy
fn parent_matches<N: AstNode>(token: &SyntaxToken) -> bool {
token.parent().map_or(false, |it| N::can_cast(it.kind()))
}
fn is_in_fn_with_self_param(node: &ast::NameRef) -> bool {
node.syntax()
.ancestors()
.find_map(ast::Item::cast)
.and_then(|item| match item {
ast::Item::Fn(fn_) => fn_.param_list()?.self_param(),
_ => None,
})
.is_some()
}

View File

@ -463,13 +463,8 @@ impl server::Punct for Rustc {
}
impl server::Ident for Rustc {
fn new(&mut self, string: &str, _span: Self::Span, _is_raw: bool) -> Self::Ident {
IdentId(
self.ident_interner.intern(&IdentData(tt::Ident {
text: string.into(),
id: tt::TokenId::unspecified(),
})),
)
fn new(&mut self, string: &str, span: Self::Span, _is_raw: bool) -> Self::Ident {
IdentId(self.ident_interner.intern(&IdentData(tt::Ident { text: string.into(), id: span })))
}
fn span(&mut self, ident: Self::Ident) -> Self::Span {

View File

@ -463,13 +463,8 @@ impl server::Punct for Rustc {
}
impl server::Ident for Rustc {
fn new(&mut self, string: &str, _span: Self::Span, _is_raw: bool) -> Self::Ident {
IdentId(
self.ident_interner.intern(&IdentData(tt::Ident {
text: string.into(),
id: tt::TokenId::unspecified(),
})),
)
fn new(&mut self, string: &str, span: Self::Span, _is_raw: bool) -> Self::Ident {
IdentId(self.ident_interner.intern(&IdentData(tt::Ident { text: string.into(), id: span })))
}
fn span(&mut self, ident: Self::Ident) -> Self::Span {

View File

@ -464,13 +464,8 @@ impl server::Punct for Rustc {
}
impl server::Ident for Rustc {
fn new(&mut self, string: &str, _span: Self::Span, _is_raw: bool) -> Self::Ident {
IdentId(
self.ident_interner.intern(&IdentData(tt::Ident {
text: string.into(),
id: tt::TokenId::unspecified(),
})),
)
fn new(&mut self, string: &str, span: Self::Span, _is_raw: bool) -> Self::Ident {
IdentId(self.ident_interner.intern(&IdentData(tt::Ident { text: string.into(), id: span })))
}
fn span(&mut self, ident: Self::Ident) -> Self::Span {

View File

@ -468,13 +468,8 @@ impl server::Punct for Rustc {
}
impl server::Ident for Rustc {
fn new(&mut self, string: &str, _span: Self::Span, _is_raw: bool) -> Self::Ident {
IdentId(
self.ident_interner.intern(&IdentData(tt::Ident {
text: string.into(),
id: tt::TokenId::unspecified(),
})),
)
fn new(&mut self, string: &str, span: Self::Span, _is_raw: bool) -> Self::Ident {
IdentId(self.ident_interner.intern(&IdentData(tt::Ident { text: string.into(), id: span })))
}
fn span(&mut self, ident: Self::Ident) -> Self::Span {