@@ -54,9 +54,10 @@ import {
54
54
} from './codeAnalysis' ;
55
55
import { Location , TextEdit , WorkspaceEdit } from './commonTypes' ;
56
56
import * as configs from './configurations' ;
57
+ import { CopilotCompletionContextProvider } from './copilotCompletionContextProvider' ;
57
58
import { DataBinding } from './dataBinding' ;
58
59
import { 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' ;
60
61
import { LocalizeStringParams , getLocaleId , getLocalizedString } from './localization' ;
61
62
import { PersistentFolderState , PersistentState , PersistentWorkspaceState } from './persistentState' ;
62
63
import { RequestCancelled , ServerCancelled , createProtocolFilter } from './protocolFilter' ;
@@ -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 {
@@ -575,6 +577,18 @@ interface FilesEncodingChanged {
575
577
foldersFilesEncoding : FolderFilesEncodingChanged [ ] ;
576
578
}
577
579
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
+
578
592
// Requests
579
593
const PreInitializationRequest : RequestType < void , string , void > = new RequestType < void , string , void > ( 'cpptools/preinitialize' ) ;
580
594
const InitializationRequest : RequestType < CppInitializationParams , void , void > = new RequestType < CppInitializationParams , void , void > ( 'cpptools/initialize' ) ;
@@ -597,6 +611,7 @@ const ChangeCppPropertiesRequest: RequestType<CppPropertiesParams, void, void> =
597
611
const IncludesRequest : RequestType < GetIncludesParams , GetIncludesResult , void > = new RequestType < GetIncludesParams , GetIncludesResult , void > ( 'cpptools/getIncludes' ) ;
598
612
const CppContextRequest : RequestType < TextDocumentIdentifier , ChatContextResult , void > = new RequestType < TextDocumentIdentifier , ChatContextResult , void > ( 'cpptools/getChatContext' ) ;
599
613
const 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' ) ;
600
615
601
616
// Notifications to the server
602
617
const DidOpenNotification : NotificationType < DidOpenTextDocumentParams > = new NotificationType < DidOpenTextDocumentParams > ( 'textDocument/didOpen' ) ;
@@ -832,6 +847,7 @@ export interface Client {
832
847
getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > ;
833
848
getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > ;
834
849
filesEncodingChanged ( filesEncodingChanged : FilesEncodingChanged ) : void ;
850
+ getCompletionContext ( fileName : vscode . Uri , caretOffset : number , token : vscode . CancellationToken ) : Promise < CopilotCompletionContextResult > ;
835
851
}
836
852
837
853
export function createClient ( workspaceFolder ?: vscode . WorkspaceFolder ) : Client {
@@ -866,6 +882,7 @@ export class DefaultClient implements Client {
866
882
private configurationProvider ?: string ;
867
883
private hoverProvider : HoverProvider | undefined ;
868
884
private copilotHoverProvider : CopilotHoverProvider | undefined ;
885
+ private copilotCompletionProvider ?: CopilotCompletionContextProvider ;
869
886
870
887
public lastCustomBrowseConfiguration : PersistentFolderState < WorkspaceBrowseConfiguration | undefined > | undefined ;
871
888
public lastCustomBrowseConfigurationProviderId : PersistentFolderState < string | undefined > | undefined ;
@@ -1344,6 +1361,9 @@ export class DefaultClient implements Client {
1344
1361
this . semanticTokensProviderDisposable = vscode . languages . registerDocumentSemanticTokensProvider ( util . documentSelector , this . semanticTokensProvider , semanticTokensLegend ) ;
1345
1362
}
1346
1363
1364
+ this . copilotCompletionProvider = await CopilotCompletionContextProvider . Create ( ) ;
1365
+ this . disposables . push ( this . copilotCompletionProvider ) ;
1366
+
1347
1367
// Listen for messages from the language server.
1348
1368
this . registerNotifications ( ) ;
1349
1369
@@ -1875,6 +1895,7 @@ export class DefaultClient implements Client {
1875
1895
if ( diagnosticsCollectionIntelliSense ) {
1876
1896
diagnosticsCollectionIntelliSense . delete ( document . uri ) ;
1877
1897
}
1898
+ this . copilotCompletionProvider ?. removeFile ( uri ) ;
1878
1899
openFileVersions . delete ( uri ) ;
1879
1900
}
1880
1901
@@ -2254,7 +2275,6 @@ export class DefaultClient implements Client {
2254
2275
return util . extractCompilerPathAndArgs ( ! ! settings . legacyCompilerArgsBehavior ,
2255
2276
this . configuration . CurrentConfiguration ?. compilerPath ,
2256
2277
this . configuration . CurrentConfiguration ?. compilerArgs ) ;
2257
-
2258
2278
}
2259
2279
2260
2280
public async getVcpkgInstalled ( ) : Promise < boolean > {
@@ -2323,6 +2343,12 @@ export class DefaultClient implements Client {
2323
2343
( ) => this . languageClient . sendRequest ( CppContextRequest , params , token ) , token ) ;
2324
2344
}
2325
2345
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
+
2326
2352
/**
2327
2353
* a Promise that can be awaited to know when it's ok to proceed.
2328
2354
*
@@ -2695,7 +2721,8 @@ export class DefaultClient implements Client {
2695
2721
if ( notificationBody . event === "includeSquiggles" && this . configurationProvider && notificationBody . properties ) {
2696
2722
notificationBody . properties [ "providerId" ] = this . configurationProvider ;
2697
2723
}
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 ) ;
2699
2726
}
2700
2727
2701
2728
private async updateStatus ( notificationBody : ReportStatusNotificationBody ) : Promise < void > {
@@ -4251,4 +4278,5 @@ class NullClient implements Client {
4251
4278
getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > { return Promise . resolve ( { } as ChatContextResult ) ; }
4252
4279
getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > { return Promise . resolve ( { } as ProjectContextResult ) ; }
4253
4280
filesEncodingChanged ( filesEncodingChanged : FilesEncodingChanged ) : void { }
4281
+ getCompletionContext ( file : vscode . Uri , caretOffset : number , token : vscode . CancellationToken ) : Promise < CopilotCompletionContextResult > { return Promise . resolve ( { } as CopilotCompletionContextResult ) ; }
4254
4282
}
0 commit comments