Skip to content

Commit 2c60608

Browse files
committed
merge: handle tsUtils conflicts
2 parents 3cf254a + b17b3fa commit 2c60608

File tree

16 files changed

+277
-57
lines changed

16 files changed

+277
-57
lines changed

.github/workflows/node.js.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
- run: npm run testCompile
5858
- run: npm run lint
5959

60-
jscpd:
60+
lint-duplicate-code:
6161
needs: lint-commits
6262
if: ${{ github.event_name == 'pull_request'}}
6363
runs-on: ubuntu-latest
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
version: 0.2
2+
3+
phases:
4+
install:
5+
runtime-versions:
6+
nodejs: 16
7+
8+
commands:
9+
- apt update
10+
- apt install -y wget gpg
11+
- curl -sSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
12+
- install -o root -g root -m 644 packages.microsoft.gpg /etc/apt/trusted.gpg.d/
13+
- sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'
14+
- apt update
15+
- apt install -y code
16+
17+
pre_build:
18+
commands:
19+
# Check for implicit env vars passed from the release pipeline.
20+
- test -n "${TARGET_EXTENSION}"
21+
22+
build:
23+
commands:
24+
- VERSION=$(node -e "console.log(require('./packages/${TARGET_EXTENSION}/package.json').version);")
25+
# get extension name
26+
- |
27+
if [ "${TARGET_EXTENSION}" = "amazonq" ]; then
28+
extension_name="amazonwebservices.amazon-q-vscode"
29+
elif [ "${TARGET_EXTENSION}" = "toolkit" ]; then
30+
extension_name="amazonwebservices.aws-toolkit-vscode"
31+
else
32+
echo checkmarketplace: "Unknown TARGET_EXTENSION: ${TARGET_EXTENSION}"
33+
exit 1
34+
fi
35+
# keep reinstalling the extension until the desired version is updated. Otherwise fail on codebuild timeout (1 hour).
36+
- |
37+
while true; do
38+
code --uninstall-extension "${extension_name}" --no-sandbox --user-data-dir /tmp/vscode
39+
code --install-extension ${extension_name} --no-sandbox --user-data-dir /tmp/vscode
40+
cur_version=$(code --list-extensions --show-versions --no-sandbox --user-data-dir /tmp/vscode | grep ${extension_name} | cut -d'@' -f2)
41+
if [ "${cur_version}" = "${VERSION}" ]; then
42+
echo "checkmarketplace: Extension ${extension_name} is updated to version '${cur_version}.'"
43+
break
44+
else
45+
echo "checkmarketplace: Current version '${cur_version}' does not match expected version '${VERSION}'. Retrying..."
46+
fi
47+
sleep 120 # Wait for 2 minutes before retrying
48+
done

packages/amazonq/src/lsp/lspInstaller.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
fs,
1313
LspResolution,
1414
getNodeExecutableName,
15+
cleanLspDownloads,
1516
} from 'aws-core-vscode/shared'
1617
import path from 'path'
1718

@@ -46,7 +47,7 @@ export class AmazonQLSPResolver implements LspResolver {
4647
const nodePath = path.join(installationResult.assetDirectory, `servers/${getNodeExecutableName()}`)
4748
await fs.chmod(nodePath, 0o755)
4849

49-
// TODO Cleanup old versions of language servers
50+
await cleanLspDownloads(manifest.versions, path.dirname(installationResult.assetDirectory))
5051
return {
5152
...installationResult,
5253
resourcePaths: {

packages/core/package.nls.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"AWS.configuration.description.suppressPrompts": "Prompts which ask for confirmation. Checking an item suppresses the prompt.",
2121
"AWS.configuration.enableCodeLenses": "Enable SAM hints in source code and template.yaml files",
2222
"AWS.configuration.description.resources.enabledResources": "AWS resources to display in the 'Resources' portion of the explorer.",
23-
"AWS.configuration.description.experiments": "Try experimental features and give feedback. Note that experimental features may be removed at any time.\n * `jsonResourceModification` - Enables basic create, update, and delete support for cloud resources via the JSON Resources explorer component.\n * `ec2RemoteConnect` - Allows interfacing with EC2 instances with options to start, stop, and establish remote connections. Remote connections are done over SSM and can be through a terminal or a remote VSCode window.",
23+
"AWS.configuration.description.experiments": "Try experimental features and give feedback. Note that experimental features may be removed at any time.\n * `jsonResourceModification` - Enables basic create, update, and delete support for cloud resources via the JSON Resources explorer component.",
2424
"AWS.stepFunctions.asl.format.enable.desc": "Enables the default formatter used with Amazon States Language files",
2525
"AWS.stepFunctions.asl.maxItemsComputed.desc": "The maximum number of outline symbols and folding regions computed (limited for performance reasons).",
2626
"AWS.configuration.description.awssam.debug.api": "API Gateway configuration",
@@ -295,6 +295,7 @@
295295
"AWS.codewhisperer.customization.notification.new_customizations.learn_more": "Learn More",
296296
"AWS.amazonq.title": "Amazon Q",
297297
"AWS.amazonq.chat": "Chat",
298+
"AWS.amazonq.chat.workspacecontext.enable.message": "Amazon Q: Workspace index is now enabled. You can disable it from Amazon Q settings.",
298299
"AWS.amazonq.security": "Code Issues",
299300
"AWS.amazonq.login": "Login",
300301
"AWS.amazonq.learnMore": "Learn More About Amazon Q",
@@ -404,6 +405,7 @@
404405
"AWS.amazonq.doc.pillText.reject": "Reject",
405406
"AWS.amazonq.doc.pillText.makeChanges": "Make changes",
406407
"AWS.amazonq.inline.invokeChat": "Inline chat",
408+
"AWS.amazonq.opensettings:": "Open settings",
407409
"AWS.toolkit.lambda.walkthrough.quickpickTitle": "Application Builder Walkthrough",
408410
"AWS.toolkit.lambda.walkthrough.title": "Get started building your application",
409411
"AWS.toolkit.lambda.walkthrough.description": "Your quick guide to build an application visually, iterate locally, and deploy to the cloud!",

packages/core/src/amazonq/lsp/workspaceInstaller.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { LanguageServerResolver } from '../../shared/lsp/lspResolver'
1010
import { Range } from 'semver'
1111
import { getNodeExecutableName } from '../../shared/lsp/utils/platform'
1212
import { fs } from '../../shared/fs/fs'
13+
import { cleanLspDownloads } from '../../shared'
1314

1415
const manifestUrl = 'https://aws-toolkit-language-servers.amazonaws.com/q-context/manifest.json'
1516
// this LSP client in Q extension is only going to work with these LSP server versions
@@ -30,7 +31,7 @@ export class WorkspaceLSPResolver implements LspResolver {
3031
const nodePath = path.join(installationResult.assetDirectory, nodeName)
3132
await fs.chmod(nodePath, 0o755)
3233

33-
// TODO Cleanup old versions of language servers
34+
await cleanLspDownloads(manifest.versions, path.basename(installationResult.assetDirectory))
3435
return {
3536
...installationResult,
3637
resourcePaths: {

packages/core/src/awsexplorer/regionNode.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import { getEcsRootNode } from '../awsService/ecs/model'
3030
import { compareTreeItems, TreeShim } from '../shared/treeview/utils'
3131
import { Ec2ParentNode } from '../awsService/ec2/explorer/ec2ParentNode'
3232
import { Ec2Client } from '../shared/clients/ec2Client'
33-
import { Experiments } from '../shared/settings'
3433

3534
interface ServiceNode {
3635
allRegions?: boolean
@@ -64,7 +63,6 @@ const serviceCandidates: ServiceNode[] = [
6463
},
6564
{
6665
serviceId: 'ec2',
67-
when: () => Experiments.instance.isExperimentEnabled('ec2RemoteConnect'),
6866
createFn: (regionCode: string, partitionId: string) =>
6967
new Ec2ParentNode(regionCode, partitionId, new Ec2Client(regionCode)),
7068
},

packages/core/src/shared/featureConfig.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
ListFeatureEvaluationsResponse,
1111
} from '../codewhisperer/client/codewhispereruserclient'
1212
import * as vscode from 'vscode'
13+
import * as nls from 'vscode-nls'
1314
import { codeWhispererClient as client } from '../codewhisperer/client/codewhisperer'
1415
import { AuthUtil } from '../codewhisperer/util/authUtil'
1516
import { getLogger } from './logger'
@@ -19,7 +20,9 @@ import globals from './extensionGlobals'
1920
import { getClientId, getOperatingSystem } from './telemetry/util'
2021
import { extensionVersion } from './vscode/env'
2122
import { telemetry } from './telemetry'
22-
import { Auth } from '../auth'
23+
import { Commands } from './vscode/commands2'
24+
25+
const localize = nls.loadMessageBundle()
2326

2427
export class FeatureContext {
2528
constructor(
@@ -35,6 +38,7 @@ export const Features = {
3538
customizationArnOverride: 'customizationArnOverride',
3639
dataCollectionFeature: 'IDEProjectContextDataCollection',
3740
projectContextFeature: 'ProjectContextV2',
41+
workspaceContextFeature: 'WorkspaceContext',
3842
test: 'testFeature',
3943
} as const
4044

@@ -83,6 +87,21 @@ export class FeatureConfigProvider {
8387
}
8488
}
8589

90+
getWorkspaceContextGroup(): 'control' | 'treatment' {
91+
const variation = this.featureConfigs.get(Features.projectContextFeature)?.variation
92+
93+
switch (variation) {
94+
case 'CONTROL':
95+
return 'control'
96+
97+
case 'TREATMENT':
98+
return 'treatment'
99+
100+
default:
101+
return 'control'
102+
}
103+
}
104+
86105
public async listFeatureEvaluations(): Promise<ListFeatureEvaluationsResponse> {
87106
const request: ListFeatureEvaluationsRequest = {
88107
userContext: {
@@ -154,12 +173,26 @@ export class FeatureConfigProvider {
154173
await vscode.commands.executeCommand('aws.amazonq.refreshStatusBar')
155174
}
156175
}
157-
if (Auth.instance.isInternalAmazonUser()) {
176+
if (this.getWorkspaceContextGroup() === 'treatment') {
158177
// Enable local workspace index by default only once, for Amzn users.
159178
const isSet = globals.globalState.get<boolean>('aws.amazonq.workspaceIndexToggleOn') || false
160179
if (!isSet) {
161180
await CodeWhispererSettings.instance.enableLocalIndex()
162181
globals.globalState.tryUpdate('aws.amazonq.workspaceIndexToggleOn', true)
182+
183+
await vscode.window
184+
.showInformationMessage(
185+
localize(
186+
'AWS.amazonq.chat.workspacecontext.enable.message',
187+
'Amazon Q: Workspace index is now enabled. You can disable it from Amazon Q settings.'
188+
),
189+
localize('AWS.amazonq.opensettings', 'Open settings')
190+
)
191+
.then((r) => {
192+
if (r === 'Open settings') {
193+
void Commands.tryExecute('aws.amazonq.configure').then()
194+
}
195+
})
163196
}
164197
}
165198
} catch (e) {

packages/core/src/shared/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export * from './lsp/manifestResolver'
6464
export * from './lsp/lspResolver'
6565
export * from './lsp/types'
6666
export * from './lsp/utils/setupStage'
67+
export * from './lsp/utils/cleanup'
6768
export { default as request } from './request'
6869
export * from './lsp/utils/platform'
6970
export * as processUtils from './utilities/processUtils'

packages/core/src/shared/lsp/lspResolver.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,13 @@ export class LanguageServerResolver {
382382
return version.targets.find((x) => x.arch === arch && x.platform === platform)
383383
}
384384

385+
// lazy calls to `getApplicationSupportFolder()` to avoid failure on windows.
386+
public static get defaultDir() {
387+
return path.join(getApplicationSupportFolder(), `aws/toolkits/language-servers`)
388+
}
389+
385390
defaultDownloadFolder() {
386-
const applicationSupportFolder = getApplicationSupportFolder()
387-
return path.join(applicationSupportFolder, `aws/toolkits/language-servers/${this.lsName}`)
391+
return path.join(LanguageServerResolver.defaultDir, `${this.lsName}`)
388392
}
389393

390394
private getDownloadDirectory(version: string) {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import path from 'path'
7+
import { LspVersion } from '../types'
8+
import { fs } from '../../../shared/fs/fs'
9+
import { partition } from '../../../shared/utilities/tsUtils'
10+
import { sort } from 'semver'
11+
12+
async function getDownloadedVersions(installLocation: string) {
13+
return (await fs.readdir(installLocation)).map(([f, _], __) => f)
14+
}
15+
16+
function isDelisted(manifestVersions: LspVersion[], targetVersion: string): boolean {
17+
return manifestVersions.find((v) => v.serverVersion === targetVersion)?.isDelisted ?? false
18+
}
19+
20+
/**
21+
* Delete all delisted versions and keep the two newest versions that remain
22+
* @param manifest
23+
* @param downloadDirectory
24+
*/
25+
export async function cleanLspDownloads(manifestVersions: LspVersion[], downloadDirectory: string): Promise<void> {
26+
const downloadedVersions = await getDownloadedVersions(downloadDirectory)
27+
const [delistedVersions, remainingVersions] = partition(downloadedVersions, (v: string) =>
28+
isDelisted(manifestVersions, v)
29+
)
30+
for (const v of delistedVersions) {
31+
await fs.delete(path.join(downloadDirectory, v), { force: true, recursive: true })
32+
}
33+
34+
if (remainingVersions.length <= 2) {
35+
return
36+
}
37+
38+
for (const v of sort(remainingVersions).slice(0, -2)) {
39+
await fs.delete(path.join(downloadDirectory, v), { force: true, recursive: true })
40+
}
41+
}

0 commit comments

Comments
 (0)