@@ -4,31 +4,39 @@ import { TreeItemCollapsibleState, TreeItemLabel } from "vscode";
44import { Mutex } from "./utils" ;
55
66class ItemBase extends vscode . TreeItem {
7+ private _document : WeakRef < vscode . TextDocument > ;
8+
9+ public get document ( ) : vscode . TextDocument | undefined {
10+ return this . _document . deref ( ) ;
11+ }
12+
713 public constructor (
14+ document : vscode . TextDocument ,
815 public readonly label : string | TreeItemLabel ,
916 public readonly collapsibleState ?: TreeItemCollapsibleState ,
1017 ) {
1118 super ( label , collapsibleState ) ;
19+ this . _document = new WeakRef ( document ) ;
1220 }
1321}
1422
1523const SYMBOL_NAMESPACE = new vscode . ThemeIcon ( "symbol-namespace" ) ;
1624const SYMBOL_FUNCTION = new vscode . ThemeIcon ( "symbol-function" ) ;
1725
18- class KeywordItem extends vscode . TreeItem {
26+ class KeywordItem extends ItemBase {
1927 public readonly iconPath = SYMBOL_FUNCTION ;
2028 public readonly contextValue = "keyword" ;
2129 //public readonly command: vscode.Command;
2230
2331 public constructor (
24- public readonly document : vscode . TextDocument ,
32+ document : vscode . TextDocument ,
2533 public readonly parent : ImportItem | undefined ,
2634 public readonly label : string | TreeItemLabel ,
2735 public readonly id : string | undefined ,
2836 public readonly description ?: string ,
2937 public readonly tooltip ?: string | vscode . MarkdownString | undefined ,
3038 ) {
31- super ( label , TreeItemCollapsibleState . None ) ;
39+ super ( document , label , TreeItemCollapsibleState . None ) ;
3240 // this.command = {
3341 // command: "robotcode.keywordsTreeView.openItem",
3442 // title: "open",
@@ -37,20 +45,20 @@ class KeywordItem extends vscode.TreeItem {
3745 }
3846}
3947
40- class ImportItem extends vscode . TreeItem {
48+ class ImportItem extends ItemBase {
4149 public readonly iconPath = SYMBOL_NAMESPACE ;
4250 public readonly contextValue = "import" ;
4351
4452 public constructor (
45- public readonly document : vscode . TextDocument ,
53+ document : vscode . TextDocument ,
4654 public readonly label : string | TreeItemLabel ,
4755 public readonly id : string | undefined ,
4856 public readonly description ?: string ,
4957 public readonly tooltip ?: string | vscode . MarkdownString | undefined ,
5058 public keywords : KeywordItem [ ] = [ ] ,
5159 collapsibleState ?: TreeItemCollapsibleState ,
5260 ) {
53- super ( label , collapsibleState || TreeItemCollapsibleState . Collapsed ) ;
61+ super ( document , label , collapsibleState || TreeItemCollapsibleState . Collapsed ) ;
5462 }
5563}
5664
@@ -59,17 +67,28 @@ class DocumentData {
5967 keywords : KeywordItem [ ] = [ ] ;
6068}
6169
62- export class KeywordsTreeViewProvider implements vscode . TreeDataProvider < ItemBase > {
70+ export class KeywordsTreeViewProvider
71+ implements vscode . TreeDataProvider < ItemBase > , vscode . TreeDragAndDropController < ItemBase >
72+ {
6373 private _disposables : vscode . Disposable ;
6474
6575 private _cancelationSource : vscode . CancellationTokenSource | undefined ;
6676 private _documentsData : WeakMap < vscode . TextDocument , DocumentData > = new WeakMap ( ) ;
6777 private _currentDocumentData : DocumentData | undefined ;
6878
6979 constructor (
80+ context : vscode . ExtensionContext ,
7081 public languageClientsManager : LanguageClientsManager ,
7182 public outputChannel : vscode . OutputChannel ,
7283 ) {
84+ const view = vscode . window . createTreeView ( "robotcode.keywordsTreeView" , {
85+ treeDataProvider : this ,
86+ showCollapseAll : true ,
87+ //canSelectMany: true,
88+ dragAndDropController : this ,
89+ } ) ;
90+ context . subscriptions . push ( view ) ;
91+ view . badge = { tooltip : "Robot Framework Keywords" , value : 23 } ;
7392 this . _disposables = vscode . Disposable . from (
7493 vscode . window . onDidChangeActiveTextEditor ( async ( _editor ) => {
7594 await this . refresh ( ) ;
@@ -84,10 +103,6 @@ export class KeywordsTreeViewProvider implements vscode.TreeDataProvider<ItemBas
84103 await this . refresh ( ) ;
85104 } ) ,
86105
87- // vscode.commands.registerCommand("robotcode.keywordsTreeView.openItem", async (...args) => {
88- // console.log("openItem", args);
89- // //await this.refresh(true);
90- // }),
91106 vscode . commands . registerCommand ( "robotcode.keywordsTreeView.refresh" , async ( ) => {
92107 await this . refresh ( true ) ;
93108 } ) ,
@@ -108,8 +123,12 @@ export class KeywordsTreeViewProvider implements vscode.TreeDataProvider<ItemBas
108123 let url : string | undefined = undefined ;
109124
110125 if ( item instanceof KeywordItem ) {
126+ if ( item . document === undefined ) return ;
127+
111128 url = await this . languageClientsManager . getDocumentionUrl ( item . document , item . parent ?. id , item . id ) ;
112129 } else if ( item instanceof ImportItem ) {
130+ if ( item . document === undefined ) return ;
131+
113132 url = await this . languageClientsManager . getDocumentionUrl ( item . document , item . id ) ;
114133 }
115134
@@ -124,6 +143,21 @@ export class KeywordsTreeViewProvider implements vscode.TreeDataProvider<ItemBas
124143 ( ) => undefined ,
125144 ) ;
126145 }
146+ readonly dropMimeTypes : readonly string [ ] = [ ] ;
147+ readonly dragMimeTypes : readonly string [ ] = [ "text/plain" ] ;
148+
149+ // eslint-disable-next-line class-methods-use-this
150+ handleDrag (
151+ source : readonly ItemBase [ ] ,
152+ dataTransfer : vscode . DataTransfer ,
153+ _token : vscode . CancellationToken ,
154+ ) : void | Thenable < void > {
155+ for ( const item of source ) {
156+ if ( item instanceof KeywordItem ) {
157+ dataTransfer . set ( "text/plain" , new vscode . DataTransferItem ( item . label as string ) ) ;
158+ }
159+ }
160+ }
127161
128162 dispose ( ) : void {
129163 this . _disposables . dispose ( ) ;
0 commit comments