1
- import vscode , { MarkdownString , ThemeIcon , TreeItem , window , workspace } from "vscode" ;
1
+ import { commands , EventEmitter , ExtensionContext , MarkdownString , ThemeIcon , TreeItem , TreeItemCollapsibleState , window , workspace , Event } from "vscode" ;
2
2
import { TreeDataProvider } from "vscode" ;
3
3
import { Config } from "../../config" ;
4
- import { QueryHistoryItem } from "../../Storage" ;
5
4
6
5
const openSqlDocumentCommand = `vscode-db2i.openSqlDocument` ;
7
6
8
7
export class queryHistory implements TreeDataProvider < any > {
9
- private _onDidChangeTreeData : vscode . EventEmitter < vscode . TreeItem | undefined | null | void > = new vscode . EventEmitter < vscode . TreeItem | undefined | null | void > ( ) ;
10
- readonly onDidChangeTreeData : vscode . Event < vscode . TreeItem | undefined | null | void > = this . _onDidChangeTreeData . event ;
8
+ private _onDidChangeTreeData : EventEmitter < TreeItem | undefined | null | void > = new EventEmitter < TreeItem | undefined | null | void > ( ) ;
9
+ readonly onDidChangeTreeData : Event < TreeItem | undefined | null | void > = this . _onDidChangeTreeData . event ;
11
10
12
- constructor ( context : vscode . ExtensionContext ) {
11
+ constructor ( context : ExtensionContext ) {
13
12
context . subscriptions . push (
14
- vscode . commands . registerCommand ( openSqlDocumentCommand , ( query : string = `` ) => {
13
+ commands . registerCommand ( openSqlDocumentCommand , ( query : string = `` ) => {
15
14
workspace . openTextDocument ( {
16
15
language : `sql` ,
17
16
content : ( typeof query === `string` ? query : `` )
@@ -20,7 +19,7 @@ export class queryHistory implements TreeDataProvider<any> {
20
19
} ) ;
21
20
} ) ,
22
21
23
- vscode . commands . registerCommand ( `vscode-db2i.queryHistory.prepend` , async ( newQuery ?: string ) => {
22
+ commands . registerCommand ( `vscode-db2i.queryHistory.prepend` , async ( newQuery ?: string ) => {
24
23
if ( newQuery && Config . ready ) {
25
24
let currentList = Config . getPastQueries ( ) ;
26
25
const existingQuery = currentList . findIndex ( queryItem => queryItem . query . trim ( ) === newQuery . trim ( ) ) ;
@@ -44,7 +43,7 @@ export class queryHistory implements TreeDataProvider<any> {
44
43
}
45
44
} ) ,
46
45
47
- vscode . commands . registerCommand ( `vscode-db2i.queryHistory.remove` , async ( node : PastQueryNode ) => {
46
+ commands . registerCommand ( `vscode-db2i.queryHistory.remove` , async ( node : PastQueryNode ) => {
48
47
if ( node && Config . ready ) {
49
48
let currentList = Config . getPastQueries ( ) ;
50
49
const chosenQuery = node . query ;
@@ -61,7 +60,7 @@ export class queryHistory implements TreeDataProvider<any> {
61
60
}
62
61
} ) ,
63
62
64
- vscode . commands . registerCommand ( `vscode-db2i.queryHistory.clear` , async ( ) => {
63
+ commands . registerCommand ( `vscode-db2i.queryHistory.clear` , async ( ) => {
65
64
if ( Config . ready ) {
66
65
await Config . setPastQueries ( [ ] ) ;
67
66
this . refresh ( ) ;
@@ -74,11 +73,11 @@ export class queryHistory implements TreeDataProvider<any> {
74
73
this . _onDidChangeTreeData . fire ( ) ;
75
74
}
76
75
77
- getTreeItem ( element : vscode . TreeItem ) {
76
+ getTreeItem ( element : TreeItem ) {
78
77
return element ;
79
78
}
80
79
81
- async getChildren ( timePeriod ?: TimePeriodNode ) : Promise < vscode . TreeItem [ ] > {
80
+ async getChildren ( timePeriod ?: TimePeriodNode ) : Promise < TreeItem [ ] > {
82
81
if ( Config . ready ) {
83
82
if ( timePeriod ) {
84
83
return timePeriod . getChildren ( ) ;
@@ -137,10 +136,9 @@ export class queryHistory implements TreeDataProvider<any> {
137
136
}
138
137
}
139
138
140
- class TimePeriodNode extends vscode . TreeItem {
139
+ class TimePeriodNode extends TreeItem {
141
140
constructor ( public period : string , private nodes : PastQueryNode [ ] , expanded = false ) {
142
- super ( period , expanded ? vscode . TreeItemCollapsibleState . Expanded : vscode . TreeItemCollapsibleState . Collapsed ) ;
143
-
141
+ super ( period , expanded ? TreeItemCollapsibleState . Expanded : TreeItemCollapsibleState . Collapsed ) ;
144
142
this . contextValue = `timePeriod` ;
145
143
146
144
this . iconPath = new ThemeIcon ( `calendar` ) ;
@@ -151,7 +149,7 @@ class TimePeriodNode extends vscode.TreeItem {
151
149
}
152
150
}
153
151
154
- class PastQueryNode extends vscode . TreeItem {
152
+ class PastQueryNode extends TreeItem {
155
153
constructor ( public query : string ) {
156
154
super ( query . length > 63 ? query . substring ( 0 , 60 ) + `...` : query ) ;
157
155
0 commit comments