@@ -43,6 +43,7 @@ import { localizedStringCount, lookupString } from '../nativeStrings';
43
43
import { SessionState } from '../sessionState' ;
44
44
import * as telemetry from '../telemetry' ;
45
45
import { TestHook , getTestHook } from '../testHook' ;
46
+ import { CopilotHoverProvider } from './Providers/CopilotHoverProvider' ;
46
47
import { HoverProvider } from './Providers/HoverProvider' ;
47
48
import {
48
49
CodeAnalysisDiagnosticIdentifiersAndUri ,
@@ -533,6 +534,15 @@ export interface GetIncludesResult {
533
534
includedFiles : string [ ] ;
534
535
}
535
536
537
+ export interface GetCopilotHoverInfoParams {
538
+ textDocument : TextDocumentIdentifier ;
539
+ position : Position ;
540
+ }
541
+
542
+ interface GetCopilotHoverInfoResult {
543
+ content : string ;
544
+ }
545
+
536
546
export interface ChatContextResult {
537
547
language : string ;
538
548
standardVersion : string ;
@@ -567,6 +577,7 @@ export const FormatDocumentRequest: RequestType<FormatParams, FormatResult, void
567
577
export const FormatRangeRequest : RequestType < FormatParams , FormatResult , void > = new RequestType < FormatParams , FormatResult , void > ( 'cpptools/formatRange' ) ;
568
578
export const FormatOnTypeRequest : RequestType < FormatParams , FormatResult , void > = new RequestType < FormatParams , FormatResult , void > ( 'cpptools/formatOnType' ) ;
569
579
export const HoverRequest : RequestType < TextDocumentPositionParams , vscode . Hover , void > = new RequestType < TextDocumentPositionParams , vscode . Hover , void > ( 'cpptools/hover' ) ;
580
+ export const GetCopilotHoverInfoRequest : RequestType < GetCopilotHoverInfoParams , GetCopilotHoverInfoResult , void > = new RequestType < GetCopilotHoverInfoParams , GetCopilotHoverInfoResult , void > ( 'cpptools/getCopilotHoverInfo' ) ;
570
581
const CreateDeclarationOrDefinitionRequest : RequestType < CreateDeclarationOrDefinitionParams , CreateDeclarationOrDefinitionResult , void > = new RequestType < CreateDeclarationOrDefinitionParams , CreateDeclarationOrDefinitionResult , void > ( 'cpptools/createDeclDef' ) ;
571
582
const ExtractToFunctionRequest : RequestType < ExtractToFunctionParams , WorkspaceEditResult , void > = new RequestType < ExtractToFunctionParams , WorkspaceEditResult , void > ( 'cpptools/extractToFunction' ) ;
572
583
const GoToDirectiveInGroupRequest : RequestType < GoToDirectiveInGroupParams , Position | undefined , void > = new RequestType < GoToDirectiveInGroupParams , Position | undefined , void > ( 'cpptools/goToDirectiveInGroup' ) ;
@@ -804,6 +815,7 @@ export interface Client {
804
815
getShowConfigureIntelliSenseButton ( ) : boolean ;
805
816
setShowConfigureIntelliSenseButton ( show : boolean ) : void ;
806
817
addTrustedCompiler ( path : string ) : Promise < void > ;
818
+ getCopilotHoverProvider ( ) : CopilotHoverProvider | undefined ;
807
819
getIncludes ( maxDepth : number ) : Promise < GetIncludesResult > ;
808
820
getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > ;
809
821
getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > ;
@@ -839,11 +851,14 @@ export class DefaultClient implements Client {
839
851
private settingsTracker : SettingsTracker ;
840
852
private loggingLevel : number = 1 ;
841
853
private configurationProvider ?: string ;
854
+ private hoverProvider : HoverProvider | undefined ;
855
+ private copilotHoverProvider : CopilotHoverProvider | undefined ;
842
856
843
857
public lastCustomBrowseConfiguration : PersistentFolderState < WorkspaceBrowseConfiguration | undefined > | undefined ;
844
858
public lastCustomBrowseConfigurationProviderId : PersistentFolderState < string | undefined > | undefined ;
845
859
public lastCustomBrowseConfigurationProviderVersion : PersistentFolderState < Version > | undefined ;
846
860
public currentCaseSensitiveFileSupport : PersistentWorkspaceState < boolean > | undefined ;
861
+ public currentCopilotHoverEnabled : PersistentWorkspaceState < string > | undefined ;
847
862
private registeredProviders : PersistentFolderState < string [ ] > | undefined ;
848
863
849
864
private configStateReceived : ConfigStateReceived = { compilers : false , compileCommands : false , configProviders : undefined , timeout : false } ;
@@ -1273,8 +1288,16 @@ export class DefaultClient implements Client {
1273
1288
this . registerFileWatcher ( ) ;
1274
1289
initializedClientCount = 0 ;
1275
1290
this . inlayHintsProvider = new InlayHintsProvider ( ) ;
1291
+ this . hoverProvider = new HoverProvider ( this ) ;
1276
1292
1277
- this . disposables . push ( vscode . languages . registerHoverProvider ( util . documentSelector , new HoverProvider ( this ) ) ) ;
1293
+ const settings : CppSettings = new CppSettings ( ) ;
1294
+ this . currentCopilotHoverEnabled = new PersistentWorkspaceState < string > ( "cpp.copilotHover" , settings . copilotHover ) ;
1295
+ if ( settings . copilotHover === "enabled" ||
1296
+ ( settings . copilotHover === "default" && await telemetry . isFlightEnabled ( "CppCopilotHover" ) ) ) {
1297
+ this . copilotHoverProvider = new CopilotHoverProvider ( this ) ;
1298
+ this . disposables . push ( vscode . languages . registerHoverProvider ( util . documentSelector , this . copilotHoverProvider ) ) ;
1299
+ }
1300
+ this . disposables . push ( vscode . languages . registerHoverProvider ( util . documentSelector , this . hoverProvider ) ) ;
1278
1301
this . disposables . push ( vscode . languages . registerInlayHintsProvider ( util . documentSelector , this . inlayHintsProvider ) ) ;
1279
1302
this . disposables . push ( vscode . languages . registerRenameProvider ( util . documentSelector , new RenameProvider ( this ) ) ) ;
1280
1303
this . disposables . push ( vscode . languages . registerReferenceProvider ( util . documentSelector , new FindAllReferencesProvider ( this ) ) ) ;
@@ -1292,7 +1315,6 @@ export class DefaultClient implements Client {
1292
1315
this . codeFoldingProvider = new FoldingRangeProvider ( this ) ;
1293
1316
this . codeFoldingProviderDisposable = vscode . languages . registerFoldingRangeProvider ( util . documentSelector , this . codeFoldingProvider ) ;
1294
1317
1295
- const settings : CppSettings = new CppSettings ( ) ;
1296
1318
if ( settings . isEnhancedColorizationEnabled && semanticTokensLegend ) {
1297
1319
this . semanticTokensProvider = new SemanticTokensProvider ( ) ;
1298
1320
this . semanticTokensProviderDisposable = vscode . languages . registerDocumentSemanticTokensProvider ( util . documentSelector , this . semanticTokensProvider , semanticTokensLegend ) ;
@@ -1473,6 +1495,9 @@ export class DefaultClient implements Client {
1473
1495
if ( this . currentCaseSensitiveFileSupport && workspaceSettings . isCaseSensitiveFileSupportEnabled !== this . currentCaseSensitiveFileSupport . Value ) {
1474
1496
void util . promptForReloadWindowDueToSettingsChange ( ) ;
1475
1497
}
1498
+ if ( this . currentCopilotHoverEnabled && workspaceSettings . copilotHover !== this . currentCopilotHoverEnabled . Value ) {
1499
+ void util . promptForReloadWindowDueToSettingsChange ( ) ;
1500
+ }
1476
1501
return {
1477
1502
filesAssociations : workspaceOtherSettings . filesAssociations ,
1478
1503
workspaceFallbackEncoding : workspaceOtherSettings . filesEncoding ,
@@ -1495,6 +1520,7 @@ export class DefaultClient implements Client {
1495
1520
codeAnalysisMaxConcurrentThreads : workspaceSettings . codeAnalysisMaxConcurrentThreads ,
1496
1521
codeAnalysisMaxMemory : workspaceSettings . codeAnalysisMaxMemory ,
1497
1522
codeAnalysisUpdateDelay : workspaceSettings . codeAnalysisUpdateDelay ,
1523
+ copilotHover : workspaceSettings . copilotHover ,
1498
1524
workspaceFolderSettings : workspaceFolderSettingsParams
1499
1525
} ;
1500
1526
}
@@ -1605,6 +1631,12 @@ export class DefaultClient implements Client {
1605
1631
// We manually restart the language server so tell the LanguageClient not to do it automatically for us.
1606
1632
return { action : CloseAction . DoNotRestart , message } ;
1607
1633
}
1634
+ } ,
1635
+ markdown : {
1636
+ isTrusted : true
1637
+ // TODO: support for icons in markdown is not yet in the released version of vscode-languageclient.
1638
+ // Based on PR (https://github.com/microsoft/vscode-languageserver-node/pull/1504)
1639
+ //supportThemeIcons: true
1608
1640
}
1609
1641
1610
1642
// TODO: should I set the output channel? Does this sort output between servers?
@@ -4045,6 +4077,14 @@ export class DefaultClient implements Client {
4045
4077
compilerDefaults = await this . requestCompiler ( path ) ;
4046
4078
DebugConfigurationProvider . ClearDetectedBuildTasks ( ) ;
4047
4079
}
4080
+
4081
+ public getHoverProvider ( ) : HoverProvider | undefined {
4082
+ return this . hoverProvider ;
4083
+ }
4084
+
4085
+ public getCopilotHoverProvider ( ) : CopilotHoverProvider | undefined {
4086
+ return this . copilotHoverProvider ;
4087
+ }
4048
4088
}
4049
4089
4050
4090
function getLanguageServerFileName ( ) : string {
@@ -4156,6 +4196,7 @@ class NullClient implements Client {
4156
4196
getShowConfigureIntelliSenseButton ( ) : boolean { return false ; }
4157
4197
setShowConfigureIntelliSenseButton ( show : boolean ) : void { }
4158
4198
addTrustedCompiler ( path : string ) : Promise < void > { return Promise . resolve ( ) ; }
4199
+ getCopilotHoverProvider ( ) : CopilotHoverProvider | undefined { return undefined ; }
4159
4200
getIncludes ( maxDepth : number ) : Promise < GetIncludesResult > { return Promise . resolve ( { } as GetIncludesResult ) ; }
4160
4201
getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > { return Promise . resolve ( { } as ChatContextResult ) ; }
4161
4202
getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > { return Promise . resolve ( { } as ProjectContextResult ) ; }
0 commit comments