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
14 changes: 14 additions & 0 deletions packages/core/src/codewhisperer/models/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ export const AWSTemplateKeyWords = ['AWSTemplateFormatVersion', 'Resources', 'AW

export const AWSTemplateCaseInsensitiveKeyWords = ['cloudformation', 'cfn', 'template', 'description']

export const JsonConfigFileNamingConvention = new Set([
'app.json',
'appsettings.json',
'bower.json',
'composer.json',
'db.json',
'manifest.json',
'package.json',
'schema.json',
'settings.json',
'tsconfig.json',
'vcpkg.json',
])

export const normalTextChangeRegex = /[A-Za-z0-9]/g

export const autoSuggestionConfig = {
Expand Down
13 changes: 9 additions & 4 deletions packages/core/src/codewhisperer/util/commonUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import * as vscode from 'vscode'
import * as semver from 'semver'
import { isCloud9 } from '../../shared/extensionUtilities'
import { getInlineSuggestEnabled } from '../../shared/utilities/editorUtilities'
import { AWSTemplateCaseInsensitiveKeyWords, AWSTemplateKeyWords } from '../models/constants'
import {
AWSTemplateCaseInsensitiveKeyWords,
AWSTemplateKeyWords,
JsonConfigFileNamingConvention,
} from '../models/constants'

export function getLocalDatetime() {
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone
Expand Down Expand Up @@ -61,11 +65,12 @@ export function getPrefixSuffixOverlap(firstString: string, secondString: string
return secondString.slice(0, i)
}

export function checkLeftContextKeywordsForJsonAndYaml(leftFileContent: string, language: string): boolean {
export function checkKeywordsForJson(fileName: string, leftFileContent: string, language: string): boolean {
if (
(language === 'json' || language === 'yaml') &&
language === 'json' &&
!AWSTemplateKeyWords.some((substring) => leftFileContent.includes(substring)) &&
!AWSTemplateCaseInsensitiveKeyWords.some((substring) => leftFileContent.toLowerCase().includes(substring))
!AWSTemplateCaseInsensitiveKeyWords.some((substring) => leftFileContent.toLowerCase().includes(substring)) &&
!JsonConfigFileNamingConvention.has(fileName)
) {
return true
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/codewhisperer/util/editorContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { fetchSupplementalContext } from './supplementalContext/supplementalCont
import { supplementalContextTimeoutInMs } from '../models/constants'
import { getSelectedCustomization } from './customizationUtil'
import { selectFrom } from '../../shared/utilities/tsUtils'
import { checkLeftContextKeywordsForJsonAndYaml } from './commonUtil'
import { checkKeywordsForJson } from './commonUtil'
import { CodeWhispererSupplementalContext } from '../models/model'
import { getOptOutPreference } from '../../shared/telemetry/util'

Expand All @@ -39,7 +39,7 @@ export function extractContextForCodeWhisperer(editor: vscode.TextEditor): codew
)
)
let languageName = 'plaintext'
if (!checkLeftContextKeywordsForJsonAndYaml(caretLeftFileContext, editor.document.languageId)) {
if (!checkKeywordsForJson(document.fileName, caretLeftFileContext, editor.document.languageId)) {
languageName =
runtimeLanguageContext.normalizeLanguage(editor.document.languageId) ?? editor.document.languageId
}
Expand Down
Loading