@@ -2,60 +2,86 @@ import * as vscode from "vscode";
22import { DebugProtocol } from "@vscode/debugprotocol" ;
33import { DebugSessionTracker } from "../debug-session-tracker" ;
44
5- /** A tree data provider for listing loaded modules for the active debug session. */
6- export class ModulesDataProvider
7- implements vscode . TreeDataProvider < DebugProtocol . Module >
8- {
9- private changeTreeData = new vscode . EventEmitter < void > ( ) ;
10- readonly onDidChangeTreeData = this . changeTreeData . event ;
5+ export interface ModuleProperty {
6+ key : string ;
7+ value : string ;
8+ }
119
12- constructor ( private readonly tracker : DebugSessionTracker ) {
13- tracker . onDidChangeModules ( ( ) => this . changeTreeData . fire ( ) ) ;
14- vscode . debug . onDidChangeActiveDebugSession ( ( ) =>
15- this . changeTreeData . fire ( ) ,
16- ) ;
10+ /** Type to represent both Module and ModuleProperty since TreeDataProvider
11+ * expects one concrete type */
12+ type TreeData = DebugProtocol . Module | ModuleProperty ;
13+
14+ function isModule ( type : TreeData ) : type is DebugProtocol . Module {
15+ return ( type as DebugProtocol . Module ) . id !== undefined ;
16+ }
17+
18+ class ModuleItem extends vscode . TreeItem {
19+ constructor ( module : DebugProtocol . Module ) {
20+ super ( module . name , vscode . TreeItemCollapsibleState . Collapsed ) ;
21+ this . description = module . symbolStatus ;
1722 }
1823
19- getTreeItem ( module : DebugProtocol . Module ) : vscode . TreeItem {
20- let treeItem = new vscode . TreeItem ( /*label=*/ module . name ) ;
21- if ( module . path ) {
22- treeItem . description = `${ module . id } -- ${ module . path } ` ;
23- } else {
24- treeItem . description = `${ module . id } ` ;
25- }
24+ static getProperties ( module : DebugProtocol . Module ) : ModuleProperty [ ] {
25+ // does not include the name and symbol status as it is show in the parent.
26+ let children : ModuleProperty [ ] = [ ] ;
27+ children . push ( { key : "id:" , value : module . id . toString ( ) } ) ;
2628
27- const tooltip = new vscode . MarkdownString ( ) ;
28- tooltip . appendMarkdown ( `# ${ module . name } \n\n` ) ;
29- tooltip . appendMarkdown ( `- **ID**: ${ module . id } \n` ) ;
3029 if ( module . addressRange ) {
31- tooltip . appendMarkdown (
32- `- **Load address**: 0x${ Number ( module . addressRange ) . toString ( 16 ) } \n` ,
33- ) ;
30+ children . push ( {
31+ key : "load address:" ,
32+ value : module . addressRange ,
33+ } ) ;
3434 }
3535 if ( module . path ) {
36- tooltip . appendMarkdown ( `- **Path**: ${ module . path } \n` ) ;
36+ children . push ( { key : "path:" , value : module . path } ) ;
3737 }
3838 if ( module . version ) {
39- tooltip . appendMarkdown ( `- **Version**: ${ module . version } \n` ) ;
40- }
41- if ( module . symbolStatus ) {
42- tooltip . appendMarkdown ( `- **Symbol status**: ${ module . symbolStatus } \n` ) ;
39+ children . push ( { key : "version:" , value : module . version } ) ;
4340 }
4441 if ( module . symbolFilePath ) {
45- tooltip . appendMarkdown (
46- `- **Symbol file path**: ${ module . symbolFilePath } \n` ,
47- ) ;
42+ children . push ( { key : "symbol filepath:" , value : module . symbolFilePath } ) ;
43+ }
44+ return children ;
45+ }
46+ }
47+
48+ /** A tree data provider for listing loaded modules for the active debug session. */
49+ export class ModulesDataProvider implements vscode . TreeDataProvider < TreeData > {
50+ private changeTreeData = new vscode . EventEmitter < void > ( ) ;
51+ readonly onDidChangeTreeData = this . changeTreeData . event ;
52+
53+ constructor ( private readonly tracker : DebugSessionTracker ) {
54+ tracker . onDidChangeModules ( ( ) => this . changeTreeData . fire ( ) ) ;
55+ vscode . debug . onDidChangeActiveDebugSession ( ( ) =>
56+ this . changeTreeData . fire ( ) ,
57+ ) ;
58+ }
59+
60+ getTreeItem ( module : TreeData ) : vscode . TreeItem {
61+ if ( isModule ( module ) ) {
62+ return new ModuleItem ( module ) ;
4863 }
4964
50- treeItem . tooltip = tooltip ;
51- return treeItem ;
65+ let item = new vscode . TreeItem ( module . key ) ;
66+ item . description = module . value ;
67+ item . tooltip = `${ module . key } ${ module . value } ` ;
68+ item . contextValue = "property" ;
69+ return item ;
5270 }
5371
54- getChildren ( ) : DebugProtocol . Module [ ] {
72+ getChildren ( element ?: TreeData ) : TreeData [ ] {
5573 if ( ! vscode . debug . activeDebugSession ) {
5674 return [ ] ;
5775 }
5876
59- return this . tracker . debugSessionModules ( vscode . debug . activeDebugSession ) ;
77+ if ( ! element ) {
78+ return this . tracker . debugSessionModules ( vscode . debug . activeDebugSession ) ;
79+ }
80+
81+ if ( isModule ( element ) ) {
82+ return ModuleItem . getProperties ( element ) ;
83+ }
84+
85+ return [ ] ;
6086 }
6187}
0 commit comments