Skip to content

Commit

Permalink
Always use the whole Attr location for Name
Browse files Browse the repository at this point in the history
  • Loading branch information
oxalica committed Sep 5, 2022
1 parent dd476b3 commit 0cdcbe9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
16 changes: 7 additions & 9 deletions crates/ide/src/def/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl LowerCtx<'_> {
}

enum AttrKind {
Static(SmolStr, AstPtr),
Static(SmolStr),
Dynamic(Option<ast::Expr>),
}

Expand All @@ -295,7 +295,7 @@ impl AttrKind {
let name = n
.token()
.map_or_else(Default::default, |tok| tok.text().into());
return Self::Static(name, AstPtr::new(n.syntax()));
return Self::Static(name);
}
// Unwrap parenthesis around string literals.
// `{ ${(("foo"))} = 1; }` => `{ "foo" = 1; }`
Expand Down Expand Up @@ -335,8 +335,7 @@ impl AttrKind {
}
}
});
let ptr = AstPtr::new(string_node.syntax());
Self::Static(content.into(), ptr)
Self::Static(content.into())
}
}

Expand Down Expand Up @@ -410,8 +409,8 @@ impl MergingSet {
no_attrs = false;

let ptr = AstPtr::new(attr.syntax());
let (text, ptr) = match AttrKind::classify(attr) {
AttrKind::Static(name, ptr) => (name, ptr),
let text = match AttrKind::classify(attr) {
AttrKind::Static(name) => name,
// `inherit ${expr}` or `inherit (expr) ${expr}` is invalid.
AttrKind::Dynamic(expr) => {
ctx.diagnostic(Diagnostic::new(
Expand Down Expand Up @@ -471,10 +470,9 @@ impl MergingSet {
};

loop {
let mut attr_ptr = AstPtr::new(next_attr.syntax());
let attr_ptr = AstPtr::new(next_attr.syntax());
let entry = match AttrKind::classify(next_attr) {
AttrKind::Static(text, ptr) => {
attr_ptr = ptr;
AttrKind::Static(text) => {
match self.statics.entry(text.clone()) {
Entry::Occupied(entry) => {
// Append this location to the existing name.
Expand Down
5 changes: 4 additions & 1 deletion crates/ide/src/ide/references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ mod tests {
fn special_attr() {
check(r#"let $0" " = 1; in { inherit $1" "; }"#);
check(r#"let "$0 " = 1; in { inherit $1" "; }"#);
check(r#"let " " = 1; in rec { inherit $0" "; x = { inherit ${$1" "}; }; }"#);

// The location of static `${}` attrs are the whole `${}`. Not the inner string.
// This behavior is relied by `ide::rename`.
check(r#"let " " = 1; in rec { inherit $0" "; x = { inherit $1${" "}; }; }"#);
}

#[test]
Expand Down

0 comments on commit 0cdcbe9

Please sign in to comment.