Skip to content

Commit 8045bb6

Browse files
authored
Merge branch 'aws:master' into master
2 parents 344a5f3 + 4369fb5 commit 8045bb6

File tree

13 files changed

+124
-27
lines changed

13 files changed

+124
-27
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Avoid inline completion 'Improperly formed request' errors when file is too large"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Named agent tabs sometimes open with unnecessary input options"
4+
}

packages/amazonq/src/lsp/client.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import vscode, { env, version } from 'vscode'
77
import * as nls from 'vscode-nls'
8-
import * as crypto from 'crypto'
98
import { LanguageClient, LanguageClientOptions, RequestType, State } from 'vscode-languageclient'
109
import { InlineCompletionManager } from '../app/inline/completion'
1110
import { AmazonQLspAuth, encryptionKey, notificationTypes } from './auth'
@@ -34,6 +33,7 @@ import {
3433
getOptOutPreference,
3534
isAmazonInternalOs,
3635
fs,
36+
getClientId,
3737
} from 'aws-core-vscode/shared'
3838
import { processUtils } from 'aws-core-vscode/shared'
3939
import { activate } from './chat/activation'
@@ -120,7 +120,7 @@ export async function startLanguageServer(
120120
name: 'AmazonQ-For-VSCode',
121121
version: '0.0.1',
122122
},
123-
clientId: crypto.randomUUID(),
123+
clientId: getClientId(globals.globalState),
124124
},
125125
awsClientCapabilities: {
126126
q: {
@@ -131,6 +131,9 @@ export async function startLanguageServer(
131131
showSaveFileDialog: true,
132132
},
133133
},
134+
contextConfiguration: {
135+
workspaceIdentifier: extensionContext.storageUri,
136+
},
134137
logLevel: toAmazonQLSPLogLevel(globals.logOutputChannel.logLevel),
135138
},
136139
credentials: {

packages/amazonq/test/e2e/lsp/lspInstallerUtil.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
ManifestResolver,
1515
request,
1616
TargetContent,
17+
ToolkitError,
1718
} from 'aws-core-vscode/shared'
1819
import * as semver from 'semver'
1920
import { assertTelemetry } from 'aws-core-vscode/test'
@@ -201,12 +202,6 @@ export function createLspInstallerTests({
201202
id: lspConfig.id,
202203
manifestLocation: 'remote',
203204
languageServerSetupStage: 'getManifest',
204-
result: 'Failed',
205-
},
206-
{
207-
id: lspConfig.id,
208-
manifestLocation: 'cache',
209-
languageServerSetupStage: 'getManifest',
210205
result: 'Succeeded',
211206
},
212207
{
@@ -282,6 +277,34 @@ export function createLspInstallerTests({
282277
const download = await createInstaller(lspConfig).resolve()
283278
assert.ok(download.assetDirectory.endsWith('-rc.0'))
284279
})
280+
281+
it('throws on firewall error', async () => {
282+
// Stub the manifest resolver to return a valid manifest
283+
sandbox.stub(ManifestResolver.prototype, 'resolve').resolves({
284+
manifestSchemaVersion: '0.0.0',
285+
artifactId: 'foo',
286+
artifactDescription: 'foo',
287+
isManifestDeprecated: false,
288+
versions: [createVersion('1.0.0', targetContents)],
289+
})
290+
291+
// Fail all HTTP requests for the language server
292+
sandbox.stub(request, 'fetch').returns({
293+
response: Promise.resolve({
294+
ok: false,
295+
}),
296+
} as any)
297+
298+
// This should now throw a NetworkConnectivityError
299+
await assert.rejects(
300+
async () => await installer.resolve(),
301+
(err: ToolkitError) => {
302+
assert.strictEqual(err.code, 'NetworkConnectivityError')
303+
assert.ok(err.message.includes('Unable to download dependencies'))
304+
return true
305+
}
306+
)
307+
})
285308
})
286309
})
287310
}

packages/amazonq/test/unit/codewhisperer/util/runtimeLanguageContext.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@
44
*/
55

66
import assert from 'assert'
7-
import { resetCodeWhispererGlobalVariables, toTextDocument } from 'aws-core-vscode/test'
7+
import { resetCodeWhispererGlobalVariables, TestFolder, toTextDocument } from 'aws-core-vscode/test'
88
import { runtimeLanguageContext, RuntimeLanguageContext, PlatformLanguageId } from 'aws-core-vscode/codewhisperer'
99
import * as codewhispererClient from 'aws-core-vscode/codewhisperer'
1010
import { CodewhispererLanguage } from 'aws-core-vscode/shared'
1111

1212
describe('runtimeLanguageContext', function () {
1313
const languageContext = new RuntimeLanguageContext()
14+
let tempFolder: TestFolder
15+
16+
before(async function () {
17+
tempFolder = await TestFolder.create()
18+
})
1419

1520
describe('test isLanguageSupported', function () {
1621
const cases: [string, boolean][] = [
@@ -104,13 +109,12 @@ describe('runtimeLanguageContext', function () {
104109
['helloUnknown', false],
105110
['helloFoo.foo', false],
106111
]
107-
108112
for (const tuple of cases) {
109113
const fileName = tuple[0]
110114
const expected = tuple[1]
111115

112116
it(`pass document ${fileName} as argument should first try determine by languageId then file extensions`, async function () {
113-
const doc = await toTextDocument('', fileName)
117+
const doc = await toTextDocument('', fileName, tempFolder.path)
114118
const actual = languageContext.isLanguageSupported(doc)
115119
assert.strictEqual(actual, expected)
116120
})

packages/core/src/amazonq/webview/ui/quickActions/handler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ export class QuickActionHandler {
355355
loadingChat: true,
356356
cancelButtonWhenLoading: false,
357357
})
358+
} else {
359+
this.mynahUI.updateStore(affectedTabId, { promptInputOptions: [] })
358360
}
359361

360362
if (affectedTabId && this.isHybridChatEnabled) {

packages/core/src/codewhisperer/models/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ export const lineBreakWin = '\r\n'
8787
export const supplementalContextTimeoutInMs = 100
8888

8989
export const supplementalContextMaxTotalLength = 20480
90+
91+
export const editorStateMaxLength = 40000
92+
9093
/**
9194
* Ux of recommendations
9295
*/

packages/core/src/codewhisperer/util/customizationUtil.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const onProfileChangedListener: (event: ProfileChangedEvent) => any = asy
5959
if (event.intent === 'customization') {
6060
return
6161
}
62-
62+
const logger = getLogger()
6363
if (!event.profile) {
6464
await setSelectedCustomization(baseCustomization)
6565
return
@@ -69,7 +69,16 @@ export const onProfileChangedListener: (event: ProfileChangedEvent) => any = asy
6969
const selectedCustomization = getSelectedCustomization()
7070
// No need to validate base customization which has empty arn.
7171
if (selectedCustomization.arn.length > 0) {
72-
await switchToBaseCustomizationAndNotify()
72+
const customizationProvider = await CustomizationProvider.init(event.profile)
73+
const customizations = await customizationProvider.listAvailableCustomizations()
74+
75+
const r = customizations.find((it) => it.arn === selectedCustomization.arn)
76+
if (!r) {
77+
logger.debug(
78+
`profile ${event.profile.name} doesnt have access to customization ${selectedCustomization.name} but has access to ${customizations.map((it) => it.name)}`
79+
)
80+
await switchToBaseCustomizationAndNotify()
81+
}
7382
}
7483
}
7584

packages/core/src/codewhisperer/util/editorContext.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import * as codewhispererClient from '../client/codewhisperer'
88
import * as path from 'path'
99
import * as CodeWhispererConstants from '../models/constants'
1010
import { getTabSizeSetting } from '../../shared/utilities/editorUtilities'
11+
import { truncate } from '../../shared/utilities/textUtilities'
1112
import { getLogger } from '../../shared/logger/logger'
1213
import { runtimeLanguageContext } from './runtimeLanguageContext'
1314
import { fetchSupplementalContext } from './supplementalContext/supplementalContextUtil'
14-
import { supplementalContextTimeoutInMs } from '../models/constants'
15+
import { editorStateMaxLength, supplementalContextTimeoutInMs } from '../models/constants'
1516
import { getSelectedCustomization } from './customizationUtil'
1617
import { selectFrom } from '../../shared/utilities/tsUtils'
1718
import { checkLeftContextKeywordsForJson } from './commonUtil'
@@ -216,13 +217,29 @@ export function getTabSize(): number {
216217

217218
export function getEditorState(editor: vscode.TextEditor, fileContext: codewhispererClient.FileContext): any {
218219
try {
220+
const cursorPosition = editor.selection.active
221+
const cursorOffset = editor.document.offsetAt(cursorPosition)
222+
const documentText = editor.document.getText()
223+
224+
// Truncate if document content is too large (defined in constants.ts)
225+
let fileText = documentText
226+
if (documentText.length > editorStateMaxLength) {
227+
const halfLength = Math.floor(editorStateMaxLength / 2)
228+
229+
// Use truncate function to get the text around the cursor position
230+
const leftPart = truncate(documentText.substring(0, cursorOffset), -halfLength, '')
231+
const rightPart = truncate(documentText.substring(cursorOffset), halfLength, '')
232+
233+
fileText = leftPart + rightPart
234+
}
235+
219236
return {
220237
document: {
221238
programmingLanguage: {
222239
languageName: fileContext.programmingLanguage.languageName,
223240
},
224241
relativeFilePath: fileContext.filename,
225-
text: editor.document.getText(),
242+
text: fileText,
226243
},
227244
cursorState: {
228245
position: {

packages/core/src/shared/lsp/baseLspInstaller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export abstract class BaseLspInstaller<T extends ResourcePaths = ResourcePaths,
4545
new Range(supportedVersions, {
4646
includePrerelease: true,
4747
}),
48+
manifestUrl,
4849
this.downloadMessageOverride
4950
).resolve()
5051

0 commit comments

Comments
 (0)