@@ -43,6 +43,7 @@ import { localizedStringCount, lookupString } from '../nativeStrings';
4343import { SessionState } from '../sessionState' ;
4444import * as telemetry from '../telemetry' ;
4545import { TestHook , getTestHook } from '../testHook' ;
46+ import { CopilotHoverProvider } from './Providers/CopilotHoverProvider' ;
4647import { HoverProvider } from './Providers/HoverProvider' ;
4748import {
4849 CodeAnalysisDiagnosticIdentifiersAndUri ,
@@ -533,6 +534,15 @@ export interface GetIncludesResult {
533534 includedFiles : string [ ] ;
534535}
535536
537+ export interface GetCopilotHoverInfoParams {
538+ textDocument : TextDocumentIdentifier ;
539+ position : Position ;
540+ }
541+
542+ interface GetCopilotHoverInfoResult {
543+ content : string ;
544+ }
545+
536546export interface ChatContextResult {
537547 language : string ;
538548 standardVersion : string ;
@@ -567,6 +577,7 @@ export const FormatDocumentRequest: RequestType<FormatParams, FormatResult, void
567577export const FormatRangeRequest : RequestType < FormatParams , FormatResult , void > = new RequestType < FormatParams , FormatResult , void > ( 'cpptools/formatRange' ) ;
568578export const FormatOnTypeRequest : RequestType < FormatParams , FormatResult , void > = new RequestType < FormatParams , FormatResult , void > ( 'cpptools/formatOnType' ) ;
569579export 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' ) ;
570581const CreateDeclarationOrDefinitionRequest : RequestType < CreateDeclarationOrDefinitionParams , CreateDeclarationOrDefinitionResult , void > = new RequestType < CreateDeclarationOrDefinitionParams , CreateDeclarationOrDefinitionResult , void > ( 'cpptools/createDeclDef' ) ;
571582const ExtractToFunctionRequest : RequestType < ExtractToFunctionParams , WorkspaceEditResult , void > = new RequestType < ExtractToFunctionParams , WorkspaceEditResult , void > ( 'cpptools/extractToFunction' ) ;
572583const GoToDirectiveInGroupRequest : RequestType < GoToDirectiveInGroupParams , Position | undefined , void > = new RequestType < GoToDirectiveInGroupParams , Position | undefined , void > ( 'cpptools/goToDirectiveInGroup' ) ;
@@ -804,6 +815,7 @@ export interface Client {
804815 getShowConfigureIntelliSenseButton ( ) : boolean ;
805816 setShowConfigureIntelliSenseButton ( show : boolean ) : void ;
806817 addTrustedCompiler ( path : string ) : Promise < void > ;
818+ getCopilotHoverProvider ( ) : CopilotHoverProvider | undefined ;
807819 getIncludes ( maxDepth : number ) : Promise < GetIncludesResult > ;
808820 getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > ;
809821 getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > ;
@@ -839,11 +851,14 @@ export class DefaultClient implements Client {
839851 private settingsTracker : SettingsTracker ;
840852 private loggingLevel : number = 1 ;
841853 private configurationProvider ?: string ;
854+ private hoverProvider : HoverProvider | undefined ;
855+ private copilotHoverProvider : CopilotHoverProvider | undefined ;
842856
843857 public lastCustomBrowseConfiguration : PersistentFolderState < WorkspaceBrowseConfiguration | undefined > | undefined ;
844858 public lastCustomBrowseConfigurationProviderId : PersistentFolderState < string | undefined > | undefined ;
845859 public lastCustomBrowseConfigurationProviderVersion : PersistentFolderState < Version > | undefined ;
846860 public currentCaseSensitiveFileSupport : PersistentWorkspaceState < boolean > | undefined ;
861+ public currentCopilotHoverEnabled : PersistentWorkspaceState < string > | undefined ;
847862 private registeredProviders : PersistentFolderState < string [ ] > | undefined ;
848863
849864 private configStateReceived : ConfigStateReceived = { compilers : false , compileCommands : false , configProviders : undefined , timeout : false } ;
@@ -1273,8 +1288,16 @@ export class DefaultClient implements Client {
12731288 this . registerFileWatcher ( ) ;
12741289 initializedClientCount = 0 ;
12751290 this . inlayHintsProvider = new InlayHintsProvider ( ) ;
1291+ this . hoverProvider = new HoverProvider ( this ) ;
12761292
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 ) ) ;
12781301 this . disposables . push ( vscode . languages . registerInlayHintsProvider ( util . documentSelector , this . inlayHintsProvider ) ) ;
12791302 this . disposables . push ( vscode . languages . registerRenameProvider ( util . documentSelector , new RenameProvider ( this ) ) ) ;
12801303 this . disposables . push ( vscode . languages . registerReferenceProvider ( util . documentSelector , new FindAllReferencesProvider ( this ) ) ) ;
@@ -1292,7 +1315,6 @@ export class DefaultClient implements Client {
12921315 this . codeFoldingProvider = new FoldingRangeProvider ( this ) ;
12931316 this . codeFoldingProviderDisposable = vscode . languages . registerFoldingRangeProvider ( util . documentSelector , this . codeFoldingProvider ) ;
12941317
1295- const settings : CppSettings = new CppSettings ( ) ;
12961318 if ( settings . isEnhancedColorizationEnabled && semanticTokensLegend ) {
12971319 this . semanticTokensProvider = new SemanticTokensProvider ( ) ;
12981320 this . semanticTokensProviderDisposable = vscode . languages . registerDocumentSemanticTokensProvider ( util . documentSelector , this . semanticTokensProvider , semanticTokensLegend ) ;
@@ -1473,6 +1495,9 @@ export class DefaultClient implements Client {
14731495 if ( this . currentCaseSensitiveFileSupport && workspaceSettings . isCaseSensitiveFileSupportEnabled !== this . currentCaseSensitiveFileSupport . Value ) {
14741496 void util . promptForReloadWindowDueToSettingsChange ( ) ;
14751497 }
1498+ if ( this . currentCopilotHoverEnabled && workspaceSettings . copilotHover !== this . currentCopilotHoverEnabled . Value ) {
1499+ void util . promptForReloadWindowDueToSettingsChange ( ) ;
1500+ }
14761501 return {
14771502 filesAssociations : workspaceOtherSettings . filesAssociations ,
14781503 workspaceFallbackEncoding : workspaceOtherSettings . filesEncoding ,
@@ -1495,6 +1520,7 @@ export class DefaultClient implements Client {
14951520 codeAnalysisMaxConcurrentThreads : workspaceSettings . codeAnalysisMaxConcurrentThreads ,
14961521 codeAnalysisMaxMemory : workspaceSettings . codeAnalysisMaxMemory ,
14971522 codeAnalysisUpdateDelay : workspaceSettings . codeAnalysisUpdateDelay ,
1523+ copilotHover : workspaceSettings . copilotHover ,
14981524 workspaceFolderSettings : workspaceFolderSettingsParams
14991525 } ;
15001526 }
@@ -1605,6 +1631,12 @@ export class DefaultClient implements Client {
16051631 // We manually restart the language server so tell the LanguageClient not to do it automatically for us.
16061632 return { action : CloseAction . DoNotRestart , message } ;
16071633 }
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
16081640 }
16091641
16101642 // TODO: should I set the output channel? Does this sort output between servers?
@@ -4045,6 +4077,14 @@ export class DefaultClient implements Client {
40454077 compilerDefaults = await this . requestCompiler ( path ) ;
40464078 DebugConfigurationProvider . ClearDetectedBuildTasks ( ) ;
40474079 }
4080+
4081+ public getHoverProvider ( ) : HoverProvider | undefined {
4082+ return this . hoverProvider ;
4083+ }
4084+
4085+ public getCopilotHoverProvider ( ) : CopilotHoverProvider | undefined {
4086+ return this . copilotHoverProvider ;
4087+ }
40484088}
40494089
40504090function getLanguageServerFileName ( ) : string {
@@ -4156,6 +4196,7 @@ class NullClient implements Client {
41564196 getShowConfigureIntelliSenseButton ( ) : boolean { return false ; }
41574197 setShowConfigureIntelliSenseButton ( show : boolean ) : void { }
41584198 addTrustedCompiler ( path : string ) : Promise < void > { return Promise . resolve ( ) ; }
4199+ getCopilotHoverProvider ( ) : CopilotHoverProvider | undefined { return undefined ; }
41594200 getIncludes ( maxDepth : number ) : Promise < GetIncludesResult > { return Promise . resolve ( { } as GetIncludesResult ) ; }
41604201 getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > { return Promise . resolve ( { } as ChatContextResult ) ; }
41614202 getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > { return Promise . resolve ( { } as ProjectContextResult ) ; }
0 commit comments