@@ -54,6 +54,7 @@ import {
54
54
} from './codeAnalysis' ;
55
55
import { Location , TextEdit , WorkspaceEdit } from './commonTypes' ;
56
56
import * as configs from './configurations' ;
57
+ import { CopilotCompletionContextFeatureFlag , CopilotCompletionContextProvider , SnippetEntry } from './copilotCompletionContextProvider' ;
57
58
import { DataBinding } from './dataBinding' ;
58
59
import { cachedEditorConfigSettings , getEditorConfigSettings } from './editorConfig' ;
59
60
import { CppSourceStr , clients , configPrefix , updateLanguageConfigurations , usesCrashHandler , watchForCrashes } from './extension' ;
@@ -183,6 +184,7 @@ interface TelemetryPayload {
183
184
event : string ;
184
185
properties ?: Record < string , string > ;
185
186
metrics ?: Record < string , number > ;
187
+ signedMetrics ?: Record < string , number > ;
186
188
}
187
189
188
190
interface ReportStatusNotificationBody extends WorkspaceFolderParams {
@@ -577,6 +579,21 @@ interface FilesEncodingChanged {
577
579
foldersFilesEncoding : FolderFilesEncodingChanged [ ] ;
578
580
}
579
581
582
+ export interface CopilotCompletionContextResult {
583
+ requestId : number ;
584
+ isResultMissing : boolean ;
585
+ snippets : SnippetEntry [ ] ;
586
+ translationUnitUri : string ;
587
+ caretOffset : number ;
588
+ featureFlag : CopilotCompletionContextFeatureFlag ;
589
+ }
590
+
591
+ export interface CopilotCompletionContextParams {
592
+ uri : string ;
593
+ caretOffset : number ;
594
+ featureFlag : CopilotCompletionContextFeatureFlag ;
595
+ }
596
+
580
597
// Requests
581
598
const PreInitializationRequest : RequestType < void , string , void > = new RequestType < void , string , void > ( 'cpptools/preinitialize' ) ;
582
599
const InitializationRequest : RequestType < CppInitializationParams , void , void > = new RequestType < CppInitializationParams , void , void > ( 'cpptools/initialize' ) ;
@@ -599,6 +616,7 @@ const ChangeCppPropertiesRequest: RequestType<CppPropertiesParams, void, void> =
599
616
const IncludesRequest : RequestType < GetIncludesParams , GetIncludesResult , void > = new RequestType < GetIncludesParams , GetIncludesResult , void > ( 'cpptools/getIncludes' ) ;
600
617
const CppContextRequest : RequestType < TextDocumentIdentifier , ChatContextResult , void > = new RequestType < TextDocumentIdentifier , ChatContextResult , void > ( 'cpptools/getChatContext' ) ;
601
618
const ProjectContextRequest : RequestType < TextDocumentIdentifier , ProjectContextResult , void > = new RequestType < TextDocumentIdentifier , ProjectContextResult , void > ( 'cpptools/getProjectContext' ) ;
619
+ const CopilotCompletionContextRequest : RequestType < CopilotCompletionContextParams , CopilotCompletionContextResult , void > = new RequestType < CopilotCompletionContextParams , CopilotCompletionContextResult , void > ( 'cpptools/getCompletionContext' ) ;
602
620
603
621
// Notifications to the server
604
622
const DidOpenNotification : NotificationType < DidOpenTextDocumentParams > = new NotificationType < DidOpenTextDocumentParams > ( 'textDocument/didOpen' ) ;
@@ -834,6 +852,7 @@ export interface Client {
834
852
getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > ;
835
853
getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > ;
836
854
filesEncodingChanged ( filesEncodingChanged : FilesEncodingChanged ) : void ;
855
+ getCompletionContext ( fileName : vscode . Uri , caretOffset : number , featureFlag : CopilotCompletionContextFeatureFlag , token : vscode . CancellationToken ) : Promise < CopilotCompletionContextResult > ;
837
856
}
838
857
839
858
export function createClient ( workspaceFolder ?: vscode . WorkspaceFolder ) : Client {
@@ -868,6 +887,7 @@ export class DefaultClient implements Client {
868
887
private configurationProvider ?: string ;
869
888
private hoverProvider : HoverProvider | undefined ;
870
889
private copilotHoverProvider : CopilotHoverProvider | undefined ;
890
+ private copilotCompletionProvider ?: CopilotCompletionContextProvider ;
871
891
872
892
public lastCustomBrowseConfiguration : PersistentFolderState < WorkspaceBrowseConfiguration | undefined > | undefined ;
873
893
public lastCustomBrowseConfigurationProviderId : PersistentFolderState < string | undefined > | undefined ;
@@ -1346,6 +1366,9 @@ export class DefaultClient implements Client {
1346
1366
this . semanticTokensProviderDisposable = vscode . languages . registerDocumentSemanticTokensProvider ( util . documentSelector , this . semanticTokensProvider , semanticTokensLegend ) ;
1347
1367
}
1348
1368
1369
+ this . copilotCompletionProvider = await CopilotCompletionContextProvider . Create ( ) ;
1370
+ this . disposables . push ( this . copilotCompletionProvider ) ;
1371
+
1349
1372
// Listen for messages from the language server.
1350
1373
this . registerNotifications ( ) ;
1351
1374
@@ -1878,6 +1901,7 @@ export class DefaultClient implements Client {
1878
1901
if ( diagnosticsCollectionIntelliSense ) {
1879
1902
diagnosticsCollectionIntelliSense . delete ( document . uri ) ;
1880
1903
}
1904
+ this . copilotCompletionProvider ?. removeFile ( uri ) ;
1881
1905
openFileVersions . delete ( uri ) ;
1882
1906
}
1883
1907
@@ -2259,7 +2283,6 @@ export class DefaultClient implements Client {
2259
2283
return util . extractCompilerPathAndArgs ( ! ! settings . legacyCompilerArgsBehavior ,
2260
2284
this . configuration . CurrentConfiguration ?. compilerPath ,
2261
2285
this . configuration . CurrentConfiguration ?. compilerArgs ) ;
2262
-
2263
2286
}
2264
2287
2265
2288
public async getVcpkgInstalled ( ) : Promise < boolean > {
@@ -2328,6 +2351,14 @@ export class DefaultClient implements Client {
2328
2351
( ) => this . languageClient . sendRequest ( CppContextRequest , params , token ) , token ) ;
2329
2352
}
2330
2353
2354
+ public async getCompletionContext ( file : vscode . Uri , caretOffset : number , featureFlag : CopilotCompletionContextFeatureFlag ,
2355
+ token : vscode . CancellationToken ) : Promise < CopilotCompletionContextResult > {
2356
+ await withCancellation ( this . ready , token ) ;
2357
+ return DefaultClient . withLspCancellationHandling (
2358
+ ( ) => this . languageClient . sendRequest ( CopilotCompletionContextRequest ,
2359
+ { uri : file . toString ( ) , caretOffset, featureFlag } , token ) , token ) ;
2360
+ }
2361
+
2331
2362
/**
2332
2363
* a Promise that can be awaited to know when it's ok to proceed.
2333
2364
*
@@ -2700,7 +2731,8 @@ export class DefaultClient implements Client {
2700
2731
if ( notificationBody . event === "includeSquiggles" && this . configurationProvider && notificationBody . properties ) {
2701
2732
notificationBody . properties [ "providerId" ] = this . configurationProvider ;
2702
2733
}
2703
- telemetry . logLanguageServerEvent ( notificationBody . event , notificationBody . properties , notificationBody . metrics ) ;
2734
+ const metrics_unified : Record < string , number > = { ...notificationBody . metrics , ...notificationBody . signedMetrics } ;
2735
+ telemetry . logLanguageServerEvent ( notificationBody . event , notificationBody . properties , metrics_unified ) ;
2704
2736
}
2705
2737
2706
2738
private async updateStatus ( notificationBody : ReportStatusNotificationBody ) : Promise < void > {
@@ -4256,4 +4288,5 @@ class NullClient implements Client {
4256
4288
getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > { return Promise . resolve ( { } as ChatContextResult ) ; }
4257
4289
getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > { return Promise . resolve ( { } as ProjectContextResult ) ; }
4258
4290
filesEncodingChanged ( filesEncodingChanged : FilesEncodingChanged ) : void { }
4291
+ getCompletionContext ( file : vscode . Uri , caretOffset : number , featureFlag : CopilotCompletionContextFeatureFlag , token : vscode . CancellationToken ) : Promise < CopilotCompletionContextResult > { return Promise . resolve ( { } as CopilotCompletionContextResult ) ; }
4259
4292
}
0 commit comments