Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
14f2659
add settings for workspace context feature
leigaol Mar 21, 2025
9df0b01
rc5
leigaol Mar 21, 2025
ce37759
aggressive sync cred
leigaol Mar 21, 2025
f767505
merge
leigaol Mar 23, 2025
86df670
rc8
leigaol Mar 25, 2025
00bf62c
merge
leigaol Mar 25, 2025
37aeb2b
Merge branch 'master' of github.com:leigaol/aws-toolkit-vscode into sspc
leigaol Mar 26, 2025
12d7169
get ws id from flare
leigaol Mar 26, 2025
cb16c75
Merge branch 'master' of github.com:leigaol/aws-toolkit-vscode into sspc
leigaol Mar 27, 2025
b16e0d2
rc 22
leigaol Mar 27, 2025
724308e
merge
leigaol Mar 31, 2025
81597ea
pr
leigaol Mar 31, 2025
9ad7a12
format
leigaol Mar 31, 2025
1a2f2f5
d
leigaol Mar 31, 2025
f71e05b
update
leigaol Mar 31, 2025
5d4b6d9
add message
leigaol Mar 31, 2025
f9433f6
merge
leigaol Apr 1, 2025
836ac80
merge
leigaol Apr 1, 2025
6704a46
update
leigaol Apr 1, 2025
74629c8
update imports:
leigaol Apr 1, 2025
f293cac
minimize changes
leigaol Apr 1, 2025
e596890
minimize changes
leigaol Apr 1, 2025
8194371
update
leigaol Apr 1, 2025
27cf915
merge
leigaol Apr 3, 2025
847cbff
remove settings
leigaol Apr 4, 2025
9387633
Merge branch 'master' of github.com:leigaol/aws-toolkit-vscode into s…
leigaol Apr 15, 2025
97447cd
endpoint
leigaol Apr 15, 2025
3109971
ws
leigaol Apr 15, 2025
ea8582b
default start for internal
leigaol Apr 17, 2025
c6269e7
merge
leigaol Apr 17, 2025
30a9bfb
add profile update
leigaol Apr 17, 2025
7c31f3a
Merge branch 'master' of github.com:leigaol/aws-toolkit-vscode into s…
leigaol Apr 17, 2025
32009cd
update profile and init profile
leigaol Apr 17, 2025
3a71511
profile support
leigaol Apr 17, 2025
ddb9734
update log
leigaol Apr 17, 2025
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
36 changes: 18 additions & 18 deletions aws-toolkit-vscode.code-workspace
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"folders": [
{
"path": "."
},
{
"path": "packages/toolkit"
},
{
"path": "packages/core"
},
{
"path": "packages/amazonq"
}
],
"settings": {
"typescript.tsdk": "node_modules/typescript/lib"
}
}
"folders": [
{
"path": ".",
},
{
"path": "packages/toolkit",
},
{
"path": "packages/core",
},
{
"path": "packages/amazonq",
},
],
"settings": {
"typescript.tsdk": "node_modules/typescript/lib",
},
}
5 changes: 5 additions & 0 deletions packages/amazonq/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@
"default": true,
"scope": "application"
},
"amazonQ.workspaceContext": {
"type": "boolean",
"markdownDescription": "%AWS.configuration.description.amazonq.workspaceContext%",
"default": true
},
"amazonQ.workspaceIndex": {
"type": "boolean",
"markdownDescription": "%AWS.configuration.description.amazonq.workspaceIndex%",
Expand Down
9 changes: 3 additions & 6 deletions packages/amazonq/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,9 @@ export async function activateAmazonQCommon(context: vscode.ExtensionContext, is
}
// This contains every lsp agnostic things (auth, security scan, code scan)
await activateCodeWhisperer(extContext as ExtContext)
if (Experiments.instance.get('amazonqLSP', false)) {
await activateAmazonqLsp(context)
} else {
await activateInlineCompletion()
}

// start Amazon Q LSP for everyone
await activateAmazonqLsp(context)
await activateInlineCompletion()
// Generic extension commands
registerGenericCommands(context, amazonQContextPrefix)

Expand Down
20 changes: 11 additions & 9 deletions packages/amazonq/src/lsp/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@
import vscode from 'vscode'
import { startLanguageServer } from './client'
import { AmazonQLspInstaller } from './lspInstaller'
import { Commands, lspSetupStage, ToolkitError } from 'aws-core-vscode/shared'
import { lspSetupStage, ToolkitError } from 'aws-core-vscode/shared'

export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
try {
await lspSetupStage('all', async () => {
const installResult = await new AmazonQLspInstaller().resolve()
await lspSetupStage('launch', async () => await startLanguageServer(ctx, installResult.resourcePaths))
})
ctx.subscriptions.push(
Commands.register({ id: 'aws.amazonq.invokeInlineCompletion', autoconnect: true }, async () => {
await vscode.commands.executeCommand('editor.action.inlineSuggest.trigger')
}),
vscode.workspace.onDidCloseTextDocument(async () => {
await vscode.commands.executeCommand('aws.amazonq.rejectCodeSuggestion')
})
)
// Do not enable inline code path in LSP from 04/16 to 06/30.
// Workspace context needs to use IDE inline completion code path for AB test
// ctx.subscriptions.push(
// Commands.register({ id: 'aws.amazonq.invokeInlineCompletion', autoconnect: true }, async () => {
// await vscode.commands.executeCommand('editor.action.inlineSuggest.trigger')
// }),
// vscode.workspace.onDidCloseTextDocument(async () => {
// await vscode.commands.executeCommand('aws.amazonq.rejectCodeSuggestion')
// })
// )
} catch (err) {
const e = err as ToolkitError
void vscode.window.showInformationMessage(`Unable to launch amazonq language server: ${e.message}`)
Expand Down
79 changes: 72 additions & 7 deletions packages/amazonq/src/lsp/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@
import vscode, { env, version } from 'vscode'
import * as nls from 'vscode-nls'
import * as crypto from 'crypto'
import { LanguageClient, LanguageClientOptions } from 'vscode-languageclient'
import { InlineCompletionManager } from '../app/inline/completion'
import { LanguageClient, LanguageClientOptions, RequestType } from 'vscode-languageclient'
//import { InlineCompletionManager } from '../app/inline/completion'
import { AmazonQLspAuth, encryptionKey, notificationTypes } from './auth'
import { AuthUtil } from 'aws-core-vscode/codewhisperer'
import { ConnectionMetadata } from '@aws/language-server-runtimes/protocol'
import {
ConnectionMetadata,
CreateFilesParams,
DeleteFilesParams,
DidChangeWorkspaceFoldersParams,
DidSaveTextDocumentParams,
GetConfigurationFromServerParams,
RenameFilesParams,
ResponseMessage,
WorkspaceFolder,
} from '@aws/language-server-runtimes/protocol'
import { Settings, oidcClientName, createServerOptions, globals, Experiments, getLogger } from 'aws-core-vscode/shared'
import { activate } from './chat/activation'
import { AmazonQResourcePaths } from './lspInstaller'
Expand Down Expand Up @@ -94,8 +104,8 @@ export async function startLanguageServer(

return client.onReady().then(async () => {
await auth.init()
const inlineManager = new InlineCompletionManager(client)
inlineManager.registerInlineCompletion()
//const inlineManager = new InlineCompletionManager(client)
//inlineManager.registerInlineCompletion()
if (Experiments.instance.get('amazonqChatLSP', false)) {
activate(client, encryptionKey, resourcePaths.mynahUI)
}
Expand All @@ -117,7 +127,7 @@ export async function startLanguageServer(
getLogger('amazonqLsp').error('Unable to update bearer token: %s', (e as Error).message)
clearInterval(authInterval)
}
}, 300000) // every 5 minutes
}, 30 * 1000) // every 30 seconds

toDispose.push(
AuthUtil.instance.auth.onDidChangeActiveConnection(async () => {
Expand All @@ -126,7 +136,62 @@ export async function startLanguageServer(
AuthUtil.instance.auth.onDidDeleteConnection(async () => {
client.sendNotification(notificationTypes.deleteBearerToken.method)
}),
inlineManager
vscode.commands.registerCommand('aws.amazonq.getWorkspaceId', async () => {
const requestType = new RequestType<GetConfigurationFromServerParams, ResponseMessage, Error>(
'aws/getConfigurationFromServer'
)
const workspaceIdResp = await client.sendRequest(requestType.method, {
section: 'aws.q.workspaceContext',
})
return workspaceIdResp
}),
vscode.workspace.onDidCreateFiles((e) => {
client.sendNotification('workspace/didCreateFiles', {
files: e.files.map((it) => {
return { uri: it.fsPath }
Comment on lines +192 to +194
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this event trigger for in-memory (non-file) editors? If so, should those be skipped, since the LSP can't do anything with them unless we send the file contents?

}),
} as CreateFilesParams)
}),
vscode.workspace.onDidDeleteFiles((e) => {
client.sendNotification('workspace/didDeleteFiles', {
files: e.files.map((it) => {
return { uri: it.fsPath }
}),
} as DeleteFilesParams)
}),
vscode.workspace.onDidRenameFiles((e) => {
client.sendNotification('workspace/didRenameFiles', {
files: e.files.map((it) => {
return { oldUri: it.oldUri.fsPath, newUri: it.newUri.fsPath }
}),
} as RenameFilesParams)
}),
vscode.workspace.onDidSaveTextDocument((e) => {
client.sendNotification('workspace/didSaveTextDocument', {
textDocument: {
uri: e.uri.fsPath,
},
} as DidSaveTextDocumentParams)
}),
vscode.workspace.onDidChangeWorkspaceFolders((e) => {
client.sendNotification('workspace/didChangeWorkspaceFolder', {
event: {
added: e.added.map((it) => {
return {
name: it.name,
uri: it.uri.fsPath,
} as WorkspaceFolder
}),
removed: e.removed.map((it) => {
return {
name: it.name,
uri: it.uri.fsPath,
} as WorkspaceFolder
}),
},
} as DidChangeWorkspaceFoldersParams)
})
//inlineManager
)
})
}
1 change: 1 addition & 0 deletions packages/core/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"AWS.configuration.description.amazonq": "Amazon Q creates a code reference when you insert a code suggestion from Amazon Q that is similar to training data. When unchecked, Amazon Q will not show code suggestions that have code references. If you authenticate through IAM Identity Center, this setting is controlled by your Amazon Q administrator. [Learn More](https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/code-reference.html)",
"AWS.configuration.description.amazonq.shareContentWithAWS": "When checked, your content processed by Amazon Q may be used for service improvement (except for content processed for users with the Amazon Q Developer Pro Tier). Unchecking this box will cause AWS to delete any of your content used for that purpose. The information used to provide the Amazon Q service to you will not be affected. See the [Service Terms](https://aws.amazon.com/service-terms) for more details.",
"AWS.configuration.description.amazonq.importRecommendation": "Amazon Q will add import statements with inline code suggestions when necessary.",
"AWS.configuration.description.amazonq.workspaceContext": "Allow Amazon Q to create remote workspace for quality improvements.",
"AWS.configuration.description.amazonq.workspaceIndex": "When you add @workspace to your question in Amazon Q chat, Amazon Q will index your workspace files locally to use as context for its response. Extra CPU usage is expected while indexing a workspace. This will not impact Amazon Q features or your IDE, but you may manage CPU usage by setting the number of local threads in 'Local Workspace Index Threads'.",
"AWS.configuration.description.amazonq.workspaceIndexWorkerThreads": "Number of worker threads of Amazon Q local index process. '0' will use the system default worker threads for balance performance. You may increase this number to more quickly index your workspace, but only up to your hardware's number of CPU cores. Please restart VS Code or reload the VS Code window after changing worker threads.",
"AWS.configuration.description.amazonq.workspaceIndexUseGPU": "Enable GPU to help index your local workspace files. Only applies to Linux and Windows.",
Expand Down
17 changes: 17 additions & 0 deletions packages/core/src/codewhisperer/util/editorContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ export function getFileRelativePath(editor: vscode.TextEditor): string {
return relativePath.substring(0, CodeWhispererConstants.filenameCharsLimit)
}

async function getWorkspaceId(editor: vscode.TextEditor): Promise<string | undefined> {
try {
const workspaceIds: { workspaces: { workspaceRoot: string; workspaceId: string }[] } =
await vscode.commands.executeCommand('aws.amazonq.getWorkspaceId')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a command instead of a plain function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid cyclic dependency. The Flare LSP code was in the packages/amazonq which imports packages/core, but the CW code here is in packages/core.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the command isn't defined? Sometimes there are startup ordering issues which result in "command not found" errors. Using a plain function would avoid that and add confidence.

There are more robust ways of avoiding cyclic dependencies. Commands should be a last resort.

for (const item of workspaceIds.workspaces) {
const path = vscode.Uri.parse(item.workspaceRoot).fsPath
if (editor.document.uri.fsPath.startsWith(path)) {
return item.workspaceId
}
}
} catch (err) {
getLogger().warn(`No workspace id found ${err}`)
}
return undefined
}

export async function buildListRecommendationRequest(
editor: vscode.TextEditor,
nextToken: string,
Expand Down Expand Up @@ -118,6 +134,7 @@ export async function buildListRecommendationRequest(
supplementalContexts: supplementalContext,
customizationArn: selectedCustomization.arn === '' ? undefined : selectedCustomization.arn,
optOutPreference: getOptOutPreference(),
workspaceId: await getWorkspaceId(editor),
},
supplementalMetadata: supplementalContexts,
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/shared/settings-amazonq.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const amazonqSettings = {
"amazonQ.allowFeatureDevelopmentToRunCodeAndTests": {},
"amazonQ.importRecommendationForInlineCodeSuggestions": {},
"amazonQ.shareContentWithAWS": {},
"amazonQ.workspaceContext": {},
"amazonQ.workspaceIndex": {},
"amazonQ.workspaceIndexWorkerThreads": {},
"amazonQ.workspaceIndexUseGPU": {},
Expand Down
Loading