|
1 | 1 | import vscode from 'vscode'; |
2 | | -import path from 'path'; |
| 2 | +import { detectLanguage } from './processors/detectLanguage'; |
| 3 | +import { fileHeaders } from './processors/fileHeaders'; |
| 4 | +import { languages } from './processors/languages'; |
3 | 5 |
|
4 | 6 | export async function preparePrompt(document: vscode.TextDocument, position: vscode.Position, context: vscode.InlineCompletionContext) { |
5 | 7 |
|
6 | 8 | // Load document text |
7 | 9 | let text = document.getText(); |
8 | 10 | let offset = document.offsetAt(position); |
9 | 11 | let prefix = text.slice(0, offset); |
10 | | - let suffix = text.slice(offset); |
| 12 | + let suffix: string | null = text.slice(offset); |
11 | 13 |
|
12 | 14 | // Trim suffix |
13 | | - // NOTE: It seems that most neural networks are built have a focus on last characters and we therefore need to trim them to not get weird results. |
14 | | - // TODO: Better solution? |
15 | | - // TODO: Am i right here? What if we would want to generate something that uses something in the end of the file? |
16 | | - if (suffix.length > 256) { |
17 | | - suffix = suffix.slice(0, 256); |
| 15 | + // If suffix is too small it is safe to assume that it could be ignored which would allow us to use |
| 16 | + // more powerful completition instead of in middle one |
| 17 | + if (suffix.length < 256) { |
| 18 | + suffix = null; |
18 | 19 | } |
19 | 20 |
|
20 | 21 | // Add filename and language to prefix |
21 | 22 | // NOTE: Most networks don't have a concept of filenames and expected language, but we expect that some files in training set has something in title that |
22 | 23 | // would indicate filename and language |
23 | | - // NOTE: We are building for typescript for now so we can use C-style comments to indicate filename |
24 | | - let filename = path.basename(document.fileName); |
25 | | - let language = document.languageId; |
26 | | - let filenamePrefix = `/* ${language}, filename: ${filename} */`; |
27 | | - prefix = filenamePrefix + '\n' + prefix; |
| 24 | + // NOTE: If we can't detect language, we could ignore this since the number of languages that need detection is limited |
| 25 | + let language = detectLanguage(document.uri.fsPath, document.languageId); |
| 26 | + if (language) { |
| 27 | + prefix = fileHeaders(prefix, document.uri.fsPath, languages[language]); |
| 28 | + } |
28 | 29 |
|
29 | 30 | return { |
30 | 31 | prefix, |
|
0 commit comments