Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit 009671e

Browse files
committed
adopt latest API changes and URI format
1 parent c20c857 commit 009671e

File tree

6 files changed

+33
-31
lines changed

6 files changed

+33
-31
lines changed

src/calls/model.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as vscode from 'vscode';
77
import { SymbolItemDragAndDrop, SymbolItemEditorHighlights, SymbolItemNavigation, SymbolTreeInput } from '../references-view';
8-
import { del, getThemeIcon, tail } from '../utils';
8+
import { asResourceUrl, del, getThemeIcon, tail } from '../utils';
99

1010

1111
export class CallsTreeInput implements SymbolTreeInput<CallItem> {
@@ -134,7 +134,7 @@ class CallsModel implements SymbolItemNavigation<CallItem>, SymbolItemEditorHigh
134134
// --- dnd
135135

136136
getDragUri(item: CallItem): vscode.Uri | undefined {
137-
return item.item.uri.with({ fragment: `L${1 + item.item.range.start.line},${item.item.range.start.character}` });
137+
return asResourceUrl(item.item.uri, item.item.range);
138138
}
139139

140140
// --- highlights

src/references/model.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as vscode from 'vscode';
77
import { SymbolItemDragAndDrop, SymbolItemEditorHighlights, SymbolItemNavigation, SymbolTreeInput, SymbolTreeModel } from '../references-view';
8-
import { del, getPreviewChunks, tail } from '../utils';
8+
import { asResourceUrl, del, getPreviewChunks, tail } from '../utils';
99

1010
export class ReferencesTreeInput implements SymbolTreeInput<FileItem | ReferenceItem> {
1111

@@ -250,9 +250,7 @@ export class ReferencesModel implements SymbolItemNavigation<FileItem | Referenc
250250
if (item instanceof FileItem) {
251251
return item.uri;
252252
} else {
253-
return item.file.uri.with({
254-
fragment: `L${item.location.range.start.line + 1},${item.location.range.start.character + 1}`
255-
});
253+
return asResourceUrl(item.file.uri, item.location.range);
256254
}
257255
}
258256
}

src/tree.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ class TreeDndDelegate implements vscode.TreeDragAndDropController<undefined> {
189189

190190
private _delegate: SymbolItemDragAndDrop<undefined> | undefined;
191191

192-
readonly supportedMimeTypes: string[] = ['resourceurls'];
192+
readonly dropMimeTypes: string[] = [];
193+
194+
readonly dragMimeTypes: string[] = ['resourceurls'];
193195

194196
update(delegate: Promise<SymbolItemDragAndDrop<unknown> | undefined>) {
195197
this._delegate = undefined;

src/types/model.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as vscode from 'vscode';
77
import { SymbolItemDragAndDrop, SymbolItemEditorHighlights, SymbolItemNavigation, SymbolTreeInput } from '../references-view';
8-
import { del, getThemeIcon, tail } from '../utils';
8+
import { asResourceUrl, del, getThemeIcon, tail } from '../utils';
99

1010

1111
export class TypesTreeInput implements SymbolTreeInput<TypeItem> {
@@ -102,7 +102,7 @@ class TypesModel implements SymbolItemNavigation<TypeItem>, SymbolItemEditorHigh
102102
// -- dnd
103103

104104
getDragUri(item: TypeItem): vscode.Uri | undefined {
105-
return item.item.uri.with({ fragment: `L${1 + item.item.range.start.line},${1 + item.item.range.start.character}` });
105+
return asResourceUrl(item.item.uri, item.item.range);
106106
}
107107

108108
// -- navigation

src/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export function tail<T>(array: T[]): T | undefined {
1616
return array[array.length - 1];
1717
}
1818

19+
export function asResourceUrl(uri: vscode.Uri, range: vscode.Range): vscode.Uri {
20+
return uri.with({ fragment: `L${1 + range.start.line},${1 + range.start.character}-${range.end.line},${range.end.character}` });
21+
}
22+
1923
export async function isValidRequestPosition(uri: vscode.Uri, position: vscode.Position) {
2024
const doc = await vscode.workspace.openTextDocument(uri);
2125
let range = doc.getWordRangeAtPosition(position);
@@ -129,4 +133,4 @@ const _themeIconIds = [
129133
export function getThemeIcon(kind: vscode.SymbolKind): vscode.ThemeIcon | undefined {
130134
let id = _themeIconIds[kind];
131135
return id ? new vscode.ThemeIcon(id) : undefined;
132-
}
136+
}

vscode.proposed.treeViewDragAndDrop.d.ts

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,13 @@ declare module 'vscode' {
2929
/**
3030
* A class for encapsulating data transferred during a tree drag and drop event.
3131
*
32-
* If your `DragAndDropController` implements `handleDrag`, you can extend `TreeDataTransferItem` and return
33-
* an instance of your new class for easy access to the source tree items.
34-
*
35-
* ```ts
36-
* class TestViewObjectTransferItem extends vscode.TreeDataTransferItem {
37-
* constructor(private _nodes: Node[]) {
38-
* super(_nodes);
39-
* }
40-
*
41-
* asObject(): Node[] {
42-
* return this._nodes;
43-
* }
44-
* }
45-
* ```
32+
* If your `DragAndDropController` implements `handleDrag`, you can use the `value` of the `TreeDataTransferItem`
33+
* to get back the object you put into it so long as the extension that created the `TreeDataTransferItem` runs in the same
34+
* extension host.
4635
*/
4736
export class TreeDataTransferItem {
4837
asString(): Thenable<string>;
49-
38+
readonly value: any;
5039
constructor(value: any);
5140
}
5241

@@ -82,8 +71,8 @@ declare module 'vscode' {
8271
export interface TreeDragAndDropController<T> {
8372

8473
/**
85-
* The mime types that the `drop` method of this `DragAndDropController` supports. This could be well-defined, existing, mime types,
86-
* and also mime types defined by the extension that are returned in the `TreeDataTransfer` from `handleDrag`.
74+
* The mime types that the `handleDrop` method of this `DragAndDropController` supports.
75+
* This could be well-defined, existing, mime types, and also mime types defined by the extension.
8776
*
8877
* Each tree will automatically support drops from it's own `DragAndDropController`. To support drops from other trees,
8978
* you will need to add the mime type of that tree. The mime type of a tree is of the format `tree/treeidlowercase`.
@@ -93,7 +82,13 @@ declare module 'vscode' {
9382
* 2. Use the Developer: Set Log Level... command to set the level to "Debug"
9483
* 3. Open the developer tools and drag the item with unknown mime type over your tree. The mime types will be logged to the developer console
9584
*/
96-
readonly supportedMimeTypes: string[];
85+
readonly dropMimeTypes: string[];
86+
87+
/**
88+
* The mime types that the `handleDrag` method of this `TreeDragAndDropController` may add to the tree data transfer.
89+
* This could be well-defined, existing, mime types, and also mime types defined by the extension.
90+
*/
91+
readonly dragMimeTypes: string[];
9792

9893
/**
9994
* When the user starts dragging items from this `DragAndDropController`, `handleDrag` will be called.
@@ -108,17 +103,20 @@ declare module 'vscode' {
108103
*
109104
* @param source The source items for the drag and drop operation.
110105
* @param treeDataTransfer The data transfer associated with this drag.
106+
* @param token A cancellation token indicating that drag has been cancelled.
111107
*/
112-
handleDrag?(source: T[], treeDataTransfer: TreeDataTransfer): Thenable<void> | void;
108+
handleDrag?(source: T[], treeDataTransfer: TreeDataTransfer, token: CancellationToken): Thenable<void> | void;
113109

114110
/**
115111
* Called when a drag and drop action results in a drop on the tree that this `DragAndDropController` belongs too.
116112
*
117113
* Extensions should fire `TreeDataProvider.onDidChangeTreeData` for any elements that need to be refreshed.
118114
*
119115
* @param source The data transfer items of the source of the drag.
120-
* @param target The target tree element that the drop is occuring on.
116+
* @param target The target tree element that the drop is occurring on.
117+
* @param token TODO @alexr00: When would this operation actually be cancelled?
121118
*/
122-
handleDrop(source: TreeDataTransfer, target: T): Thenable<void> | void;
119+
// TODO@API align order of TreeDataTransfer and T with handleDrag
120+
handleDrop(source: TreeDataTransfer, target: T, token: CancellationToken): Thenable<void> | void;
123121
}
124122
}

0 commit comments

Comments
 (0)