@@ -20,9 +20,10 @@ import * as util from '../common';
2020import { getCrashCallStacksChannel } from '../logger' ;
2121import { PlatformInformation } from '../platform' ;
2222import * as telemetry from '../telemetry' ;
23- import { Client , DefaultClient , DoxygenCodeActionCommandArguments , GetIncludesResult , openFileVersions } from './client' ;
23+ import { Client , DefaultClient , DoxygenCodeActionCommandArguments , openFileVersions } from './client' ;
2424import { ClientCollection } from './clientCollection' ;
2525import { CodeActionDiagnosticInfo , CodeAnalysisDiagnosticIdentifiersAndUri , codeAnalysisAllFixes , codeAnalysisCodeToFixes , codeAnalysisFileToCodeActions } from './codeAnalysis' ;
26+ import { registerRelatedFilesCommands , registerRelatedFilesProvider } from './copilotProviders' ;
2627import { CppBuildTaskProvider } from './cppBuildTaskProvider' ;
2728import { getCustomConfigProviders } from './customProviders' ;
2829import { getLanguageConfig } from './languageConfig' ;
@@ -33,24 +34,6 @@ import { CppSettings } from './settings';
3334import { LanguageStatusUI , getUI } from './ui' ;
3435import { makeLspRange , rangeEquals , showInstallCompilerWalkthrough } from './utils' ;
3536
36- interface CopilotTrait {
37- name : string ;
38- value : string ;
39- includeInPrompt ?: boolean ;
40- promptTextOverride ?: string ;
41- }
42-
43- interface CopilotApi {
44- registerRelatedFilesProvider (
45- providerId : { extensionId : string ; languageId : string } ,
46- callback : (
47- uri : vscode . Uri ,
48- context : { flags : Record < string , unknown > } ,
49- cancellationToken : vscode . CancellationToken
50- ) => Promise < { entries : vscode . Uri [ ] ; traits ?: CopilotTrait [ ] } >
51- ) : Disposable ;
52- }
53-
5437nls . config ( { messageFormat : nls . MessageFormat . bundle , bundleFormat : nls . BundleFormat . standalone } ) ( ) ;
5538const localize : nls . LocalizeFunc = nls . loadMessageBundle ( ) ;
5639export const CppSourceStr : string = "C/C++" ;
@@ -201,8 +184,7 @@ export async function activate(): Promise<void> {
201184
202185 void clients . ActiveClient . ready . then ( ( ) => intervalTimer = global . setInterval ( onInterval , 2500 ) ) ;
203186
204- const isRelatedFilesApiEnabled = await telemetry . isExperimentEnabled ( "CppToolsRelatedFilesApi" ) ;
205- registerCommands ( true , isRelatedFilesApiEnabled ) ;
187+ await registerCommands ( true ) ;
206188
207189 vscode . tasks . onDidStartTask ( ( ) => getActiveClient ( ) . PauseCodeAnalysis ( ) ) ;
208190
@@ -274,22 +256,7 @@ export async function activate(): Promise<void> {
274256 disposables . push ( tool ) ;
275257 }
276258
277- if ( isRelatedFilesApiEnabled ) {
278- const api = await getCopilotApi ( ) ;
279- if ( util . extensionContext && api ) {
280- try {
281- for ( const languageId of [ 'c' , 'cpp' , 'cuda-cpp' ] ) {
282- api . registerRelatedFilesProvider (
283- { extensionId : util . extensionContext . extension . id , languageId } ,
284- async ( _uri : vscode . Uri , _context : { flags : Record < string , unknown > } , token : vscode . CancellationToken ) =>
285- ( { entries : ( await getIncludesWithCancellation ( 1 , token ) ) ?. includedFiles . map ( file => vscode . Uri . file ( file ) ) ?? [ ] } )
286- ) ;
287- }
288- } catch {
289- console . log ( "Failed to register Copilot related files provider." ) ;
290- }
291- }
292- }
259+ await registerRelatedFilesProvider ( ) ;
293260}
294261
295262export function updateLanguageConfigurations ( ) : void {
@@ -386,7 +353,7 @@ function onInterval(): void {
386353/**
387354 * registered commands
388355 */
389- export function registerCommands ( enabled : boolean , isRelatedFilesApiEnabled : boolean ) : void {
356+ export async function registerCommands ( enabled : boolean ) : Promise < void > {
390357 commandDisposables . forEach ( d => d . dispose ( ) ) ;
391358 commandDisposables . length = 0 ;
392359 commandDisposables . push ( vscode . commands . registerCommand ( 'C_Cpp.SwitchHeaderSource' , enabled ? onSwitchHeaderSource : onDisabledCommand ) ) ;
@@ -445,9 +412,7 @@ export function registerCommands(enabled: boolean, isRelatedFilesApiEnabled: boo
445412 commandDisposables . push ( vscode . commands . registerCommand ( 'C_Cpp.ExtractToMemberFunction' , enabled ? ( ) => onExtractToFunction ( false , true ) : onDisabledCommand ) ) ;
446413 commandDisposables . push ( vscode . commands . registerCommand ( 'C_Cpp.ExpandSelection' , enabled ? ( r : Range ) => onExpandSelection ( r ) : onDisabledCommand ) ) ;
447414
448- if ( ! isRelatedFilesApiEnabled ) {
449- commandDisposables . push ( vscode . commands . registerCommand ( 'C_Cpp.getIncludes' , enabled ? ( maxDepth : number ) => getIncludes ( maxDepth ) : ( ) => Promise . resolve ( ) ) ) ;
450- }
415+ await registerRelatedFilesCommands ( commandDisposables , enabled ) ;
451416}
452417
453418function onDisabledCommand ( ) {
@@ -1412,42 +1377,3 @@ export async function preReleaseCheck(): Promise<void> {
14121377 }
14131378 }
14141379}
1415-
1416- export async function getIncludesWithCancellation ( maxDepth : number , token : vscode . CancellationToken ) : Promise < GetIncludesResult > {
1417- const includes = await clients . ActiveClient . getIncludes ( maxDepth , token ) ;
1418- const wksFolder = clients . ActiveClient . RootUri ?. toString ( ) ;
1419-
1420- if ( ! wksFolder ) {
1421- return includes ;
1422- }
1423-
1424- includes . includedFiles = includes . includedFiles . filter ( header => vscode . Uri . file ( header ) . toString ( ) . startsWith ( wksFolder ) ) ;
1425- return includes ;
1426- }
1427-
1428- async function getIncludes ( maxDepth : number ) : Promise < GetIncludesResult > {
1429- const tokenSource = new vscode . CancellationTokenSource ( ) ;
1430- try {
1431- const includes = await getIncludesWithCancellation ( maxDepth , tokenSource . token ) ;
1432- return includes ;
1433- } finally {
1434- tokenSource . dispose ( ) ;
1435- }
1436- }
1437-
1438- async function getCopilotApi ( ) : Promise < CopilotApi | undefined > {
1439- const copilotExtension = vscode . extensions . getExtension < CopilotApi > ( 'github.copilot' ) ;
1440- if ( ! copilotExtension ) {
1441- return undefined ;
1442- }
1443-
1444- if ( ! copilotExtension . isActive ) {
1445- try {
1446- return await copilotExtension . activate ( ) ;
1447- } catch {
1448- return undefined ;
1449- }
1450- } else {
1451- return copilotExtension . exports ;
1452- }
1453- }
0 commit comments