@@ -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 { CopilotCompletionContextFeatureFlag , 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,20 @@ 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
+ featureFlag : CopilotCompletionContextFeatureFlag ;
586
+ }
587
+
588
+ export interface CopilotCompletionContextParams {
589
+ uri : string ;
590
+ caretOffset : number ;
591
+ featureFlag : CopilotCompletionContextFeatureFlag ;
592
+ }
593
+
578
594
// Requests
579
595
const PreInitializationRequest : RequestType < void , string , void > = new RequestType < void , string , void > ( 'cpptools/preinitialize' ) ;
580
596
const InitializationRequest : RequestType < CppInitializationParams , void , void > = new RequestType < CppInitializationParams , void , void > ( 'cpptools/initialize' ) ;
@@ -597,6 +613,7 @@ const ChangeCppPropertiesRequest: RequestType<CppPropertiesParams, void, void> =
597
613
const IncludesRequest : RequestType < GetIncludesParams , GetIncludesResult , void > = new RequestType < GetIncludesParams , GetIncludesResult , void > ( 'cpptools/getIncludes' ) ;
598
614
const CppContextRequest : RequestType < TextDocumentIdentifier , ChatContextResult , void > = new RequestType < TextDocumentIdentifier , ChatContextResult , void > ( 'cpptools/getChatContext' ) ;
599
615
const 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' ) ;
600
617
601
618
// Notifications to the server
602
619
const DidOpenNotification : NotificationType < DidOpenTextDocumentParams > = new NotificationType < DidOpenTextDocumentParams > ( 'textDocument/didOpen' ) ;
@@ -832,6 +849,7 @@ export interface Client {
832
849
getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > ;
833
850
getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > ;
834
851
filesEncodingChanged ( filesEncodingChanged : FilesEncodingChanged ) : void ;
852
+ getCompletionContext ( fileName : vscode . Uri , caretOffset : number , featureFlag : CopilotCompletionContextFeatureFlag , token : vscode . CancellationToken ) : Promise < CopilotCompletionContextResult > ;
835
853
}
836
854
837
855
export function createClient ( workspaceFolder ?: vscode . WorkspaceFolder ) : Client {
@@ -866,6 +884,7 @@ export class DefaultClient implements Client {
866
884
private configurationProvider ?: string ;
867
885
private hoverProvider : HoverProvider | undefined ;
868
886
private copilotHoverProvider : CopilotHoverProvider | undefined ;
887
+ private copilotCompletionProvider ?: CopilotCompletionContextProvider ;
869
888
870
889
public lastCustomBrowseConfiguration : PersistentFolderState < WorkspaceBrowseConfiguration | undefined > | undefined ;
871
890
public lastCustomBrowseConfigurationProviderId : PersistentFolderState < string | undefined > | undefined ;
@@ -1344,6 +1363,9 @@ export class DefaultClient implements Client {
1344
1363
this . semanticTokensProviderDisposable = vscode . languages . registerDocumentSemanticTokensProvider ( util . documentSelector , this . semanticTokensProvider , semanticTokensLegend ) ;
1345
1364
}
1346
1365
1366
+ this . copilotCompletionProvider = await CopilotCompletionContextProvider . Create ( ) ;
1367
+ this . disposables . push ( this . copilotCompletionProvider ) ;
1368
+
1347
1369
// Listen for messages from the language server.
1348
1370
this . registerNotifications ( ) ;
1349
1371
@@ -1875,6 +1897,7 @@ export class DefaultClient implements Client {
1875
1897
if ( diagnosticsCollectionIntelliSense ) {
1876
1898
diagnosticsCollectionIntelliSense . delete ( document . uri ) ;
1877
1899
}
1900
+ this . copilotCompletionProvider ?. removeFile ( uri ) ;
1878
1901
openFileVersions . delete ( uri ) ;
1879
1902
}
1880
1903
@@ -2254,7 +2277,6 @@ export class DefaultClient implements Client {
2254
2277
return util . extractCompilerPathAndArgs ( ! ! settings . legacyCompilerArgsBehavior ,
2255
2278
this . configuration . CurrentConfiguration ?. compilerPath ,
2256
2279
this . configuration . CurrentConfiguration ?. compilerArgs ) ;
2257
-
2258
2280
}
2259
2281
2260
2282
public async getVcpkgInstalled ( ) : Promise < boolean > {
@@ -2323,6 +2345,14 @@ export class DefaultClient implements Client {
2323
2345
( ) => this . languageClient . sendRequest ( CppContextRequest , params , token ) , token ) ;
2324
2346
}
2325
2347
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
+
2326
2356
/**
2327
2357
* a Promise that can be awaited to know when it's ok to proceed.
2328
2358
*
@@ -2695,7 +2725,8 @@ export class DefaultClient implements Client {
2695
2725
if ( notificationBody . event === "includeSquiggles" && this . configurationProvider && notificationBody . properties ) {
2696
2726
notificationBody . properties [ "providerId" ] = this . configurationProvider ;
2697
2727
}
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 ) ;
2699
2730
}
2700
2731
2701
2732
private async updateStatus ( notificationBody : ReportStatusNotificationBody ) : Promise < void > {
@@ -4251,4 +4282,5 @@ class NullClient implements Client {
4251
4282
getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > { return Promise . resolve ( { } as ChatContextResult ) ; }
4252
4283
getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > { return Promise . resolve ( { } as ProjectContextResult ) ; }
4253
4284
filesEncodingChanged ( filesEncodingChanged : FilesEncodingChanged ) : void { }
4285
+ getCompletionContext ( file : vscode . Uri , caretOffset : number , featureFlag : CopilotCompletionContextFeatureFlag , token : vscode . CancellationToken ) : Promise < CopilotCompletionContextResult > { return Promise . resolve ( { } as CopilotCompletionContextResult ) ; }
4254
4286
}
0 commit comments