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
9 changes: 4 additions & 5 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.321",
"@aws-toolkits/telemetry": "^1.0.322",
"@playwright/browser-chromium": "^1.43.1",
"@stylistic/eslint-plugin": "^2.11.0",
"@types/he": "^1.2.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Feature",
"description": "Add inline completion support for abap language"
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ describe('runtimeLanguageContext', function () {
'jsx',
'kotlin',
'php',
'plaintext',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

'python',
'ruby',
'rust',
Expand Down Expand Up @@ -288,7 +287,6 @@ describe('runtimeLanguageContext', function () {
['jsx', 'jsx'],
['kotlin', 'kt'],
['php', 'php'],
['plaintext', 'txt'],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

['python', 'py'],
['ruby', 'rb'],
['rust', 'rs'],
Expand Down
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 @@ -151,8 +151,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)
}
if (editor.document.uri.scheme === 'vscode-notebook-cell') {
const notebook = getEnclosingNotebook(editor)
Expand Down
25 changes: 21 additions & 4 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<
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 @@ -85,7 +85,6 @@ export class RuntimeLanguageContext {
jsx: 'jsx',
kotlin: 'kotlin',
packer: 'tf',
plaintext: 'plaintext',
php: 'php',
python: 'python',
ruby: 'ruby',
Expand All @@ -112,6 +111,7 @@ export class RuntimeLanguageContext {
systemverilog: 'systemVerilog',
verilog: 'systemVerilog',
vue: 'vue',
abap: 'abap',
})
this.supportedLanguageExtensionMap = createConstantMap<string, CodewhispererLanguage>({
c: 'c',
Expand Down Expand Up @@ -152,6 +152,8 @@ export class RuntimeLanguageContext {
ps1: 'powershell',
psm1: 'powershell',
r: 'r',
abap: 'abap',
acds: 'abap',
})
this.languageSingleLineCommentPrefixMap = createConstantMap<CodewhispererLanguage, string>({
c: '// ',
Expand Down Expand Up @@ -185,9 +187,14 @@ 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 @@ -317,8 +324,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 @@ -341,6 +347,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()
Loading