Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

completions: add result type based completions for builtin arguments #1720

Merged
merged 2 commits into from
Sep 20, 2024

Conversation

mlugg
Copy link
Contributor

@mlugg mlugg commented Jan 17, 2024

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*

Copy link

codecov bot commented Jan 17, 2024

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 ⚠️
src/analysis.zig 85.29% 5 Missing ⚠️
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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@Techatrix Techatrix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks great but some new code completion tests would be nice.

@llogick llogick force-pushed the feat/builtin-arg-result-type branch 2 times, most recently from df01f13 to 9a127f1 Compare February 6, 2024 03:00
@mlugg
Copy link
Contributor Author

mlugg commented Feb 7, 2024

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.

@llogick
Copy link
Contributor

llogick commented Feb 7, 2024

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 llogick force-pushed the feat/builtin-arg-result-type branch 2 times, most recently from f1de644 to c9867e8 Compare February 21, 2024 03:37
@llogick llogick force-pushed the feat/builtin-arg-result-type branch from c9867e8 to 7fcfdc5 Compare March 1, 2024 16:39
@Techatrix Techatrix added this to the 0.12.0 milestone Mar 2, 2024
@llogick llogick force-pushed the feat/builtin-arg-result-type branch from 7fcfdc5 to 6e98ced Compare March 4, 2024 20:41
@llogick llogick force-pushed the feat/builtin-arg-result-type branch from 6e98ced to 4ebeccf Compare April 14, 2024 16:38
@Techatrix Techatrix removed this from the 0.12.0 milestone Apr 20, 2024
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*`
Co-authored-by: nullptrdevs <16590917+nullptrdevs@users.noreply.github.com>
Co-authored-by: Techatrix <techatrix@mailbox.org>
@Techatrix
Copy link
Member

After 5 months of negligence by me, it is finally time to get this merged. Soon™

@Techatrix Techatrix merged commit f4d7e0b into zigtools:master Sep 20, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants