@@ -54,9 +54,10 @@ import {
5454} from './codeAnalysis' ;
5555import { Location , TextEdit , WorkspaceEdit } from './commonTypes' ;
5656import * as configs from './configurations' ;
57+ import { 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,18 @@ interface FilesEncodingChanged {
575577 foldersFilesEncoding : FolderFilesEncodingChanged [ ] ;
576578}
577579
580+ export interface CopilotCompletionContextResult {
581+ isResultMissing : boolean ;
582+ snippets : SnippetEntry [ ] ;
583+ translationUnitUri : string ;
584+ caretOffset : number ;
585+ }
586+
587+ export interface CopilotCompletionContextParams {
588+ uri : string ;
589+ caretOffset : number ;
590+ }
591+
578592// Requests
579593const PreInitializationRequest : RequestType < void , string , void > = new RequestType < void , string , void > ( 'cpptools/preinitialize' ) ;
580594const InitializationRequest : RequestType < CppInitializationParams , void , void > = new RequestType < CppInitializationParams , void , void > ( 'cpptools/initialize' ) ;
@@ -597,6 +611,7 @@ const ChangeCppPropertiesRequest: RequestType<CppPropertiesParams, void, void> =
597611const IncludesRequest : RequestType < GetIncludesParams , GetIncludesResult , void > = new RequestType < GetIncludesParams , GetIncludesResult , void > ( 'cpptools/getIncludes' ) ;
598612const CppContextRequest : RequestType < TextDocumentIdentifier , ChatContextResult , void > = new RequestType < TextDocumentIdentifier , ChatContextResult , void > ( 'cpptools/getChatContext' ) ;
599613const ProjectContextRequest : RequestType < TextDocumentIdentifier , ProjectContextResult , void > = new RequestType < TextDocumentIdentifier , ProjectContextResult , void > ( 'cpptools/getProjectContext' ) ;
614+ const CopilotCompletionContextRequest : RequestType < CopilotCompletionContextParams , CopilotCompletionContextResult , void > = new RequestType < CopilotCompletionContextParams , CopilotCompletionContextResult , void > ( 'cpptools/getCompletionContext' ) ;
600615
601616// Notifications to the server
602617const DidOpenNotification : NotificationType < DidOpenTextDocumentParams > = new NotificationType < DidOpenTextDocumentParams > ( 'textDocument/didOpen' ) ;
@@ -832,6 +847,7 @@ export interface Client {
832847 getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > ;
833848 getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > ;
834849 filesEncodingChanged ( filesEncodingChanged : FilesEncodingChanged ) : void ;
850+ getCompletionContext ( fileName : vscode . Uri , caretOffset : number , token : vscode . CancellationToken ) : Promise < CopilotCompletionContextResult > ;
835851}
836852
837853export function createClient ( workspaceFolder ?: vscode . WorkspaceFolder ) : Client {
@@ -866,6 +882,7 @@ export class DefaultClient implements Client {
866882 private configurationProvider ?: string ;
867883 private hoverProvider : HoverProvider | undefined ;
868884 private copilotHoverProvider : CopilotHoverProvider | undefined ;
885+ private copilotCompletionProvider ?: CopilotCompletionContextProvider ;
869886
870887 public lastCustomBrowseConfiguration : PersistentFolderState < WorkspaceBrowseConfiguration | undefined > | undefined ;
871888 public lastCustomBrowseConfigurationProviderId : PersistentFolderState < string | undefined > | undefined ;
@@ -1344,6 +1361,9 @@ export class DefaultClient implements Client {
13441361 this . semanticTokensProviderDisposable = vscode . languages . registerDocumentSemanticTokensProvider ( util . documentSelector , this . semanticTokensProvider , semanticTokensLegend ) ;
13451362 }
13461363
1364+ this . copilotCompletionProvider = await CopilotCompletionContextProvider . Create ( ) ;
1365+ this . disposables . push ( this . copilotCompletionProvider ) ;
1366+
13471367 // Listen for messages from the language server.
13481368 this . registerNotifications ( ) ;
13491369
@@ -1875,6 +1895,7 @@ export class DefaultClient implements Client {
18751895 if ( diagnosticsCollectionIntelliSense ) {
18761896 diagnosticsCollectionIntelliSense . delete ( document . uri ) ;
18771897 }
1898+ this . copilotCompletionProvider ?. removeFile ( uri ) ;
18781899 openFileVersions . delete ( uri ) ;
18791900 }
18801901
@@ -2254,7 +2275,6 @@ export class DefaultClient implements Client {
22542275 return util . extractCompilerPathAndArgs ( ! ! settings . legacyCompilerArgsBehavior ,
22552276 this . configuration . CurrentConfiguration ?. compilerPath ,
22562277 this . configuration . CurrentConfiguration ?. compilerArgs ) ;
2257-
22582278 }
22592279
22602280 public async getVcpkgInstalled ( ) : Promise < boolean > {
@@ -2323,6 +2343,12 @@ export class DefaultClient implements Client {
23232343 ( ) => this . languageClient . sendRequest ( CppContextRequest , params , token ) , token ) ;
23242344 }
23252345
2346+ public async getCompletionContext ( file : vscode . Uri , caretOffset : number , token : vscode . CancellationToken ) : Promise < CopilotCompletionContextResult > {
2347+ await withCancellation ( this . ready , token ) ;
2348+ return DefaultClient . withLspCancellationHandling (
2349+ ( ) => this . languageClient . sendRequest ( CopilotCompletionContextRequest , { uri : file . toString ( ) , caretOffset } , token ) , token ) ;
2350+ }
2351+
23262352 /**
23272353 * a Promise that can be awaited to know when it's ok to proceed.
23282354 *
@@ -2695,7 +2721,8 @@ export class DefaultClient implements Client {
26952721 if ( notificationBody . event === "includeSquiggles" && this . configurationProvider && notificationBody . properties ) {
26962722 notificationBody . properties [ "providerId" ] = this . configurationProvider ;
26972723 }
2698- telemetry . logLanguageServerEvent ( notificationBody . event , notificationBody . properties , notificationBody . metrics ) ;
2724+ const metrics_unified : Record < string , number > = { ...notificationBody . metrics , ...notificationBody . signedMetrics } ;
2725+ telemetry . logLanguageServerEvent ( notificationBody . event , notificationBody . properties , metrics_unified ) ;
26992726 }
27002727
27012728 private async updateStatus ( notificationBody : ReportStatusNotificationBody ) : Promise < void > {
@@ -4251,4 +4278,5 @@ class NullClient implements Client {
42514278 getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > { return Promise . resolve ( { } as ChatContextResult ) ; }
42524279 getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > { return Promise . resolve ( { } as ProjectContextResult ) ; }
42534280 filesEncodingChanged ( filesEncodingChanged : FilesEncodingChanged ) : void { }
4281+ getCompletionContext ( file : vscode . Uri , caretOffset : number , token : vscode . CancellationToken ) : Promise < CopilotCompletionContextResult > { return Promise . resolve ( { } as CopilotCompletionContextResult ) ; }
42544282}
0 commit comments