@@ -54,6 +54,7 @@ import {
5454} from './codeAnalysis' ;
5555import { Location , TextEdit , WorkspaceEdit } from './commonTypes' ;
5656import * as configs from './configurations' ;
57+ import { CopilotCompletionContextFeatures , CopilotCompletionContextProvider , SnippetEntry } from './copilotCompletionContextProvider' ;
5758import { DataBinding } from './dataBinding' ;
5859import { cachedEditorConfigSettings , getEditorConfigSettings } from './editorConfig' ;
5960import { CppSourceStr , clients , configPrefix , updateLanguageConfigurations , usesCrashHandler , watchForCrashes } from './extension' ;
@@ -183,6 +184,7 @@ interface TelemetryPayload {
183184 event : string ;
184185 properties ?: Record < string , string > ;
185186 metrics ?: Record < string , number > ;
187+ signedMetrics ?: Record < string , number > ;
186188}
187189
188190interface ReportStatusNotificationBody extends WorkspaceFolderParams {
@@ -576,6 +578,21 @@ interface FilesEncodingChanged {
576578 foldersFilesEncoding : FolderFilesEncodingChanged [ ] ;
577579}
578580
581+ export interface CopilotCompletionContextResult {
582+ requestId : number ;
583+ isResultMissing : boolean ;
584+ snippets : SnippetEntry [ ] ;
585+ translationUnitUri : string ;
586+ caretOffset : number ;
587+ featureFlag : CopilotCompletionContextFeatures ;
588+ }
589+
590+ export interface CopilotCompletionContextParams {
591+ uri : string ;
592+ caretOffset : number ;
593+ featureFlag : CopilotCompletionContextFeatures ;
594+ }
595+
579596// Requests
580597const PreInitializationRequest : RequestType < void , string , void > = new RequestType < void , string , void > ( 'cpptools/preinitialize' ) ;
581598const InitializationRequest : RequestType < CppInitializationParams , void , void > = new RequestType < CppInitializationParams , void , void > ( 'cpptools/initialize' ) ;
@@ -598,6 +615,7 @@ const ChangeCppPropertiesRequest: RequestType<CppPropertiesParams, void, void> =
598615const IncludesRequest : RequestType < GetIncludesParams , GetIncludesResult , void > = new RequestType < GetIncludesParams , GetIncludesResult , void > ( 'cpptools/getIncludes' ) ;
599616const CppContextRequest : RequestType < TextDocumentIdentifier , ChatContextResult , void > = new RequestType < TextDocumentIdentifier , ChatContextResult , void > ( 'cpptools/getChatContext' ) ;
600617const ProjectContextRequest : RequestType < TextDocumentIdentifier , ProjectContextResult , void > = new RequestType < TextDocumentIdentifier , ProjectContextResult , void > ( 'cpptools/getProjectContext' ) ;
618+ const CopilotCompletionContextRequest : RequestType < CopilotCompletionContextParams , CopilotCompletionContextResult , void > = new RequestType < CopilotCompletionContextParams , CopilotCompletionContextResult , void > ( 'cpptools/getCompletionContext' ) ;
601619
602620// Notifications to the server
603621const DidOpenNotification : NotificationType < DidOpenTextDocumentParams > = new NotificationType < DidOpenTextDocumentParams > ( 'textDocument/didOpen' ) ;
@@ -833,6 +851,7 @@ export interface Client {
833851 getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > ;
834852 getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > ;
835853 filesEncodingChanged ( filesEncodingChanged : FilesEncodingChanged ) : void ;
854+ getCompletionContext ( fileName : vscode . Uri , caretOffset : number , featureFlag : CopilotCompletionContextFeatures , token : vscode . CancellationToken ) : Promise < CopilotCompletionContextResult > ;
836855}
837856
838857export function createClient ( workspaceFolder ?: vscode . WorkspaceFolder ) : Client {
@@ -867,6 +886,7 @@ export class DefaultClient implements Client {
867886 private configurationProvider ?: string ;
868887 private hoverProvider : HoverProvider | undefined ;
869888 private copilotHoverProvider : CopilotHoverProvider | undefined ;
889+ private copilotCompletionProvider ?: CopilotCompletionContextProvider ;
870890
871891 public lastCustomBrowseConfiguration : PersistentFolderState < WorkspaceBrowseConfiguration | undefined > | undefined ;
872892 public lastCustomBrowseConfigurationProviderId : PersistentFolderState < string | undefined > | undefined ;
@@ -1343,6 +1363,9 @@ export class DefaultClient implements Client {
13431363 this . semanticTokensProviderDisposable = vscode . languages . registerDocumentSemanticTokensProvider ( util . documentSelector , this . semanticTokensProvider , semanticTokensLegend ) ;
13441364 }
13451365
1366+ this . copilotCompletionProvider = await CopilotCompletionContextProvider . Create ( ) ;
1367+ this . disposables . push ( this . copilotCompletionProvider ) ;
1368+
13461369 // Listen for messages from the language server.
13471370 this . registerNotifications ( ) ;
13481371
@@ -1875,6 +1898,7 @@ export class DefaultClient implements Client {
18751898 if ( diagnosticsCollectionIntelliSense ) {
18761899 diagnosticsCollectionIntelliSense . delete ( document . uri ) ;
18771900 }
1901+ this . copilotCompletionProvider ?. removeFile ( uri ) ;
18781902 openFileVersions . delete ( uri ) ;
18791903 }
18801904
@@ -2256,7 +2280,6 @@ export class DefaultClient implements Client {
22562280 return util . extractCompilerPathAndArgs ( ! ! settings . legacyCompilerArgsBehavior ,
22572281 this . configuration . CurrentConfiguration ?. compilerPath ,
22582282 this . configuration . CurrentConfiguration ?. compilerArgs ) ;
2259-
22602283 }
22612284
22622285 public async getVcpkgInstalled ( ) : Promise < boolean > {
@@ -2325,6 +2348,14 @@ export class DefaultClient implements Client {
23252348 ( ) => this . languageClient . sendRequest ( CppContextRequest , params , token ) , token ) ;
23262349 }
23272350
2351+ public async getCompletionContext ( file : vscode . Uri , caretOffset : number , featureFlag : CopilotCompletionContextFeatures ,
2352+ token : vscode . CancellationToken ) : Promise < CopilotCompletionContextResult > {
2353+ await withCancellation ( this . ready , token ) ;
2354+ return DefaultClient . withLspCancellationHandling (
2355+ ( ) => this . languageClient . sendRequest ( CopilotCompletionContextRequest ,
2356+ { uri : file . toString ( ) , caretOffset, featureFlag } , token ) , token ) ;
2357+ }
2358+
23282359 /**
23292360 * a Promise that can be awaited to know when it's ok to proceed.
23302361 *
@@ -2697,7 +2728,8 @@ export class DefaultClient implements Client {
26972728 if ( notificationBody . event === "includeSquiggles" && this . configurationProvider && notificationBody . properties ) {
26982729 notificationBody . properties [ "providerId" ] = this . configurationProvider ;
26992730 }
2700- telemetry . logLanguageServerEvent ( notificationBody . event , notificationBody . properties , notificationBody . metrics ) ;
2731+ const metrics_unified : Record < string , number > = { ...notificationBody . metrics , ...notificationBody . signedMetrics } ;
2732+ telemetry . logLanguageServerEvent ( notificationBody . event , notificationBody . properties , metrics_unified ) ;
27012733 }
27022734
27032735 private async updateStatus ( notificationBody : ReportStatusNotificationBody ) : Promise < void > {
@@ -4259,4 +4291,5 @@ class NullClient implements Client {
42594291 getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > { return Promise . resolve ( { } as ChatContextResult ) ; }
42604292 getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > { return Promise . resolve ( { } as ProjectContextResult ) ; }
42614293 filesEncodingChanged ( filesEncodingChanged : FilesEncodingChanged ) : void { }
4294+ getCompletionContext ( file : vscode . Uri , caretOffset : number , featureFlag : CopilotCompletionContextFeatures , token : vscode . CancellationToken ) : Promise < CopilotCompletionContextResult > { return Promise . resolve ( { } as CopilotCompletionContextResult ) ; }
42624295}
0 commit comments