zls
zls copied to clipboard
Fix/improve `union(enum)` completions
Resolves #1707
It'd require some rework but should this be extended to anon struct inits?
Should completions include = for struct fields?
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 78.27%. Comparing base (
7d6a9e2) to head (06e87d2).
Additional details and impacted files
@@ Coverage Diff @@
## master #1719 +/- ##
==========================================
+ Coverage 78.24% 78.27% +0.03%
==========================================
Files 35 35
Lines 10512 10523 +11
==========================================
+ Hits 8225 8237 +12
+ Misses 2287 2286 -1
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
It'd require some rework but should this be extended to anon struct inits?
Could give an explanation on how completions would look like with anon struct inits?
Should completions include
=for struct fields?
I would say yes otherwise it may be a bit unclear on what to type next.
It'd require some rework but should this be extended to anon struct inits?
Could give an explanation on how completions would look like with anon struct inits?
I'm thinking it'd be identical, ieb.addExecutable(. would list the fields, just as it does with b.addExecutable(.{., but insert text would be { .field_name =.. how jarring would it be for .name to be { .field_name = ?
(If . and prev tok is = or ( offer to add the {)
~~Seems CodeCov didn't catch that last push, but it's there https://app.codecov.io/gh/zigtools/zls/pull/1719?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=checks&utm_campaign=pr+comments&utm_term=zigtools~~ nvm, it took it 2 edits
im messing around with this branch a bit and noticed if i tab thru the list of completions it pastes the text including the snippet placeholders
this doesnt happen with any other types of snippets afaict, is this a bug? editor issue? ideally it would just fill the name of the variant when im tabbing then do the snippet on enter
also why is this only done for tagged unions? regular unions are initialized the same way
im messing around with this branch a bit and noticed if i tab thru the list of completions it pastes the text including the snippet placeholders
this doesnt happen with any other types of snippets afaict, is this a bug? editor issue? ideally it would just fill the name of the variant when im tabbing then do the snippet on enter
VSCode just selects whichever is highlighted :shrug:
Hmm, hmm, hmm ... still undecided if the label should be name or { .name =
name imo, and then .{ . should also complete
...
.{ .should also complete
it does, as long as it is after the const exe = b.addExecutable(...
The amount of times I've spent back and forth debugging those situations $#^#^@^@#
The regression you made me aware is analyser.resolveOptionalChildType not working as before, eg exe.libc_file = . assigning to optional should unwrap the type.
@nullptrdevs I could take care of rebasing this PR if you'd like.
@nullptrdevs I could take care of rebasing this PR if you'd like.
Yes, please do take over.
PS Dropping insertText would require some work to support incomplete fields completions.
I've removed the second copy of every test that tested with and without snippets and instead used the new testCompletionTextEdit function to test completion is performing the expected text edit.
FYI insertText gets converted into textEdit before sending the response.
FYI
insertTextgets converted intotextEditbefore sending the response.
It was worth finding out, :+1:
Does your approval stand on this one, merge?
I have found an issue. In the following example I am doing a comparison which should only complete to alpha but completes to { .alpha = <cursor>}.
const Birdie = enum { canary };
const U = union(enum) { alpha: []const u8 };
const u: U = undefined;
const boolean = u == .<cursor>
Can be tested with:
try testCompletionTextEdit(.{
.source =
\\const U = union(enum) { alpha: []const u8 };
\\const u: U = undefined;
\\const boolean = u == .<cursor>
,
.label = "alpha",
.expected_insert_line = "const foo: U = .alphh",
.expected_replace_line = "const foo: U = .alphh",
});
this doesnt happen with any other types of snippets afaict, is this a bug? editor issue? ideally it would just fill the name of the variant when im tabbing then do the snippet on enter