From db0debf76ec630312fa7edff2f38a7ea578d5c12 Mon Sep 17 00:00:00 2001 From: caixw Date: Wed, 29 Jul 2020 15:36:45 +0800 Subject: [PATCH] =?UTF-8?q?fix(internal/lsp/search):=20=E5=85=81=E8=AE=B8?= =?UTF-8?q?=E9=95=BF=E5=BA=A6=E4=B8=BA=E9=9B=B6=E7=9A=84=20token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 比如 default="" 的属性形式,其值的长度为 0 --- internal/lsp/search/semantic.go | 2 +- internal/lsp/search/semantic_test.go | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) 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() {