@@ -23,7 +23,13 @@ import {
2323import { waitUntil } from '../../../shared/utilities/timeoutUtils'
2424import { FeatureConfigProvider } from '../../../shared/featureConfig'
2525import fs from '../../../shared/fs/fs'
26+ import { LanguageClient } from 'vscode-languageclient'
2627
28+ import {
29+ GetSupplementalContextParams ,
30+ getSupplementalContextRequestType ,
31+ SupplementalContextItem ,
32+ } from '@aws/language-server-runtimes/protocol'
2733type CrossFileSupportedLanguage =
2834 | 'java'
2935 | 'python'
@@ -66,7 +72,8 @@ type SupplementalContextConfig = 'none' | 'opentabs' | 'codemap' | 'bm25' | 'def
6672
6773export async function fetchSupplementalContextForSrc (
6874 editor : vscode . TextEditor ,
69- cancellationToken : vscode . CancellationToken
75+ cancellationToken : vscode . CancellationToken ,
76+ languageClient ?: LanguageClient
7077) : Promise < Pick < CodeWhispererSupplementalContext , 'supplementalContextItems' | 'strategy' > | undefined > {
7178 const supplementalContextConfig = getSupplementalContextConfig ( editor . document . languageId )
7279
@@ -101,7 +108,7 @@ export async function fetchSupplementalContextForSrc(
101108 async function ( ) {
102109 const result : CodeWhispererSupplementalContextItem [ ] = [ ]
103110 const opentabsContext = await fetchOpentabsContext ( editor , cancellationToken )
104- const codemap = await fetchProjectContext ( editor , 'codemap' )
111+ const codemap = await fetchProjectContext ( editor , 'codemap' , languageClient )
105112
106113 function addToResult ( items : CodeWhispererSupplementalContextItem [ ] ) {
107114 for ( const item of items ) {
@@ -145,7 +152,7 @@ export async function fetchSupplementalContextForSrc(
145152 if ( supplementalContextConfig === 'bm25' ) {
146153 const projectBM25Promise = waitUntil (
147154 async function ( ) {
148- return await fetchProjectContext ( editor , 'bm25' )
155+ return await fetchProjectContext ( editor , 'bm25' , languageClient )
149156 } ,
150157 { timeout : supplementalContextTimeoutInMs , interval : 5 , truthy : false }
151158 )
@@ -168,7 +175,7 @@ export async function fetchSupplementalContextForSrc(
168175 // global bm25 with repomap
169176 const projectContextAndCodemapPromise = waitUntil (
170177 async function ( ) {
171- return await fetchProjectContext ( editor , 'default' )
178+ return await fetchProjectContext ( editor , 'default' , languageClient )
172179 } ,
173180 { timeout : supplementalContextTimeoutInMs , interval : 5 , truthy : false }
174181 )
@@ -192,13 +199,20 @@ export async function fetchSupplementalContextForSrc(
192199
193200export async function fetchProjectContext (
194201 editor : vscode . TextEditor ,
195- target : 'default' | 'codemap' | 'bm25'
202+ target : 'default' | 'codemap' | 'bm25' ,
203+ languageclient ?: LanguageClient
196204) : Promise < CodeWhispererSupplementalContextItem [ ] > {
197- // const inputChunkContent = getInputChunk(editor)
198- // TODO:
199- const inlineProjectContext : { content : string ; score : number ; filePath : string } [ ] = [ ]
200-
201- return inlineProjectContext
205+ if ( languageclient ) {
206+ const request : GetSupplementalContextParams = {
207+ filePath : editor . document . uri . fsPath ,
208+ }
209+ const response = await languageclient . sendRequest < SupplementalContextItem [ ] > (
210+ getSupplementalContextRequestType . method ,
211+ request
212+ )
213+ return response as CodeWhispererSupplementalContextItem [ ]
214+ }
215+ return [ ]
202216}
203217
204218export async function fetchOpentabsContext (
0 commit comments