zls icon indicating copy to clipboard operation
zls copied to clipboard

completions: add result type based completions for builtin arguments

Open mlugg opened this issue 1 year ago • 3 comments

When writing arguments to builtins like @Type, even when using inferred initialization syntax (i.e. @Type(.{ .), completions are now provided. This case is detected in exactly the same way as the corresponding case for a normal function argument.

This logic has been implemented for the following builtins, since they use a non-trivial type from std.builtin:

  • @Type
  • @typeInfo
  • @src
  • @setFloatMode
  • @prefetch
  • @reduce
  • @export
  • @extern
  • @fence
  • @cmpxchg*
  • @atomic*

mlugg avatar Jan 17 '24 03:01 mlugg

Codecov Report

Attention: Patch coverage is 89.65517% with 15 lines in your changes are missing coverage. Please review.

Project coverage is 78.73%. Comparing base (172c8f2) to head (4ebeccf).

Files Patch % Lines
src/features/completions.zig 90.99% 10 Missing :warning:
src/analysis.zig 85.29% 5 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1720      +/-   ##
==========================================
+ Coverage   78.49%   78.73%   +0.24%     
==========================================
  Files          34       34              
  Lines       10648    10731      +83     
==========================================
+ Hits         8358     8449      +91     
+ Misses       2290     2282       -8     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jan 17 '24 03:01 codecov[bot]

Oh yeah, sorry, forgot about this PR - I realised that nested completions don't currently work here, i.e. @Type(.{ . will complete but @Type(.{ .Struct = .{ won't. That should probably be resolved before merge.

mlugg avatar Feb 07 '24 00:02 mlugg

EDIT: Did a offsets.tokenToLoc(handle.tree, el_dot_context.identifier_token_index).end,

Oh yeah, sorry, forgot about this PR - I realised that nested completions don't currently work here, i.e. @Type(.{ . will complete but @Type(.{ .Struct = .{ won't. That should probably be resolved before merge.

Sure,

diff --git a/src/features/completions.zig b/src/features/completions.zig
index 572e282..6983563 100644
--- a/src/features/completions.zig
+++ b/src/features/completions.zig
@@ -1193,6 +1193,11 @@ fn collectContainerNodes(
         .field_access => |loc| try collectFieldAccessContainerNodes(analyser, arena, handle, loc, dot_context, &types_with_handles),
         .enum_literal => |loc| try collectEnumLiteralContainerNodes(analyser, arena, handle, loc, &types_with_handles),
         .builtin => |loc| try collectBuiltinContainerNodes(analyser, arena, handle, loc, dot_context, &types_with_handles),
+        .empty => blk: {
+            const name = handle.tree.tokenSlice(dot_context.identifier_token_index);
+            if (name.len < 1 and name[0] != '@' or name[1] == '"') break :blk;
+            try collectBuiltinContainerNodes(analyser, arena, handle, offsets.tokenToLoc(handle.tree, dot_context.identifier_token_index), dot_context, &types_with_handles);
+        },
         else => {},
     }
     return types_with_handles.toOwnedSlice(arena);

but my work is known to be at a low acceptance % :D

llogick avatar Feb 07 '24 02:02 llogick