@@ -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 { CopilotCompletionContextFeatures , 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 {
@@ -576,6 +578,21 @@ interface FilesEncodingChanged {
576
578
foldersFilesEncoding : FolderFilesEncodingChanged [ ] ;
577
579
}
578
580
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
+
579
596
// Requests
580
597
const PreInitializationRequest : RequestType < void , string , void > = new RequestType < void , string , void > ( 'cpptools/preinitialize' ) ;
581
598
const InitializationRequest : RequestType < CppInitializationParams , void , void > = new RequestType < CppInitializationParams , void , void > ( 'cpptools/initialize' ) ;
@@ -598,6 +615,7 @@ const ChangeCppPropertiesRequest: RequestType<CppPropertiesParams, void, void> =
598
615
const IncludesRequest : RequestType < GetIncludesParams , GetIncludesResult , void > = new RequestType < GetIncludesParams , GetIncludesResult , void > ( 'cpptools/getIncludes' ) ;
599
616
const CppContextRequest : RequestType < TextDocumentIdentifier , ChatContextResult , void > = new RequestType < TextDocumentIdentifier , ChatContextResult , void > ( 'cpptools/getChatContext' ) ;
600
617
const 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' ) ;
601
619
602
620
// Notifications to the server
603
621
const DidOpenNotification : NotificationType < DidOpenTextDocumentParams > = new NotificationType < DidOpenTextDocumentParams > ( 'textDocument/didOpen' ) ;
@@ -833,6 +851,7 @@ export interface Client {
833
851
getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > ;
834
852
getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > ;
835
853
filesEncodingChanged ( filesEncodingChanged : FilesEncodingChanged ) : void ;
854
+ getCompletionContext ( fileName : vscode . Uri , caretOffset : number , featureFlag : CopilotCompletionContextFeatures , token : vscode . CancellationToken ) : Promise < CopilotCompletionContextResult > ;
836
855
}
837
856
838
857
export function createClient ( workspaceFolder ?: vscode . WorkspaceFolder ) : Client {
@@ -867,6 +886,7 @@ export class DefaultClient implements Client {
867
886
private configurationProvider ?: string ;
868
887
private hoverProvider : HoverProvider | undefined ;
869
888
private copilotHoverProvider : CopilotHoverProvider | undefined ;
889
+ private copilotCompletionProvider ?: CopilotCompletionContextProvider ;
870
890
871
891
public lastCustomBrowseConfiguration : PersistentFolderState < WorkspaceBrowseConfiguration | undefined > | undefined ;
872
892
public lastCustomBrowseConfigurationProviderId : PersistentFolderState < string | undefined > | undefined ;
@@ -1343,6 +1363,9 @@ export class DefaultClient implements Client {
1343
1363
this . semanticTokensProviderDisposable = vscode . languages . registerDocumentSemanticTokensProvider ( util . documentSelector , this . semanticTokensProvider , semanticTokensLegend ) ;
1344
1364
}
1345
1365
1366
+ this . copilotCompletionProvider = await CopilotCompletionContextProvider . Create ( ) ;
1367
+ this . disposables . push ( this . copilotCompletionProvider ) ;
1368
+
1346
1369
// Listen for messages from the language server.
1347
1370
this . registerNotifications ( ) ;
1348
1371
@@ -1875,6 +1898,7 @@ export class DefaultClient implements Client {
1875
1898
if ( diagnosticsCollectionIntelliSense ) {
1876
1899
diagnosticsCollectionIntelliSense . delete ( document . uri ) ;
1877
1900
}
1901
+ this . copilotCompletionProvider ?. removeFile ( uri ) ;
1878
1902
openFileVersions . delete ( uri ) ;
1879
1903
}
1880
1904
@@ -2256,7 +2280,6 @@ export class DefaultClient implements Client {
2256
2280
return util . extractCompilerPathAndArgs ( ! ! settings . legacyCompilerArgsBehavior ,
2257
2281
this . configuration . CurrentConfiguration ?. compilerPath ,
2258
2282
this . configuration . CurrentConfiguration ?. compilerArgs ) ;
2259
-
2260
2283
}
2261
2284
2262
2285
public async getVcpkgInstalled ( ) : Promise < boolean > {
@@ -2325,6 +2348,14 @@ export class DefaultClient implements Client {
2325
2348
( ) => this . languageClient . sendRequest ( CppContextRequest , params , token ) , token ) ;
2326
2349
}
2327
2350
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
+
2328
2359
/**
2329
2360
* a Promise that can be awaited to know when it's ok to proceed.
2330
2361
*
@@ -2697,7 +2728,8 @@ export class DefaultClient implements Client {
2697
2728
if ( notificationBody . event === "includeSquiggles" && this . configurationProvider && notificationBody . properties ) {
2698
2729
notificationBody . properties [ "providerId" ] = this . configurationProvider ;
2699
2730
}
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 ) ;
2701
2733
}
2702
2734
2703
2735
private async updateStatus ( notificationBody : ReportStatusNotificationBody ) : Promise < void > {
@@ -4259,4 +4291,5 @@ class NullClient implements Client {
4259
4291
getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > { return Promise . resolve ( { } as ChatContextResult ) ; }
4260
4292
getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > { return Promise . resolve ( { } as ProjectContextResult ) ; }
4261
4293
filesEncodingChanged ( filesEncodingChanged : FilesEncodingChanged ) : void { }
4294
+ getCompletionContext ( file : vscode . Uri , caretOffset : number , featureFlag : CopilotCompletionContextFeatures , token : vscode . CancellationToken ) : Promise < CopilotCompletionContextResult > { return Promise . resolve ( { } as CopilotCompletionContextResult ) ; }
4262
4295
}
0 commit comments