Skip to content
Closed
Show file tree
Hide file tree
Changes from 10 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
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",
},
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions packages/amazonq/.changes/1.60.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"date": "2025-04-18",
"version": "1.60.0",
"entries": [
{
"type": "Bug Fix",
"description": "Users might be bound to a customization which they dont have access with the selected profile and it causes service throwing 403 when using inline suggestion and chat features"
}
]
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "bugfix",
"description": "/review: disable auto-review by default"
}
4 changes: 4 additions & 0 deletions packages/amazonq/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.60.0 2025-04-18

- **Bug Fix** Users might be bound to a customization which they dont have access with the selected profile and it causes service throwing 403 when using inline suggestion and chat features

## 1.59.0 2025-04-11

- **Bug Fix** Code fix line number or file is sometimes not accurate
Expand Down
2 changes: 1 addition & 1 deletion packages/amazonq/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "amazon-q-vscode",
"displayName": "Amazon Q",
"description": "The most capable generative AI-powered assistant for building, operating, and transforming software, with advanced capabilities for managing data and AI",
"version": "1.60.0-SNAPSHOT",
"version": "1.61.0-SNAPSHOT",
"extensionKind": [
"workspace"
],
Expand Down
10 changes: 7 additions & 3 deletions packages/amazonq/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { AuthUtils, CredentialsStore, LoginManager, initializeAuth } from 'aws-core-vscode/auth'
import { Auth, AuthUtils, CredentialsStore, LoginManager, initializeAuth } from 'aws-core-vscode/auth'
import { activate as activateCodeWhisperer, shutdown as shutdownCodeWhisperer } from 'aws-core-vscode/codewhisperer'
import { makeEndpointsProvider, registerGenericCommands } from 'aws-core-vscode'
import { CommonAuthWebview } from 'aws-core-vscode/login'
Expand Down Expand Up @@ -43,6 +43,7 @@ import { registerCommands } from './commands'
import { focusAmazonQPanel } from 'aws-core-vscode/codewhispererChat'
import { activate as activateAmazonqLsp } from './lsp/activation'
import { activate as activateInlineCompletion } from './app/inline/activation'
import { isAmazonInternalOs } from 'aws-core-vscode/shared'

export const amazonQContextPrefix = 'amazonq'

Expand Down Expand Up @@ -119,10 +120,13 @@ 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)) {
if (
(Experiments.instance.get('amazonqLSP', false) || Auth.instance.isInternalAmazonUser()) &&
!isAmazonInternalOs()
) {
// start the Amazon Q LSP for internal users first
await activateAmazonqLsp(context)
}

if (!Experiments.instance.get('amazonqLSPInline', false)) {
await activateInlineCompletion()
}
Expand Down
15 changes: 11 additions & 4 deletions packages/amazonq/src/lsp/chat/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,17 @@ export function registerMessageListeners(
languageClient.onRequest<ShowDocumentParams, ShowDocumentResult>(
ShowDocumentRequest.method,
async (params: ShowDocumentParams): Promise<ShowDocumentParams | ResponseError<ShowDocumentResult>> => {
const uri = vscode.Uri.parse(params.uri)
const doc = await vscode.workspace.openTextDocument(uri)
await vscode.window.showTextDocument(doc, { preview: false })
return params
try {
const uri = vscode.Uri.parse(params.uri)
const doc = await vscode.workspace.openTextDocument(uri)
await vscode.window.showTextDocument(doc, { preview: false })
return params
} catch (e) {
return new ResponseError(
LSPErrorCodes.RequestFailed,
`Failed to open document: ${(e as Error).message}`
)
}
}
)

Expand Down
97 changes: 94 additions & 3 deletions packages/amazonq/src/lsp/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,30 @@
import vscode, { env, version } from 'vscode'
import * as nls from 'vscode-nls'
import * as crypto from 'crypto'
import { LanguageClient, LanguageClientOptions } from 'vscode-languageclient'
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,
updateConfigurationRequestType,
WorkspaceFolder,
} from '@aws/language-server-runtimes/protocol'
import {
Settings,
oidcClientName,
createServerOptions,
globals,
Experiments,
Commands,
oneSecond,
validateNodeExe,
getLogger,
} from 'aws-core-vscode/shared'
Expand Down Expand Up @@ -75,6 +87,9 @@ export async function startLanguageServer(
window: {
notifications: true,
},
q: {
developerProfiles: true,
},
},
},
credentials: {
Expand Down Expand Up @@ -134,7 +149,27 @@ export async function startLanguageServer(
activate(client, encryptionKey, resourcePaths.ui)
}

const refreshInterval = auth.startTokenRefreshInterval()
const refreshInterval = auth.startTokenRefreshInterval(10 * oneSecond)

const sendProfileToLsp = async () => {
try {
const result = await client.sendRequest(updateConfigurationRequestType.method, {
section: 'aws.q',
settings: {
profileArn: AuthUtil.instance.regionProfileManager.activeRegionProfile?.arn,
},
})
client.info(
`Client: Updated Amazon Q Profile ${AuthUtil.instance.regionProfileManager.activeRegionProfile?.arn} to Amazon Q LSP`,
result
)
} catch (err) {
client.error('Error when setting Q Developer Profile to Amazon Q LSP', err)
}
}

// send profile to lsp once.
void sendProfileToLsp()

toDispose.push(
AuthUtil.instance.auth.onDidChangeActiveConnection(async () => {
Expand All @@ -143,6 +178,62 @@ export async function startLanguageServer(
AuthUtil.instance.auth.onDidDeleteConnection(async () => {
client.sendNotification(notificationTypes.deleteBearerToken.method)
}),
AuthUtil.instance.regionProfileManager.onDidChangeRegionProfile(sendProfileToLsp),
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 }
}),
} 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)
}),
{ dispose: () => clearInterval(refreshInterval) }
)
})
Expand Down
4 changes: 2 additions & 2 deletions packages/amazonq/src/lsp/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export interface ExtendedAmazonQLSPConfig extends LspConfig {
}

export const defaultAmazonQLspConfig: ExtendedAmazonQLSPConfig = {
manifestUrl: 'https://aws-toolkit-language-servers.amazonaws.com/codewhisperer/0/manifest.json',
supportedVersions: '^3.1.1',
manifestUrl: 'https://aws-toolkit-language-servers.amazonaws.com/remoteWorkspaceContext/0/manifest.json',
supportedVersions: '^1.0.0',
id: 'AmazonQ', // used across IDEs for identifying global storage/local disk locations. Do not change.
suppressPromptPrefix: 'amazonQ',
path: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
pollScanJobStatus,
SecurityScanTimedOutError,
CodeWhispererConstants,
CodeScansState,
} from 'aws-core-vscode/codewhisperer'
import { timeoutUtils } from 'aws-core-vscode/shared'
import assert from 'assert'
Expand Down Expand Up @@ -281,6 +282,7 @@ describe('securityScanHandler', function () {
shouldAdvanceTime: true,
})
sinon.stub(timeoutUtils, 'sleep').resolves()
sinon.stub(CodeScansState.instance, 'isScansEnabled').returns(true)
})

afterEach(function () {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/codewhisperer/models/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export class CodeScansState {
return (this.#instance ??= new this())
}

protected constructor(fallback: boolean = true) {
protected constructor(fallback: boolean = false) {
this.#fallback = fallback
}

Expand Down
18 changes: 18 additions & 0 deletions packages/core/src/codewhisperer/util/editorContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { checkLeftContextKeywordsForJson } from './commonUtil'
import { CodeWhispererSupplementalContext } from '../models/model'
import { getOptOutPreference } from '../../shared/telemetry/util'
import { indent } from '../../shared/utilities/textUtilities'
import { isInDirectory } from '../../shared/filesystemUtilities'
import { AuthUtil } from './authUtil'

let tabSize: number = getTabSizeSetting()
Expand Down Expand Up @@ -83,6 +84,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')
for (const item of workspaceIds.workspaces) {
const path = vscode.Uri.parse(item.workspaceRoot).fsPath
if (isInDirectory(path, editor.document.uri.fsPath)) {
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 @@ -121,6 +138,7 @@ export async function buildListRecommendationRequest(
supplementalContexts: supplementalContext,
customizationArn: selectedCustomization.arn === '' ? undefined : selectedCustomization.arn,
optOutPreference: getOptOutPreference(),
workspaceId: await getWorkspaceId(editor),
profileArn: profile?.arn,
},
supplementalMetadata: supplementalContexts,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export * from './extensionUtilities'
export * from './extensionStartup'
export { RegionProvider } from './regions/regionProvider'
export { Commands } from './vscode/commands2'
export { getMachineId, getServiceEnvVarConfig } from './vscode/env'
export { getMachineId, getServiceEnvVarConfig, isAmazonInternalOs } from './vscode/env'
export { getLogger } from './logger/logger'
export { activateExtension, openUrl } from './utilities/vsCodeUtils'
export { waitUntil, sleep, Timeout } from './utilities/timeoutUtils'
Expand Down
Loading