From e564ef6c7db08e9739604f6c702cf60f74224ef7 Mon Sep 17 00:00:00 2001 From: Jiatong Li Date: Mon, 19 May 2025 12:54:39 -0700 Subject: [PATCH 1/2] feat(codewhisperer): add fileUri to FileContext (#7294) ## Problem In order to coordinate the new https://github.com/aws/language-servers/pull/1348 change, GenerateCompletions requests would start expecting the `fileUri` field to be set. ## Solution Add `fileUri` to FileContext --- - 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. --------- Co-authored-by: Jiatong Li --- .../test/unit/codewhisperer/util/editorContext.test.ts | 3 +++ packages/core/src/codewhisperer/client/service-2.json | 9 +++++++++ .../core/src/codewhisperer/client/user-service-2.json | 7 +++++++ packages/core/src/codewhisperer/util/editorContext.ts | 1 + 4 files changed, 20 insertions(+) diff --git a/packages/amazonq/test/unit/codewhisperer/util/editorContext.test.ts b/packages/amazonq/test/unit/codewhisperer/util/editorContext.test.ts index f8265a4fa86..3875dbbd0f2 100644 --- a/packages/amazonq/test/unit/codewhisperer/util/editorContext.test.ts +++ b/packages/amazonq/test/unit/codewhisperer/util/editorContext.test.ts @@ -56,6 +56,7 @@ describe('editorContext', function () { const editor = createMockTextEditor('import math\ndef two_sum(nums, target):\n', 'test.py', 'python', 1, 17) const actual = EditorContext.extractContextForCodeWhisperer(editor) const expected: codewhispererClient.FileContext = { + fileUri: 'file:///test.py', filename: 'test.py', programmingLanguage: { languageName: 'python', @@ -76,6 +77,7 @@ describe('editorContext', function () { ) const actual = EditorContext.extractContextForCodeWhisperer(editor) const expected: codewhispererClient.FileContext = { + fileUri: 'file:///test.py', filename: 'test.py', programmingLanguage: { languageName: 'python', @@ -112,6 +114,7 @@ describe('editorContext', function () { const actual = EditorContext.extractContextForCodeWhisperer(editor) const expected: codewhispererClient.FileContext = { + fileUri: editor.document.uri.toString(), filename: 'Untitled-1.py', programmingLanguage: { languageName: 'python', diff --git a/packages/core/src/codewhisperer/client/service-2.json b/packages/core/src/codewhisperer/client/service-2.json index ca57c0f29c6..3e063c38a10 100644 --- a/packages/core/src/codewhisperer/client/service-2.json +++ b/packages/core/src/codewhisperer/client/service-2.json @@ -612,11 +612,20 @@ "filename": { "shape": "FileContextFilenameString" }, + "fileUri": { + "shape": "FileContextFileUriString" + }, "programmingLanguage": { "shape": "ProgrammingLanguage" } } }, + "FileContextFileUriString": { + "type": "string", + "max": 1024, + "min": 1, + "sensitive": true + }, "FileContextFilenameString": { "type": "string", "max": 1024, diff --git a/packages/core/src/codewhisperer/client/user-service-2.json b/packages/core/src/codewhisperer/client/user-service-2.json index 969abf41f1a..714937ed402 100644 --- a/packages/core/src/codewhisperer/client/user-service-2.json +++ b/packages/core/src/codewhisperer/client/user-service-2.json @@ -1852,9 +1852,16 @@ "leftFileContent": { "shape": "FileContextLeftFileContentString" }, "rightFileContent": { "shape": "FileContextRightFileContentString" }, "filename": { "shape": "FileContextFilenameString" }, + "fileUri": { "shape": "FileContextFileUriString" }, "programmingLanguage": { "shape": "ProgrammingLanguage" } } }, + "FileContextFileUriString": { + "type": "string", + "max": 1024, + "min": 1, + "sensitive": true + }, "FileContextFilenameString": { "type": "string", "max": 1024, diff --git a/packages/core/src/codewhisperer/util/editorContext.ts b/packages/core/src/codewhisperer/util/editorContext.ts index 756d9fb2a00..95df5eb509a 100644 --- a/packages/core/src/codewhisperer/util/editorContext.ts +++ b/packages/core/src/codewhisperer/util/editorContext.ts @@ -167,6 +167,7 @@ export function extractContextForCodeWhisperer(editor: vscode.TextEditor): codew } return { + fileUri: editor.document.uri.toString().substring(0, CodeWhispererConstants.filenameCharsLimit), filename: getFileRelativePath(editor), programmingLanguage: { languageName: languageName, From 1d585e99e6cfad694898b0baaaf10fc0ee3031c6 Mon Sep 17 00:00:00 2001 From: Jason Guo <81202082+jguoamz@users.noreply.github.com> Date: Mon, 19 May 2025 14:12:26 -0700 Subject: [PATCH 2/2] feat(chat): Add ripgrep path and make it executable (#7325) ## Problem - AgenticChat will add a grepSearch tool which depends on ripgrep binary ## Solution - Add ripgrep path and make it executable --- - 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. --- packages/amazonq/src/lsp/lspInstaller.ts | 13 ++++++++++++- packages/core/src/shared/lsp/utils/platform.ts | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/amazonq/src/lsp/lspInstaller.ts b/packages/amazonq/src/lsp/lspInstaller.ts index 72fa091f027..84d5ee8961b 100644 --- a/packages/amazonq/src/lsp/lspInstaller.ts +++ b/packages/amazonq/src/lsp/lspInstaller.ts @@ -3,12 +3,17 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { fs, getNodeExecutableName, BaseLspInstaller, ResourcePaths } from 'aws-core-vscode/shared' +import { fs, getNodeExecutableName, getRgExecutableName, BaseLspInstaller, ResourcePaths } from 'aws-core-vscode/shared' import path from 'path' import { ExtendedAmazonQLSPConfig, getAmazonQLspConfig } from './config' export interface AmazonQResourcePaths extends ResourcePaths { ui: string + /** + * Path to `rg` (or `rg.exe`) executable/binary. + * Example: `"/aws/toolkits/language-servers/AmazonQ/3.3.0/servers/rg"` + */ + ripGrep: string } export class AmazonQLspInstaller extends BaseLspInstaller.BaseLspInstaller< @@ -22,6 +27,9 @@ export class AmazonQLspInstaller extends BaseLspInstaller.BaseLspInstaller< protected override async postInstall(assetDirectory: string): Promise { const resourcePaths = this.resourcePaths(assetDirectory) await fs.chmod(resourcePaths.node, 0o755) + if (await fs.exists(resourcePaths.ripGrep)) { + await fs.chmod(resourcePaths.ripGrep, 0o755) + } } protected override resourcePaths(assetDirectory?: string): AmazonQResourcePaths { @@ -29,14 +37,17 @@ export class AmazonQLspInstaller extends BaseLspInstaller.BaseLspInstaller< return { lsp: this.config.path ?? '', node: getNodeExecutableName(), + ripGrep: `ripgrep/${getRgExecutableName()}`, ui: this.config.ui ?? '', } } const nodePath = path.join(assetDirectory, `servers/${getNodeExecutableName()}`) + const rgPath = path.join(assetDirectory, `servers/ripgrep/${getRgExecutableName()}`) return { lsp: path.join(assetDirectory, 'servers/aws-lsp-codewhisperer.js'), node: nodePath, + ripGrep: rgPath, ui: path.join(assetDirectory, 'clients/amazonq-ui.js'), } } diff --git a/packages/core/src/shared/lsp/utils/platform.ts b/packages/core/src/shared/lsp/utils/platform.ts index 2555793ceb5..39284e8a0ac 100644 --- a/packages/core/src/shared/lsp/utils/platform.ts +++ b/packages/core/src/shared/lsp/utils/platform.ts @@ -13,6 +13,10 @@ export function getNodeExecutableName(): string { return process.platform === 'win32' ? 'node.exe' : 'node' } +export function getRgExecutableName(): string { + return process.platform === 'win32' ? 'rg.exe' : 'rg' +} + /** * Get a json payload that will be sent to the language server, who is waiting to know what the encryption key is. * Code reference: https://github.com/aws/language-servers/blob/7da212185a5da75a72ce49a1a7982983f438651a/client/vscode/src/credentialsActivation.ts#L77