Giter Site home page Giter Site logo

Comments (4)

llogick avatar llogick commented on September 22, 2024
Hmm
diff --git a/src/analysis.zig b/src/analysis.zig
index c49780b2..1f7b5c41 100644
--- a/src/analysis.zig
+++ b/src/analysis.zig
@@ -887,7 +887,7 @@ pub fn resolveFuncProtoOfCallable(analyser: *Analyser, ty: Type) error{OutOfMemo
 /// resolve a pointer dereference
 /// `pointer.*`
 pub fn resolveDerefType(analyser: *Analyser, pointer: Type) error{OutOfMemory}!?Type {
-    if (pointer.is_type_val) return null;
+    // if (pointer.is_type_val) return null;
 
     switch (pointer.data) {
         .pointer => |info| switch (info.size) {
@@ -904,6 +904,9 @@ pub fn resolveDerefType(analyser: *Analyser, pointer: Type) error{OutOfMemory}!?
                 else => return null,
             }
         },
+        // XXX: Look into just returning the type as is? the following expr is very common
+        // `const type_expr = try analyser.resolveDerefType(result) orelse result;`
+        // although there's a couple of places where it really matters
         else => return null,
     }
 }
@@ -2402,9 +2405,9 @@ pub const Type = struct {
     }
 
     pub fn instanceTypeVal(self: Type, analyser: *Analyser) error{OutOfMemory}!?Type {
-        if (!self.is_type_val) return null;
         return switch (self.data) {
             .ip_index => |payload| {
+                if (!self.is_type_val) return null;
                 if (payload.index == .unknown_type) return null;
                 return Type{
                     .data = .{
@@ -2602,7 +2605,7 @@ pub const Type = struct {
     }
 
     pub fn fmtTypeVal(ty: Type, analyser: *Analyser, options: FormatOptions) std.fmt.Formatter(format) {
-        std.debug.assert(ty.is_type_val);
+        // std.debug.assert(ty.is_type_val);
         return .{ .data = .{ .ty = ty, .analyser = analyser, .options = options } };
     }
 
@@ -3284,7 +3287,9 @@ pub fn getPositionContext(
                 .period, .period_asterisk => switch (curr_ctx.ctx) {
                     .empty, .pre_label => curr_ctx.ctx = .{ .enum_literal = tok.loc },
                     .enum_literal => curr_ctx.ctx = .empty,
-                    .field_access => {},
+                    .field_access => curr_ctx.ctx = .{
+                        .field_access = tokenLocAppend(curr_ctx.ctx.loc().?, tok),
+                    },
                     .other => {},
                     .global_error_set => {},
                     .label => |filled| if (filled) {
@@ -3301,7 +3306,9 @@ pub fn getPositionContext(
                     curr_ctx.ctx = .empty;
                 },
                 .question_mark => switch (curr_ctx.ctx) {
-                    .field_access => {},
+                    .field_access => curr_ctx.ctx = .{
+                        .field_access = tokenLocAppend(curr_ctx.ctx.loc().?, tok),
+                    },
                     else => curr_ctx.ctx = .empty,
                 },
                 .l_paren => try stack.append(allocator, .{ .ctx = .empty, .stack_id = .Paren }),
@@ -3737,13 +3744,29 @@ pub const DeclWithHandle = struct {
                 })) orelse return null,
                 .error_set,
             ),
-            .for_loop_payload => |pay| try analyser.resolveBracketAccessType(
-                (try analyser.resolveTypeOfNodeInternal(.{
-                    .node = pay.condition,
-                    .handle = self.handle,
-                })) orelse return null,
-                .Single,
-            ),
+            .for_loop_payload => |pay| flp: {
+                const node = try analyser.resolveBracketAccessType(
+                    (try analyser.resolveTypeOfNodeInternal(.{
+                        .node = pay.condition,
+                        .handle = self.handle,
+                    })) orelse return null,
+                    .Single,
+                ) orelse return null;
+                break :flp if (self.handle.tree.tokens.items(.tag)[pay.identifier - 1] == .asterisk) ptr: {
+                    const ty = try analyser.arena.allocator().create(Type);
+                    ty.* = node;
+                    break :ptr .{
+                        .data = .{
+                            .pointer = .{
+                                .size = .One,
+                                .elem_ty = ty,
+                                .is_const = true,
+                            },
+                        },
+                        .is_type_val = false,
+                    };
+                } else node;
+            },
             .assign_destructure => |pay| {
                 const type_node = pay.getFullVarDecl(tree).ast.type_node;
                 if (type_node != 0) {
diff --git a/src/features/completions.zig b/src/features/completions.zig
index abd802c0..4a5e3424 100644
--- a/src/features/completions.zig
+++ b/src/features/completions.zig
@@ -49,11 +49,14 @@ fn typeToCompletion(
                     ),
                 });
 
-                if (info.size == .C) return;
+                // XXX: `for (array.items[0..]) |*item| { item.*.?.printHello(); }` requires the `.*`
+                // Reevaluate conditions or delete:
 
-                if (try builder.analyser.resolveDerefType(ty)) |child_ty| {
-                    try typeToCompletion(builder, child_ty, null);
-                }
+                // if (info.size == .C) return;
+
+                // if (try builder.analyser.resolveDerefType(ty)) |child_ty| {
+                //     try typeToCompletion(builder, child_ty, null);
+                // }
             },
             .Slice => {
                 if (ty.is_type_val) return;
diff --git a/src/features/inlay_hints.zig b/src/features/inlay_hints.zig
index 4e267977..751309fa 100644
--- a/src/features/inlay_hints.zig
+++ b/src/features/inlay_hints.zig
@@ -389,11 +389,10 @@ fn writeForCaptureHint(builder: *Builder, for_node: Ast.Node.Index) !void {
         const capture_by_ref = token_tags[capture_token] == .asterisk;
         const name_token = capture_token + @intFromBool(capture_by_ref);
         if (try typeStrOfToken(builder, name_token)) |type_str| {
-            const prepend = if (capture_by_ref) "*" else "";
             try appendTypeHintString(
                 builder,
                 name_token,
-                try std.fmt.allocPrint(builder.arena, "{s}{s}", .{ prepend, type_str }),
+                try std.fmt.allocPrint(builder.arena, "{s}", .{type_str}),
             );
         }
         capture_token = name_token + 2;
diff --git a/tests/lsp_features/completion.zig b/tests/lsp_features/completion.zig
index 6de690af..4916236e 100644
--- a/tests/lsp_features/completion.zig
+++ b/tests/lsp_features/completion.zig
@@ -320,7 +320,7 @@ test "std.ArrayHashMap" {
         \\const foo = gop.value_ptr.<cursor>
     , &.{
         .{ .label = "*", .kind = .Operator, .detail = "S" },
-        .{ .label = "alpha", .kind = .Field, .detail = "u32" },
+        // .{ .label = "alpha", .kind = .Field, .detail = "u32" },
     });
 }
 
@@ -352,7 +352,7 @@ test "std.HashMap" {
         \\const foo = gop.value_ptr.<cursor>
     , &.{
         .{ .label = "*", .kind = .Operator, .detail = "S" },
-        .{ .label = "alpha", .kind = .Field, .detail = "u32" },
+        // .{ .label = "alpha", .kind = .Field, .detail = "u32" },
     });
 }
 
@@ -456,7 +456,7 @@ test "pointer deref" {
         \\const bar = foo.<cursor>
     , &.{
         .{ .label = "*", .kind = .Operator, .detail = "S" },
-        .{ .label = "alpha", .kind = .Field, .detail = "u32" },
+        // .{ .label = "alpha", .kind = .Field, .detail = "u32" },
     });
     try testCompletion(
         \\const S = struct { alpha: u32 };
@@ -597,7 +597,7 @@ test "address of" {
         \\const foo = value_ptr.<cursor>;
     , &.{
         .{ .label = "*", .kind = .Operator, .detail = "S" },
-        .{ .label = "alpha", .kind = .Field, .detail = "u32" },
+        // .{ .label = "alpha", .kind = .Field, .detail = "u32" },
     });
 }
 
@@ -659,7 +659,7 @@ test "single pointer to array" {
         \\const bar = foo.<cursor>
     , &.{
         .{ .label = "*", .kind = .Operator, .detail = "[3]u32" },
-        .{ .label = "len", .kind = .Field, .detail = "usize = 3" },
+        // .{ .label = "len", .kind = .Field, .detail = "usize = 3" },
     });
     try testCompletion(
         \\const S = struct { alpha: u32 };

from zls.

 avatar commented on September 22, 2024

Hmm

Tested and now it works in my projects and this example above.

image

from zls.

wizzymore avatar wizzymore commented on September 22, 2024

Can confirm, i was following the ziglings exercises and had a little bit of trouble at exercise 58 because of this:
image
Instead of *?NotebookEntry i get ?NotebookEntry and when trying to return the correct &entry.*.? i get no autocomplete. I get the autocomplete for entry.?.something which is wrong.

from zls.

Techatrix avatar Techatrix commented on September 22, 2024

fixed by #1893

from zls.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.