From 61ca32558bd9de67c8967dd083c86eb00e1bc65a Mon Sep 17 00:00:00 2001 From: hkobew Date: Thu, 24 Oct 2024 14:37:42 -0400 Subject: [PATCH 1/3] remove duplicate list of language names --- .../editor/context/file/languages.ts | 136 ++++++------------ 1 file changed, 46 insertions(+), 90 deletions(-) diff --git a/packages/core/src/codewhispererChat/editor/context/file/languages.ts b/packages/core/src/codewhispererChat/editor/context/file/languages.ts index b2dac49f2ad..e5d733c1660 100644 --- a/packages/core/src/codewhispererChat/editor/context/file/languages.ts +++ b/packages/core/src/codewhispererChat/editor/context/file/languages.ts @@ -5,57 +5,57 @@ import { TextDocument } from 'vscode' +const validLanguageIds = [ + 'yaml', + 'xsl', + 'xml', + 'vue', + 'tex', + 'typescript', + 'swift', + 'stylus', + 'sql', + 'slim', + 'shaderlab', + 'sass', + 'rust', + 'ruby', + 'r', + 'python', + 'pug', + 'powershell', + 'php', + 'perl', + 'markdown', + 'makefile', + 'lua', + 'less', + 'latex', + 'json', + 'javascript', + 'java', + 'ini', + 'html', + 'haml', + 'handlebars', + 'groovy', + 'go', + 'diff', + 'css', + 'c', + 'coffeescript', + 'clojure', + 'bibtex', + 'abap', +] + export function extractLanguageNameFromFile(file: TextDocument): string | undefined { const languageId = file.languageId if (languageId === undefined) { return undefined } - if ( - [ - 'yaml', - 'xsl', - 'xml', - 'vue', - 'tex', - 'typescript', - 'swift', - 'stylus', - 'sql', - 'slim', - 'shaderlab', - 'sass', - 'rust', - 'ruby', - 'r', - 'python', - 'pug', - 'powershell', - 'php', - 'perl', - 'markdown', - 'makefile', - 'lua', - 'less', - 'latex', - 'json', - 'javascript', - 'java', - 'ini', - 'html', - 'haml', - 'handlebars', - 'groovy', - 'go', - 'diff', - 'css', - 'c', - 'coffeescript', - 'clojure', - 'bibtex', - 'abap', - ].includes(languageId) - ) { + if (validLanguageIds.includes(languageId)) { return languageId } switch (languageId) { @@ -120,51 +120,7 @@ export function extractAdditionalLanguageMatchPoliciesFromFile(file: TextDocumen if (languageId === undefined) { return new Set() } - if ( - [ - 'yaml', - 'xsl', - 'xml', - 'vue', - 'tex', - 'typescript', - 'swift', - 'stylus', - 'sql', - 'slim', - 'shaderlab', - 'sass', - 'rust', - 'ruby', - 'r', - 'python', - 'pug', - 'powershell', - 'php', - 'perl', - 'markdown', - 'makefile', - 'lua', - 'less', - 'latex', - 'json', - 'javascript', - 'java', - 'ini', - 'html', - 'haml', - 'handlebars', - 'groovy', - 'go', - 'diff', - 'css', - 'c', - 'coffeescript', - 'clojure', - 'bibtex', - 'abap', - ].includes(languageId) - ) { + if (validLanguageIds.includes(languageId)) { return new Set() } switch (languageId) { From 4767f9b5b785558331e8fdeebb48347c2c4b40bc Mon Sep 17 00:00:00 2001 From: hkobew Date: Thu, 24 Oct 2024 14:40:37 -0400 Subject: [PATCH 2/3] remove redundant if --- .../src/codewhispererChat/editor/context/file/languages.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/core/src/codewhispererChat/editor/context/file/languages.ts b/packages/core/src/codewhispererChat/editor/context/file/languages.ts index e5d733c1660..f5c882a7989 100644 --- a/packages/core/src/codewhispererChat/editor/context/file/languages.ts +++ b/packages/core/src/codewhispererChat/editor/context/file/languages.ts @@ -117,10 +117,7 @@ export function extractLanguageNameFromFile(file: TextDocument): string | undefi export function extractAdditionalLanguageMatchPoliciesFromFile(file: TextDocument): Set { const languageId = file.languageId - if (languageId === undefined) { - return new Set() - } - if (validLanguageIds.includes(languageId)) { + if (languageId === undefined || validLanguageIds.includes(languageId)) { return new Set() } switch (languageId) { From 884ccda5d8b2074a7a60994d5891164d9c57a5f7 Mon Sep 17 00:00:00 2001 From: hkobew Date: Thu, 24 Oct 2024 16:33:25 -0400 Subject: [PATCH 3/3] rename var --- .../src/codewhispererChat/editor/context/file/languages.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/src/codewhispererChat/editor/context/file/languages.ts b/packages/core/src/codewhispererChat/editor/context/file/languages.ts index f5c882a7989..51887eaf31b 100644 --- a/packages/core/src/codewhispererChat/editor/context/file/languages.ts +++ b/packages/core/src/codewhispererChat/editor/context/file/languages.ts @@ -5,7 +5,7 @@ import { TextDocument } from 'vscode' -const validLanguageIds = [ +const defaultLanguages = [ 'yaml', 'xsl', 'xml', @@ -55,7 +55,7 @@ export function extractLanguageNameFromFile(file: TextDocument): string | undefi if (languageId === undefined) { return undefined } - if (validLanguageIds.includes(languageId)) { + if (defaultLanguages.includes(languageId)) { return languageId } switch (languageId) { @@ -117,7 +117,7 @@ export function extractLanguageNameFromFile(file: TextDocument): string | undefi export function extractAdditionalLanguageMatchPoliciesFromFile(file: TextDocument): Set { const languageId = file.languageId - if (languageId === undefined || validLanguageIds.includes(languageId)) { + if (languageId === undefined || defaultLanguages.includes(languageId)) { return new Set() } switch (languageId) {