feat(lsp): add code actions, signature help, and document highlights
Assisted-by: MiMo V2.5 Pro
This commit is contained in:
@@ -373,6 +373,83 @@ func TestInlayHints(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCodeActions(t *testing.T) {
|
||||
badDoc := "#include \"textflag.h\"\n" +
|
||||
"TEXT ·foo(SB), NOSPLIT, $0\n" +
|
||||
"\tMOVQ AX, CX\n"
|
||||
in := session("file:///f_amd64.s", badDoc) +
|
||||
frame(10, "textDocument/codeAction", map[string]any{
|
||||
"textDocument": map[string]any{"uri": "file:///f_amd64.s"},
|
||||
"range": map[string]any{"start": map[string]any{"line": 0, "character": 0}, "end": map[string]any{"line": 2, "character": 0}},
|
||||
"context": map[string]any{"diagnostics": []map[string]any{{"code": "missing-ret", "range": map[string]any{"start": map[string]any{"line": 0, "character": 0}, "end": map[string]any{"line": 0, "character": 4}}}}},
|
||||
}) + frame(nil, "exit", nil)
|
||||
msgs := run(t, in)
|
||||
resp := findByID(msgs, 10)
|
||||
if resp == nil {
|
||||
t.Fatal("no codeAction response")
|
||||
}
|
||||
var actions []CodeAction
|
||||
if err := json.Unmarshal(mustResult(t, resp), &actions); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(actions) == 0 {
|
||||
t.Fatal("want at least 1 code action for missing-ret")
|
||||
}
|
||||
if actions[0].Title != "Add RET" {
|
||||
t.Errorf("action title = %q, want Add RET", actions[0].Title)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSignatureHelp(t *testing.T) {
|
||||
doc := "#include \"textflag.h\"\n" +
|
||||
"TEXT ·add(SB), NOSPLIT, $0-24\n" +
|
||||
"\tMOVQ AX, CX\n" +
|
||||
"\tRET\n" +
|
||||
"TEXT ·caller(SB), NOSPLIT, $0\n" +
|
||||
"\tCALL ·add(SB)\n" +
|
||||
"\tRET\n"
|
||||
in := session("file:///f_amd64.s", doc) +
|
||||
frame(11, "textDocument/signatureHelp", map[string]any{
|
||||
"textDocument": map[string]any{"uri": "file:///f_amd64.s"},
|
||||
"position": map[string]any{"line": 5, "character": 6},
|
||||
}) + frame(nil, "exit", nil)
|
||||
msgs := run(t, in)
|
||||
resp := findByID(msgs, 11)
|
||||
if resp == nil {
|
||||
t.Fatal("no signatureHelp response")
|
||||
}
|
||||
var sh SignatureHelp
|
||||
if err := json.Unmarshal(mustResult(t, resp), &sh); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(sh.Signatures) == 0 {
|
||||
t.Fatal("want at least 1 signature")
|
||||
}
|
||||
if !strings.Contains(sh.Signatures[0].Label, "add") {
|
||||
t.Errorf("signature label = %q, want add", sh.Signatures[0].Label)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDocumentHighlights(t *testing.T) {
|
||||
in := session("file:///f_amd64.s", cleanDoc) +
|
||||
frame(12, "textDocument/documentHighlight", map[string]any{
|
||||
"textDocument": map[string]any{"uri": "file:///f_amd64.s"},
|
||||
"position": map[string]any{"line": 4, "character": 5},
|
||||
}) + frame(nil, "exit", nil)
|
||||
msgs := run(t, in)
|
||||
resp := findByID(msgs, 12)
|
||||
if resp == nil {
|
||||
t.Fatal("no documentHighlight response")
|
||||
}
|
||||
var highlights []DocumentHighlight
|
||||
if err := json.Unmarshal(mustResult(t, resp), &highlights); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(highlights) < 2 {
|
||||
t.Fatalf("want at least 2 highlights (definition + use), got %d", len(highlights))
|
||||
}
|
||||
}
|
||||
|
||||
func TestMethodNotFound(t *testing.T) {
|
||||
in := frame(9, "bogus/method", map[string]any{}) + frame(nil, "exit", nil)
|
||||
msgs := run(t, in)
|
||||
|
||||
Reference in New Issue
Block a user