diff --git a/src/vs/workbench/contrib/void/browser/helpers/detectLanguage.ts b/src/vs/workbench/contrib/void/browser/helpers/detectLanguage.ts new file mode 100644 index 00000000..b4b9d513 --- /dev/null +++ b/src/vs/workbench/contrib/void/browser/helpers/detectLanguage.ts @@ -0,0 +1,170 @@ + +// eg "bash" -> "shell" +export const nameToVscodeLanguage: { [key: string]: string } = { + // Web Technologies + 'html': 'html', + 'css': 'css', + 'scss': 'scss', + 'sass': 'scss', + 'less': 'less', + 'javascript': 'typescript', + 'js': 'typescript', // use more general renderer + 'jsx': 'typescript', + 'typescript': 'typescript', + 'ts': 'typescript', + 'tsx': 'typescript', + 'json': 'json', + 'jsonc': 'json', + + // Programming Languages + 'python': 'python', + 'py': 'python', + 'java': 'java', + 'cpp': 'cpp', + 'c++': 'cpp', + 'c': 'c', + 'csharp': 'csharp', + 'cs': 'csharp', + 'c#': 'csharp', + 'go': 'go', + 'golang': 'go', + 'rust': 'rust', + 'rs': 'rust', + 'ruby': 'ruby', + 'rb': 'ruby', + 'php': 'php', + 'shell': 'shell', + 'bash': 'shell', + 'sh': 'shell', + 'zsh': 'shell', + + // Markup and Config + 'markdown': 'markdown', + 'md': 'markdown', + 'xml': 'xml', + 'svg': 'xml', + 'yaml': 'yaml', + 'yml': 'yaml', + 'ini': 'ini', + 'toml': 'ini', + + // Database and Query Languages + 'sql': 'sql', + 'mysql': 'sql', + 'postgresql': 'sql', + 'graphql': 'graphql', + 'gql': 'graphql', + + // Others + 'dockerfile': 'dockerfile', + 'docker': 'dockerfile', + 'makefile': 'makefile', + 'plaintext': 'plaintext', + 'text': 'plaintext' +}; + + + +// eg ".ts" -> "typescript" +const fileExtensionToVscodeLanguage: { [key: string]: string } = { + // Web + 'html': 'html', + 'htm': 'html', + 'css': 'css', + 'scss': 'scss', + 'less': 'less', + 'js': 'javascript', + 'jsx': 'javascript', + 'ts': 'typescript', + 'tsx': 'typescript', + 'json': 'json', + 'jsonc': 'json', + + // Programming Languages + 'py': 'python', + 'java': 'java', + 'cpp': 'cpp', + 'cc': 'cpp', + 'c': 'c', + 'h': 'cpp', + 'hpp': 'cpp', + 'cs': 'csharp', + 'go': 'go', + 'rs': 'rust', + 'rb': 'ruby', + 'php': 'php', + 'sh': 'shell', + 'bash': 'shell', + 'zsh': 'shell', + + // Markup/Config + 'md': 'markdown', + 'markdown': 'markdown', + 'xml': 'xml', + 'svg': 'xml', + 'yaml': 'yaml', + 'yml': 'yaml', + 'ini': 'ini', + 'toml': 'ini', + + // Other + 'sql': 'sql', + 'graphql': 'graphql', + 'gql': 'graphql', + 'dockerfile': 'dockerfile', + 'docker': 'dockerfile', + 'mk': 'makefile', + + // Config Files and Dot Files + 'npmrc': 'ini', + 'env': 'ini', + 'gitignore': 'ignore', + 'dockerignore': 'ignore', + 'eslintrc': 'json', + 'babelrc': 'json', + 'prettierrc': 'json', + 'stylelintrc': 'json', + 'editorconfig': 'ini', + 'htaccess': 'apacheconf', + 'conf': 'ini', + 'config': 'ini', + + // Package Files + 'package': 'json', + 'package-lock': 'json', + 'gemfile': 'ruby', + 'podfile': 'ruby', + 'rakefile': 'ruby', + + // Build Systems + 'cmake': 'cmake', + 'makefile': 'makefile', + 'gradle': 'groovy', + + // Shell Scripts + 'bashrc': 'shell', + 'zshrc': 'shell', + 'fish': 'shell', + + // Version Control + 'gitconfig': 'ini', + 'hgrc': 'ini', + 'svnconfig': 'ini', + + // Web Server + 'nginx': 'nginx', + + // Misc Config + 'properties': 'properties', + 'cfg': 'ini', + 'reg': 'ini' +}; + + +export function filenameToVscodeLanguage(filename: string): string | undefined { + + const ext = filename.toLowerCase().split('.').pop(); + if (!ext) return undefined; + + return fileExtensionToVscodeLanguage[ext]; +} diff --git a/src/vs/workbench/contrib/void/browser/inlineDiffsService.ts b/src/vs/workbench/contrib/void/browser/inlineDiffsService.ts index 00fe8b50..c5207eb0 100644 --- a/src/vs/workbench/contrib/void/browser/inlineDiffsService.ts +++ b/src/vs/workbench/contrib/void/browser/inlineDiffsService.ts @@ -1078,7 +1078,7 @@ class InlineDiffsService extends Disposable implements IInlineDiffsService { let messages: LLMMessage[] if (featureName === 'Ctrl+L') { - const userContent = ctrlLStream_prompt({ originalCode, userMessage }) + const userContent = ctrlLStream_prompt({ originalCode, userMessage, uri }) messages = [ // TODO include more context too { role: 'system', content: ctrlLStream_systemMessage, }, @@ -1087,7 +1087,7 @@ class InlineDiffsService extends Disposable implements IInlineDiffsService { } else if (featureName === 'Ctrl+K') { const { prefix, suffix } = ctrlKStream_prefixAndSuffix({ fullFileStr: currentFileStr, startLine, endLine }) - const userContent = ctrlKStream_prompt({ selection: originalCode, userMessage, prefix, suffix, modelWasTrainedOnFIM, fimTags: modelFimTags }) + const userContent = ctrlKStream_prompt({ selection: originalCode, userMessage, prefix, suffix, modelWasTrainedOnFIM, fimTags: modelFimTags, uri }) console.log('PREFIX:\n', prefix) console.log('SUFFIX:\n', suffix) console.log('USER CONTENT:\n', userContent) diff --git a/src/vs/workbench/contrib/void/browser/prompt/prompts.ts b/src/vs/workbench/contrib/void/browser/prompt/prompts.ts index 132acaea..bc42b581 100644 --- a/src/vs/workbench/contrib/void/browser/prompt/prompts.ts +++ b/src/vs/workbench/contrib/void/browser/prompt/prompts.ts @@ -4,6 +4,8 @@ *--------------------------------------------------------------------------------------*/ +import { URI } from '../../../../../base/common/uri.js'; +import { filenameToVscodeLanguage } from '../helpers/detectLanguage.js'; import { CodeSelection } from '../threadHistoryService.js'; export const chat_systemMessage = `\ @@ -22,25 +24,25 @@ Instructions: FILES selected file \`math.ts\`: -\`\`\` +\`\`\` typescript const addNumbers = (a, b) => a + b const subtractNumbers = (a, b) => a - b const divideNumbers = (a, b) => a / b \`\`\` SELECTION -\`\`\` +\`\`\` typescript const subtractNumbers = (a, b) => a - b \`\`\` INSTRUCTIONS -\`\`\` +\`\`\` typescript add a function that multiplies numbers below this \`\`\` EXPECTED OUTPUT We can add the following code to the file: -\`\`\` +\`\`\` typescript // existing code... const subtractNumbers = (a, b) => a - b; const multiplyNumbers = (a, b) => a * b; @@ -51,7 +53,7 @@ const multiplyNumbers = (a, b) => a * b; FILES selected file \`fib.ts\`: -\`\`\` +\`\`\` typescript const dfs = (root) => { if (!root) return; @@ -66,18 +68,18 @@ const fib = (n) => { \`\`\` SELECTION -\`\`\` +\`\`\` typescript return fib(n - 1) + fib(n - 2) \`\`\` INSTRUCTIONS -\`\`\` +\`\`\` typescript memoize results \`\`\` EXPECTED OUTPUT To implement memoization in your Fibonacci function, you can use a JavaScript object to store previously computed results. This will help avoid redundant calculations and improve performance. Here's how you can modify your function: -\`\`\` +\`\`\` typescript // existing code... const fib = (n, memo = {}) => { if (n < 1) return 1; @@ -100,7 +102,7 @@ const stringifySelections = (selections: CodeSelection[]) => { return selections.map(({ fileURI, content, selectionStr }) => `\ File: ${fileURI.fsPath} -\`\`\` +\`\`\` ${filenameToVscodeLanguage(fileURI.fsPath) ?? ''} ${content // this was the enite file which is foolish } \`\`\`${selectionStr === null ? '' : ` @@ -136,7 +138,7 @@ Directions: ORIGINAL_FILE \`Sidebar.tsx\`: -\`\`\` +\`\`\` typescript import React from 'react'; import styles from './Sidebar.module.css'; @@ -172,7 +174,7 @@ export default Sidebar; \`\`\` DIFF -\`\`\` +\`\`\` typescript @@ ... @@ -
-