|
3 | 3 | * SPDX-License-Identifier: Apache-2.0 |
4 | 4 | */ |
5 | 5 |
|
| 6 | +import * as vscode from 'vscode' |
6 | 7 | import { getLogger } from '../../shared/logger/logger' |
7 | 8 | import { CodewhispererLanguage } from '../../shared/telemetry/telemetry.gen' |
8 | 9 | import { createConstantMap, ConstantMap } from '../../shared/utilities/tsUtils' |
9 | 10 | import * as codewhispererClient from '../client/codewhisperer' |
10 | 11 | import * as CodeWhispererConstants from '../models/constants' |
| 12 | +import * as path from 'path' |
11 | 13 |
|
12 | 14 | type RuntimeLanguage = Exclude<CodewhispererLanguage, 'jsx' | 'tsx' | 'systemVerilog'> | 'systemverilog' |
13 | 15 |
|
@@ -251,24 +253,24 @@ export class RuntimeLanguageContext { |
251 | 253 | } |
252 | 254 | } |
253 | 255 |
|
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 |
264 | 262 |
|
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)) |
267 | 269 |
|
268 | | - default: |
269 | | - return true |
| 270 | + return byLanguageId || byFileExtension |
270 | 271 | } |
271 | 272 | } |
| 273 | + |
272 | 274 | /** |
273 | 275 | * |
274 | 276 | * @param fileFormat : vscode editor filecontext filename extension |
|
0 commit comments