@@ -2,6 +2,7 @@ import vscode from 'vscode';
2
2
import { detectLanguage } from './processors/detectLanguage' ;
3
3
import { fileHeaders } from './processors/fileHeaders' ;
4
4
import { languages } from './processors/languages' ;
5
+ import { config } from '../config' ;
5
6
6
7
var decoder = new TextDecoder ( "utf8" ) ;
7
8
@@ -13,12 +14,13 @@ function getNotebookDocument(document: vscode.TextDocument): vscode.NotebookDocu
13
14
export async function preparePrompt ( document : vscode . TextDocument , position : vscode . Position , context : vscode . InlineCompletionContext ) {
14
15
15
16
// Load document text
16
- console . log ( document ) ;
17
17
let text = document . getText ( ) ;
18
18
let offset = document . offsetAt ( position ) ;
19
19
let prefix = text . slice ( 0 , offset ) ;
20
20
let suffix : string = text . slice ( offset ) ;
21
21
22
+ let notebookConfig = config . notebook ;
23
+
22
24
// If this is a notebook, add the surrounding cells to the prefix and suffix
23
25
let notebookDocument = getNotebookDocument ( document ) ;
24
26
let language = detectLanguage ( document . uri . fsPath , document . languageId ) ;
@@ -43,21 +45,26 @@ export async function preparePrompt(document: vscode.TextDocument, position: vsc
43
45
44
46
// add the markdown cell output to the prompt as a comment
45
47
if ( cell . kind === vscode . NotebookCellKind . Markup && commentStart ) {
46
- for ( const line of cell . document . getText ( ) . split ( '\n' ) ) {
47
- out += `\n${ commentStart } ${ line } ` ;
48
+ if ( notebookConfig . includeMarkup ) {
49
+ for ( const line of cell . document . getText ( ) . split ( '\n' ) ) {
50
+ out += `\n${ commentStart } ${ line } ` ;
51
+ }
48
52
}
49
53
} else {
50
54
out += cell . document . getText ( ) ;
51
55
}
52
56
53
57
// if there is any outputs add them to the prompt as a comment
54
- if ( cell . kind === vscode . NotebookCellKind . Code && commentStart ) {
55
- console . log ( cell . outputs ) ;
58
+ const addCellOutputs = notebookConfig . includeCellOutputs
59
+ && beforeCurrentCell
60
+ && cell . kind === vscode . NotebookCellKind . Code
61
+ && commentStart ;
62
+ if ( addCellOutputs ) {
56
63
let cellOutputs = cell . outputs
57
64
. map ( x => x . items
58
65
. filter ( x => x . mime === 'text/plain' )
59
66
. map ( x => decoder . decode ( x . data ) )
60
- . map ( x => x . slice ( 0 , 256 ) . split ( '\n' ) ) ) // limit to 256 characters
67
+ . map ( x => x . slice ( 0 , notebookConfig . cellOutputLimit ) . split ( '\n' ) ) )
61
68
. flat ( 3 ) ;
62
69
63
70
if ( cellOutputs . length > 0 ) {
0 commit comments