-
Notifications
You must be signed in to change notification settings - Fork 751
feat(lsp): older and delisted versions of lsp are automatically removed #6409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
9cd4544
implement heuristic
Hweinstock e7bf0af
clean up handling on optional args
Hweinstock 90d23b1
add tests for utility method
Hweinstock 2c19cf4
fetch versions from manifest file
Hweinstock 1c366ef
skip integ tests on non-mac
Hweinstock b00ec0d
skip beforeAll hook on non-mac
Hweinstock 4198611
pull out helper function so that it can be used by other modules
Hweinstock 32d2ba3
handle case where remaining versions is 2 or less
Hweinstock a7a89c1
add comment to partition helper function
Hweinstock ee7343b
remove special logic for integ tests
Hweinstock 604d2e1
increase test coverage for cases when < 2 versions
Hweinstock 78aae8f
rename file
Hweinstock 3b9878f
Merge branch 'feature/amazonqLSP' into lsp/cleanUp
Hweinstock 3b693c6
fix: generalize cleanup to apply to other installer
Hweinstock d5b972e
refactor: avoid exporting unnecessarily
Hweinstock bf36a48
refactor: reduce noise in changes
Hweinstock 88db689
refactor: move cleanup work to more general location
Hweinstock bace7ca
refactor: rename cleanup function and move test file
Hweinstock 5e47cb5
Merge branch 'feature/amazonqLSP' into lsp/cleanup
Hweinstock da20782
fix: migrate old name
Hweinstock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /*! | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import path from 'path' | ||
| import { LspVersion } from '../types' | ||
| import { fs } from '../../../shared/fs/fs' | ||
| import { partition } from '../../../shared/utilities/tsUtils' | ||
| import { sort } from 'semver' | ||
|
|
||
| async function getDownloadedVersions(installLocation: string) { | ||
| return (await fs.readdir(installLocation)).map(([f, _], __) => f) | ||
| } | ||
|
|
||
| function isDelisted(manifestVersions: LspVersion[], targetVersion: string): boolean { | ||
| return manifestVersions.find((v) => v.serverVersion === targetVersion)?.isDelisted ?? false | ||
| } | ||
|
|
||
| /** | ||
| * Delete all delisted versions and keep the two newest versions that remain | ||
| * @param manifest | ||
| * @param downloadDirectory | ||
| */ | ||
| export async function cleanUpLSPDownloads(manifestVersions: LspVersion[], downloadDirectory: string): Promise<void> { | ||
| const downloadedVersions = await getDownloadedVersions(downloadDirectory) | ||
| const [delistedVersions, remainingVersions] = partition(downloadedVersions, (v: string) => | ||
| isDelisted(manifestVersions, v) | ||
| ) | ||
| for (const v of delistedVersions) { | ||
| await fs.delete(path.join(downloadDirectory, v), { force: true, recursive: true }) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess force=true avoids any potential failures. So we don't need to use |
||
| } | ||
|
|
||
| if (remainingVersions.length <= 2) { | ||
| return | ||
| } | ||
|
|
||
| for (const v of sort(remainingVersions).slice(0, -2)) { | ||
| await fs.delete(path.join(downloadDirectory, v), { force: true, recursive: true }) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /*! | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { Uri } from 'vscode' | ||
| import { cleanUpLSPDownloads, fs } from '../../../shared' | ||
| import { createTestWorkspaceFolder } from '../../testUtil' | ||
| import path from 'path' | ||
| import assert from 'assert' | ||
|
|
||
| async function fakeInstallVersion(version: string, installationDir: string): Promise<void> { | ||
| const versionDir = path.join(installationDir, version) | ||
| await fs.mkdir(versionDir) | ||
| await fs.writeFile(path.join(versionDir, 'file.txt'), 'content') | ||
| } | ||
|
|
||
| async function fakeInstallVersions(versions: string[], installationDir: string): Promise<void> { | ||
| for (const v of versions) { | ||
| await fakeInstallVersion(v, installationDir) | ||
| } | ||
| } | ||
|
|
||
| describe('cleanUpLSPDownloads', function () { | ||
| let installationDir: Uri | ||
|
|
||
| before(async function () { | ||
| installationDir = (await createTestWorkspaceFolder()).uri | ||
| }) | ||
|
|
||
| afterEach(async function () { | ||
| const files = await fs.readdir(installationDir.fsPath) | ||
| for (const [name, _type] of files) { | ||
| await fs.delete(path.join(installationDir.fsPath, name), { force: true, recursive: true }) | ||
| } | ||
| }) | ||
|
|
||
| after(async function () { | ||
| await fs.delete(installationDir, { force: true, recursive: true }) | ||
| }) | ||
|
|
||
| it('keeps two newest versions', async function () { | ||
| await fakeInstallVersions(['1.0.0', '1.0.1', '1.1.1', '2.1.1'], installationDir.fsPath) | ||
| await cleanUpLSPDownloads([], installationDir.fsPath) | ||
|
|
||
| const result = (await fs.readdir(installationDir.fsPath)).map(([filename, _filetype], _index) => filename) | ||
| assert.strictEqual(result.length, 2) | ||
| assert.ok(result.includes('2.1.1')) | ||
| assert.ok(result.includes('1.1.1')) | ||
| }) | ||
|
|
||
| it('deletes delisted versions', async function () { | ||
| await fakeInstallVersions(['1.0.0', '1.0.1', '1.1.1', '2.1.1'], installationDir.fsPath) | ||
| await cleanUpLSPDownloads([{ serverVersion: '1.1.1', isDelisted: true, targets: [] }], installationDir.fsPath) | ||
|
|
||
| const result = (await fs.readdir(installationDir.fsPath)).map(([filename, _filetype], _index) => filename) | ||
| assert.strictEqual(result.length, 2) | ||
| assert.ok(result.includes('2.1.1')) | ||
| assert.ok(result.includes('1.0.1')) | ||
| }) | ||
|
|
||
| it('handles case where less than 2 versions are not delisted', async function () { | ||
| await fakeInstallVersions(['1.0.0', '1.0.1', '1.1.1', '2.1.1'], installationDir.fsPath) | ||
| await cleanUpLSPDownloads( | ||
| [ | ||
| { serverVersion: '1.1.1', isDelisted: true, targets: [] }, | ||
| { serverVersion: '2.1.1', isDelisted: true, targets: [] }, | ||
| { serverVersion: '1.0.0', isDelisted: true, targets: [] }, | ||
| ], | ||
| installationDir.fsPath | ||
| ) | ||
|
|
||
| const result = (await fs.readdir(installationDir.fsPath)).map(([filename, _filetype], _index) => filename) | ||
| assert.strictEqual(result.length, 1) | ||
| assert.ok(result.includes('1.0.1')) | ||
| }) | ||
|
|
||
| it('handles case where less than 2 versions exist', async function () { | ||
| await fakeInstallVersions(['1.0.0'], installationDir.fsPath) | ||
| await cleanUpLSPDownloads([], installationDir.fsPath) | ||
|
|
||
| const result = (await fs.readdir(installationDir.fsPath)).map(([filename, _filetype], _index) => filename) | ||
| assert.strictEqual(result.length, 1) | ||
| }) | ||
|
|
||
| it('does not install delisted version when no other option exists', async function () { | ||
| await fakeInstallVersions(['1.0.0'], installationDir.fsPath) | ||
| await cleanUpLSPDownloads([{ serverVersion: '1.0.0', isDelisted: true, targets: [] }], installationDir.fsPath) | ||
|
|
||
| const result = (await fs.readdir(installationDir.fsPath)).map(([filename, _filetype], _index) => filename) | ||
| assert.strictEqual(result.length, 0) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| /*! | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { partition } from '../../../shared/utilities/tsUtils' | ||
| import assert from 'assert' | ||
|
|
||
| describe('partition', function () { | ||
| it('should split the list according to predicate', function () { | ||
| const items = [1, 2, 3, 4, 5, 6, 7, 8] | ||
| const [even, odd] = partition(items, (i) => i % 2 === 0) | ||
| assert.deepStrictEqual(even, [2, 4, 6, 8]) | ||
| assert.deepStrictEqual(odd, [1, 3, 5, 7]) | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.