feat: match named arg parent in literals (#1418)

This commit is contained in:
Myriad-Dreamin 2025-02-27 14:48:57 +08:00 committed by GitHub
parent ebfc93c104
commit 96cdab38f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 71 additions and 0 deletions

View file

@ -1240,6 +1240,20 @@ fn arg_context<'a>(
Some(ArgClass::Named(args_node.find(param_ident.span())?))
}
_ => {
let parent = node.parent();
if let Some(parent) = parent {
if parent.kind() == SyntaxKind::Named {
let param_ident = parent.cast::<ast::Named>()?;
let name = param_ident.name();
let init = param_ident.expr();
let init = parent.find(init.span())?;
if init.range().contains(&node.offset()) {
let name = args_node.find(name.span())?;
return Some(ArgClass::Named(name));
}
}
}
let mut spreads = EcoVec::new();
let mut positional = 0;
let is_spread = node.kind() == SyntaxKind::Spread;

View file

@ -0,0 +1,3 @@
/// contains: "New Computer Modern"
#set text(font: (name: "" /* range -2..0 */))

View file

@ -0,0 +1,54 @@
---
source: crates/tinymist-query/src/completion.rs
description: "Completion on \" (63..65)"
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/modify_string_3.typ
---
[
{
"isIncomplete": false,
"items": [
{
"kind": 6,
"label": "\"New Computer Modern\"",
"sortText": "003",
"textEdit": {
"newText": "New Computer Modern",
"range": {
"end": {
"character": 24,
"line": 2
},
"start": {
"character": 24,
"line": 2
}
}
}
}
]
},
{
"isIncomplete": false,
"items": [
{
"kind": 6,
"label": "\"New Computer Modern\"",
"sortText": "003",
"textEdit": {
"newText": "New Computer Modern\"",
"range": {
"end": {
"character": 25,
"line": 2
},
"start": {
"character": 25,
"line": 2
}
}
}
}
]
}
]