Merge pull request #578 from gpanders/highlight-uri

Only return highlights for symbols in current document
This commit is contained in:
Auguste Rame 2022-08-11 17:26:05 +02:00 committed by GitHub
commit c632a7f29d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1144,12 +1144,15 @@ fn referencesDefinitionGlobal(
const result: types.ResponseParams = if (highlight) result: { const result: types.ResponseParams = if (highlight) result: {
var highlights = try std.ArrayList(types.DocumentHighlight).initCapacity(server.arena.allocator(), locs.items.len); var highlights = try std.ArrayList(types.DocumentHighlight).initCapacity(server.arena.allocator(), locs.items.len);
const uri = handle.uri();
for (locs.items) |loc| { for (locs.items) |loc| {
if (std.mem.eql(u8, loc.uri, uri)) {
highlights.appendAssumeCapacity(.{ highlights.appendAssumeCapacity(.{
.range = loc.range, .range = loc.range,
.kind = .Text, .kind = .Text,
}); });
} }
}
break :result .{ .DocumentHighlight = highlights.items }; break :result .{ .DocumentHighlight = highlights.items };
} else .{ .Locations = locs.items }; } else .{ .Locations = locs.items };
@ -1187,12 +1190,15 @@ fn referencesDefinitionFieldAccess(
); );
const result: types.ResponseParams = if (highlight) result: { const result: types.ResponseParams = if (highlight) result: {
var highlights = try std.ArrayList(types.DocumentHighlight).initCapacity(server.arena.allocator(), locs.items.len); var highlights = try std.ArrayList(types.DocumentHighlight).initCapacity(server.arena.allocator(), locs.items.len);
const uri = handle.uri();
for (locs.items) |loc| { for (locs.items) |loc| {
if (std.mem.eql(u8, loc.uri, uri)) {
highlights.appendAssumeCapacity(.{ highlights.appendAssumeCapacity(.{
.range = loc.range, .range = loc.range,
.kind = .Text, .kind = .Text,
}); });
} }
}
break :result .{ .DocumentHighlight = highlights.items }; break :result .{ .DocumentHighlight = highlights.items };
} else .{ .Locations = locs.items }; } else .{ .Locations = locs.items };
try send(writer, server.arena.allocator(), types.Response{ try send(writer, server.arena.allocator(), types.Response{
@ -1218,12 +1224,15 @@ fn referencesDefinitionLabel(
try references.labelReferences(&server.arena, decl, server.offset_encoding, include_decl, &locs, std.ArrayList(types.Location).append); try references.labelReferences(&server.arena, decl, server.offset_encoding, include_decl, &locs, std.ArrayList(types.Location).append);
const result: types.ResponseParams = if (highlight) result: { const result: types.ResponseParams = if (highlight) result: {
var highlights = try std.ArrayList(types.DocumentHighlight).initCapacity(server.arena.allocator(), locs.items.len); var highlights = try std.ArrayList(types.DocumentHighlight).initCapacity(server.arena.allocator(), locs.items.len);
const uri = handle.uri();
for (locs.items) |loc| { for (locs.items) |loc| {
if (std.mem.eql(u8, loc.uri, uri)) {
highlights.appendAssumeCapacity(.{ highlights.appendAssumeCapacity(.{
.range = loc.range, .range = loc.range,
.kind = .Text, .kind = .Text,
}); });
} }
}
break :result .{ .DocumentHighlight = highlights.items }; break :result .{ .DocumentHighlight = highlights.items };
} else .{ .Locations = locs.items }; } else .{ .Locations = locs.items };
try send(writer, server.arena.allocator(), types.Response{ try send(writer, server.arena.allocator(), types.Response{