Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 docs/lsp.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ sequenceDiagram
"amazonqLSPChat": true // optional: enables chat from flare
}
```
4. Uncomment the `__AMAZONQLSP_PATH` variable in `amazonq/.vscode/launch.json` Extension configuration
1. Uncomment the `__AMAZONQLSP_UI` variable in `amazonq/.vscode/launch.json` Extension configuration if you want to debug the flare chat-client as well
4. Uncomment the `__AMAZONQLSP_PATH` and `__AMAZONQLSP_UI` variables in the `amazonq/.vscode/launch.json` extension configuration
5. Use the `Launch LSP with Debugging` configuration and set breakpoints in VSCode or the language server
6. (Optional): Enable `"amazonq.trace.server": "on"` or `"amazonq.trace.server": "verbose"` in your VSCode settings to view detailed log messages sent to/from the language server. These log messages will show up in the "Amazon Q Language Server" output channel

## Amazon Q Inline Activation

Expand Down
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"
}
2 changes: 1 addition & 1 deletion packages/amazonq/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"env": {
"SSMDOCUMENT_LANGUAGESERVER_PORT": "6010",
"WEBPACK_DEVELOPER_SERVER": "http://localhost:8080"
// "__AMAZONQLSP_PATH": "${workspaceFolder}/../../../language-servers/app/aws-lsp-codewhisperer-runtimes/out/token-standalone.js",
// "__AMAZONQLSP_PATH": "${workspaceFolder}/../../../language-servers/app/aws-lsp-codewhisperer-runtimes/out/agent-standalone.js",
// "__AMAZONQLSP_UI": "${workspaceFolder}/../../../language-servers/chat-client/build/amazonq-ui.js"
},
"envFile": "${workspaceFolder}/.local.env",
Expand Down
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', true)) {
if (
(Experiments.instance.get('amazonqLSP', true) || 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
22 changes: 15 additions & 7 deletions packages/amazonq/src/lsp/chat/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import { AuthUtil } from 'aws-core-vscode/codewhisperer'
import { updateConfigurationRequestType } from '@aws/language-server-runtimes/protocol'

export async function activate(languageClient: LanguageClient, encryptionKey: Buffer, mynahUIPath: string) {
const disposables = globals.context.subscriptions

// Make sure we've sent an auth profile to the language server before even initializing the UI
await updateProfile(languageClient)

const provider = new AmazonQChatViewProvider(mynahUIPath)

globals.context.subscriptions.push(
disposables.push(
window.registerWebviewViewProvider(AmazonQChatViewProvider.viewType, provider, {
webviewOptions: {
retainContextWhenHidden: true,
Expand All @@ -36,12 +38,18 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu
registerLanguageServerEventListener(languageClient, provider)

provider.onDidResolveWebview(() => {
if (provider.webview) {
DefaultAmazonQAppInitContext.instance.getAppsToWebViewMessageListener().onMessage((msg) => {
provider.webview?.postMessage(msg).then(undefined, (e) => {
getLogger().error('webView.postMessage failed: %s', (e as Error).message)
})
const disposable = DefaultAmazonQAppInitContext.instance.getAppsToWebViewMessageListener().onMessage((msg) => {
provider.webview?.postMessage(msg).then(undefined, (e) => {
getLogger().error('webView.postMessage failed: %s', (e as Error).message)
})
})

if (provider.webviewView) {
disposables.push(
provider.webviewView.onDidDispose(() => {
disposable.dispose()
})
)
}

registerMessageListeners(languageClient, provider, encryptionKey)
Expand All @@ -50,7 +58,7 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu
// register event listeners from the legacy agent flow
await registerLegacyChatListeners(globals.context)

globals.context.subscriptions.push(
disposables.push(
AuthUtil.instance.regionProfileManager.onDidChangeRegionProfile(async () => {
void updateProfile(languageClient)
await provider.refreshWebview()
Expand Down
32 changes: 27 additions & 5 deletions packages/amazonq/src/lsp/chat/webviewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import {
EventEmitter,
CancellationToken,
Webview,
WebviewView,
WebviewViewProvider,
WebviewViewResolveContext,
Uri,
Webview,
} from 'vscode'
import * as path from 'path'
import {
Expand All @@ -22,13 +22,15 @@ import {
} from 'aws-core-vscode/shared'
import { AuthUtil, RegionProfile } from 'aws-core-vscode/codewhisperer'
import { featureConfig } from 'aws-core-vscode/amazonq'
import { getAmazonQLspConfig } from '../config'

export class AmazonQChatViewProvider implements WebviewViewProvider {
public static readonly viewType = 'aws.amazonq.AmazonQChatView'
private readonly onDidResolveWebviewEmitter = new EventEmitter<void>()
public readonly onDidResolveWebview = this.onDidResolveWebviewEmitter.event

webview: Webview | undefined
webviewView?: WebviewView
webview?: Webview

connectorAdapterPath?: string
uiPath?: string
Expand All @@ -40,14 +42,25 @@ export class AmazonQChatViewProvider implements WebviewViewProvider {
context: WebviewViewResolveContext,
_token: CancellationToken
) {
this.webview = webviewView.webview

const lspDir = Uri.parse(LanguageServerResolver.defaultDir())
const dist = Uri.joinPath(globals.context.extensionUri, 'dist')

const resourcesRoots = [lspDir, dist]

/**
* if the mynah chat client is defined, then make sure to add it to the resource roots, otherwise
* it will 401 when trying to load
*/
const mynahUIPath = getAmazonQLspConfig().ui
if (process.env.WEBPACK_DEVELOPER_SERVER && mynahUIPath) {
const dir = path.dirname(mynahUIPath)
resourcesRoots.push(Uri.parse(dir))
}

webviewView.webview.options = {
enableScripts: true,
enableCommandUris: true,
localResourceRoots: [lspDir, dist],
localResourceRoots: resourcesRoots,
}

const source = 'vue/src/amazonq/webview/ui/amazonq-ui-connector-adapter.js' // Sent to dist/vue folder in webpack.
Expand All @@ -63,7 +76,16 @@ export class AmazonQChatViewProvider implements WebviewViewProvider {

webviewView.webview.html = await this.getWebviewContent()

this.webviewView = webviewView
this.webview = this.webviewView.webview

this.onDidResolveWebviewEmitter.fire()
globals.context.subscriptions.push(
this.webviewView.onDidDispose(() => {
this.webviewView = undefined
this.webview = undefined
})
)
performance.mark(amazonqMark.open)
}

Expand Down
94 changes: 91 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 @@ -138,7 +150,27 @@ export async function startLanguageServer(
await 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 @@ -147,6 +179,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
Loading
Loading