Comments (4)
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.
Hmm
Tested and now it works in my projects and this example above.
from zls.
Can confirm, i was following the ziglings exercises and had a little bit of trouble at exercise 58 because of this:
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.
fixed by #1893
from zls.
Related Issues (20)
- referencing the same module by different import names has regressed
- no type completions for primitive types like u16, u32, f32 etc. HOT 4
- Provide a configuration option to use incremental compilation for build-on-save HOT 3
- use document highlighting to show matching control flow statements
- Build error zig master 8/20 release HOT 1
- Imports aren't identified if artifacts aren't created HOT 3
- Autocomplete should not insert parenthesis for function pointers
- ZLS fails to build on latest master release of Zig (version 0.14.0-dev.1342+1a178d499). HOT 2
- no completions after branches with no braces HOT 5
- Unused variables should be detected by the language server HOT 2
- no diagnostics for everything that depends on semantic analysis HOT 3
- use reference trace to provide better build-on-save source locations for errors
- `typeDefinition` goes to variables type annotation when provided instead of the types definition
- No inlay hints/hover/completions for `@"i d e n t"` syntax
- assertion failure in `identifierLocFromIndex` HOT 2
- Autocomplete and hover information for decl literals HOT 1
- Assertion failure in `identifierTokenToNameSlice` HOT 3
- Labelled Switch Support HOT 1
- Add a nix binary cache to for ZLS
- Bug in identifier detection HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zls.