@@ -2,6 +2,7 @@ import vscode from 'vscode';
22import { detectLanguage } from './processors/detectLanguage' ;
33import { fileHeaders } from './processors/fileHeaders' ;
44import { languages } from './processors/languages' ;
5+ import { config } from '../config' ;
56
67var decoder = new TextDecoder ( "utf8" ) ;
78
@@ -13,12 +14,13 @@ function getNotebookDocument(document: vscode.TextDocument): vscode.NotebookDocu
1314export async function preparePrompt ( document :vscode . TextDocument , position :vscode . Position , context :vscode . InlineCompletionContext ) {
1415
1516// Load document text
16- console . log ( document ) ;
1717let text = document . getText ( ) ;
1818let offset = document . offsetAt ( position ) ;
1919let prefix = text . slice ( 0 , offset ) ;
2020let suffix :string = text . slice ( offset ) ;
2121
22+ let notebookConfig = config . notebook ;
23+
2224// If this is a notebook, add the surrounding cells to the prefix and suffix
2325let notebookDocument = getNotebookDocument ( document ) ;
2426let language = detectLanguage ( document . uri . fsPath , document . languageId ) ;
@@ -43,21 +45,26 @@ export async function preparePrompt(document: vscode.TextDocument, position: vsc
4345
4446// add the markdown cell output to the prompt as a comment
4547if ( 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+ }
4852}
4953} else {
5054out += cell . document . getText ( ) ;
5155}
5256
5357// 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 ) {
5663let cellOutputs = cell . outputs
5764. map ( x => x . items
5865. filter ( x => x . mime === 'text/plain' )
5966. 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' ) ) )
6168. flat ( 3 ) ;
6269
6370if ( cellOutputs . length > 0 ) {