Skip to content

Commit 0e0570f

Browse files
Merge branch 'master' into break
2 parents cfe3341 + 6a12251 commit 0e0570f

13 files changed

Lines changed: 189 additions & 241 deletions

File tree

build.zig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const builtin = @import("builtin");
66
const zls_version: std.SemanticVersion = .{ .major = 0, .minor = 15, .patch = 0, .pre = "dev" };
77

88
/// Specify the minimum Zig version that is required to compile and test ZLS:
9-
/// compiler: Allow configuring UBSan mode at the module level.
9+
/// std.Build: resolved generated paths are cwd-relative
1010
///
1111
/// If you do not use Nix, a ZLS maintainer can take care of this.
1212
/// Whenever this version is increased, run the following command:
@@ -15,7 +15,7 @@ const zls_version: std.SemanticVersion = .{ .major = 0, .minor = 15, .patch = 0,
1515
/// ```
1616
///
1717
/// Also update the `minimum_zig_version` in `build.zig.zon`.
18-
const minimum_build_zig_version = "0.15.0-dev.393+5668c8b7b";
18+
const minimum_build_zig_version = "0.15.0-dev.631+9a3540d61";
1919

2020
/// Specify the minimum Zig version that is required to run ZLS:
2121
/// Release 0.14.0
@@ -84,7 +84,6 @@ pub fn build(b: *Build) !void {
8484
test_options.step.name = "ZLS test options";
8585

8686
test_options.addOptionPath("zig_exe_path", .{ .cwd_relative = b.graph.zig_exe });
87-
// TODO these paths may be relative
8887
test_options.addOptionPath("zig_lib_path", .{ .cwd_relative = b.fmt("{}", .{b.graph.zig_lib_directory}) });
8988
test_options.addOptionPath("global_cache_path", .{ .cwd_relative = b.cache_root.join(b.allocator, &.{"zls"}) catch @panic("OOM") });
9089

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
.version = "0.15.0-dev",
55
// Must be kept in line with the `minimum_build_zig_version` in `build.zig`.
66
// Should be a Zig version that is downloadable from https://ziglang.org/download/ or a mirror.
7-
.minimum_zig_version = "0.15.0-dev.441+c1649d586",
7+
.minimum_zig_version = "0.15.0-dev.631+9a3540d61",
88
// If you do not use Nix, a ZLS maintainer can take care of this.
99
// Whenever the dependencies are updated, run the following command:
1010
// ```bash

flake.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/analysis.zig

Lines changed: 15 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ pub const DocumentScope = @import("DocumentScope.zig");
2323
pub const Declaration = DocumentScope.Declaration;
2424
pub const Scope = DocumentScope.Scope;
2525

26+
const version_data = @import("version_data");
27+
2628
const Analyser = @This();
2729

2830
gpa: std.mem.Allocator,
@@ -2101,10 +2103,6 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, options: ResolveOptions) error
21012103
return resolved_type.typeOf(analyser);
21022104
}
21032105

2104-
if (std.mem.eql(u8, call_name, "@typeInfo")) {
2105-
return analyser.instanceStdBuiltinType("Type");
2106-
}
2107-
21082106
const type_map: std.StaticStringMap(InternPool.Index) = .initComptime(.{
21092107
.{ "type", .type_type },
21102108
.{ "void", .void_type },
@@ -2183,20 +2181,10 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, options: ResolveOptions) error
21832181
return try analyser.resolveFieldAccess(lhs, field_name);
21842182
}
21852183

2186-
if (std.mem.eql(u8, call_name, "@src")) {
2187-
return analyser.instanceStdBuiltinType("SourceLocation");
2188-
}
2189-
21902184
if (std.mem.eql(u8, call_name, "@compileError")) {
21912185
return .{ .data = .{ .compile_error = node_handle }, .is_type_val = false };
21922186
}
21932187

2194-
if (std.mem.eql(u8, call_name, "@panic") or
2195-
std.mem.eql(u8, call_name, "@trap"))
2196-
{
2197-
return Type.fromIP(analyser, .noreturn_type, null);
2198-
}
2199-
22002188
if (std.mem.eql(u8, call_name, "@Vector")) {
22012189
if (params.len != 2) return null;
22022190

@@ -2220,6 +2208,13 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, options: ResolveOptions) error
22202208

22212209
return Type.fromIP(analyser, .type_type, vector_ty_ip_index);
22222210
}
2211+
2212+
if (version_data.builtins.get(call_name)) |data| {
2213+
const type_str = data.return_type;
2214+
if (try analyser.resolvePrimitive(type_str)) |primitive|
2215+
return Type.fromIP(analyser, primitive, null);
2216+
return analyser.instanceStdBuiltinType(type_str);
2217+
}
22232218
},
22242219
.fn_proto,
22252220
.fn_proto_multi,
@@ -5827,88 +5822,12 @@ pub fn resolveExpressionTypeFromAncestors(
58275822
return try ty.instanceTypeVal(analyser);
58285823
}
58295824

5830-
if (std.mem.eql(u8, call_name, "@branchHint")) {
5831-
if (params.len == 0) return null;
5832-
if (params[0] != node) return null;
5833-
return analyser.instanceStdBuiltinType("BranchHint");
5834-
}
5835-
5836-
if (std.mem.eql(u8, call_name, "@atomicLoad")) {
5837-
if (params.len <= 2) return null;
5838-
if (params[2] != node) return null;
5839-
return analyser.instanceStdBuiltinType("AtomicOrder");
5840-
}
5841-
5842-
if (std.mem.eql(u8, call_name, "@atomicRmw")) {
5843-
if (params.len > 2 and params[2] == node)
5844-
return analyser.instanceStdBuiltinType("AtomicRmwOp");
5845-
if (params.len > 4 and params[4] == node)
5846-
return analyser.instanceStdBuiltinType("AtomicOrder");
5847-
return null;
5848-
}
5849-
5850-
if (std.mem.eql(u8, call_name, "@atomicStore")) {
5851-
if (params.len <= 3) return null;
5852-
if (params[3] != node) return null;
5853-
return analyser.instanceStdBuiltinType("AtomicOrder");
5854-
}
5855-
5856-
if (std.mem.eql(u8, call_name, "@cmpxchgStrong")) {
5857-
if (params.len > 4 and params[4] == node)
5858-
return analyser.instanceStdBuiltinType("AtomicOrder");
5859-
if (params.len > 5 and params[5] == node)
5860-
return analyser.instanceStdBuiltinType("AtomicOrder");
5861-
return null;
5862-
}
5863-
5864-
if (std.mem.eql(u8, call_name, "@cmpxchgWeak")) {
5865-
if (params.len > 4 and params[4] == node)
5866-
return analyser.instanceStdBuiltinType("AtomicOrder");
5867-
if (params.len > 5 and params[5] == node)
5868-
return analyser.instanceStdBuiltinType("AtomicOrder");
5869-
return null;
5870-
}
5871-
5872-
if (std.mem.eql(u8, call_name, "@call")) {
5873-
if (params.len == 0) return null;
5874-
if (params[0] != node) return null;
5875-
return analyser.instanceStdBuiltinType("CallModifier");
5876-
}
5877-
5878-
if (std.mem.eql(u8, call_name, "@export")) {
5879-
if (params.len <= 1) return null;
5880-
if (params[1] != node) return null;
5881-
return analyser.instanceStdBuiltinType("ExportOptions");
5882-
}
5883-
5884-
if (std.mem.eql(u8, call_name, "@extern")) {
5885-
if (params.len <= 1) return null;
5886-
if (params[1] != node) return null;
5887-
return analyser.instanceStdBuiltinType("ExternOptions");
5888-
}
5889-
5890-
if (std.mem.eql(u8, call_name, "@prefetch")) {
5891-
if (params.len <= 1) return null;
5892-
if (params[1] != node) return null;
5893-
return analyser.instanceStdBuiltinType("PrefetchOptions");
5894-
}
5895-
5896-
if (std.mem.eql(u8, call_name, "@reduce")) {
5897-
if (params.len == 0) return null;
5898-
if (params[0] != node) return null;
5899-
return analyser.instanceStdBuiltinType("ReduceOp");
5900-
}
5901-
5902-
if (std.mem.eql(u8, call_name, "@setFloatMode")) {
5903-
if (params.len == 0) return null;
5904-
if (params[0] != node) return null;
5905-
return analyser.instanceStdBuiltinType("FloatMode");
5906-
}
5907-
5908-
if (std.mem.eql(u8, call_name, "@Type")) {
5909-
if (params.len == 0) return null;
5910-
if (params[0] != node) return null;
5911-
return analyser.instanceStdBuiltinType("Type");
5825+
if (version_data.builtins.get(call_name)) |data| {
5826+
const index = std.mem.indexOfScalar(Ast.Node.Index, params, node) orelse return null;
5827+
if (index >= data.parameters.len) return null;
5828+
const parameter = data.parameters[index];
5829+
const type_str = parameter.type orelse return null;
5830+
return analyser.instanceStdBuiltinType(type_str);
59125831
}
59135832
},
59145833

src/features/completions.zig

Lines changed: 5 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ fn completeBuiltin(builder: *Builder) error{OutOfMemory}!void {
529529
.only_name => .{ name, .PlainText },
530530
.snippet => blk: {
531531
std.debug.assert(use_snippets);
532-
if (builtin.arguments.len == 0) break :blk .{ try std.fmt.allocPrint(builder.arena, "{s}()", .{name}), .PlainText };
532+
if (builtin.parameters.len == 0) break :blk .{ try std.fmt.allocPrint(builder.arena, "{s}()", .{name}), .PlainText };
533533
if (use_placeholders) break :blk .{ builtin.snippet, .Snippet };
534534
break :blk .{ try std.fmt.allocPrint(builder.arena, "{s}(${{1:}})", .{name}), .Snippet };
535535
},
@@ -1516,95 +1516,10 @@ fn resolveBuiltinFnArg(
15161516
/// Includes leading `@`
15171517
name: []const u8,
15181518
) std.mem.Allocator.Error!?Analyser.Type {
1519-
const builtin_name: []const u8 = name: {
1520-
if (std.mem.eql(u8, name, "@Type")) {
1521-
switch (arg_index) {
1522-
0 => break :name "Type",
1523-
else => return null,
1524-
}
1525-
}
1526-
1527-
if (std.mem.eql(u8, name, "@setFloatMode")) {
1528-
switch (arg_index) {
1529-
0 => break :name "FloatMode",
1530-
else => return null,
1531-
}
1532-
}
1533-
1534-
if (std.mem.eql(u8, name, "@prefetch")) {
1535-
switch (arg_index) {
1536-
1 => break :name "PrefetchOptions",
1537-
else => return null,
1538-
}
1539-
}
1540-
1541-
if (std.mem.eql(u8, name, "@reduce")) {
1542-
switch (arg_index) {
1543-
0 => break :name "ReduceOp",
1544-
else => return null,
1545-
}
1546-
}
1547-
1548-
if (std.mem.eql(u8, name, "@export")) {
1549-
switch (arg_index) {
1550-
1 => break :name "ExportOptions",
1551-
else => return null,
1552-
}
1553-
}
1554-
1555-
if (std.mem.eql(u8, name, "@extern")) {
1556-
switch (arg_index) {
1557-
1 => break :name "ExternOptions",
1558-
else => return null,
1559-
}
1560-
}
1561-
1562-
if (std.mem.eql(u8, name, "@cmpxchgWeak") or std.mem.eql(u8, name, "@cmpxchgStrong")) {
1563-
switch (arg_index) {
1564-
4, 5 => break :name "AtomicOrder",
1565-
else => return null,
1566-
}
1567-
}
1568-
1569-
if (std.mem.eql(u8, name, "@atomicLoad")) {
1570-
switch (arg_index) {
1571-
2 => break :name "AtomicOrder",
1572-
else => return null,
1573-
}
1574-
}
1575-
1576-
if (std.mem.eql(u8, name, "@atomicStore")) {
1577-
switch (arg_index) {
1578-
3 => break :name "AtomicOrder",
1579-
else => return null,
1580-
}
1581-
}
1582-
1583-
if (std.mem.eql(u8, name, "@atomicRmw")) {
1584-
switch (arg_index) {
1585-
2 => break :name "AtomicRmwOp",
1586-
4 => break :name "AtomicOrder",
1587-
else => return null,
1588-
}
1589-
}
1590-
1591-
if (std.mem.eql(u8, name, "@call")) {
1592-
switch (arg_index) {
1593-
0 => break :name "CallModifier",
1594-
else => return null,
1595-
}
1596-
}
1597-
1598-
if (std.mem.eql(u8, name, "@branchHint")) {
1599-
switch (arg_index) {
1600-
0 => break :name "BranchHint",
1601-
else => return null,
1602-
}
1603-
}
1604-
1605-
return null;
1606-
};
1607-
1519+
const builtin = version_data.builtins.get(name) orelse return null;
1520+
if (arg_index >= builtin.parameters.len) return null;
1521+
const param = builtin.parameters[arg_index];
1522+
const builtin_name = param.type orelse return null;
16081523
return analyser.instanceStdBuiltinType(builtin_name);
16091524
}
16101525

src/features/inlay_hints.zig

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -282,26 +282,28 @@ fn writeCallHint(
282282
}
283283
}
284284

285-
/// takes parameter nodes from the ast and function parameter names from `Builtin.arguments` and writes parameter hints into `builder.hints`
286-
fn writeBuiltinHint(builder: *Builder, parameters: []const Ast.Node.Index, arguments: []const []const u8) !void {
285+
/// takes parameter nodes from the ast and function parameter names from `Builtin.parameters` and writes parameter hints into `builder.hints`
286+
fn writeBuiltinHint(builder: *Builder, parameters: []const Ast.Node.Index, params: []const data.Builtin.Parameter) !void {
287287
const tracy_zone = tracy.trace(@src());
288288
defer tracy_zone.end();
289289

290290
const handle = builder.handle;
291291
const tree = handle.tree;
292292

293-
const len = @min(arguments.len, parameters.len);
294-
for (arguments[0..len], parameters[0..len]) |arg, parameter| {
295-
if (arg.len == 0) continue;
293+
const len = @min(params.len, parameters.len);
294+
for (params[0..len], parameters[0..len]) |param, parameter| {
295+
const signature = param.signature;
296+
if (signature.len == 0) continue;
296297

297-
const colonIndex = std.mem.indexOfScalar(u8, arg, ':');
298-
const type_expr: []const u8 = if (colonIndex) |index| arg[index + 1 ..] else &.{};
298+
const colonIndex = std.mem.indexOfScalar(u8, signature, ':');
299+
const type_expr = param.type orelse "";
299300

301+
// TODO: parse noalias/comptime/label in config_gen.zig
300302
var maybe_label: ?[]const u8 = null;
301303
var no_alias = false;
302304
var comp_time = false;
303305

304-
var it = std.mem.splitScalar(u8, arg[0 .. colonIndex orelse arg.len], ' ');
306+
var it = std.mem.splitScalar(u8, signature[0 .. colonIndex orelse signature.len], ' ');
305307
while (it.next()) |item| {
306308
if (item.len == 0) continue;
307309
maybe_label = item;
@@ -518,7 +520,7 @@ fn writeNodeInlayHint(
518520
if (params.len == 0) return;
519521

520522
if (data.builtins.get(name)) |builtin| {
521-
try writeBuiltinHint(builder, params, builtin.arguments);
523+
try writeBuiltinHint(builder, params, builtin.parameters);
522524
}
523525
},
524526
.struct_init_one,

src/features/signature_help.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,11 @@ pub fn getSignatureInfo(
193193
const builtin = data.builtins.get(tree.tokenSlice(expr_last_token)) orelse return null;
194194
const param_infos = try arena.alloc(
195195
types.ParameterInformation,
196-
builtin.arguments.len,
196+
builtin.parameters.len,
197197
);
198-
for (param_infos, builtin.arguments) |*info, argument| {
198+
for (param_infos, builtin.parameters) |*info, parameter| {
199199
info.* = .{
200-
.label = .{ .string = argument },
200+
.label = .{ .string = parameter.signature },
201201
.documentation = null,
202202
};
203203
}

0 commit comments

Comments
 (0)