Skip to content

Commit aed6187

Browse files
authored
fix: remove duplicate uri of workspace paths sent by VS (#585)
* fix: remove duplicate uri of workspace paths sent by VS * fix: add tests for deduplication filter
1 parent ad940a5 commit aed6187

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

runtimes/runtimes/lsp/router/lspRouter.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,31 @@ describe('LspRouter', () => {
678678
assert.deepStrictEqual(lspRouter.getAllWorkspaceFolders(), expectedFolders)
679679
assert(didChangeWorkspaceFoldersSpy.calledWith({ event }))
680680
})
681+
682+
it('should filter out duplicate workspace folder URIs when adding', () => {
683+
const initialFolders = [
684+
{ name: 'existing', uri: 'file:///existing' },
685+
{ name: 'another', uri: 'file:///another' },
686+
]
687+
lspRouter['workspaceFolders'] = initialFolders
688+
689+
const event = {
690+
added: [
691+
{ name: 'new', uri: 'file:///new' },
692+
{ name: 'duplicate', uri: 'file:///existing' }, // duplicate URI
693+
],
694+
removed: [],
695+
}
696+
697+
lspRouter.didChangeWorkspaceFolders(event)
698+
699+
const expectedFolders = [
700+
{ name: 'existing', uri: 'file:///existing' },
701+
{ name: 'another', uri: 'file:///another' },
702+
{ name: 'new', uri: 'file:///new' },
703+
]
704+
assert.deepStrictEqual(lspRouter.getAllWorkspaceFolders(), expectedFolders)
705+
})
681706
})
682707

683708
describe('didCreateFiles', () => {

runtimes/runtimes/lsp/router/lspRouter.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ ${JSON.stringify({ ...result.capabilities, ...result.awsServerCapabilities })}`
144144
this.workspaceFolders = this.workspaceFolders.filter(
145145
folder => !event.removed.some(removed => removed.uri === folder.uri)
146146
)
147-
this.workspaceFolders.push(...event.added)
147+
this.workspaceFolders.push(
148+
...event.added.filter(added => !this.workspaceFolders.some(existing => existing.uri === added.uri))
149+
)
148150
const params: DidChangeWorkspaceFoldersParams = { event }
149151

150152
this.routeNotificationToAllServers((server, params) => {

0 commit comments

Comments
 (0)