summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/Output.zig9
-rw-r--r--core/Pick.zig10
-rw-r--r--core/Query.zig7
-rw-r--r--core/root.zig2
-rw-r--r--core/syntax.zig48
-rw-r--r--dev/lsp/lsp_client.zig39
-rw-r--r--docs/typ/guide.typ2
-rw-r--r--docs/typ/reference.typ3
-rw-r--r--test/behaviour/language_servers.zig25
-rw-r--r--test/lspmock.zig11
-rw-r--r--test/snapshots/lsp.golden12
11 files changed, 130 insertions, 38 deletions
diff --git a/core/Output.zig b/core/Output.zig
index fe1543fe..e55ff4a3 100644
--- a/core/Output.zig
+++ b/core/Output.zig
@@ -198,11 +198,15 @@ pub fn traits(o: Origin) Traits {
};
}
+/// A list laid out as Locations (each place's lines from its file, in
+/// their order): not a file's symbols, a row each in their own order (UX
+/// DESIGN N: types, functions, fields, the rest).
pub fn usesLocationsConfig(from: Origin) bool {
const tr = traits(from);
return tr.steps and !tr.commands and from != .kind and
!std.meta.eql(from, Origin{ .query = .completion }) and
- !std.meta.eql(from, Origin{ .query = .callstack });
+ !std.meta.eql(from, Origin{ .query = .callstack }) and
+ !std.meta.eql(from, Origin{ .query = .document_symbols });
}
pub fn fileTraits(out: ?State) Traits {
@@ -244,6 +248,8 @@ pub fn isResultRow(file: *const File.State, row: usize) bool {
return !locations.isContextLine(modal.lineSlice(file.content, row));
}
+/// A language server's places in the order of their places; a file's
+/// symbols stay in theirs (lsp_client: types, functions, fields, the rest).
fn sortResults(arena: std.mem.Allocator, from: Origin, content: []u8, anchor: ?usize) !?usize {
switch (from) {
.search => {},
@@ -258,7 +264,6 @@ fn sortResults(arena: std.mem.Allocator, from: Origin, content: []u8, anchor: ?u
.outgoing_calls,
.supertypes,
.subtypes,
- .document_symbols,
.workspace_symbols,
.diagnostics,
.workspace_diagnostics,
diff --git a/core/Pick.zig b/core/Pick.zig
index 2b5714cb..dcb838f3 100644
--- a/core/Pick.zig
+++ b/core/Pick.zig
@@ -677,10 +677,9 @@ fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) std.me
for (marks_in, row.marks) |*m, at| m.* = at -| line;
row.marks = marks_in;
const name_at = cand.key - line;
- const dot = std.mem.lastIndexOfScalar(u8, row.text[name_at .. name_at + cand.key_len], '.');
row.kind = @intCast(name_at - 1);
row.pre = @intCast(name_at);
- row.faint = @intCast(if (dot) |at| at + 1 else 0);
+ row.faint = cand.base;
if (name_at + cand.key_len < row.text.len) row.quiet = .{ @intCast(name_at + cand.key_len), @intCast(row.text.len) };
const owner = p.panes[p.paneBySerial(pk.owner) orelse return row] orelse return row;
const f = owner.file orelse return row;
@@ -3357,7 +3356,7 @@ const counts_zig =
\\pub fn count(text: []const u8) Counts {
\\ return .{ .lines = text.len };
\\}
- \\test "count" {}
+ \\test "count.add" {}
\\
;
@@ -3381,9 +3380,12 @@ test "Symbols (UX DESIGN N): a Zig file's rows types, functions, fields, then th
\\ 1 n std = @import("std")
\\ 5 c Counts.zero : Counts = .{}
\\12 v hits : u32 = 0
- \\16 · "count"
+ \\16 · "count.add"
\\
, try rowLines(p, a));
+ // The qualifier dim, `Counts.`; a name holding a `.` none of it.
+ try std.testing.expectEqual(@as(u16, "Counts.".len), (try rowAt(p, live(p).?, a, 4)).faint);
+ try std.testing.expectEqual(@as(u16, 0), (try rowAt(p, live(p).?, a, 11)).faint);
// Drawn: `m Counts.lines : usize = 0` (not the cursor's row).
const pane = p.panes[p.paneBySerial(live(p).?.landing).?].?;
_ = try p.render(a);
diff --git a/core/Query.zig b/core/Query.zig
index 743e9540..a5926e23 100644
--- a/core/Query.zig
+++ b/core/Query.zig
@@ -785,7 +785,8 @@ pub fn gather(p: *Pardes, names: *Names, source: Source, dir: []const u8, self:
// line, its mark, its name qualified by the ones it is in, then
// what its first line says after the name; types, functions,
// fields, then the rest, each in the text's order (UX DESIGN N).
- // The name alone is matched.
+ // The qualified name alone is matched, its own name the
+ // basename.
for (0..4) |group| for (symbols) |sym| {
if (sym.kind.group() != group or sym.kind == .scope or sym.end > text.len) continue;
var buf: [512]u8 = undefined;
@@ -793,13 +794,15 @@ pub fn gather(p: *Pardes, names: *Names, source: Source, dir: []const u8, self:
row.print("{d: >6} {s} ", .{ sym.line + 1, sym.kind.mark() }) catch continue;
const key_at = row.end;
qualify(&row, symbols, text, sym.parent, 4) catch continue;
+ // The name its basename: the qualifier dim (Pick.rowAt).
+ const base = row.end - key_at;
row.writeAll(text[sym.name_start..sym.name_end]) catch continue;
const key_len = row.end - key_at;
const rest = text[sym.name_end..@max(sym.name_end, sym.end)];
var detail = std.mem.trim(u8, rest[0 .. std.mem.indexOfScalar(u8, rest, '\n') orelse rest.len], " \t\r");
detail = std.mem.trimEnd(u8, std.mem.trimEnd(u8, detail, "{,;"), " \t");
if (detail.len > 0) row.print(" {s}", .{detail[0..@min(detail.len, buf.len - row.end -| 2)]}) catch {};
- names.add(gpa, row.buffered(), key_at, key_len, 0, sym.line + 1) catch break;
+ names.add(gpa, row.buffered(), key_at, key_len, @intCast(base), sym.line + 1) catch break;
names.cands.items[names.cands.items.len - 1].group = @intCast(group);
};
},
diff --git a/core/root.zig b/core/root.zig
index 86ca62e0..a9c95a96 100644
--- a/core/root.zig
+++ b/core/root.zig
@@ -461,7 +461,7 @@ test {
_ = @import("FrameStats.zig");
_ = @import("Query.zig");
_ = @import("Names.zig");
- _ = @import("syntax.zig"); // its tests ran nowhere before
+ _ = @import("syntax.zig"); // without it a -Dtest-filter run compiles none of its tests (a whole run has them)
_ = @import("Stream.zig");
_ = @import("Tables.zig");
_ = @import("Handover.zig");
diff --git a/core/syntax.zig b/core/syntax.zig
index 5cdc2ff3..9fbad3cf 100644
--- a/core/syntax.zig
+++ b/core/syntax.zig
@@ -1135,6 +1135,9 @@ const SymbolWalk = struct {
fn visit(w: *SymbolWalk, node: ts.Node) !void {
while (w.depth > 0 and w.scopes[w.depth - 1].end <= node.startByte()) w.depth -= 1;
const in: Scope = if (w.depth > 0) w.scopes[w.depth - 1] else .{ .end = 0, .kind = .module, .symbol = 0 };
+ // A test's body (a macro's) lists nothing: its types are its
+ // locals' (a test's `const Find = struct`).
+ if (in.kind == .other) return;
const kind_name = node.kind();
const rule = for (w.rules) |r| {
if (std.mem.eql(u8, r.node, kind_name)) break r;
@@ -1145,11 +1148,17 @@ const SymbolWalk = struct {
if (local and (found.kind == .constant or found.kind == .variable)) return;
var named = in.symbol;
if (found.name) |name| {
+ // A longer name is cut (a test's sentence), on a character.
+ var end = name.endByte();
+ if (end - name.startByte() > max_name) {
+ end = name.startByte() + max_name;
+ while (end > name.startByte() and w.source[end] & 0xc0 == 0x80) end -= 1;
+ }
try w.out.append(w.gpa, .{
.kind = found.kind,
.line = name.startPoint().row,
.name_start = name.startByte(),
- .name_end = name.endByte(),
+ .name_end = end,
.end = found.end,
.parent = in.symbol,
});
@@ -1190,7 +1199,10 @@ fn symbolOf(rule: Rule, node: ts.Node, source: []const u8, in: SymbolKind) ?stru
if (kind == .variable and constant(source, node.startByte(), name orelse return null)) kind = .constant;
},
.value => {
+ // Named by a name, never a pattern (`const { a, b } = ...`,
+ // OCaml's `let () = ...`).
name = nameOf(node, rule.name);
+ if (name) |n| if (!nameLike(n.kind())) return null;
kind = valueKind(node, source) orelse kind;
// JavaScript's keyword is its declaration's (`const a = 1, b`).
const from = if (std.mem.eql(u8, rule.node, "variable_declarator")) (node.parent() orelse node).startByte() else node.startByte();
@@ -1228,20 +1240,24 @@ fn symbolOf(rule: Rule, node: ts.Node, source: []const u8, in: SymbolKind) ?stru
if (childOfKind(node, "Block")) |block| end = block.startByte();
}
if (name == null and kind != .scope) return null;
- if (name) |n| if (n.endByte() <= n.startByte() or n.endByte() - n.startByte() > max_name) return null;
+ if (name) |n| if (n.endByte() <= n.startByte()) return null;
return .{ .kind = kind, .name = name, .end = end };
}
-/// The longest name a symbol has: a longer one is no name.
+/// The longest name a symbol has: a longer one is cut.
const max_name = 200;
-/// The node naming `node`: its field `field`; without one, its declarator's
-/// (C's `int *f(void)`: `f`); else the first name under it, past its
-/// type, value, body and parameters (Kotlin's, Fortran's).
+/// The node naming `node`: its field `field`, whole on its line (C++'s
+/// `namespace v8::internal`, Rust's `impl Vec<T>`); without one, its
+/// declarator's (C's `int *f(void)`: `f`); else the first name under it,
+/// past its type, value, body and parameters (Kotlin's, Fortran's).
fn nameOf(node: ts.Node, field: []const u8) ?ts.Node {
if (field.len == 0) return null;
var n = node;
- if (node.childByFieldName(field)) |f| n = f else while (n.childByFieldName("declarator")) |d| n = d;
+ if (node.childByFieldName(field)) |f| {
+ if (f.startPoint().row == f.endPoint().row) return f;
+ n = f;
+ } else while (n.childByFieldName("declarator")) |d| n = d;
if (nameLike(n.kind())) return n;
if (n.childByFieldName("name")) |f| if (nameLike(f.kind())) return f;
return firstName(n, 3);
@@ -2786,12 +2802,20 @@ test "syntax symbols: a Zig file's types, functions, fields and the rest by thei
\\fn List(comptime T: type) type {
\\ return struct { items: []T };
\\}
- \\test "count" {}
+ \\test "count" {
+ \\ const Local = struct {
+ \\ fn helper() void {}
+ \\ };
+ \\ _ = Local;
+ \\}
\\test {}
\\extern fn tick() void;
\\
;
- const lines = try symbolLines(gpa, "a.zig", source);
+ // A test's name longer than a row's room is cut, its body still none.
+ const xs: [250]u8 = @splat('x');
+ const long = "test \"" ++ xs ++ "\" {\n const Inner = struct {};\n _ = Inner;\n}\n";
+ const lines = try symbolLines(gpa, "a.zig", source ++ long);
defer gpa.free(lines);
try std.testing.expectEqualStrings(
\\n std
@@ -2810,7 +2834,7 @@ test "syntax symbols: a Zig file's types, functions, fields and the rest by thei
\\· "count"
\\f tick
\\
- , lines);
+ ++ "· \"" ++ xs[0 .. max_name - 1].* ++ "\n", lines);
}
test "syntax symbols: C, C++, Rust, Go, Python and JavaScript by their kind tables, members named in their types, an impl's in its type, locals none" {
@@ -2820,11 +2844,11 @@ test "syntax symbols: C, C++, Rust, Go, Python and JavaScript by their kind tabl
defer stop();
const cases = [_]struct { path: []const u8, source: []const u8, want: []const u8 }{
.{ .path = "a.c", .source = "#define LIMIT 4\nstruct point { int x; int *y; };\ntypedef struct { int a; } pair;\nenum color { RED };\nstatic int counter = 0;\nconst int limit = 4;\nint add(int a) { int local = a; return local; }\nint later(void);\nstruct point p;\n", .want = "· LIMIT\nt point\nm point.x\nm point.y\nt pair\nm pair.a\nt color\nm color.RED\nv counter\nc limit\nf add\nf later\nv p\n" },
- .{ .path = "a.cc", .source = "namespace torque {\nclass Parser : public Base {\n public:\n Parser();\n int Parse(int depth) const { return depth; }\n int depth_;\n};\nint Parser::Run(int n) { int local = n; return local; }\nusing Alias = int;\n}\n", .want = "n torque\nt torque.Parser\nf torque.Parser.Parser\nf torque.Parser.Parse\nm torque.Parser.depth_\nf torque.Parser::Run\nt torque.Alias\n" },
+ .{ .path = "a.cc", .source = "namespace torque {\nclass Parser : public Base {\n public:\n Parser();\n int Parse(int depth) const { return depth; }\n int depth_;\n};\nint Parser::Run(int n) { int local = n; return local; }\nusing Alias = int;\n}\nnamespace v8::internal {\nint flags;\n}\n", .want = "n torque\nt torque.Parser\nf torque.Parser.Parser\nf torque.Parser.Parse\nm torque.Parser.depth_\nf torque.Parser::Run\nt torque.Alias\nn v8::internal\nv v8::internal.flags\n" },
.{ .path = "a.rs", .source = "mod m {\npub struct S { pub a: u32 }\nenum E { A, B(u32) }\ntrait T { fn f(&self); }\nimpl S { pub fn new() -> Self { let x = 1; S { a: x } } }\nconst C: u32 = 1;\nstatic G: u32 = 2;\nmacro_rules! mac { () => {} }\n}\n", .want = "n m\nt m.S\nm m.S.a\nt m.E\nm m.E.A\nm m.E.B\nt m.T\nf m.T.f\nf m.S.new\nc m.C\nv m.G\n· m.mac\n" },
.{ .path = "a.go", .source = "package main\ntype S struct { A int }\ntype I interface { M() }\nconst C = 1\nvar V = 2\nfunc F() { var x = 1; _ = x }\nfunc (s *S) M() {}\n", .want = "t S\nm S.A\nt I\nf I.M\nc C\nv V\nf F\nf M\n" },
.{ .path = "a.py", .source = "X = 1\nclass C:\n attr = 2\n def m(self):\n y = 3\n self.z = 4\ndef f():\n pass\n", .want = "v X\nt C\nm C.attr\nf C.m\nf f\n" },
- .{ .path = "a.js", .source = "const A = 1;\nlet b = 2;\nfunction f() { const local = 1; }\nclass K { field = 1; m() {} }\nconst arrow = () => 1;\nconst Klass = class {};\n", .want = "c A\nv b\nf f\nt K\nm K.field\nf K.m\nf arrow\nt Klass\n" },
+ .{ .path = "a.js", .source = "const A = 1;\nlet b = 2;\nfunction f() { const local = 1; }\nclass K { field = 1; m() {} }\nconst arrow = () => 1;\nconst Klass = class {};\nconst { x, y } = A;\n", .want = "c A\nv b\nf f\nt K\nm K.field\nf K.m\nf arrow\nt Klass\n" },
};
for (cases) |case| {
const lines = try symbolLines(gpa, case.path, case.source);
diff --git a/dev/lsp/lsp_client.zig b/dev/lsp/lsp_client.zig
index a53ff57f..b76be78c 100644
--- a/dev/lsp/lsp_client.zig
+++ b/dev/lsp/lsp_client.zig
@@ -50,6 +50,7 @@ const std = @import("std");
const builtin = @import("builtin");
const libc = std.c;
const lsp = @import("core").lsp;
+const SymbolKind = @import("core").syntax.SymbolKind;
const Scip = @import("Scip.zig");
extern "c" fn execv(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8) c_int;
@@ -1002,7 +1003,11 @@ fn run(c: *Conn, io: std.Io, si: usize, arena: std.mem.Allocator, req: lsp.Req,
.document_symbols => {
const b = try docParams(arena, uri.items);
const result = (try call(c, io, arena, "textDocument/documentSymbol", b.items, deadline)) orelse return;
- try walkSymbols(&cx, c.caps.enc, uri.items, result, 0);
+ // Types, functions, fields, then the rest, each in the
+ // server's order (UX DESIGN N, the Symbols picker's).
+ var found: std.ArrayList(Symbol) = .empty;
+ try walkSymbols(arena, &found, uri.items, result, "", 0);
+ for (0..4) |group| for (found.items) |sym| if (sym.kind.group() == group) try emitRange(&cx, c.caps.enc, sym.uri, sym.range, sym.note);
},
.workspace_symbols => {
var b: std.ArrayList(u8) = .empty;
@@ -1106,20 +1111,42 @@ fn locations(cx: *Cx, enc: Enc, result: std.json.Value) Err!void {
}
}
-/// DocumentSymbol[] nests (`children`), SymbolInformation[] is flat.
-fn walkSymbols(cx: *Cx, enc: Enc, uri: []const u8, node: std.json.Value, depth: u8) Err!void {
+/// A symbol a server listed: its row's place and words, `t Shape.area`.
+const Symbol = struct { kind: SymbolKind, uri: []const u8, range: ?std.json.Value, note: []const u8 };
+
+/// DocumentSymbol[] nests (`children`), SymbolInformation[] is flat: each
+/// its kind's mark and its name qualified by the ones it is in (the
+/// nesting, or SymbolInformation's `containerName`), into `out`.
+fn walkSymbols(arena: std.mem.Allocator, out: *std.ArrayList(Symbol), uri: []const u8, node: std.json.Value, qualifier: []const u8, depth: u8) Err!void {
if (depth > 8) return;
for (items(node)) |sym| {
const name = str(get(sym, "name")) orelse continue;
+ const kind = symbolKind(num(get(sym, "kind")) orelse 0);
+ const container = if (qualifier.len > 0) qualifier else str(get(sym, "containerName")) orelse "";
+ const qualified = if (container.len > 0) try std.fmt.allocPrint(arena, "{s}.{s}", .{ container, name }) else name;
+ const note = try std.fmt.allocPrint(arena, "{s} {s}", .{ kind.mark(), qualified });
if (get(get(sym, "location"), "range")) |r| {
- try emitRange(cx, enc, str(get(get(sym, "location"), "uri")) orelse uri, r, name);
+ try out.append(arena, .{ .kind = kind, .uri = str(get(get(sym, "location"), "uri")) orelse uri, .range = r, .note = note });
} else {
- try emitRange(cx, enc, uri, get(sym, "selectionRange") orelse get(sym, "range"), name);
+ try out.append(arena, .{ .kind = kind, .uri = uri, .range = get(sym, "selectionRange") orelse get(sym, "range"), .note = note });
}
- if (get(sym, "children")) |kids| try walkSymbols(cx, enc, uri, kids, depth + 1);
+ if (get(sym, "children")) |kids| try walkSymbols(arena, out, uri, kids, qualified, depth + 1);
}
}
+/// LSP's SymbolKind as the Symbols picker's (UX DESIGN N2).
+fn symbolKind(lsp_kind: i64) SymbolKind {
+ return switch (lsp_kind) {
+ 5, 10, 11, 23, 26 => .type,
+ 6, 9, 12, 25 => .function,
+ 7, 8, 22 => .field,
+ 14 => .constant,
+ 13, 15...21, 24 => .variable,
+ 1...4 => .module,
+ else => .other,
+ };
+}
+
/// Pull when the server does (LSP 3.17), the push store otherwise. The store
/// path waits briefly for a publish that postdates the didChange we just
/// sent, so `]d` right after an edit sees the new truth, not the old one.
diff --git a/docs/typ/guide.typ b/docs/typ/guide.typ
index 66d3bb00..d80302c5 100644
--- a/docs/typ/guide.typ
+++ b/docs/typ/guide.typ
@@ -207,7 +207,7 @@ Line 1's first word names what it searches, and editing the word changes it:
[`Grep text`], [the lines of those files holding `text`, literally (#key("SPC f g"), #word("Grep")); past 2000 lines #word("More") goes on],
[`Recent name`], [the files opened lately, in any window (#key("SPC f r"), #word("Recent"))],
[`Panes name`], [the open panes, then the ones closed this session, `(closed)` and dimmer: #key("Enter") (or a #word("Look") at its `@pN`) brings one back where it was, its text with it (#key("SPC b b"), #word("Panes"))],
- [`Symbols name`], [the text's declarations (#key("SPC s s"))],
+ [`Symbols name`], [the text's symbols, a row each: its kind's mark (`t` type, `f` function, `m` field, `c` const, `v` var, `n` module, `·` other), its name in the ones it is in (`Counts.lines`), what its line says after the name; types, functions, fields, then the rest, each in the text's order, and so while typed, the best match current (#key("SPC s s"))],
[`All pat`], [every open pane's text, its rows under each pane (#key("SPC /"))],
[`Refs`, `Def`, `Impl`, `Diagnostics`], [the language server's lists (#key("g r"), #key("g d"), #key("g i"), #key("SPC l d")): one answer is a jump, none a message; several open the list with the keyboard on its current row in normal mode (#keys("j", "k", "n", "N") step it, #key("Enter") lands, #key("Esc") goes back), the diagnostics' keeping it in the text for `]d`; their places in the text tinted as a `/`'s are],
)
diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ
index 42b44fc9..035625cf 100644
--- a/docs/typ/reference.typ
+++ b/docs/typ/reference.typ
@@ -290,7 +290,8 @@ A line written to #file("exec") is #word("Exec"):
runtime depth (1–64, default 8) for subsequent queries.
#word("Callers") and #word("Callees") keep their short
lists and single-result jumps.
- #word("Diagnostics") and #word("Symbols") list the file's in `+Search`;
+ #word("Diagnostics") and #word("Symbols") list the file's in `+Search`
+ (its symbols marked and in the order #key("SPC s s") lists them);
#word("Lspinfo") fills `+Lsp`, the pane its write answers, with the
index the file asks (`scip: <path>, <size>, <documents>, <symbols>,
indexed <when>, <n> files newer`, or `scip: no index.scip above <dir>;
diff --git a/test/behaviour/language_servers.zig b/test/behaviour/language_servers.zig
index 13e42fa6..80d1cb1e 100644
--- a/test/behaviour/language_servers.zig
+++ b/test/behaviour/language_servers.zig
@@ -206,7 +206,7 @@ test "language-servers: Symbols lists the file's definitions by name, a local's
try s.write(s.at("/pane/{d}/look", .{main}), s.at("{s}/lib.rs\n", .{std.fs.path.dirname(std.mem.trimEnd(u8, try s.read(s.at("/pane/{d}/name", .{main})), "\n")).?}));
try s.write(s.at("/pane/{d}/ctl", .{try s.focused()}), "Symbols\n");
const rows = try bodyOf(&s, "+Search");
- for ([_][]const u8{ "lib.rs:1:11-15\nShape\n", "lib.rs:2:8-11\narea\n", "lib.rs:5:8-10\nadd\n", "lib.rs:8:12-17\nSquare\n", "lib.rs:10:8-11\narea\n" }) |row|
+ for ([_][]const u8{ "lib.rs:1:11-15 Shape\n", "lib.rs:2:8-11 area\n", "lib.rs:5:8-10 add\n", "lib.rs:8:12-17 Square\n", "lib.rs:10:8-11 area\n" }) |row|
try std.testing.expect(has(rows, row));
try std.testing.expect(!has(rows, "lib.rs:5:12"));
}
@@ -323,3 +323,26 @@ test "language-servers: SPC l a lists the server's code actions in the pane's ta
try s.keys("u");
try s.expect(body, before);
}
+
+test "language-servers: a server's Symbols are the Symbols picker's rows: types, functions, fields, then the rest, each its kind's mark and its name in the ones it is in (UX DESIGN N)" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var s = try Session.initLanguage(std.testing.allocator);
+ defer s.deinit();
+ try s.write("/ctl", "Jumps new-pane\n");
+ // No index: the server is asked.
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "shapes.rs", .data = "const LIMIT: u32 = 4;\n\nfn main() {}\npub struct Shape {\n side: u32,\n fn area() {}\n}\nenum Kind {\n Round,\n}\nmod lib;\n" });
+ var buf: [4096]u8 = undefined;
+ const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)];
+ const shapes = try s.lookFile(s.at("{s}/shapes.rs:1:1", .{dir}));
+ try s.write(s.at("/pane/{d}/ctl", .{shapes}), "Symbols\n");
+ const rows = try bodyOf(&s, "+Search");
+ var at: usize = 0;
+ for ([_][]const u8{ "shapes.rs:4:12-16 t Shape\n", "shapes.rs:8:6-9 t Kind\n", "shapes.rs:3:4-7 f main\n", "shapes.rs:6:8-11 f Shape.area\n", "shapes.rs:5:5-8 m Shape.side\n", "shapes.rs:9:5-9 m Kind.Round\n", "shapes.rs:1:7-11 c LIMIT\n", "shapes.rs:11:5-7 n lib\n" }) |row| {
+ const found = std.mem.indexOfPos(u8, rows, at, row) orelse {
+ std.debug.print("{s} not after {d} in\n{s}\n", .{ row, at, rows });
+ return error.TestUnexpectedResult;
+ };
+ at = found + row.len;
+ }
+}
diff --git a/test/lspmock.zig b/test/lspmock.zig
index 0fd34677..6f52f568 100644
--- a/test/lspmock.zig
+++ b/test/lspmock.zig
@@ -257,8 +257,15 @@ fn handle(a: std.mem.Allocator, raw: []const u8) void {
} else if (std.mem.eql(u8, method, "textDocument/hover")) {
reply(a, rid, "{{\"contents\":{{\"kind\":\"markdown\",\"value\":\"mock hover: pub fn add\"}}}}", .{});
} else if (std.mem.eql(u8, method, "textDocument/documentSymbol")) {
- reply(a, rid, "[{{\"name\":\"main\",\"kind\":12,\"range\":{s},\"selectionRange\":{s}}}]", .{
- range(a, 2, 0, 11), range(a, 2, 3, 7),
+ // Nested and in no kind's order: a const, a function, a struct
+ // with a field and a method, an enum with a member, a module.
+ reply(a, rid, "[{{\"name\":\"LIMIT\",\"kind\":14,\"range\":{s},\"selectionRange\":{s}}},{{\"name\":\"main\",\"kind\":12,\"range\":{s},\"selectionRange\":{s}}}," ++
+ "{{\"name\":\"Shape\",\"kind\":23,\"range\":{s},\"selectionRange\":{s},\"children\":[{{\"name\":\"side\",\"kind\":8,\"range\":{s},\"selectionRange\":{s}}},{{\"name\":\"area\",\"kind\":6,\"range\":{s},\"selectionRange\":{s}}}]}}," ++
+ "{{\"name\":\"Kind\",\"kind\":10,\"range\":{s},\"selectionRange\":{s},\"children\":[{{\"name\":\"Round\",\"kind\":22,\"range\":{s},\"selectionRange\":{s}}}]}},{{\"name\":\"lib\",\"kind\":2,\"range\":{s},\"selectionRange\":{s}}}]", .{
+ range(a, 0, 0, 21), range(a, 0, 6, 11), range(a, 2, 0, 11), range(a, 2, 3, 7),
+ range(a, 3, 0, 18), range(a, 3, 11, 16), range(a, 4, 4, 14), range(a, 4, 4, 8),
+ range(a, 5, 4, 16), range(a, 5, 7, 11), range(a, 7, 0, 11), range(a, 7, 5, 9),
+ range(a, 8, 4, 10), range(a, 8, 4, 9), range(a, 10, 0, 8), range(a, 10, 4, 7),
});
} else if (std.mem.eql(u8, method, "workspace/symbol")) {
const q = str(get(params, "query")) orelse "";
diff --git a/test/snapshots/lsp.golden b/test/snapshots/lsp.golden
index c680700d..0db3b21e 100644
--- a/test/snapshots/lsp.golden
+++ b/test/snapshots/lsp.golden
@@ -59,13 +59,13 @@
== snap symbols grid=120x41 cursor=24,2
|2: ^ a.zig:8 › ␣ l Symbols 1/3
|3: │ │ Walk Look Split Newcol Grep Edit Copy Keep Drop | Find Grep Recent Panes Symbols All Jumplist
-|4: │ │ ▶ a.zig:1:7-9 std
-|5: │ │ a.zig:3:4-9 helper
-|6: │ │ a.zig:7:8-11 main
+|4: │ │ ▶ a.zig:3:4-9 f helper
+|5: │ │ a.zig:7:8-11 f main
+|6: │ │ a.zig:1:7-9 c std
|7: │ │
-|8: 1▸const std = @import("std");
+|8: 1 const std = @import("std");
|9: 2
-|10: 3 fn helper(x: u32) u32 {
+|10: 3▸fn helper(x: u32) u32 {
|11: fn helper(x: u32) u32
|12: (fn (u32) u32)
|13: 4 return x + 1;
@@ -81,6 +81,6 @@
|4: │ │ nothing matches
|5: │ │
|6: │ │
-|8: 1 const std = @import("std");
+|10: 3 fn helper(x: u32) u32 {
== snap nothing grid=120x41 cursor=29,2
|2: ^ a.zig:8 › ␣ l Symbols jngd 0