diff --git a/internal/lsp/search/semantic.go b/internal/lsp/search/semantic.go index 3f12f800..8156c0eb 100644 --- a/internal/lsp/search/semantic.go +++ b/internal/lsp/search/semantic.go @@ -31,7 +31,7 @@ func (b *tokenBuilder) append(r core.Range, token int) { } l := r.End.Character - r.Start.Character - if l <= 0 { + if l < 0 { // 可能存在长度为 0 的,比如 default="" 值的长度为 0 panic(fmt.Sprintf("无效的参数 range,其长度为 %d", l)) } diff --git a/internal/lsp/search/semantic_test.go b/internal/lsp/search/semantic_test.go index 4e2099c8..5444136a 100644 --- a/internal/lsp/search/semantic_test.go +++ b/internal/lsp/search/semantic_test.go @@ -27,12 +27,11 @@ func TestTokenBuilder_append(t *testing.T) { a.Equal(1, len(b.tokens)) // 长度为 0 - a.Panic(func() { - b.append(core.Range{ - Start: core.Position{Line: 1, Character: 11}, - End: core.Position{Line: 1, Character: 11}, - }, 1) - }) + b.append(core.Range{ + Start: core.Position{Line: 1, Character: 11}, + End: core.Position{Line: 1, Character: 11}, + }, 1) + a.Equal(2, len(b.tokens)) // 长度为负数 a.Panic(func() {