Skip to content
Closed
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
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"skippedTestReport": "ts-node ./scripts/skippedTestReport.ts ./packages/amazonq/test/e2e/"
},
"devDependencies": {
"@aws-toolkits/telemetry": "^1.0.322",
"@aws-toolkits/telemetry": "^1.0.321",
"@playwright/browser-chromium": "^1.43.1",
"@stylistic/eslint-plugin": "^2.11.0",
"@types/he": "^1.2.3",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ describe('runtimeLanguageContext', function () {
'jsx',
'kotlin',
'php',
'plaintext',
'python',
'ruby',
'rust',
Expand Down Expand Up @@ -287,6 +288,7 @@ describe('runtimeLanguageContext', function () {
['jsx', 'jsx'],
['kotlin', 'kt'],
['php', 'php'],
['plaintext', 'txt'],
['python', 'py'],
['ruby', 'rb'],
['rust', 'rs'],
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/codewhisperer/util/editorContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ export function extractContextForCodeWhisperer(editor: vscode.TextEditor): codew
)
let languageName = 'plaintext'
if (!checkLeftContextKeywordsForJson(document.fileName, caretLeftFileContext, editor.document.languageId)) {
languageName = runtimeLanguageContext.resolveLang(editor.document)
languageName =
runtimeLanguageContext.normalizeLanguage(editor.document.languageId) ?? editor.document.languageId
}
if (editor.document.uri.scheme === 'vscode-notebook-cell') {
const notebook = getEnclosingNotebook(editor)
Expand Down
25 changes: 4 additions & 21 deletions packages/core/src/codewhisperer/util/runtimeLanguageContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class RuntimeLanguageContext {

constructor() {
this.supportedLanguageMap = createConstantMap<
Exclude<CodeWhispererConstants.PlatformLanguageId | CodewhispererLanguage, 'plaintext'>,
CodeWhispererConstants.PlatformLanguageId | CodewhispererLanguage,
CodewhispererLanguage
>({
c: 'c',
Expand All @@ -85,6 +85,7 @@ export class RuntimeLanguageContext {
jsx: 'jsx',
kotlin: 'kotlin',
packer: 'tf',
plaintext: 'plaintext',
php: 'php',
python: 'python',
ruby: 'ruby',
Expand All @@ -111,7 +112,6 @@ export class RuntimeLanguageContext {
systemverilog: 'systemVerilog',
verilog: 'systemVerilog',
vue: 'vue',
abap: 'abap',
})
this.supportedLanguageExtensionMap = createConstantMap<string, CodewhispererLanguage>({
c: 'c',
Expand Down Expand Up @@ -152,8 +152,6 @@ export class RuntimeLanguageContext {
ps1: 'powershell',
psm1: 'powershell',
r: 'r',
abap: 'abap',
acds: 'abap',
})
this.languageSingleLineCommentPrefixMap = createConstantMap<CodewhispererLanguage, string>({
c: '// ',
Expand Down Expand Up @@ -187,14 +185,9 @@ export class RuntimeLanguageContext {
vue: '', // vue lacks a single-line comment prefix
yaml: '# ',
yml: '# ',
abap: '',
})
}

public resolveLang(doc: vscode.TextDocument): CodewhispererLanguage {
return this.normalizeLanguage(doc.languageId) || this.byFileExt(doc) || 'plaintext'
}

/**
* To add a new platform language id:
* 1. add new platform language ID constant in the file codewhisperer/constant.ts
Expand Down Expand Up @@ -324,7 +317,8 @@ export class RuntimeLanguageContext {
} else {
const normalizedLanguageId = this.normalizeLanguage(arg.languageId)
const byLanguageId = !normalizedLanguageId || normalizedLanguageId === 'plaintext' ? false : true
const byFileExtension = this.byFileExt(arg) !== undefined
const extension = path.extname(arg.uri.fsPath)
const byFileExtension = this.isFileFormatSupported(extension.substring(1))

return byLanguageId || byFileExtension
}
Expand All @@ -347,17 +341,6 @@ export class RuntimeLanguageContext {
public getLanguageFromFileExtension(fileExtension: string) {
return this.supportedLanguageExtensionMap.get(fileExtension)
}

private byFileExt(doc: vscode.TextDocument): CodewhispererLanguage | undefined {
const extension = path.extname(doc.uri.fsPath)
const byExt = this.supportedLanguageExtensionMap.get(extension.substring(1))

if (byExt === 'plaintext') {
return undefined
}

return byExt
}
}

export const runtimeLanguageContext = new RuntimeLanguageContext()
Loading