Skip to content

Conversation

SuperAuguste
Copy link
Member

@SuperAuguste SuperAuguste commented Mar 4, 2023

Finally, our mortal enemy has been defeated over the course of a stream. (shameless plug)

image

  • Resolve branching types in completions
  • Resolve in goto def (multi Location result)
  • Resolve in hover
  • Resolve in signatureHelp (it's so hard 😭)

@SuperAuguste SuperAuguste force-pushed the either-type-branching branch from bacd001 to 69072d3 Compare March 5, 2023 23:02
@SuperAuguste SuperAuguste marked this pull request as ready for review March 6, 2023 18:02
@SuperAuguste SuperAuguste added the pr:fuzz Attach to a PR to start fuzzing / continually fuzz (please do this before merging!) label Mar 6, 2023
@leecannon
Copy link
Member

const std = @import("std");

pub fn main() !void {
    const t = std.os.system.dup(1);
    _ = t;
}

Hover over dup:

error: (server): got error. error while handling textDocument/hover
/home/lee/src/zls/src/analysis.zig:1142:9: 0x45eca9 in getAllTypesWithHandlesArrayList (zls)
        return switch (ty.type.data) {
        ^
/home/lee/src/zls/src/analysis.zig:1137:9: 0x45edea in getAllTypesWithHandles (zls)
        try ty.getAllTypesWithHandlesArrayList(arena, &all_types);
        ^
/home/lee/src/zls/src/Server.zig:1190:40: 0x4f71d7 in getSymbolFieldAccesses (zls)
        const container_handle_nodes = try container_handle.getAllTypesWithHandles(server.arena.allocator());
                                       ^
/home/lee/src/zls/src/Server.zig:1244:20: 0x473b3a in hoverDefinitionFieldAccess (zls)
    const decls = (try server.getSymbolFieldAccesses(handle, source_index, loc)) orelse return null;
                   ^
/home/lee/src/zls/src/Server.zig:2469:32: 0x3eff9c in hoverHandler (zls)
        .field_access => |loc| try server.hoverDefinitionFieldAccess(handle, source_index, loc),
                               ^
debug: (server): Took 232ms to process method textDocument/hover
[Error - 18:07:20] Request textDocument/hover failed.
  Message: InternalError
  Code: 108

@SuperAuguste
Copy link
Member Author

Hmm I can't seem to reproduce this...

@leecannon
Copy link
Member

Looks like this might be a miscompilation, its fixed by removing return from getAllTypesWithHandlesArrayList:

pub fn getAllTypesWithHandlesArrayList(ty: TypeWithHandle, arena: std.mem.Allocator, all_types: *std.ArrayListUnmanaged(TypeWithHandle)) !void {
    switch (ty.type.data) {
        .pointer, .slice, .error_union, .other, .primitive => try all_types.append(arena, ty),
        .either => |e| for (e) |i| try i.type_with_handle.getAllTypesWithHandlesArrayList(arena, all_types),
        .array_index, .@"comptime" => {
            // TODO
        },
    }
}

@SuperAuguste
Copy link
Member Author

wtf... nice find Lee! Also getAllTypesWithHandlesArrayList should just have an else instead of that first condition :P I'll fix it now!

@leecannon
Copy link
Member

That works for me now, I absolutely love this feature!

Something not required but would be nice, is showing the source of each declaration as while messing with this I immediately hit one where the types are different (although mostly compatible):
image

@SuperAuguste SuperAuguste force-pushed the either-type-branching branch from 75c2d5a to 4439d32 Compare March 6, 2023 19:16
@Jarred-Sumner
Copy link
Contributor

very exciting

@SuperAuguste
Copy link
Member Author

That works for me now, I absolutely love this feature!

Something not required but would be nice, is showing the source of each declaration as while messing with this I immediately hit one where the types are different (although mostly compatible): image

Tried implementing this but it's a bit of a hackfest, I think merging this now and then adding this later makes sense. I might take a jab at rewriting some analysis code so it's a bit less of a rats nest and try again. :)

@SuperAuguste SuperAuguste requested a review from leecannon March 7, 2023 05:42
@SuperAuguste SuperAuguste merged commit 2ce59a3 into master Mar 7, 2023
@SuperAuguste SuperAuguste deleted the either-type-branching branch March 7, 2023 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:fuzz Attach to a PR to start fuzzing / continually fuzz (please do this before merging!)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants