Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/core/src/shared/lsp/utils/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 13 additions & 1 deletion packages/core/src/test/shared/lsp/utils/cleanup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
})
})