Files
MyGolandRelease/internal/lsp/syntax_diag_probe_test.go
T
zerorigin 5a87a61e29 fix: 实时诊断波浪线不显示——零长 range 扩展 1 字节后画线
根因:gopls 对语法错误常推零长 range(start==end,插入点),
且常落在行尾,编辑器按零长画线=画不出,用户看不到任何提示。
修复:诊断入编辑器前把零长 range 扩展为 1 字节(行首且列>0 向左扩,否则向右扩),
与 VS Code 显示行为一致。e2e 截图验证波浪线+悬浮提示正常。

附带:
- internal/lsp/syntax_diag_probe_test.go 真 gopls 语法错误诊断推送探针
- internal/godoc CommonPkgs 清单修正(hash/md5 -> crypto/md5 等不存在的包路径)
- .gitignore 增加 *.sock / e2e_shot*.png(Windows 上 socket 文件删不掉导致 add 失败)
2026-11-04 18:12:31 +08:00

71 lines
1.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package lsp
// 探针:语法错误(go func 缺调用括号)gopls 会不会推诊断、带不带版本号。
// 决定「写代码时实时标红」链路在哪一环断掉。
import (
"context"
"path/filepath"
"testing"
"time"
)
func TestProbeSyntaxErrorDiagnostics(t *testing.T) {
if testing.Short() {
t.Skip("集成测试需要 gopls")
}
dir := t.TempDir()
writeFile(t, filepath.Join(dir, "go.mod"), "module demo\n\ngo 1.21\n")
// go func() { ... } 缺最后的 ()——运行时 go run 才报的语法错误。
src := "package main\n\nimport \"fmt\"\n\nfunc main() {\n\tgo func() {\n\t\tfmt.Println(\"123\")\n\t}\n}\n"
path := filepath.Join(dir, "main.go")
writeFile(t, path, src)
type push struct {
ver int
ds []Diagnostic
}
pushes := make(chan push, 16)
c, err := Start(context.Background(), Options{
Root: dir,
Logf: t.Logf,
OnDiagnostics: func(uri string, version int, ds []Diagnostic) {
select {
case pushes <- push{version, ds}:
default:
}
},
})
if err != nil {
t.Skipf("gopls 不可用: %v", err)
}
t.Cleanup(func() { _ = c.Close() })
uri := PathToURI(path)
if err := c.DidOpen(uri, "go", 1, src); err != nil {
t.Fatal(err)
}
deadline := time.After(45 * time.Second)
for {
select {
case p := <-pushes:
t.Logf("推送: version=%d 条数=%d", p.ver, len(p.ds))
for _, d := range p.ds {
t.Logf(" L%d C%d: [%s] %s", d.Range.Start.Line+1, d.Range.Start.Character+1, d.Source, d.Message)
}
if len(p.ds) > 0 {
if p.ver == 0 {
t.Log("version=0:app 层走 buf 分支,应能画出")
} else {
t.Logf("version=%d:app 层要求 == buf.Version() 或 prev.Version()", p.ver)
}
return
}
case <-deadline:
t.Fatal("45 秒内没收到任何诊断——gopls 对语法错误不推送")
}
}
}