feat(lsp): quick fixes for the textflag include and the argument area
Test / test (push) Successful in 2m56s

Assisted-by: GLM 5.3 Flash
This commit is contained in:
2026-09-23 20:23:35 +02:00
parent 4be16dcdf5
commit 8eed54b3da
7 changed files with 208 additions and 3 deletions
+56
View File
@@ -11,6 +11,7 @@ import (
"regexp"
"runtime"
"slices"
"strconv"
"strings"
"unicode"
"unicode/utf16"
@@ -386,6 +387,61 @@ func (s *Server) codeActions(p codeActionParams) []CodeAction {
}
}
}
case "missing-textflag-include":
// Offer to #include the header that defines the flag macros:
// after the last existing include, or at the top of the file
// when there is none.
insertLine := 0
lines := strings.Split(text, "\n")
for i, line := range lines {
if includeRe.MatchString(line) {
insertLine = i + 1
}
}
actions = append(actions, CodeAction{
Title: `Add #include "textflag.h"`,
Kind: "quickfix",
Edit: &WorkspaceEdit{
Changes: map[string][]TextEdit{p.TextDocument.URI: {{
Range: Range{Start: Position{Line: insertLine, Character: 0}, End: Position{Line: insertLine, Character: 0}},
NewText: "#include \"textflag.h\"\n",
}}},
},
})
case "abi-argsize":
// Offer to set the TEXT argument area to the size the // func
// signature implies. The diagnostic's range covers the TEXT
// keyword, so a line match picks the function it belongs to.
f, _ := parser.Parse(uriPath(p.TextDocument.URI), text)
if f == nil {
continue
}
for _, d := range f.Decls {
t, ok := d.(*ast.Text)
if !ok || t.Keyword.Pos.Line-1 != int(diag.Range.Start.Line) {
continue
}
want, ok := lint.ExpectedArgSize(t.Doc)
if !ok || t.Args == nil || !t.Args.Imm.HasVal || t.Args.Imm.Val == want {
continue
}
// The parser records the argument area with its leading
// minus, so the replacement spans the whole `-16` shape.
rng := clientRange(text, Range{
Start: Position{Line: t.Args.Pos.Line - 1, Character: t.Args.Pos.Column - 1},
End: Position{Line: t.Args.Pos.Line - 1, Character: t.Args.Pos.Column - 1 + runeLen(t.Args.Raw)},
})
actions = append(actions, CodeAction{
Title: fmt.Sprintf("Set arg size to %d", want),
Kind: "quickfix",
Edit: &WorkspaceEdit{
Changes: map[string][]TextEdit{p.TextDocument.URI: {{
Range: rng,
NewText: "-" + strconv.FormatInt(want, 10),
}}},
},
})
}
}
}
return actions