diff --git a/packages/core/src/shared/lsp/utils/cleanup.ts b/packages/core/src/shared/lsp/utils/cleanup.ts index 031afbe0888..83b58e2bb8f 100644 --- a/packages/core/src/shared/lsp/utils/cleanup.ts +++ b/packages/core/src/shared/lsp/utils/cleanup.ts @@ -7,10 +7,10 @@ import path from 'path' import { LspVersion } from '../types' import { fs } from '../../../shared/fs/fs' import { partition } from '../../../shared/utilities/tsUtils' -import { sort } from 'semver' +import { parse, sort } from 'semver' -async function getDownloadedVersions(installLocation: string) { - return (await fs.readdir(installLocation)).map(([f, _], __) => f) +export async function getDownloadedVersions(installLocation: string) { + return (await fs.readdir(installLocation)).filter((x) => parse(x[0]) !== null).map(([f, _], __) => f) } function isDelisted(manifestVersions: LspVersion[], targetVersion: string): boolean { diff --git a/packages/core/src/test/shared/lsp/utils/cleanup.test.ts b/packages/core/src/test/shared/lsp/utils/cleanup.test.ts index 75d0654f04f..98f37fff28f 100644 --- a/packages/core/src/test/shared/lsp/utils/cleanup.test.ts +++ b/packages/core/src/test/shared/lsp/utils/cleanup.test.ts @@ -4,7 +4,7 @@ */ import { Uri } from 'vscode' -import { cleanLspDownloads, fs } from '../../../../shared' +import { cleanLspDownloads, fs, getDownloadedVersions } from '../../../../shared' import { createTestWorkspaceFolder } from '../../../testUtil' import path from 'path' import assert from 'assert' @@ -101,4 +101,16 @@ describe('cleanLSPDownloads', function () { assert.strictEqual(result.length, 0) assert.strictEqual(deleted.length, 1) }) + + it('ignores invalid versions', async function () { + await fakeInstallVersions(['1.0.0', '.DS_STORE'], installationDir.fsPath) + const deleted = await cleanLspDownloads( + [{ serverVersion: '1.0.0', isDelisted: true, targets: [] }], + installationDir.fsPath + ) + + const result = await getDownloadedVersions(installationDir.fsPath) + assert.strictEqual(result.length, 0) + assert.strictEqual(deleted.length, 1) + }) })