Skip to content

Commit

Permalink
fix(internal/lsp/search): 允许长度为零的 token
Browse files Browse the repository at this point in the history
比如 default="" 的属性形式,其值的长度为 0
  • Loading branch information
caixw committed Jul 29, 2020
1 parent 8c56a05 commit db0debf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion internal/lsp/search/semantic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
11 changes: 5 additions & 6 deletions internal/lsp/search/semantic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit db0debf

Please sign in to comment.