@@ -54,9 +54,10 @@ import {
5454} from './codeAnalysis' ;
5555import { Location , TextEdit , WorkspaceEdit } from './commonTypes' ;
5656import * as configs from './configurations' ;
57+ import { CopilotCompletionContextFeatureFlag , CopilotCompletionContextProvider } from './copilotCompletionContextProvider' ;
5758import { DataBinding } from './dataBinding' ;
5859import { cachedEditorConfigSettings , getEditorConfigSettings } from './editorConfig' ;
59- import { CppSourceStr , clients , configPrefix , updateLanguageConfigurations , usesCrashHandler , watchForCrashes } from './extension' ;
60+ import { CppSourceStr , SnippetEntry , clients , configPrefix , updateLanguageConfigurations , usesCrashHandler , watchForCrashes } from './extension' ;
6061import { LocalizeStringParams , getLocaleId , getLocalizedString } from './localization' ;
6162import { PersistentFolderState , PersistentState , PersistentWorkspaceState } from './persistentState' ;
6263import { RequestCancelled , ServerCancelled , createProtocolFilter } from './protocolFilter' ;
@@ -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 {
@@ -575,6 +577,20 @@ interface FilesEncodingChanged {
575577 foldersFilesEncoding : FolderFilesEncodingChanged [ ] ;
576578}
577579
580+ export interface CopilotCompletionContextResult {
581+ isResultMissing : boolean ;
582+ snippets : SnippetEntry [ ] ;
583+ translationUnitUri : string ;
584+ caretOffset : number ;
585+ featureFlag : CopilotCompletionContextFeatureFlag ;
586+ }
587+
588+ export interface CopilotCompletionContextParams {
589+ uri : string ;
590+ caretOffset : number ;
591+ featureFlag : CopilotCompletionContextFeatureFlag ;
592+ }
593+
578594// Requests
579595const PreInitializationRequest : RequestType < void , string , void > = new RequestType < void , string , void > ( 'cpptools/preinitialize' ) ;
580596const InitializationRequest : RequestType < CppInitializationParams , void , void > = new RequestType < CppInitializationParams , void , void > ( 'cpptools/initialize' ) ;
@@ -597,6 +613,7 @@ const ChangeCppPropertiesRequest: RequestType<CppPropertiesParams, void, void> =
597613const IncludesRequest : RequestType < GetIncludesParams , GetIncludesResult , void > = new RequestType < GetIncludesParams , GetIncludesResult , void > ( 'cpptools/getIncludes' ) ;
598614const CppContextRequest : RequestType < TextDocumentIdentifier , ChatContextResult , void > = new RequestType < TextDocumentIdentifier , ChatContextResult , void > ( 'cpptools/getChatContext' ) ;
599615const ProjectContextRequest : RequestType < TextDocumentIdentifier , ProjectContextResult , void > = new RequestType < TextDocumentIdentifier , ProjectContextResult , void > ( 'cpptools/getProjectContext' ) ;
616+ const CopilotCompletionContextRequest : RequestType < CopilotCompletionContextParams , CopilotCompletionContextResult , void > = new RequestType < CopilotCompletionContextParams , CopilotCompletionContextResult , void > ( 'cpptools/getCompletionContext' ) ;
600617
601618// Notifications to the server
602619const DidOpenNotification : NotificationType < DidOpenTextDocumentParams > = new NotificationType < DidOpenTextDocumentParams > ( 'textDocument/didOpen' ) ;
@@ -832,6 +849,7 @@ export interface Client {
832849 getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > ;
833850 getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > ;
834851 filesEncodingChanged ( filesEncodingChanged : FilesEncodingChanged ) : void ;
852+ getCompletionContext ( fileName : vscode . Uri , caretOffset : number , featureFlag : CopilotCompletionContextFeatureFlag , token : vscode . CancellationToken ) : Promise < CopilotCompletionContextResult > ;
835853}
836854
837855export function createClient ( workspaceFolder ?: vscode . WorkspaceFolder ) : Client {
@@ -866,6 +884,7 @@ export class DefaultClient implements Client {
866884 private configurationProvider ?: string ;
867885 private hoverProvider : HoverProvider | undefined ;
868886 private copilotHoverProvider : CopilotHoverProvider | undefined ;
887+ private copilotCompletionProvider ?: CopilotCompletionContextProvider ;
869888
870889 public lastCustomBrowseConfiguration : PersistentFolderState < WorkspaceBrowseConfiguration | undefined > | undefined ;
871890 public lastCustomBrowseConfigurationProviderId : PersistentFolderState < string | undefined > | undefined ;
@@ -1344,6 +1363,9 @@ export class DefaultClient implements Client {
13441363 this . semanticTokensProviderDisposable = vscode . languages . registerDocumentSemanticTokensProvider ( util . documentSelector , this . semanticTokensProvider , semanticTokensLegend ) ;
13451364 }
13461365
1366+ this . copilotCompletionProvider = await CopilotCompletionContextProvider . Create ( ) ;
1367+ this . disposables . push ( this . copilotCompletionProvider ) ;
1368+
13471369 // Listen for messages from the language server.
13481370 this . registerNotifications ( ) ;
13491371
@@ -1875,6 +1897,7 @@ export class DefaultClient implements Client {
18751897 if ( diagnosticsCollectionIntelliSense ) {
18761898 diagnosticsCollectionIntelliSense . delete ( document . uri ) ;
18771899 }
1900+ this . copilotCompletionProvider ?. removeFile ( uri ) ;
18781901 openFileVersions . delete ( uri ) ;
18791902 }
18801903
@@ -2254,7 +2277,6 @@ export class DefaultClient implements Client {
22542277 return util . extractCompilerPathAndArgs ( ! ! settings . legacyCompilerArgsBehavior ,
22552278 this . configuration . CurrentConfiguration ?. compilerPath ,
22562279 this . configuration . CurrentConfiguration ?. compilerArgs ) ;
2257-
22582280 }
22592281
22602282 public async getVcpkgInstalled ( ) : Promise < boolean > {
@@ -2323,6 +2345,14 @@ export class DefaultClient implements Client {
23232345 ( ) => this . languageClient . sendRequest ( CppContextRequest , params , token ) , token ) ;
23242346 }
23252347
2348+ public async getCompletionContext ( file : vscode . Uri , caretOffset : number , featureFlag : CopilotCompletionContextFeatureFlag ,
2349+ token : vscode . CancellationToken ) : Promise < CopilotCompletionContextResult > {
2350+ await withCancellation ( this . ready , token ) ;
2351+ return DefaultClient . withLspCancellationHandling (
2352+ ( ) => this . languageClient . sendRequest ( CopilotCompletionContextRequest ,
2353+ { uri : file . toString ( ) , caretOffset, featureFlag } , token ) , token ) ;
2354+ }
2355+
23262356 /**
23272357 * a Promise that can be awaited to know when it's ok to proceed.
23282358 *
@@ -2695,7 +2725,8 @@ export class DefaultClient implements Client {
26952725 if ( notificationBody . event === "includeSquiggles" && this . configurationProvider && notificationBody . properties ) {
26962726 notificationBody . properties [ "providerId" ] = this . configurationProvider ;
26972727 }
2698- telemetry . logLanguageServerEvent ( notificationBody . event , notificationBody . properties , notificationBody . metrics ) ;
2728+ const metrics_unified : Record < string , number > = { ...notificationBody . metrics , ...notificationBody . signedMetrics } ;
2729+ telemetry . logLanguageServerEvent ( notificationBody . event , notificationBody . properties , metrics_unified ) ;
26992730 }
27002731
27012732 private async updateStatus ( notificationBody : ReportStatusNotificationBody ) : Promise < void > {
@@ -4251,4 +4282,5 @@ class NullClient implements Client {
42514282 getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > { return Promise . resolve ( { } as ChatContextResult ) ; }
42524283 getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > { return Promise . resolve ( { } as ProjectContextResult ) ; }
42534284 filesEncodingChanged ( filesEncodingChanged : FilesEncodingChanged ) : void { }
4285+ getCompletionContext ( file : vscode . Uri , caretOffset : number , featureFlag : CopilotCompletionContextFeatureFlag , token : vscode . CancellationToken ) : Promise < CopilotCompletionContextResult > { return Promise . resolve ( { } as CopilotCompletionContextResult ) ; }
42544286}
0 commit comments