Use error iterator instead of manual looping in diagnostic generation

This commit is contained in:
Alexandros Naskos 2020-05-09 04:02:29 +03:00
parent 01b2c2e328
commit 922559c83a

View File

@ -143,26 +143,25 @@ fn publishDiagnostics(document: *types.TextDocument) !void {
var diagnostics = std.ArrayList(types.Diagnostic).init(&arena.allocator); var diagnostics = std.ArrayList(types.Diagnostic).init(&arena.allocator);
if (tree.errors.len > 0) { var error_it = tree.errors.iterator(0);
var index: usize = 0; while (error_it.next()) |err| {
while (index < tree.errors.len) : (index += 1) { const loc = tree.tokenLocation(0, err.loc());
const err = tree.errors.at(index);
const loc = tree.tokenLocation(0, err.loc());
var mem_buffer: [256]u8 = undefined; var mem_buffer: [256]u8 = undefined;
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(.{ try diagnostics.append(.{
.range = astLocationToRange(loc), .range = astLocationToRange(loc),
.severity = .Error, .severity = .Error,
.code = @tagName(err.*), .code = @tagName(err.*),
.source = "zls", .source = "zls",
.message = try std.mem.dupe(&arena.allocator, u8, fbs.getWritten()), .message = try std.mem.dupe(&arena.allocator, u8, fbs.getWritten()),
// .relatedInformation = undefined // .relatedInformation = undefined
}); });
} }
} else {
if (tree.errors.len == 0) {
try cacheSane(document); try cacheSane(document);
var decls = tree.root_node.decls.iterator(0); var decls = tree.root_node.decls.iterator(0);
while (decls.next()) |decl_ptr| { while (decls.next()) |decl_ptr| {