Skip to content

Commit a45aac7

Browse files
committed
fix isLanguageSupported only relies on if platform (vscode) recognize the provided file, should fallback to determine if the provided file is supported or not by file extension
1 parent a77ec12 commit a45aac7

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

packages/core/src/codewhisperer/activation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ export async function activate(context: ExtContext): Promise<void> {
478478
if (e.document !== editor.document) {
479479
return
480480
}
481-
if (!runtimeLanguageContext.isLanguageSupported(e.document.languageId)) {
481+
if (!runtimeLanguageContext.isLanguageSupported(e.document)) {
482482
return
483483
}
484484

@@ -549,7 +549,7 @@ export async function activate(context: ExtContext): Promise<void> {
549549
if (e.document !== editor.document) {
550550
return
551551
}
552-
if (!runtimeLanguageContext.isLanguageSupported(e.document.languageId)) {
552+
if (!runtimeLanguageContext.isLanguageSupported(e.document)) {
553553
return
554554
}
555555
/**

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
import * as vscode from 'vscode'
67
import { getLogger } from '../../shared/logger/logger'
78
import { CodewhispererLanguage } from '../../shared/telemetry/telemetry.gen'
89
import { createConstantMap, ConstantMap } from '../../shared/utilities/tsUtils'
910
import * as codewhispererClient from '../client/codewhisperer'
1011
import * as CodeWhispererConstants from '../models/constants'
12+
import * as path from 'path'
1113

1214
type RuntimeLanguage = Exclude<CodewhispererLanguage, 'jsx' | 'tsx' | 'systemVerilog'> | 'systemverilog'
1315

@@ -251,24 +253,24 @@ export class RuntimeLanguageContext {
251253
}
252254
}
253255

254-
/**
255-
*
256-
* @param languageId: either vscodeLanguageId or CodewhispererLanguage
257-
* @returns true if the language is supported by CodeWhisperer otherwise false
258-
*/
259-
public isLanguageSupported(languageId: string): boolean {
260-
const lang = this.normalizeLanguage(languageId)
261-
switch (lang) {
262-
case undefined:
263-
return false
256+
public isLanguageSupported(languageId: string): boolean
257+
public isLanguageSupported(doc: vscode.TextDocument): boolean
258+
public isLanguageSupported(arg: string | vscode.TextDocument): boolean {
259+
if (typeof arg === 'string') {
260+
const normalizedLanguageId = this.normalizeLanguage(arg)
261+
const byLanguageId = !normalizedLanguageId || normalizedLanguageId === 'plaintext' ? false : true
264262

265-
case 'plaintext':
266-
return false
263+
return byLanguageId
264+
} else {
265+
const normalizedLanguageId = this.normalizeLanguage(arg.languageId)
266+
const byLanguageId = !normalizedLanguageId || normalizedLanguageId === 'plaintext' ? false : true
267+
const extension = path.extname(arg.uri.fsPath)
268+
const byFileExtension = this.isFileFormatSupported(extension.substring(1))
267269

268-
default:
269-
return true
270+
return byLanguageId || byFileExtension
270271
}
271272
}
273+
272274
/**
273275
*
274276
* @param fileFormat : vscode editor filecontext filename extension

0 commit comments

Comments
 (0)