@@ -9,14 +9,15 @@ import {
99import { BranchIssue , MAX_FETCH_BRANCH_ISSUES } from '../git/IssuesManager'
1010import { differenceInDays } from 'date-fns'
1111import { Account } from '../codacy/Account'
12+ import Logger from '../common/logger'
1213
1314const RECENTLY_ADDED_DAYS = 60
1415
1516export class BranchIssuesTree extends vscode . Disposable implements vscode . TreeDataProvider < BranchIssuesTreeNode > {
1617 private _onDidChangeTreeData = new vscode . EventEmitter < BranchIssuesTreeNode | void > ( )
1718 readonly onDidChangeTreeData = this . _onDidChangeTreeData . event
1819 private _disposables : vscode . Disposable [ ] = [ ]
19- private _view : vscode . TreeView < BranchIssuesTreeNode >
20+ private _view : vscode . TreeView < BranchIssuesTreeNode > | undefined
2021
2122 private _allIssues : BranchIssue [ ] = [ ]
2223
@@ -27,29 +28,44 @@ export class BranchIssuesTree extends vscode.Disposable implements vscode.TreeDa
2728 super ( ( ) => this . dispose ( ) )
2829
2930 // create the tree view
30- this . _view = vscode . window . createTreeView ( 'codacy:branchIssues' , {
31- treeDataProvider : this ,
32- showCollapseAll : true ,
33- } )
34-
35- this . _context . subscriptions . push ( this . _view )
36-
37- // create a command to open the pull request summaryToo
38- this . _context . subscriptions . push (
39- vscode . commands . registerCommand ( 'codacy.branchIssues.open' , ( ) => {
40- this . _view . reveal ( this . _view . selection [ 0 ] )
31+ try {
32+ this . _view = vscode . window . createTreeView ( 'codacy:branchIssues' , {
33+ treeDataProvider : this ,
34+ showCollapseAll : true ,
4135 } )
42- )
4336
44- // subsribe to changes in the current branch
45- this . _codacyCloud . branchIssues . onDidUpdateBranchIssues ( ( issues : BranchIssue [ ] ) => {
46- this . _allIssues = issues
47- this . _onDidChangeTreeData . fire ( )
48-
49- this . _view . title = `${ this . _codacyCloud . head ?. name } - ${ issues . length } ${
50- issues . length >= MAX_FETCH_BRANCH_ISSUES ? '+' : ''
51- } issues`
52- } )
37+ this . _context . subscriptions . push ( this . _view )
38+ Logger . debug ( 'BranchIssuesView created successfully' )
39+
40+ // create a command to open the pull request summary
41+ this . _context . subscriptions . push (
42+ vscode . commands . registerCommand ( 'codacy.branchIssues.open' , ( ) => {
43+ if ( this . _view ) {
44+ this . _view . reveal ( this . _view . selection [ 0 ] )
45+ }
46+ } )
47+ )
48+
49+ // subscribe to changes in the current branch
50+ this . _codacyCloud . branchIssues . onDidUpdateBranchIssues ( ( issues : BranchIssue [ ] ) => {
51+ this . _allIssues = issues
52+ this . _onDidChangeTreeData . fire ( )
53+
54+ if ( this . _view ) {
55+ this . _view . title = `${ this . _codacyCloud . head ?. name } - ${ issues . length } ${
56+ issues . length >= MAX_FETCH_BRANCH_ISSUES ? '+' : ''
57+ } issues`
58+ }
59+ } )
60+ } catch ( error ) {
61+ const errorMessage = error instanceof Error ? error . message : String ( error )
62+ Logger . error ( `Failed to create BranchIssuesView: ${ errorMessage } ` )
63+ Logger . error (
64+ `[BranchIssuesView] Error stack: ${ error instanceof Error ? error . stack : '[BranchIssuesView] No stack trace' } `
65+ )
66+ this . _view = undefined
67+ // Don't re-throw - let extension continue even if this view fails
68+ }
5369 }
5470
5571 getTreeItem ( element : BranchIssuesTreeNode ) : vscode . TreeItem | Thenable < vscode . TreeItem > {
0 commit comments