11import protobuf from 'protobufjs' ;
22import Long from 'long' ;
33
4+ import { CodeCellType } from '@srcbook/shared' ;
45import languageServerProto from './language-server-proto' ;
56
67// NOTE: this EDITOR_API_KEY value was just included as a raw string in
@@ -15,6 +16,7 @@ export async function runCodeiumAiAutocomplete(
1516 source : string ,
1617 sourceLanguage : 'javascript' | 'typescript' ,
1718 cursorOffset : number ,
19+ otherCodeCells : Array < CodeCellType > = [ ] ,
1820) : Promise < CodiumCompletionResult > {
1921 const protos = protobuf . Root . fromJSON ( languageServerProto as protobuf . INamespace ) ;
2022 const GetCompletionsRequest = protos . lookupType ( 'exa.language_server_pb.GetCompletionsRequest' ) ;
@@ -28,7 +30,17 @@ export async function runCodeiumAiAutocomplete(
2830 const apiKey = optionalApiKey ?? EDITOR_API_KEY ;
2931
3032 const payload = {
31- otherDocuments : [ ] ,
33+ otherDocuments : otherCodeCells . map ( ( otherCodeCell ) =>
34+ DocumentInfo . create ( {
35+ absolutePath : otherCodeCell . filename ,
36+ relativePath : otherCodeCell . filename ,
37+ text : otherCodeCell . source ,
38+ editorLanguage : sourceLanguage ,
39+ language : Language . getOption ( sourceLanguage === 'javascript' ? 'JAVASCRIPT' : 'TYPESCRIPT' ) ,
40+ cursorOffset : Long . fromValue ( 0 ) , // NOTE: how do I represent the cursor not being in here?
41+ lineEnding : '\n' ,
42+ } ) ,
43+ ) ,
3244 metadata : Metadata . create ( {
3345 ideName : 'web' ,
3446 extensionVersion : '1.0.12' ,
0 commit comments