Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions packages/core/src/codewhisperer/util/editorContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ export function extractContextForCodeWhisperer(editor: vscode.TextEditor): codew
)
let languageName = 'plaintext'
if (!checkLeftContextKeywordsForJson(document.fileName, caretLeftFileContext, editor.document.languageId)) {
languageName =
runtimeLanguageContext.normalizeLanguage(editor.document.languageId) ?? editor.document.languageId
languageName = runtimeLanguageContext.resolveLang(editor.document)
}
return {
filename: getFileRelativePath(editor),
Expand Down
24 changes: 20 additions & 4 deletions packages/core/src/codewhisperer/util/runtimeLanguageContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class RuntimeLanguageContext {

constructor() {
this.supportedLanguageMap = createConstantMap<
CodeWhispererConstants.PlatformLanguageId | CodewhispererLanguage,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plaintext is not supported by cwspr, so it doesn't make sense to put it here

Exclude<CodeWhispererConstants.PlatformLanguageId | CodewhispererLanguage, 'plaintext'>,
CodewhispererLanguage
>({
c: 'c',
Expand All @@ -78,7 +78,6 @@ export class RuntimeLanguageContext {
jsx: 'jsx',
kotlin: 'kotlin',
packer: 'tf',
plaintext: 'plaintext',
php: 'php',
python: 'python',
ruby: 'ruby',
Expand All @@ -105,6 +104,7 @@ export class RuntimeLanguageContext {
systemverilog: 'systemVerilog',
verilog: 'systemVerilog',
vue: 'vue',
abap: 'abap',
})
this.supportedLanguageExtensionMap = createConstantMap<string, CodewhispererLanguage>({
c: 'c',
Expand Down Expand Up @@ -145,9 +145,15 @@ export class RuntimeLanguageContext {
ps1: 'powershell',
psm1: 'powershell',
r: 'r',
abap: 'abap',
acds: '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 @@ -267,8 +273,7 @@ export class RuntimeLanguageContext {
} else {
const normalizedLanguageId = this.normalizeLanguage(arg.languageId)
const byLanguageId = !normalizedLanguageId || normalizedLanguageId === 'plaintext' ? false : true
const extension = path.extname(arg.uri.fsPath)
const byFileExtension = this.isFileFormatSupported(extension.substring(1))
const byFileExtension = this.byFileExt(arg) !== undefined

return byLanguageId || byFileExtension
}
Expand All @@ -291,6 +296,17 @@ 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()
39 changes: 39 additions & 0 deletions packages/core/src/shared/telemetry/vscodeTelemetry.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
{
"types": [
{
"name": "codewhispererLanguage",
"type": "string",
"description": "Programming language of the CodeWhisperer recommendation",
"allowedValues": [
"abap",
"c",
"cpp",
"csharp",
"dart",
"go",
"hcl",
"java",
"javascript",
"json",
"jsonc",
"jsx",
"kotlin",
"lua",
"php",
"plaintext",
"powershell",
"python",
"r",
"ruby",
"rust",
"scala",
"shell",
"sql",
"swift",
"systemVerilog",
"tf",
"tsx",
"typescript",
"vue",
"yaml",
"yml"
]
},
{
"name": "amazonQProfileRegion",
"type": "string",
Expand Down
Loading