Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(cw): avoid duplicating language list. #5859

Merged
merged 3 commits into from
Oct 25, 2024
Merged
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
139 changes: 46 additions & 93 deletions packages/core/src/codewhispererChat/editor/context/file/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,57 @@

import { TextDocument } from 'vscode'

const defaultLanguages = [
'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 (defaultLanguages.includes(languageId)) {
return languageId
}
switch (languageId) {
Expand Down Expand Up @@ -117,54 +117,7 @@ export function extractLanguageNameFromFile(file: TextDocument): string | undefi
export function extractAdditionalLanguageMatchPoliciesFromFile(file: TextDocument): Set<string> {
const languageId = file.languageId

if (languageId === undefined) {
return new Set<string>()
}
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 (languageId === undefined || defaultLanguages.includes(languageId)) {
return new Set<string>()
}
switch (languageId) {
Copy link
Contributor

@hayemaxi hayemaxi Oct 25, 2024

Choose a reason for hiding this comment

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

out of scope, but man this switch statement is brutal. Could probably cut the character count by more than half by using pass-through and not typing new Set<string> everywhere.

Copy link
Contributor Author

@Hweinstock Hweinstock Oct 25, 2024

Choose a reason for hiding this comment

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

Yeah I thought the same thing lol. These functions are basically just a giant map of languages to alternative names and policies.

Expand Down
Loading