-
Notifications
You must be signed in to change notification settings - Fork 642
fix(amazonq): Profile needing to be selected on server restart #7316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
54ffbde
32f3708
9161c7d
04c91d9
ebceeff
7a525ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"type": "Bug Fix", | ||
"description": "Fix Error: 'Amazon Q service is not signed in'" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"type": "Bug Fix", | ||
"description": "Fix Error: 'Amazon Q Profile is not selected for IDC connection type'" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ import { | |
import { processUtils } from 'aws-core-vscode/shared' | ||
import { activate } from './chat/activation' | ||
import { AmazonQResourcePaths } from './lspInstaller' | ||
import { ConfigSection, isValidConfigSection, toAmazonQLSPLogLevel } from './config' | ||
import { ConfigSection, isValidConfigSection, pushConfigUpdate, toAmazonQLSPLogLevel } from './config' | ||
import { telemetry } from 'aws-core-vscode/telemetry' | ||
|
||
const localize = nls.loadMessageBundle() | ||
|
@@ -160,120 +160,141 @@ export async function startLanguageServer( | |
|
||
const disposable = client.start() | ||
toDispose.push(disposable) | ||
await client.onReady() | ||
|
||
const auth = new AmazonQLspAuth(client) | ||
const auth = await initializeAuth(client) | ||
|
||
return client.onReady().then(async () => { | ||
await auth.refreshConnection() | ||
await postStartLanguageServer(auth, client, resourcePaths, toDispose) | ||
|
||
if (Experiments.instance.get('amazonqLSPInline', false)) { | ||
const inlineManager = new InlineCompletionManager(client) | ||
inlineManager.registerInlineCompletion() | ||
toDispose.push( | ||
inlineManager, | ||
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') | ||
}) | ||
) | ||
} | ||
return client | ||
} | ||
|
||
if (Experiments.instance.get('amazonqChatLSP', true)) { | ||
await activate(client, encryptionKey, resourcePaths.ui) | ||
} | ||
async function initializeAuth(client: LanguageClient): Promise<AmazonQLspAuth> { | ||
AuthUtil.instance.regionProfileManager.onDidChangeRegionProfile(async () => { | ||
nkomonen-amazon marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. technically this listener could trigger before we push the bearer token below in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From testing I haven't found a code path where this happens. This flow will be simplified in flare and I will revisit |
||
void pushConfigUpdate(client, { | ||
type: 'profile', | ||
profileArn: AuthUtil.instance.regionProfileManager.activeRegionProfile?.arn, | ||
}) | ||
}) | ||
|
||
const refreshInterval = auth.startTokenRefreshInterval(10 * oneSecond) | ||
const auth = new AmazonQLspAuth(client) | ||
await auth.refreshConnection(true) | ||
return auth | ||
} | ||
|
||
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) | ||
} | ||
async function postStartLanguageServer( | ||
nkomonen-amazon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
auth: AmazonQLspAuth, | ||
client: LanguageClient, | ||
resourcePaths: AmazonQResourcePaths, | ||
toDispose: vscode.Disposable[] | ||
) { | ||
if (Experiments.instance.get('amazonqLSPInline', false)) { | ||
const inlineManager = new InlineCompletionManager(client) | ||
inlineManager.registerInlineCompletion() | ||
toDispose.push( | ||
inlineManager, | ||
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') | ||
}) | ||
) | ||
} | ||
|
||
if (Experiments.instance.get('amazonqChatLSP', true)) { | ||
await activate(client, encryptionKey, resourcePaths.ui) | ||
} | ||
|
||
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() | ||
// send profile to lsp once. | ||
void sendProfileToLsp() | ||
|
||
toDispose.push( | ||
AuthUtil.instance.auth.onDidChangeActiveConnection(async () => { | ||
await auth.refreshConnection() | ||
}), | ||
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 } | ||
toDispose.push( | ||
AuthUtil.instance.auth.onDidChangeActiveConnection(async () => { | ||
await auth.refreshConnection() | ||
}), | ||
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 | ||
}), | ||
} as CreateFilesParams) | ||
}), | ||
vscode.workspace.onDidDeleteFiles((e) => { | ||
client.sendNotification('workspace/didDeleteFiles', { | ||
files: e.files.map((it) => { | ||
return { uri: it.fsPath } | ||
removed: e.removed.map((it) => { | ||
return { | ||
name: it.name, | ||
uri: it.uri.fsPath, | ||
} as WorkspaceFolder | ||
}), | ||
} 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) }, | ||
// Set this inside onReady so that it only triggers on subsequent language server starts (not the first) | ||
onServerRestartHandler(client, auth) | ||
) | ||
}) | ||
}, | ||
} as DidChangeWorkspaceFoldersParams) | ||
}), | ||
{ dispose: () => clearInterval(refreshInterval) }, | ||
// Set this inside onReady so that it only triggers on subsequent language server starts (not the first) | ||
onServerRestartHandler(client, auth) | ||
) | ||
} | ||
|
||
/** | ||
|
Uh oh!
There was an error while loading. Please reload this page.