@@ -2,60 +2,86 @@ import * as vscode from "vscode";
2
2
import { DebugProtocol } from "@vscode/debugprotocol" ;
3
3
import { DebugSessionTracker } from "../debug-session-tracker" ;
4
4
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
+ }
11
9
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 ;
17
22
}
18
23
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 ( ) } ) ;
26
28
27
- const tooltip = new vscode . MarkdownString ( ) ;
28
- tooltip . appendMarkdown ( `# ${ module . name } \n\n` ) ;
29
- tooltip . appendMarkdown ( `- **ID**: ${ module . id } \n` ) ;
30
29
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
+ } ) ;
34
34
}
35
35
if ( module . path ) {
36
- tooltip . appendMarkdown ( `- **Path**: ${ module . path } \n` ) ;
36
+ children . push ( { key : "path:" , value : module . path } ) ;
37
37
}
38
38
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 } ) ;
43
40
}
44
41
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 ) ;
48
63
}
49
64
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 ;
52
70
}
53
71
54
- getChildren ( ) : DebugProtocol . Module [ ] {
72
+ getChildren ( element ?: TreeData ) : TreeData [ ] {
55
73
if ( ! vscode . debug . activeDebugSession ) {
56
74
return [ ] ;
57
75
}
58
76
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 [ ] ;
60
86
}
61
87
}
0 commit comments