Skip to content

Commit

Permalink
fix: ls provider's score is equal to the default one (#4722)
Browse files Browse the repository at this point in the history
* fix: ls provider's score is equal to the default one

For now, ls provider's score will be equal to the default one if ls
provider's documentSelector has pattern. For example, a ls registers
capability `textDocument/documentHighlight` with documentSelector
`{'language': 'cs', 'scheme': 'file', 'pattern': '**/*.cs'}`, it will
get score 5, which is equal to the default one with documentSelector
'*', even if the language id has matched. Since the capability is
registered later than the default one, DocumentHighlightManager will
only use the default one to provide highlight, which is not expected.

If all of language, scheme, and pattern match, we should return the
highest score of them, instead of the last score.

Signed-off-by: Adam Tao <tcx4c70@gmail.com>

* test: Add a testcase for score

Signed-off-by: Adam Tao <tcx4c70@gmail.com>

---------

Signed-off-by: Adam Tao <tcx4c70@gmail.com>
  • Loading branch information
tcx4c70 committed Aug 22, 2023
1 parent fab97c7 commit 0a2c8b8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/__tests__/modules/workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ describe('workspace methods', () => {
expect(workspace.match([{ scheme: 'file' }], doc.textDocument)).toBe(5)
expect(workspace.match([{ scheme: 'term' }], doc.textDocument)).toBe(0)
expect(workspace.match([{ language: 'xml' }, { scheme: 'file' }], doc.textDocument)).toBe(10)
expect(workspace.match([{ language: 'xml', scheme: 'file', pattern: '**/*.xml' }], doc.textDocument)).toBe(10)
})

it('should handle will save event', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/funcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export function score(selector: DocumentSelector | DocumentFilter | string, uri:
let p = caseInsensitive ? pattern.toLowerCase() : pattern
let f = caseInsensitive ? u.fsPath.toLowerCase() : u.fsPath
if (p === f || minimatch(f, p, { dot: true })) {
ret = 5
ret = Math.max(ret, 5)
} else {
return 0
}
Expand Down

0 comments on commit 0a2c8b8

Please sign in to comment.