Switched struct and enum literals to use the anonymous form where possible.
Added trailing commas to fields of struct literals that are followed by newline.
This commit is contained in:
parent
5bd790f416
commit
eaf0c1f3e5
108
src/main.zig
108
src/main.zig
@ -45,12 +45,12 @@ pub fn log(comptime fmt: []const u8, args: var) !void {
|
|||||||
|
|
||||||
try send(types.Notification{
|
try send(types.Notification{
|
||||||
.method = "window/logMessage",
|
.method = "window/logMessage",
|
||||||
.params = types.NotificationParams{
|
.params = .{
|
||||||
.LogMessageParams = types.LogMessageParams{
|
.LogMessageParams = .{
|
||||||
.@"type" = types.MessageType.Log,
|
.@"type" = .Log,
|
||||||
.message = message
|
.message = message,
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,9 +71,9 @@ pub fn respondGeneric(id: i64, response: []const u8) !void {
|
|||||||
|
|
||||||
pub fn openDocument(uri: []const u8, text: []const u8) !void {
|
pub fn openDocument(uri: []const u8, text: []const u8) !void {
|
||||||
const du = try std.mem.dupe(allocator, u8, uri);
|
const du = try std.mem.dupe(allocator, u8, uri);
|
||||||
_ = try documents.put(du, types.TextDocument{
|
_ = try documents.put(du, .{
|
||||||
.uri = du,
|
.uri = du,
|
||||||
.text = try std.mem.dupe(allocator, u8, text)
|
.text = try std.mem.dupe(allocator, u8, text),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,18 +93,18 @@ pub fn publishDiagnostics(document: types.TextDocument) !void {
|
|||||||
var fbs = std.io.fixedBufferStream(&mem_buffer);
|
var fbs = std.io.fixedBufferStream(&mem_buffer);
|
||||||
_ = try tree.renderError(err, fbs.outStream());
|
_ = try tree.renderError(err, fbs.outStream());
|
||||||
|
|
||||||
try diagnostics.append(types.Diagnostic{
|
try diagnostics.append(.{
|
||||||
.range = types.Range{
|
.range = .{
|
||||||
.start = types.Position{
|
.start = .{
|
||||||
.line = @intCast(i64, loc.line),
|
.line = @intCast(i64, loc.line),
|
||||||
.character = @intCast(i64, loc.column)
|
.character = @intCast(i64, loc.column),
|
||||||
},
|
},
|
||||||
.end = types.Position{
|
.end = .{
|
||||||
.line = @intCast(i64, loc.line),
|
.line = @intCast(i64, loc.line),
|
||||||
.character = @intCast(i64, loc.column)
|
.character = @intCast(i64, loc.column),
|
||||||
}
|
|
||||||
},
|
},
|
||||||
.severity = types.DiagnosticSeverity.Error,
|
},
|
||||||
|
.severity = .Error,
|
||||||
.code = @tagName(err.*),
|
.code = @tagName(err.*),
|
||||||
.source = "zls",
|
.source = "zls",
|
||||||
.message = fbs.getWritten(),
|
.message = fbs.getWritten(),
|
||||||
@ -121,18 +121,18 @@ pub fn publishDiagnostics(document: types.TextDocument) !void {
|
|||||||
if (func.name_token) |name_token| {
|
if (func.name_token) |name_token| {
|
||||||
const loc = tree.tokenLocation(0, name_token);
|
const loc = tree.tokenLocation(0, name_token);
|
||||||
if (func.extern_export_inline_token == null and !analysis.isCamelCase(tree.tokenSlice(name_token))) {
|
if (func.extern_export_inline_token == null and !analysis.isCamelCase(tree.tokenSlice(name_token))) {
|
||||||
try diagnostics.append(types.Diagnostic{
|
try diagnostics.append(.{
|
||||||
.range = types.Range{
|
.range = .{
|
||||||
.start = types.Position{
|
.start = .{
|
||||||
.line = @intCast(i64, loc.line),
|
.line = @intCast(i64, loc.line),
|
||||||
.character = @intCast(i64, loc.column)
|
.character = @intCast(i64, loc.column),
|
||||||
},
|
},
|
||||||
.end = types.Position{
|
.end = .{
|
||||||
.line = @intCast(i64, loc.line),
|
.line = @intCast(i64, loc.line),
|
||||||
.character = @intCast(i64, loc.column)
|
.character = @intCast(i64, loc.column),
|
||||||
}
|
|
||||||
},
|
},
|
||||||
.severity = types.DiagnosticSeverity.Information,
|
},
|
||||||
|
.severity = .Information,
|
||||||
.code = "BadStyle",
|
.code = "BadStyle",
|
||||||
.source = "zls",
|
.source = "zls",
|
||||||
.message = "Callables should be camelCase"
|
.message = "Callables should be camelCase"
|
||||||
@ -147,11 +147,11 @@ pub fn publishDiagnostics(document: types.TextDocument) !void {
|
|||||||
|
|
||||||
try send(types.Notification{
|
try send(types.Notification{
|
||||||
.method = "textDocument/publishDiagnostics",
|
.method = "textDocument/publishDiagnostics",
|
||||||
.params = types.NotificationParams{
|
.params = .{
|
||||||
.PublishDiagnosticsParams = types.PublishDiagnosticsParams{
|
.PublishDiagnosticsParams = .{
|
||||||
.uri = document.uri,
|
.uri = document.uri,
|
||||||
.diagnostics = diagnostics.toOwnedSlice()
|
.diagnostics = diagnostics.toOwnedSlice(),
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -174,28 +174,28 @@ pub fn completeGlobal(id: i64, document: types.TextDocument) !void {
|
|||||||
const func = decl.cast(std.zig.ast.Node.FnProto).?;
|
const func = decl.cast(std.zig.ast.Node.FnProto).?;
|
||||||
var doc_comments = try analysis.getDocComments(allocator, tree, decl);
|
var doc_comments = try analysis.getDocComments(allocator, tree, decl);
|
||||||
var doc = types.MarkupContent{
|
var doc = types.MarkupContent{
|
||||||
.kind = types.MarkupKind.Markdown,
|
.kind = .Markdown,
|
||||||
.value = doc_comments orelse ""
|
.value = doc_comments orelse "",
|
||||||
};
|
};
|
||||||
try completions.append(types.CompletionItem{
|
try completions.append(.{
|
||||||
.label = tree.tokenSlice(func.name_token.?),
|
.label = tree.tokenSlice(func.name_token.?),
|
||||||
.kind = types.CompletionItemKind.Function,
|
.kind = .Function,
|
||||||
.documentation = doc,
|
.documentation = doc,
|
||||||
.detail = analysis.getFunctionSignature(tree, func)
|
.detail = analysis.getFunctionSignature(tree, func),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
.VarDecl => {
|
.VarDecl => {
|
||||||
const var_decl = decl.cast(std.zig.ast.Node.VarDecl).?;
|
const var_decl = decl.cast(std.zig.ast.Node.VarDecl).?;
|
||||||
var doc_comments = try analysis.getDocComments(allocator, tree, decl);
|
var doc_comments = try analysis.getDocComments(allocator, tree, decl);
|
||||||
var doc = types.MarkupContent{
|
var doc = types.MarkupContent{
|
||||||
.kind = types.MarkupKind.Markdown,
|
.kind = .Markdown,
|
||||||
.value = doc_comments orelse ""
|
.value = doc_comments orelse "",
|
||||||
};
|
};
|
||||||
try completions.append(types.CompletionItem{
|
try completions.append(.{
|
||||||
.label = tree.tokenSlice(var_decl.name_token),
|
.label = tree.tokenSlice(var_decl.name_token),
|
||||||
.kind = types.CompletionItemKind.Variable,
|
.kind = .Variable,
|
||||||
.documentation = doc,
|
.documentation = doc,
|
||||||
.detail = analysis.getVariableSignature(tree, var_decl)
|
.detail = analysis.getVariableSignature(tree, var_decl),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
else => {}
|
else => {}
|
||||||
@ -205,12 +205,12 @@ pub fn completeGlobal(id: i64, document: types.TextDocument) !void {
|
|||||||
|
|
||||||
try send(types.Response{
|
try send(types.Response{
|
||||||
.id = .{.Integer = id},
|
.id = .{.Integer = id},
|
||||||
.result = types.ResponseParams{
|
.result = .{
|
||||||
.CompletionList = types.CompletionList{
|
.CompletionList = .{
|
||||||
.isIncomplete = false,
|
.isIncomplete = false,
|
||||||
.items = completions.toOwnedSlice()
|
.items = completions.toOwnedSlice(),
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,29 +305,29 @@ pub fn processJsonRpc(json: []const u8) !void {
|
|||||||
|
|
||||||
for (data.builtins) |builtin, i| {
|
for (data.builtins) |builtin, i| {
|
||||||
var cutoff = std.mem.indexOf(u8, builtin, "(") orelse builtin.len;
|
var cutoff = std.mem.indexOf(u8, builtin, "(") orelse builtin.len;
|
||||||
builtin_completions[i] = types.CompletionItem{
|
builtin_completions[i] = .{
|
||||||
.label = builtin[0..cutoff],
|
.label = builtin[0..cutoff],
|
||||||
.kind = types.CompletionItemKind.Function,
|
.kind = .Function,
|
||||||
|
|
||||||
.filterText = builtin[1..cutoff],
|
.filterText = builtin[1..cutoff],
|
||||||
.insertText = builtin[1..],
|
.insertText = builtin[1..],
|
||||||
.insertTextFormat = types.InsertTextFormat.Snippet,
|
.insertTextFormat = .Snippet,
|
||||||
.detail = data.builtin_details[i],
|
.detail = data.builtin_details[i],
|
||||||
.documentation = types.MarkupContent{
|
.documentation = .{
|
||||||
.kind = types.MarkupKind.Markdown,
|
.kind = .Markdown,
|
||||||
.value = data.builtin_docs[i]
|
.value = data.builtin_docs[i],
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
try send(types.Response{
|
try send(types.Response{
|
||||||
.id = .{.Integer = id},
|
.id = .{.Integer = id},
|
||||||
.result = types.ResponseParams{
|
.result = .{
|
||||||
.CompletionList = types.CompletionList{
|
.CompletionList = .{
|
||||||
.isIncomplete = false,
|
.isIncomplete = false,
|
||||||
.items = builtin_completions[0..]
|
.items = builtin_completions[0..],
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
} else if (char != '.') {
|
} else if (char != '.') {
|
||||||
try completeGlobal(id, document);
|
try completeGlobal(id, document);
|
||||||
|
Loading…
Reference in New Issue
Block a user