test(completion): PathKind fixtures and bibliography .yml coverage - #2388
test(completion): PathKind fixtures and bibliography .yml coverage#2388hongjr03 wants to merge 42 commits into
Conversation
Summary of ChangesHello @hongjr03, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the path completion and type inference capabilities within the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request significantly enhances completion capabilities, particularly for paths within string concatenations and various binding forms. It also extends bibliography completion to include .yml files and improves type inference for destructuring, for-loops, and dynamic dictionary keys. The changes are substantial and well-supported by a comprehensive set of new test fixtures and snapshots. My review includes a couple of suggestions to improve code clarity and style.
| let mut new_prefix = EcoString::new(); | ||
| new_prefix.push_str(lhs.as_str()); | ||
| new_prefix.push_str(prefix.as_str()); | ||
| prefix = new_prefix; |
There was a problem hiding this comment.
The logic for prepending to the prefix string can be simplified. Using the + operator for EcoString concatenation is more idiomatic and concise.
| let mut new_prefix = EcoString::new(); | |
| new_prefix.push_str(lhs.as_str()); | |
| new_prefix.push_str(prefix.as_str()); | |
| prefix = new_prefix; | |
| prefix = lhs + prefix; |
| let mut trailing_pos_after_spread = false; | ||
|
|
||
| for item in destructuring.items() { | ||
| match item { | ||
| ast::DestructuringItem::Pattern(pat) => { | ||
| if saw_spread { | ||
| trailing_pos_after_spread = true; | ||
| } else { | ||
| has_pos = true; | ||
| pos.push(pattern_binding_ty(this, pat)); | ||
| } | ||
| } | ||
| ast::DestructuringItem::Named(named_item) => { | ||
| has_named = true; | ||
| let key = Interned::new_str(named_item.name().get().as_str()); | ||
| let ty = pattern_binding_ty(this, named_item.pattern()); | ||
| named.push((key, ty)); | ||
| } | ||
| ast::DestructuringItem::Spread(..) => { | ||
| saw_spread = true; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Spreads make trailing positional mapping ambiguous. Still keep a | ||
| // prefix mapping like `(a, ..rest)` and always keep named fields. | ||
| if trailing_pos_after_spread { | ||
| has_pos = false; | ||
| pos.clear(); | ||
| } |
There was a problem hiding this comment.
The variable trailing_pos_after_spread and its associated logic appear to be unnecessary. In Typst, a spread (..) must be the last positional item in a destructuring pattern, so a positional pattern cannot appear after a spread. This means trailing_pos_after_spread will never be true, making the related code paths dead. The logic can be simplified by removing this check.
for item in destructuring.items() {
match item {
ast::DestructuringItem::Pattern(pat) => {
// According to Typst documentation, a spread must be the last
// positional item, so `saw_spread` is always false here.
has_pos = true;
pos.push(pattern_binding_ty(this, pat));
}
ast::DestructuringItem::Named(named_item) => {
has_named = true;
let key = Interned::new_str(named_item.name().get().as_str());
let ty = pattern_binding_ty(this, named_item.pattern());
named.push((key, ty));
}
ast::DestructuringItem::Spread(..) => {
saw_spread = true;
}
}
}
// Positional items after a spread are invalid syntax, so we don't need
// to handle ambiguous mappings.3510bc9 to
c7db407
Compare
c7db407 to
be4fbde
Compare
be4fbde to
9758fc3
Compare
- Tighten dict.at("key") rewrite to 1 positional arg\n- Use shared const-string-key extractor for NamedRt/Args\n- Refactor keyed dict analysis to reduce nesting
9758fc3 to
cf5f199
Compare
Adds PathKind completion fixtures/snapshots and extends bibliography completion to include .yml. Test-only changes.
Depends on #2387.