Skip to content

Commit cf83957

Browse files
authored
fix(amazonq): invalid version in language server cache causes crash (aws#6808)
## Problem If you have a `.DS_STORE` file in the same directory of the language server cache versions your language server will crash ## Solution Only look for valid semver versions when cleaning up your cache --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 8f77724 commit cf83957

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

packages/core/src/shared/lsp/utils/cleanup.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import path from 'path'
77
import { LspVersion } from '../types'
88
import { fs } from '../../../shared/fs/fs'
99
import { partition } from '../../../shared/utilities/tsUtils'
10-
import { sort } from 'semver'
10+
import { parse, sort } from 'semver'
1111

12-
async function getDownloadedVersions(installLocation: string) {
13-
return (await fs.readdir(installLocation)).map(([f, _], __) => f)
12+
export async function getDownloadedVersions(installLocation: string) {
13+
return (await fs.readdir(installLocation)).filter((x) => parse(x[0]) !== null).map(([f, _], __) => f)
1414
}
1515

1616
function isDelisted(manifestVersions: LspVersion[], targetVersion: string): boolean {

packages/core/src/test/shared/lsp/utils/cleanup.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { Uri } from 'vscode'
7-
import { cleanLspDownloads, fs } from '../../../../shared'
7+
import { cleanLspDownloads, fs, getDownloadedVersions } from '../../../../shared'
88
import { createTestWorkspaceFolder } from '../../../testUtil'
99
import path from 'path'
1010
import assert from 'assert'
@@ -101,4 +101,16 @@ describe('cleanLSPDownloads', function () {
101101
assert.strictEqual(result.length, 0)
102102
assert.strictEqual(deleted.length, 1)
103103
})
104+
105+
it('ignores invalid versions', async function () {
106+
await fakeInstallVersions(['1.0.0', '.DS_STORE'], installationDir.fsPath)
107+
const deleted = await cleanLspDownloads(
108+
[{ serverVersion: '1.0.0', isDelisted: true, targets: [] }],
109+
installationDir.fsPath
110+
)
111+
112+
const result = await getDownloadedVersions(installationDir.fsPath)
113+
assert.strictEqual(result.length, 0)
114+
assert.strictEqual(deleted.length, 1)
115+
})
104116
})

0 commit comments

Comments
 (0)