@@ -22,14 +22,13 @@ import { LLMAnalysisReportPanel } from './llmAnalysisReportPanel';
2222import CliTable3 = require( 'cli-table3' ) ;
2323import { Language , Parser , Query } from 'web-tree-sitter' ;
2424import { getValidAccessToken , performOIDCAuthorizationFlow } from './oidcAuthentication' ;
25+ import { TokenProvider , VSCodeTokenProvider } from './tokenProvider' ;
2526
2627export let outputChannelDep : DepOutputChannel ;
2728
2829export const notifications = new EventEmitter ( ) ;
2930
30-
31-
32- async function enableExtensionFeatures ( context : vscode . ExtensionContext ) : Promise < void > {
31+ async function enableExtensionFeatures ( context : vscode . ExtensionContext , tokenProvider : TokenProvider ) : Promise < void > {
3332 outputChannelDep . info ( 'Initializing RHDA analysis features' ) ;
3433
3534 context . subscriptions . push ( vscode . languages . registerCodeActionsProvider ( '*' , new class implements vscode . CodeActionProvider {
@@ -38,7 +37,7 @@ async function enableExtensionFeatures(context: vscode.ExtensionContext): Promis
3837 }
3938 } ( ) ) ) ;
4039
41- const fileHandler = new AnalysisMatcher ( ) ;
40+ const fileHandler = new AnalysisMatcher ( tokenProvider ) ;
4241 context . subscriptions . push ( vscode . workspace . onDidSaveTextDocument ( ( doc ) => fileHandler . handle ( doc , outputChannelDep ) ) ) ;
4342 // Anecdotaly, some extension(s) may cause did-open events for files that aren't actually open in the editor,
4443 // so this will trigger CA for files not actually open.
@@ -254,7 +253,7 @@ async function enableExtensionFeatures(context: vscode.ExtensionContext): Promis
254253 record ( context , TelemetryActions . componentAnalysisVulnerabilityReportQuickfixOption , { manifest : fileName , fileName : fileName } ) ;
255254 }
256255 try {
257- await generateRHDAReport ( context , fspath , outputChannelDep ) ;
256+ await generateRHDAReport ( context , tokenProvider , fspath , outputChannelDep ) ;
258257 record ( context , TelemetryActions . vulnerabilityReportDone , { manifest : fileName , fileName : fileName } ) ;
259258 } catch ( error ) {
260259 // TODO: dont show raw message
@@ -291,7 +290,7 @@ async function enableExtensionFeatures(context: vscode.ExtensionContext): Promis
291290 }
292291 ) ;
293292
294- registerStackAnalysisCommands ( context ) ;
293+ registerStackAnalysisCommands ( context , tokenProvider ) ;
295294
296295 const showVulnerabilityFoundPrompt = async ( msg : string , filePath : vscode . Uri ) => {
297296 const fileName = path . basename ( filePath . fsPath ) ;
@@ -348,14 +347,16 @@ async function enableExtensionFeatures(context: vscode.ExtensionContext): Promis
348347/**
349348 * Main activation function - checks authentication and conditionally enables features
350349 */
351- export async function activate ( context : vscode . ExtensionContext ) {
350+ export async function activate ( context : vscode . ExtensionContext ) : Promise < vscode . ExtensionContext > {
352351 outputChannelDep = new DepOutputChannel ( ) ;
353352 outputChannelDep . info ( `starting RHDA extension ${ context . extension . packageJSON [ 'version' ] } ` ) ;
354353
355354 globalConfig . linkToSecretStorage ( context ) ;
356355
357356 initTelemetry ( context ) ;
358357
358+ const tokenProvider = new VSCodeTokenProvider ( context ) ;
359+
359360 // Register authentication command (always available)
360361 const authenticateCommand = vscode . commands . registerCommand ( 'rhda.authenticate' , async ( ) => {
361362 const existingToken = await getValidAccessToken ( context ) ;
@@ -400,7 +401,9 @@ export async function activate(context: vscode.ExtensionContext) {
400401 } ) ;
401402 }
402403
403- await enableExtensionFeatures ( context ) ;
404+ await enableExtensionFeatures ( context , tokenProvider ) ;
405+
406+ return context ;
404407}
405408
406409/**
@@ -461,12 +464,12 @@ function showRHRepositoryRecommendationNotification() {
461464 * Registers stack analysis commands to track RHDA report generations.
462465 * @param context - The extension context.
463466 */
464- function registerStackAnalysisCommands ( context : vscode . ExtensionContext ) {
467+ function registerStackAnalysisCommands ( context : vscode . ExtensionContext , tokenProvider : TokenProvider ) {
465468
466469 const invokeFullStackReport = async ( filePath : string ) => {
467470 const fileName = path . basename ( filePath ) ;
468471 try {
469- await generateRHDAReport ( context , filePath , outputChannelDep ) ;
472+ await generateRHDAReport ( context , tokenProvider , filePath , outputChannelDep ) ;
470473 record ( context , TelemetryActions . vulnerabilityReportDone , { manifest : fileName , fileName : fileName } ) ;
471474 } catch ( error ) {
472475 const message = applySettingNameMappings ( ( error as Error ) . message ) ;
0 commit comments