@codingame/monaco-vscode-references-view-default-extension 1.81.8-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/extension.js +1548 -0
- package/extension.js.map +1 -0
- package/index.js +7 -0
- package/package.json +22 -0
package/extension.js
ADDED
|
@@ -0,0 +1,1548 @@
|
|
|
1
|
+
/******/ (() => { // webpackBootstrap
|
|
2
|
+
/******/ "use strict";
|
|
3
|
+
/******/ var __webpack_modules__ = ([
|
|
4
|
+
/* 0 */,
|
|
5
|
+
/* 1 */
|
|
6
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
/*---------------------------------------------------------------------------------------------
|
|
10
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
11
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
12
|
+
*--------------------------------------------------------------------------------------------*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
14
|
+
exports.register = void 0;
|
|
15
|
+
const vscode = __webpack_require__(2);
|
|
16
|
+
const utils_1 = __webpack_require__(3);
|
|
17
|
+
const model_1 = __webpack_require__(4);
|
|
18
|
+
function register(tree, context) {
|
|
19
|
+
const direction = new RichCallsDirection(context.workspaceState, 0 /* CallsDirection.Incoming */);
|
|
20
|
+
function showCallHierarchy() {
|
|
21
|
+
if (vscode.window.activeTextEditor) {
|
|
22
|
+
const input = new model_1.CallsTreeInput(new vscode.Location(vscode.window.activeTextEditor.document.uri, vscode.window.activeTextEditor.selection.active), direction.value);
|
|
23
|
+
tree.setInput(input);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function setCallsDirection(value, anchor) {
|
|
27
|
+
direction.value = value;
|
|
28
|
+
let newInput;
|
|
29
|
+
const oldInput = tree.getInput();
|
|
30
|
+
if (anchor instanceof model_1.CallItem) {
|
|
31
|
+
newInput = new model_1.CallsTreeInput(new vscode.Location(anchor.item.uri, anchor.item.selectionRange.start), direction.value);
|
|
32
|
+
}
|
|
33
|
+
else if (oldInput instanceof model_1.CallsTreeInput) {
|
|
34
|
+
newInput = new model_1.CallsTreeInput(oldInput.location, direction.value);
|
|
35
|
+
}
|
|
36
|
+
if (newInput) {
|
|
37
|
+
tree.setInput(newInput);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
context.subscriptions.push(vscode.commands.registerCommand('references-view.showCallHierarchy', showCallHierarchy), vscode.commands.registerCommand('references-view.showOutgoingCalls', (item) => setCallsDirection(1 /* CallsDirection.Outgoing */, item)), vscode.commands.registerCommand('references-view.showIncomingCalls', (item) => setCallsDirection(0 /* CallsDirection.Incoming */, item)), vscode.commands.registerCommand('references-view.removeCallItem', removeCallItem));
|
|
41
|
+
}
|
|
42
|
+
exports.register = register;
|
|
43
|
+
function removeCallItem(item) {
|
|
44
|
+
if (item instanceof model_1.CallItem) {
|
|
45
|
+
item.remove();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
class RichCallsDirection {
|
|
49
|
+
constructor(_mem, _value = 1 /* CallsDirection.Outgoing */) {
|
|
50
|
+
this._mem = _mem;
|
|
51
|
+
this._value = _value;
|
|
52
|
+
this._ctxMode = new utils_1.ContextKey('references-view.callHierarchyMode');
|
|
53
|
+
const raw = _mem.get(RichCallsDirection._key);
|
|
54
|
+
if (typeof raw === 'number' && raw >= 0 && raw <= 1) {
|
|
55
|
+
this.value = raw;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
this.value = _value;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
get value() {
|
|
62
|
+
return this._value;
|
|
63
|
+
}
|
|
64
|
+
set value(value) {
|
|
65
|
+
this._value = value;
|
|
66
|
+
this._ctxMode.set(this._value === 0 /* CallsDirection.Incoming */ ? 'showIncoming' : 'showOutgoing');
|
|
67
|
+
this._mem.update(RichCallsDirection._key, value);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
RichCallsDirection._key = 'references-view.callHierarchyMode';
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
/***/ }),
|
|
74
|
+
/* 2 */
|
|
75
|
+
/***/ ((module) => {
|
|
76
|
+
|
|
77
|
+
module.exports = require("vscode");
|
|
78
|
+
|
|
79
|
+
/***/ }),
|
|
80
|
+
/* 3 */
|
|
81
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
/*---------------------------------------------------------------------------------------------
|
|
85
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
86
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
87
|
+
*--------------------------------------------------------------------------------------------*/
|
|
88
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
89
|
+
exports.getThemeIcon = exports.WordAnchor = exports.ContextKey = exports.getPreviewChunks = exports.isValidRequestPosition = exports.asResourceUrl = exports.tail = exports.del = void 0;
|
|
90
|
+
const vscode = __webpack_require__(2);
|
|
91
|
+
function del(array, e) {
|
|
92
|
+
const idx = array.indexOf(e);
|
|
93
|
+
if (idx >= 0) {
|
|
94
|
+
array.splice(idx, 1);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.del = del;
|
|
98
|
+
function tail(array) {
|
|
99
|
+
return array[array.length - 1];
|
|
100
|
+
}
|
|
101
|
+
exports.tail = tail;
|
|
102
|
+
function asResourceUrl(uri, range) {
|
|
103
|
+
return uri.with({ fragment: `L${1 + range.start.line},${1 + range.start.character}-${1 + range.end.line},${1 + range.end.character}` });
|
|
104
|
+
}
|
|
105
|
+
exports.asResourceUrl = asResourceUrl;
|
|
106
|
+
async function isValidRequestPosition(uri, position) {
|
|
107
|
+
const doc = await vscode.workspace.openTextDocument(uri);
|
|
108
|
+
let range = doc.getWordRangeAtPosition(position);
|
|
109
|
+
if (!range) {
|
|
110
|
+
range = doc.getWordRangeAtPosition(position, /[^\s]+/);
|
|
111
|
+
}
|
|
112
|
+
return Boolean(range);
|
|
113
|
+
}
|
|
114
|
+
exports.isValidRequestPosition = isValidRequestPosition;
|
|
115
|
+
function getPreviewChunks(doc, range, beforeLen = 8, trim = true) {
|
|
116
|
+
const previewStart = range.start.with({ character: Math.max(0, range.start.character - beforeLen) });
|
|
117
|
+
const wordRange = doc.getWordRangeAtPosition(previewStart);
|
|
118
|
+
let before = doc.getText(new vscode.Range(wordRange ? wordRange.start : previewStart, range.start));
|
|
119
|
+
const inside = doc.getText(range);
|
|
120
|
+
const previewEnd = range.end.translate(0, 331);
|
|
121
|
+
let after = doc.getText(new vscode.Range(range.end, previewEnd));
|
|
122
|
+
if (trim) {
|
|
123
|
+
before = before.replace(/^\s*/g, '');
|
|
124
|
+
after = after.replace(/\s*$/g, '');
|
|
125
|
+
}
|
|
126
|
+
return { before, inside, after };
|
|
127
|
+
}
|
|
128
|
+
exports.getPreviewChunks = getPreviewChunks;
|
|
129
|
+
class ContextKey {
|
|
130
|
+
constructor(name) {
|
|
131
|
+
this.name = name;
|
|
132
|
+
}
|
|
133
|
+
async set(value) {
|
|
134
|
+
await vscode.commands.executeCommand('setContext', this.name, value);
|
|
135
|
+
}
|
|
136
|
+
async reset() {
|
|
137
|
+
await vscode.commands.executeCommand('setContext', this.name, undefined);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.ContextKey = ContextKey;
|
|
141
|
+
class WordAnchor {
|
|
142
|
+
constructor(_doc, _position) {
|
|
143
|
+
this._doc = _doc;
|
|
144
|
+
this._position = _position;
|
|
145
|
+
this._version = _doc.version;
|
|
146
|
+
this._word = this._getAnchorWord(_doc, _position);
|
|
147
|
+
}
|
|
148
|
+
_getAnchorWord(doc, pos) {
|
|
149
|
+
const range = doc.getWordRangeAtPosition(pos) || doc.getWordRangeAtPosition(pos, /[^\s]+/);
|
|
150
|
+
return range && doc.getText(range);
|
|
151
|
+
}
|
|
152
|
+
guessedTrackedPosition() {
|
|
153
|
+
// funky entry
|
|
154
|
+
if (!this._word) {
|
|
155
|
+
return this._position;
|
|
156
|
+
}
|
|
157
|
+
// no changes
|
|
158
|
+
if (this._version === this._doc.version) {
|
|
159
|
+
return this._position;
|
|
160
|
+
}
|
|
161
|
+
// no changes here...
|
|
162
|
+
const wordNow = this._getAnchorWord(this._doc, this._position);
|
|
163
|
+
if (this._word === wordNow) {
|
|
164
|
+
return this._position;
|
|
165
|
+
}
|
|
166
|
+
// changes: search _word downwards and upwards
|
|
167
|
+
const startLine = this._position.line;
|
|
168
|
+
let i = 0;
|
|
169
|
+
let line;
|
|
170
|
+
let checked;
|
|
171
|
+
do {
|
|
172
|
+
checked = false;
|
|
173
|
+
// nth line down
|
|
174
|
+
line = startLine + i;
|
|
175
|
+
if (line < this._doc.lineCount) {
|
|
176
|
+
checked = true;
|
|
177
|
+
const ch = this._doc.lineAt(line).text.indexOf(this._word);
|
|
178
|
+
if (ch >= 0) {
|
|
179
|
+
return new vscode.Position(line, ch);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
i += 1;
|
|
183
|
+
// nth line up
|
|
184
|
+
line = startLine - i;
|
|
185
|
+
if (line >= 0) {
|
|
186
|
+
checked = true;
|
|
187
|
+
const ch = this._doc.lineAt(line).text.indexOf(this._word);
|
|
188
|
+
if (ch >= 0) {
|
|
189
|
+
return new vscode.Position(line, ch);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
} while (i < 100 && checked);
|
|
193
|
+
// fallback
|
|
194
|
+
return this._position;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
exports.WordAnchor = WordAnchor;
|
|
198
|
+
// vscode.SymbolKind.File === 0, Module === 1, etc...
|
|
199
|
+
const _themeIconIds = [
|
|
200
|
+
'symbol-file', 'symbol-module', 'symbol-namespace', 'symbol-package', 'symbol-class', 'symbol-method',
|
|
201
|
+
'symbol-property', 'symbol-field', 'symbol-constructor', 'symbol-enum', 'symbol-interface',
|
|
202
|
+
'symbol-function', 'symbol-variable', 'symbol-constant', 'symbol-string', 'symbol-number', 'symbol-boolean',
|
|
203
|
+
'symbol-array', 'symbol-object', 'symbol-key', 'symbol-null', 'symbol-enum-member', 'symbol-struct',
|
|
204
|
+
'symbol-event', 'symbol-operator', 'symbol-type-parameter'
|
|
205
|
+
];
|
|
206
|
+
function getThemeIcon(kind) {
|
|
207
|
+
const id = _themeIconIds[kind];
|
|
208
|
+
return id ? new vscode.ThemeIcon(id) : undefined;
|
|
209
|
+
}
|
|
210
|
+
exports.getThemeIcon = getThemeIcon;
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
/***/ }),
|
|
214
|
+
/* 4 */
|
|
215
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
/*---------------------------------------------------------------------------------------------
|
|
219
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
220
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
221
|
+
*--------------------------------------------------------------------------------------------*/
|
|
222
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
223
|
+
exports.CallItem = exports.CallsTreeInput = void 0;
|
|
224
|
+
const vscode = __webpack_require__(2);
|
|
225
|
+
const utils_1 = __webpack_require__(3);
|
|
226
|
+
class CallsTreeInput {
|
|
227
|
+
constructor(location, direction) {
|
|
228
|
+
this.location = location;
|
|
229
|
+
this.direction = direction;
|
|
230
|
+
this.contextValue = 'callHierarchy';
|
|
231
|
+
this.title = direction === 0 /* CallsDirection.Incoming */
|
|
232
|
+
? vscode.l10n.t('Callers Of')
|
|
233
|
+
: vscode.l10n.t('Calls From');
|
|
234
|
+
}
|
|
235
|
+
async resolve() {
|
|
236
|
+
const items = await Promise.resolve(vscode.commands.executeCommand('vscode.prepareCallHierarchy', this.location.uri, this.location.range.start));
|
|
237
|
+
const model = new CallsModel(this.direction, items ?? []);
|
|
238
|
+
const provider = new CallItemDataProvider(model);
|
|
239
|
+
if (model.roots.length === 0) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
provider,
|
|
244
|
+
get message() { return model.roots.length === 0 ? vscode.l10n.t('No results.') : undefined; },
|
|
245
|
+
navigation: model,
|
|
246
|
+
highlights: model,
|
|
247
|
+
dnd: model,
|
|
248
|
+
dispose() {
|
|
249
|
+
provider.dispose();
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
with(location) {
|
|
254
|
+
return new CallsTreeInput(location, this.direction);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
exports.CallsTreeInput = CallsTreeInput;
|
|
258
|
+
class CallItem {
|
|
259
|
+
constructor(model, item, parent, locations) {
|
|
260
|
+
this.model = model;
|
|
261
|
+
this.item = item;
|
|
262
|
+
this.parent = parent;
|
|
263
|
+
this.locations = locations;
|
|
264
|
+
}
|
|
265
|
+
remove() {
|
|
266
|
+
this.model.remove(this);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
exports.CallItem = CallItem;
|
|
270
|
+
class CallsModel {
|
|
271
|
+
constructor(direction, items) {
|
|
272
|
+
this.direction = direction;
|
|
273
|
+
this.roots = [];
|
|
274
|
+
this._onDidChange = new vscode.EventEmitter();
|
|
275
|
+
this.onDidChange = this._onDidChange.event;
|
|
276
|
+
this.roots = items.map(item => new CallItem(this, item, undefined, undefined));
|
|
277
|
+
}
|
|
278
|
+
async _resolveCalls(call) {
|
|
279
|
+
if (this.direction === 0 /* CallsDirection.Incoming */) {
|
|
280
|
+
const calls = await vscode.commands.executeCommand('vscode.provideIncomingCalls', call.item);
|
|
281
|
+
return calls ? calls.map(item => new CallItem(this, item.from, call, item.fromRanges.map(range => new vscode.Location(item.from.uri, range)))) : [];
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
const calls = await vscode.commands.executeCommand('vscode.provideOutgoingCalls', call.item);
|
|
285
|
+
return calls ? calls.map(item => new CallItem(this, item.to, call, item.fromRanges.map(range => new vscode.Location(call.item.uri, range)))) : [];
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
async getCallChildren(call) {
|
|
289
|
+
if (!call.children) {
|
|
290
|
+
call.children = await this._resolveCalls(call);
|
|
291
|
+
}
|
|
292
|
+
return call.children;
|
|
293
|
+
}
|
|
294
|
+
// -- navigation
|
|
295
|
+
location(item) {
|
|
296
|
+
return new vscode.Location(item.item.uri, item.item.range);
|
|
297
|
+
}
|
|
298
|
+
nearest(uri, _position) {
|
|
299
|
+
return this.roots.find(item => item.item.uri.toString() === uri.toString()) ?? this.roots[0];
|
|
300
|
+
}
|
|
301
|
+
next(from) {
|
|
302
|
+
return this._move(from, true) ?? from;
|
|
303
|
+
}
|
|
304
|
+
previous(from) {
|
|
305
|
+
return this._move(from, false) ?? from;
|
|
306
|
+
}
|
|
307
|
+
_move(item, fwd) {
|
|
308
|
+
if (item.children?.length) {
|
|
309
|
+
return fwd ? item.children[0] : (0, utils_1.tail)(item.children);
|
|
310
|
+
}
|
|
311
|
+
const array = this.roots.includes(item) ? this.roots : item.parent?.children;
|
|
312
|
+
if (array?.length) {
|
|
313
|
+
const idx = array.indexOf(item);
|
|
314
|
+
const delta = fwd ? 1 : -1;
|
|
315
|
+
return array[idx + delta + array.length % array.length];
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
// --- dnd
|
|
319
|
+
getDragUri(item) {
|
|
320
|
+
return (0, utils_1.asResourceUrl)(item.item.uri, item.item.range);
|
|
321
|
+
}
|
|
322
|
+
// --- highlights
|
|
323
|
+
getEditorHighlights(item, uri) {
|
|
324
|
+
if (!item.locations) {
|
|
325
|
+
return item.item.uri.toString() === uri.toString() ? [item.item.selectionRange] : undefined;
|
|
326
|
+
}
|
|
327
|
+
return item.locations
|
|
328
|
+
.filter(loc => loc.uri.toString() === uri.toString())
|
|
329
|
+
.map(loc => loc.range);
|
|
330
|
+
}
|
|
331
|
+
remove(item) {
|
|
332
|
+
const isInRoot = this.roots.includes(item);
|
|
333
|
+
const siblings = isInRoot ? this.roots : item.parent?.children;
|
|
334
|
+
if (siblings) {
|
|
335
|
+
(0, utils_1.del)(siblings, item);
|
|
336
|
+
this._onDidChange.fire(this);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
class CallItemDataProvider {
|
|
341
|
+
constructor(_model) {
|
|
342
|
+
this._model = _model;
|
|
343
|
+
this._emitter = new vscode.EventEmitter();
|
|
344
|
+
this.onDidChangeTreeData = this._emitter.event;
|
|
345
|
+
this._modelListener = _model.onDidChange(e => this._emitter.fire(e instanceof CallItem ? e : undefined));
|
|
346
|
+
}
|
|
347
|
+
dispose() {
|
|
348
|
+
this._emitter.dispose();
|
|
349
|
+
this._modelListener.dispose();
|
|
350
|
+
}
|
|
351
|
+
getTreeItem(element) {
|
|
352
|
+
const item = new vscode.TreeItem(element.item.name);
|
|
353
|
+
item.description = element.item.detail;
|
|
354
|
+
item.tooltip = item.label && element.item.detail ? `${item.label} - ${element.item.detail}` : item.label ? `${item.label}` : element.item.detail;
|
|
355
|
+
item.contextValue = 'call-item';
|
|
356
|
+
item.iconPath = (0, utils_1.getThemeIcon)(element.item.kind);
|
|
357
|
+
let openArgs;
|
|
358
|
+
if (element.model.direction === 1 /* CallsDirection.Outgoing */) {
|
|
359
|
+
openArgs = [element.item.uri, { selection: element.item.selectionRange.with({ end: element.item.selectionRange.start }) }];
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
// incoming call -> reveal first call instead of caller
|
|
363
|
+
let firstLoctionStart;
|
|
364
|
+
if (element.locations) {
|
|
365
|
+
for (const loc of element.locations) {
|
|
366
|
+
if (loc.uri.toString() === element.item.uri.toString()) {
|
|
367
|
+
firstLoctionStart = firstLoctionStart?.isBefore(loc.range.start) ? firstLoctionStart : loc.range.start;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
if (!firstLoctionStart) {
|
|
372
|
+
firstLoctionStart = element.item.selectionRange.start;
|
|
373
|
+
}
|
|
374
|
+
openArgs = [element.item.uri, { selection: new vscode.Range(firstLoctionStart, firstLoctionStart) }];
|
|
375
|
+
}
|
|
376
|
+
item.command = {
|
|
377
|
+
command: 'vscode.open',
|
|
378
|
+
title: vscode.l10n.t('Open Call'),
|
|
379
|
+
arguments: openArgs
|
|
380
|
+
};
|
|
381
|
+
item.collapsibleState = vscode.TreeItemCollapsibleState.Collapsed;
|
|
382
|
+
return item;
|
|
383
|
+
}
|
|
384
|
+
getChildren(element) {
|
|
385
|
+
return element
|
|
386
|
+
? this._model.getCallChildren(element)
|
|
387
|
+
: this._model.roots;
|
|
388
|
+
}
|
|
389
|
+
getParent(element) {
|
|
390
|
+
return element.parent;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
/***/ }),
|
|
396
|
+
/* 5 */
|
|
397
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
/*---------------------------------------------------------------------------------------------
|
|
401
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
402
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
403
|
+
*--------------------------------------------------------------------------------------------*/
|
|
404
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
405
|
+
exports.register = void 0;
|
|
406
|
+
const vscode = __webpack_require__(2);
|
|
407
|
+
const model_1 = __webpack_require__(6);
|
|
408
|
+
function register(tree, context) {
|
|
409
|
+
function findLocations(title, command) {
|
|
410
|
+
if (vscode.window.activeTextEditor) {
|
|
411
|
+
const input = new model_1.ReferencesTreeInput(title, new vscode.Location(vscode.window.activeTextEditor.document.uri, vscode.window.activeTextEditor.selection.active), command);
|
|
412
|
+
tree.setInput(input);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
context.subscriptions.push(vscode.commands.registerCommand('references-view.findReferences', () => findLocations('References', 'vscode.executeReferenceProvider')), vscode.commands.registerCommand('references-view.findImplementations', () => findLocations('Implementations', 'vscode.executeImplementationProvider')),
|
|
416
|
+
// --- legacy name
|
|
417
|
+
vscode.commands.registerCommand('references-view.find', (...args) => vscode.commands.executeCommand('references-view.findReferences', ...args)), vscode.commands.registerCommand('references-view.removeReferenceItem', removeReferenceItem), vscode.commands.registerCommand('references-view.copy', copyCommand), vscode.commands.registerCommand('references-view.copyAll', copyAllCommand), vscode.commands.registerCommand('references-view.copyPath', copyPathCommand));
|
|
418
|
+
// --- references.preferredLocation setting
|
|
419
|
+
let showReferencesDisposable;
|
|
420
|
+
const config = 'references.preferredLocation';
|
|
421
|
+
function updateShowReferences(event) {
|
|
422
|
+
if (event && !event.affectsConfiguration(config)) {
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
const value = vscode.workspace.getConfiguration().get(config);
|
|
426
|
+
showReferencesDisposable?.dispose();
|
|
427
|
+
showReferencesDisposable = undefined;
|
|
428
|
+
if (value === 'view') {
|
|
429
|
+
showReferencesDisposable = vscode.commands.registerCommand('editor.action.showReferences', async (uri, position, locations) => {
|
|
430
|
+
const input = new model_1.ReferencesTreeInput(vscode.l10n.t('References'), new vscode.Location(uri, position), 'vscode.executeReferenceProvider', locations);
|
|
431
|
+
tree.setInput(input);
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(updateShowReferences));
|
|
436
|
+
context.subscriptions.push({ dispose: () => showReferencesDisposable?.dispose() });
|
|
437
|
+
updateShowReferences();
|
|
438
|
+
}
|
|
439
|
+
exports.register = register;
|
|
440
|
+
const copyAllCommand = async (item) => {
|
|
441
|
+
if (item instanceof model_1.ReferenceItem) {
|
|
442
|
+
copyCommand(item.file.model);
|
|
443
|
+
}
|
|
444
|
+
else if (item instanceof model_1.FileItem) {
|
|
445
|
+
copyCommand(item.model);
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
function removeReferenceItem(item) {
|
|
449
|
+
if (item instanceof model_1.FileItem) {
|
|
450
|
+
item.remove();
|
|
451
|
+
}
|
|
452
|
+
else if (item instanceof model_1.ReferenceItem) {
|
|
453
|
+
item.remove();
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
async function copyCommand(item) {
|
|
457
|
+
let val;
|
|
458
|
+
if (item instanceof model_1.ReferencesModel) {
|
|
459
|
+
val = await item.asCopyText();
|
|
460
|
+
}
|
|
461
|
+
else if (item instanceof model_1.ReferenceItem) {
|
|
462
|
+
val = await item.asCopyText();
|
|
463
|
+
}
|
|
464
|
+
else if (item instanceof model_1.FileItem) {
|
|
465
|
+
val = await item.asCopyText();
|
|
466
|
+
}
|
|
467
|
+
if (val) {
|
|
468
|
+
await vscode.env.clipboard.writeText(val);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
async function copyPathCommand(item) {
|
|
472
|
+
if (item instanceof model_1.FileItem) {
|
|
473
|
+
if (item.uri.scheme === 'file') {
|
|
474
|
+
vscode.env.clipboard.writeText(item.uri.fsPath);
|
|
475
|
+
}
|
|
476
|
+
else {
|
|
477
|
+
vscode.env.clipboard.writeText(item.uri.toString(true));
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
/***/ }),
|
|
484
|
+
/* 6 */
|
|
485
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
/*---------------------------------------------------------------------------------------------
|
|
489
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
490
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
491
|
+
*--------------------------------------------------------------------------------------------*/
|
|
492
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
493
|
+
exports.ReferenceItem = exports.FileItem = exports.ReferencesModel = exports.ReferencesTreeInput = void 0;
|
|
494
|
+
const vscode = __webpack_require__(2);
|
|
495
|
+
const utils_1 = __webpack_require__(3);
|
|
496
|
+
class ReferencesTreeInput {
|
|
497
|
+
constructor(title, location, _command, _result) {
|
|
498
|
+
this.title = title;
|
|
499
|
+
this.location = location;
|
|
500
|
+
this._command = _command;
|
|
501
|
+
this._result = _result;
|
|
502
|
+
this.contextValue = _command;
|
|
503
|
+
}
|
|
504
|
+
async resolve() {
|
|
505
|
+
let model;
|
|
506
|
+
if (this._result) {
|
|
507
|
+
model = new ReferencesModel(this._result);
|
|
508
|
+
}
|
|
509
|
+
else {
|
|
510
|
+
const resut = await Promise.resolve(vscode.commands.executeCommand(this._command, this.location.uri, this.location.range.start));
|
|
511
|
+
model = new ReferencesModel(resut ?? []);
|
|
512
|
+
}
|
|
513
|
+
if (model.items.length === 0) {
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
const provider = new ReferencesTreeDataProvider(model);
|
|
517
|
+
return {
|
|
518
|
+
provider,
|
|
519
|
+
get message() { return model.message; },
|
|
520
|
+
navigation: model,
|
|
521
|
+
highlights: model,
|
|
522
|
+
dnd: model,
|
|
523
|
+
dispose() {
|
|
524
|
+
provider.dispose();
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
with(location) {
|
|
529
|
+
return new ReferencesTreeInput(this.title, location, this._command);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
exports.ReferencesTreeInput = ReferencesTreeInput;
|
|
533
|
+
class ReferencesModel {
|
|
534
|
+
constructor(locations) {
|
|
535
|
+
this._onDidChange = new vscode.EventEmitter();
|
|
536
|
+
this.onDidChangeTreeData = this._onDidChange.event;
|
|
537
|
+
this.items = [];
|
|
538
|
+
let last;
|
|
539
|
+
for (const item of locations.sort(ReferencesModel._compareLocations)) {
|
|
540
|
+
const loc = item instanceof vscode.Location
|
|
541
|
+
? item
|
|
542
|
+
: new vscode.Location(item.targetUri, item.targetRange);
|
|
543
|
+
if (!last || ReferencesModel._compareUriIgnoreFragment(last.uri, loc.uri) !== 0) {
|
|
544
|
+
last = new FileItem(loc.uri.with({ fragment: '' }), [], this);
|
|
545
|
+
this.items.push(last);
|
|
546
|
+
}
|
|
547
|
+
last.references.push(new ReferenceItem(loc, last));
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
static _compareUriIgnoreFragment(a, b) {
|
|
551
|
+
const aStr = a.with({ fragment: '' }).toString();
|
|
552
|
+
const bStr = b.with({ fragment: '' }).toString();
|
|
553
|
+
if (aStr < bStr) {
|
|
554
|
+
return -1;
|
|
555
|
+
}
|
|
556
|
+
else if (aStr > bStr) {
|
|
557
|
+
return 1;
|
|
558
|
+
}
|
|
559
|
+
return 0;
|
|
560
|
+
}
|
|
561
|
+
static _compareLocations(a, b) {
|
|
562
|
+
const aUri = a instanceof vscode.Location ? a.uri : a.targetUri;
|
|
563
|
+
const bUri = b instanceof vscode.Location ? b.uri : b.targetUri;
|
|
564
|
+
if (aUri.toString() < bUri.toString()) {
|
|
565
|
+
return -1;
|
|
566
|
+
}
|
|
567
|
+
else if (aUri.toString() > bUri.toString()) {
|
|
568
|
+
return 1;
|
|
569
|
+
}
|
|
570
|
+
const aRange = a instanceof vscode.Location ? a.range : a.targetRange;
|
|
571
|
+
const bRange = b instanceof vscode.Location ? b.range : b.targetRange;
|
|
572
|
+
if (aRange.start.isBefore(bRange.start)) {
|
|
573
|
+
return -1;
|
|
574
|
+
}
|
|
575
|
+
else if (aRange.start.isAfter(bRange.start)) {
|
|
576
|
+
return 1;
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
return 0;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
// --- adapter
|
|
583
|
+
get message() {
|
|
584
|
+
if (this.items.length === 0) {
|
|
585
|
+
return vscode.l10n.t('No results.');
|
|
586
|
+
}
|
|
587
|
+
const total = this.items.reduce((prev, cur) => prev + cur.references.length, 0);
|
|
588
|
+
const files = this.items.length;
|
|
589
|
+
if (total === 1 && files === 1) {
|
|
590
|
+
return vscode.l10n.t('{0} result in {1} file', total, files);
|
|
591
|
+
}
|
|
592
|
+
else if (total === 1) {
|
|
593
|
+
return vscode.l10n.t('{0} result in {1} files', total, files);
|
|
594
|
+
}
|
|
595
|
+
else if (files === 1) {
|
|
596
|
+
return vscode.l10n.t('{0} results in {1} file', total, files);
|
|
597
|
+
}
|
|
598
|
+
else {
|
|
599
|
+
return vscode.l10n.t('{0} results in {1} files', total, files);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
location(item) {
|
|
603
|
+
return item instanceof ReferenceItem
|
|
604
|
+
? item.location
|
|
605
|
+
: new vscode.Location(item.uri, item.references[0]?.location.range ?? new vscode.Position(0, 0));
|
|
606
|
+
}
|
|
607
|
+
nearest(uri, position) {
|
|
608
|
+
if (this.items.length === 0) {
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
// NOTE: this.items is sorted by location (uri/range)
|
|
612
|
+
for (const item of this.items) {
|
|
613
|
+
if (item.uri.toString() === uri.toString()) {
|
|
614
|
+
// (1) pick the item at the request position
|
|
615
|
+
for (const ref of item.references) {
|
|
616
|
+
if (ref.location.range.contains(position)) {
|
|
617
|
+
return ref;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
// (2) pick the first item after or last before the request position
|
|
621
|
+
let lastBefore;
|
|
622
|
+
for (const ref of item.references) {
|
|
623
|
+
if (ref.location.range.end.isAfter(position)) {
|
|
624
|
+
return ref;
|
|
625
|
+
}
|
|
626
|
+
lastBefore = ref;
|
|
627
|
+
}
|
|
628
|
+
if (lastBefore) {
|
|
629
|
+
return lastBefore;
|
|
630
|
+
}
|
|
631
|
+
break;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
// (3) pick the file with the longest common prefix
|
|
635
|
+
let best = 0;
|
|
636
|
+
const bestValue = ReferencesModel._prefixLen(this.items[best].toString(), uri.toString());
|
|
637
|
+
for (let i = 1; i < this.items.length; i++) {
|
|
638
|
+
const value = ReferencesModel._prefixLen(this.items[i].uri.toString(), uri.toString());
|
|
639
|
+
if (value > bestValue) {
|
|
640
|
+
best = i;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
return this.items[best].references[0];
|
|
644
|
+
}
|
|
645
|
+
static _prefixLen(a, b) {
|
|
646
|
+
let pos = 0;
|
|
647
|
+
while (pos < a.length && pos < b.length && a.charCodeAt(pos) === b.charCodeAt(pos)) {
|
|
648
|
+
pos += 1;
|
|
649
|
+
}
|
|
650
|
+
return pos;
|
|
651
|
+
}
|
|
652
|
+
next(item) {
|
|
653
|
+
return this._move(item, true) ?? item;
|
|
654
|
+
}
|
|
655
|
+
previous(item) {
|
|
656
|
+
return this._move(item, false) ?? item;
|
|
657
|
+
}
|
|
658
|
+
_move(item, fwd) {
|
|
659
|
+
const delta = fwd ? +1 : -1;
|
|
660
|
+
const _move = (item) => {
|
|
661
|
+
const idx = (this.items.indexOf(item) + delta + this.items.length) % this.items.length;
|
|
662
|
+
return this.items[idx];
|
|
663
|
+
};
|
|
664
|
+
if (item instanceof FileItem) {
|
|
665
|
+
if (fwd) {
|
|
666
|
+
return _move(item).references[0];
|
|
667
|
+
}
|
|
668
|
+
else {
|
|
669
|
+
return (0, utils_1.tail)(_move(item).references);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
if (item instanceof ReferenceItem) {
|
|
673
|
+
const idx = item.file.references.indexOf(item) + delta;
|
|
674
|
+
if (idx < 0) {
|
|
675
|
+
return (0, utils_1.tail)(_move(item.file).references);
|
|
676
|
+
}
|
|
677
|
+
else if (idx >= item.file.references.length) {
|
|
678
|
+
return _move(item.file).references[0];
|
|
679
|
+
}
|
|
680
|
+
else {
|
|
681
|
+
return item.file.references[idx];
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
getEditorHighlights(_item, uri) {
|
|
686
|
+
const file = this.items.find(file => file.uri.toString() === uri.toString());
|
|
687
|
+
return file?.references.map(ref => ref.location.range);
|
|
688
|
+
}
|
|
689
|
+
remove(item) {
|
|
690
|
+
if (item instanceof FileItem) {
|
|
691
|
+
(0, utils_1.del)(this.items, item);
|
|
692
|
+
this._onDidChange.fire(undefined);
|
|
693
|
+
}
|
|
694
|
+
else {
|
|
695
|
+
(0, utils_1.del)(item.file.references, item);
|
|
696
|
+
if (item.file.references.length === 0) {
|
|
697
|
+
(0, utils_1.del)(this.items, item.file);
|
|
698
|
+
this._onDidChange.fire(undefined);
|
|
699
|
+
}
|
|
700
|
+
else {
|
|
701
|
+
this._onDidChange.fire(item.file);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
async asCopyText() {
|
|
706
|
+
let result = '';
|
|
707
|
+
for (const item of this.items) {
|
|
708
|
+
result += `${await item.asCopyText()}\n`;
|
|
709
|
+
}
|
|
710
|
+
return result;
|
|
711
|
+
}
|
|
712
|
+
getDragUri(item) {
|
|
713
|
+
if (item instanceof FileItem) {
|
|
714
|
+
return item.uri;
|
|
715
|
+
}
|
|
716
|
+
else {
|
|
717
|
+
return (0, utils_1.asResourceUrl)(item.file.uri, item.location.range);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
exports.ReferencesModel = ReferencesModel;
|
|
722
|
+
class ReferencesTreeDataProvider {
|
|
723
|
+
constructor(_model) {
|
|
724
|
+
this._model = _model;
|
|
725
|
+
this._onDidChange = new vscode.EventEmitter();
|
|
726
|
+
this.onDidChangeTreeData = this._onDidChange.event;
|
|
727
|
+
this._listener = _model.onDidChangeTreeData(() => this._onDidChange.fire(undefined));
|
|
728
|
+
}
|
|
729
|
+
dispose() {
|
|
730
|
+
this._onDidChange.dispose();
|
|
731
|
+
this._listener.dispose();
|
|
732
|
+
}
|
|
733
|
+
async getTreeItem(element) {
|
|
734
|
+
if (element instanceof FileItem) {
|
|
735
|
+
// files
|
|
736
|
+
const result = new vscode.TreeItem(element.uri);
|
|
737
|
+
result.contextValue = 'file-item';
|
|
738
|
+
result.description = true;
|
|
739
|
+
result.iconPath = vscode.ThemeIcon.File;
|
|
740
|
+
result.collapsibleState = vscode.TreeItemCollapsibleState.Collapsed;
|
|
741
|
+
return result;
|
|
742
|
+
}
|
|
743
|
+
else {
|
|
744
|
+
// references
|
|
745
|
+
const { range } = element.location;
|
|
746
|
+
const doc = await element.getDocument(true);
|
|
747
|
+
const { before, inside, after } = (0, utils_1.getPreviewChunks)(doc, range);
|
|
748
|
+
const label = {
|
|
749
|
+
label: before + inside + after,
|
|
750
|
+
highlights: [[before.length, before.length + inside.length]]
|
|
751
|
+
};
|
|
752
|
+
const result = new vscode.TreeItem(label);
|
|
753
|
+
result.collapsibleState = vscode.TreeItemCollapsibleState.None;
|
|
754
|
+
result.contextValue = 'reference-item';
|
|
755
|
+
result.command = {
|
|
756
|
+
command: 'vscode.open',
|
|
757
|
+
title: vscode.l10n.t('Open Reference'),
|
|
758
|
+
arguments: [
|
|
759
|
+
element.location.uri,
|
|
760
|
+
{ selection: range.with({ end: range.start }) }
|
|
761
|
+
]
|
|
762
|
+
};
|
|
763
|
+
return result;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
async getChildren(element) {
|
|
767
|
+
if (!element) {
|
|
768
|
+
return this._model.items;
|
|
769
|
+
}
|
|
770
|
+
if (element instanceof FileItem) {
|
|
771
|
+
return element.references;
|
|
772
|
+
}
|
|
773
|
+
return undefined;
|
|
774
|
+
}
|
|
775
|
+
getParent(element) {
|
|
776
|
+
return element instanceof ReferenceItem ? element.file : undefined;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
class FileItem {
|
|
780
|
+
constructor(uri, references, model) {
|
|
781
|
+
this.uri = uri;
|
|
782
|
+
this.references = references;
|
|
783
|
+
this.model = model;
|
|
784
|
+
}
|
|
785
|
+
// --- adapter
|
|
786
|
+
remove() {
|
|
787
|
+
this.model.remove(this);
|
|
788
|
+
}
|
|
789
|
+
async asCopyText() {
|
|
790
|
+
let result = `${vscode.workspace.asRelativePath(this.uri)}\n`;
|
|
791
|
+
for (const ref of this.references) {
|
|
792
|
+
result += ` ${await ref.asCopyText()}\n`;
|
|
793
|
+
}
|
|
794
|
+
return result;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
exports.FileItem = FileItem;
|
|
798
|
+
class ReferenceItem {
|
|
799
|
+
constructor(location, file) {
|
|
800
|
+
this.location = location;
|
|
801
|
+
this.file = file;
|
|
802
|
+
}
|
|
803
|
+
async getDocument(warmUpNext) {
|
|
804
|
+
if (!this._document) {
|
|
805
|
+
this._document = vscode.workspace.openTextDocument(this.location.uri);
|
|
806
|
+
}
|
|
807
|
+
if (warmUpNext) {
|
|
808
|
+
// load next document once this document has been loaded
|
|
809
|
+
const next = this.file.model.next(this.file);
|
|
810
|
+
if (next instanceof FileItem && next !== this.file) {
|
|
811
|
+
vscode.workspace.openTextDocument(next.uri);
|
|
812
|
+
}
|
|
813
|
+
else if (next instanceof ReferenceItem) {
|
|
814
|
+
vscode.workspace.openTextDocument(next.location.uri);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
return this._document;
|
|
818
|
+
}
|
|
819
|
+
// --- adapter
|
|
820
|
+
remove() {
|
|
821
|
+
this.file.model.remove(this);
|
|
822
|
+
}
|
|
823
|
+
async asCopyText() {
|
|
824
|
+
const doc = await this.getDocument();
|
|
825
|
+
const chunks = (0, utils_1.getPreviewChunks)(doc, this.location.range, 21, false);
|
|
826
|
+
return `${this.location.range.start.line + 1}, ${this.location.range.start.character + 1}: ${chunks.before + chunks.inside + chunks.after}`;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
exports.ReferenceItem = ReferenceItem;
|
|
830
|
+
|
|
831
|
+
|
|
832
|
+
/***/ }),
|
|
833
|
+
/* 7 */
|
|
834
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
/*---------------------------------------------------------------------------------------------
|
|
838
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
839
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
840
|
+
*--------------------------------------------------------------------------------------------*/
|
|
841
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
842
|
+
exports.SymbolsTree = void 0;
|
|
843
|
+
const vscode = __webpack_require__(2);
|
|
844
|
+
const highlights_1 = __webpack_require__(8);
|
|
845
|
+
const navigation_1 = __webpack_require__(9);
|
|
846
|
+
const utils_1 = __webpack_require__(3);
|
|
847
|
+
class SymbolsTree {
|
|
848
|
+
constructor() {
|
|
849
|
+
this.viewId = 'references-view.tree';
|
|
850
|
+
this._ctxIsActive = new utils_1.ContextKey('reference-list.isActive');
|
|
851
|
+
this._ctxHasResult = new utils_1.ContextKey('reference-list.hasResult');
|
|
852
|
+
this._ctxInputSource = new utils_1.ContextKey('reference-list.source');
|
|
853
|
+
this._history = new TreeInputHistory(this);
|
|
854
|
+
this._provider = new TreeDataProviderDelegate();
|
|
855
|
+
this._dnd = new TreeDndDelegate();
|
|
856
|
+
this._tree = vscode.window.createTreeView(this.viewId, {
|
|
857
|
+
treeDataProvider: this._provider,
|
|
858
|
+
showCollapseAll: true,
|
|
859
|
+
dragAndDropController: this._dnd
|
|
860
|
+
});
|
|
861
|
+
this._navigation = new navigation_1.Navigation(this._tree);
|
|
862
|
+
}
|
|
863
|
+
dispose() {
|
|
864
|
+
this._history.dispose();
|
|
865
|
+
this._tree.dispose();
|
|
866
|
+
this._sessionDisposable?.dispose();
|
|
867
|
+
}
|
|
868
|
+
getInput() {
|
|
869
|
+
return this._input;
|
|
870
|
+
}
|
|
871
|
+
async setInput(input) {
|
|
872
|
+
if (!await (0, utils_1.isValidRequestPosition)(input.location.uri, input.location.range.start)) {
|
|
873
|
+
this.clearInput();
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
876
|
+
this._ctxInputSource.set(input.contextValue);
|
|
877
|
+
this._ctxIsActive.set(true);
|
|
878
|
+
this._ctxHasResult.set(true);
|
|
879
|
+
vscode.commands.executeCommand(`${this.viewId}.focus`);
|
|
880
|
+
const newInputKind = !this._input || Object.getPrototypeOf(this._input) !== Object.getPrototypeOf(input);
|
|
881
|
+
this._input = input;
|
|
882
|
+
this._sessionDisposable?.dispose();
|
|
883
|
+
this._tree.title = input.title;
|
|
884
|
+
this._tree.message = newInputKind ? undefined : this._tree.message;
|
|
885
|
+
const modelPromise = Promise.resolve(input.resolve());
|
|
886
|
+
// set promise to tree data provider to trigger tree loading UI
|
|
887
|
+
this._provider.update(modelPromise.then(model => model?.provider ?? this._history));
|
|
888
|
+
this._dnd.update(modelPromise.then(model => model?.dnd));
|
|
889
|
+
const model = await modelPromise;
|
|
890
|
+
if (this._input !== input) {
|
|
891
|
+
return;
|
|
892
|
+
}
|
|
893
|
+
if (!model) {
|
|
894
|
+
this.clearInput();
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
this._history.add(input);
|
|
898
|
+
this._tree.message = model.message;
|
|
899
|
+
// navigation
|
|
900
|
+
this._navigation.update(model.navigation);
|
|
901
|
+
// reveal & select
|
|
902
|
+
const selection = model.navigation?.nearest(input.location.uri, input.location.range.start);
|
|
903
|
+
if (selection && this._tree.visible) {
|
|
904
|
+
await this._tree.reveal(selection, { select: true, focus: true, expand: true });
|
|
905
|
+
}
|
|
906
|
+
const disposables = [];
|
|
907
|
+
// editor highlights
|
|
908
|
+
let highlights;
|
|
909
|
+
if (model.highlights) {
|
|
910
|
+
highlights = new highlights_1.EditorHighlights(this._tree, model.highlights);
|
|
911
|
+
disposables.push(highlights);
|
|
912
|
+
}
|
|
913
|
+
// listener
|
|
914
|
+
if (model.provider.onDidChangeTreeData) {
|
|
915
|
+
disposables.push(model.provider.onDidChangeTreeData(() => {
|
|
916
|
+
this._tree.title = input.title;
|
|
917
|
+
this._tree.message = model.message;
|
|
918
|
+
highlights?.update();
|
|
919
|
+
}));
|
|
920
|
+
}
|
|
921
|
+
if (typeof model.dispose === 'function') {
|
|
922
|
+
disposables.push(new vscode.Disposable(() => model.dispose()));
|
|
923
|
+
}
|
|
924
|
+
this._sessionDisposable = vscode.Disposable.from(...disposables);
|
|
925
|
+
}
|
|
926
|
+
clearInput() {
|
|
927
|
+
this._sessionDisposable?.dispose();
|
|
928
|
+
this._input = undefined;
|
|
929
|
+
this._ctxHasResult.set(false);
|
|
930
|
+
this._ctxInputSource.reset();
|
|
931
|
+
this._tree.title = vscode.l10n.t('References');
|
|
932
|
+
this._tree.message = this._history.size === 0
|
|
933
|
+
? vscode.l10n.t('No results.')
|
|
934
|
+
: vscode.l10n.t('No results. Try running a previous search again:');
|
|
935
|
+
this._provider.update(Promise.resolve(this._history));
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
exports.SymbolsTree = SymbolsTree;
|
|
939
|
+
class TreeDataProviderDelegate {
|
|
940
|
+
constructor() {
|
|
941
|
+
this._onDidChange = new vscode.EventEmitter();
|
|
942
|
+
this.onDidChangeTreeData = this._onDidChange.event;
|
|
943
|
+
}
|
|
944
|
+
update(provider) {
|
|
945
|
+
this._sessionDispoables?.dispose();
|
|
946
|
+
this._sessionDispoables = undefined;
|
|
947
|
+
this._onDidChange.fire(undefined);
|
|
948
|
+
this.provider = provider;
|
|
949
|
+
provider.then(value => {
|
|
950
|
+
if (this.provider === provider && value.onDidChangeTreeData) {
|
|
951
|
+
this._sessionDispoables = value.onDidChangeTreeData(this._onDidChange.fire, this._onDidChange);
|
|
952
|
+
}
|
|
953
|
+
}).catch(err => {
|
|
954
|
+
this.provider = undefined;
|
|
955
|
+
console.error(err);
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
async getTreeItem(element) {
|
|
959
|
+
this._assertProvider();
|
|
960
|
+
return (await this.provider).getTreeItem(element);
|
|
961
|
+
}
|
|
962
|
+
async getChildren(parent) {
|
|
963
|
+
this._assertProvider();
|
|
964
|
+
return (await this.provider).getChildren(parent);
|
|
965
|
+
}
|
|
966
|
+
async getParent(element) {
|
|
967
|
+
this._assertProvider();
|
|
968
|
+
const provider = await this.provider;
|
|
969
|
+
return provider.getParent ? provider.getParent(element) : undefined;
|
|
970
|
+
}
|
|
971
|
+
_assertProvider() {
|
|
972
|
+
if (!this.provider) {
|
|
973
|
+
throw new Error('MISSING provider');
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
// --- tree dnd
|
|
978
|
+
class TreeDndDelegate {
|
|
979
|
+
constructor() {
|
|
980
|
+
this.dropMimeTypes = [];
|
|
981
|
+
this.dragMimeTypes = ['text/uri-list'];
|
|
982
|
+
}
|
|
983
|
+
update(delegate) {
|
|
984
|
+
this._delegate = undefined;
|
|
985
|
+
delegate.then(value => this._delegate = value);
|
|
986
|
+
}
|
|
987
|
+
handleDrag(source, data) {
|
|
988
|
+
if (this._delegate) {
|
|
989
|
+
const urls = [];
|
|
990
|
+
for (const item of source) {
|
|
991
|
+
const uri = this._delegate.getDragUri(item);
|
|
992
|
+
if (uri) {
|
|
993
|
+
urls.push(uri.toString());
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
if (urls.length > 0) {
|
|
997
|
+
data.set('text/uri-list', new vscode.DataTransferItem(urls.join('\r\n')));
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
handleDrop() {
|
|
1002
|
+
throw new Error('Method not implemented.');
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
// --- history
|
|
1006
|
+
class HistoryItem {
|
|
1007
|
+
constructor(key, word, anchor, input) {
|
|
1008
|
+
this.key = key;
|
|
1009
|
+
this.word = word;
|
|
1010
|
+
this.anchor = anchor;
|
|
1011
|
+
this.input = input;
|
|
1012
|
+
this.description = `${vscode.workspace.asRelativePath(input.location.uri)} • ${input.title.toLocaleLowerCase()}`;
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
class TreeInputHistory {
|
|
1016
|
+
constructor(_tree) {
|
|
1017
|
+
this._tree = _tree;
|
|
1018
|
+
this._onDidChangeTreeData = new vscode.EventEmitter();
|
|
1019
|
+
this.onDidChangeTreeData = this._onDidChangeTreeData.event;
|
|
1020
|
+
this._disposables = [];
|
|
1021
|
+
this._ctxHasHistory = new utils_1.ContextKey('reference-list.hasHistory');
|
|
1022
|
+
this._inputs = new Map();
|
|
1023
|
+
this._disposables.push(vscode.commands.registerCommand('references-view.clear', () => _tree.clearInput()), vscode.commands.registerCommand('references-view.clearHistory', () => {
|
|
1024
|
+
this.clear();
|
|
1025
|
+
_tree.clearInput();
|
|
1026
|
+
}), vscode.commands.registerCommand('references-view.refind', (item) => {
|
|
1027
|
+
if (item instanceof HistoryItem) {
|
|
1028
|
+
this._reRunHistoryItem(item);
|
|
1029
|
+
}
|
|
1030
|
+
}), vscode.commands.registerCommand('references-view.refresh', () => {
|
|
1031
|
+
const item = Array.from(this._inputs.values()).pop();
|
|
1032
|
+
if (item) {
|
|
1033
|
+
this._reRunHistoryItem(item);
|
|
1034
|
+
}
|
|
1035
|
+
}), vscode.commands.registerCommand('_references-view.showHistoryItem', async (item) => {
|
|
1036
|
+
if (item instanceof HistoryItem) {
|
|
1037
|
+
const position = item.anchor.guessedTrackedPosition() ?? item.input.location.range.start;
|
|
1038
|
+
await vscode.commands.executeCommand('vscode.open', item.input.location.uri, { selection: new vscode.Range(position, position) });
|
|
1039
|
+
}
|
|
1040
|
+
}), vscode.commands.registerCommand('references-view.pickFromHistory', async () => {
|
|
1041
|
+
const entries = await this.getChildren();
|
|
1042
|
+
const picks = entries.map(item => ({
|
|
1043
|
+
label: item.word,
|
|
1044
|
+
description: item.description,
|
|
1045
|
+
item
|
|
1046
|
+
}));
|
|
1047
|
+
const pick = await vscode.window.showQuickPick(picks, { placeHolder: vscode.l10n.t('Select previous reference search') });
|
|
1048
|
+
if (pick) {
|
|
1049
|
+
this._reRunHistoryItem(pick.item);
|
|
1050
|
+
}
|
|
1051
|
+
}));
|
|
1052
|
+
}
|
|
1053
|
+
dispose() {
|
|
1054
|
+
vscode.Disposable.from(...this._disposables).dispose();
|
|
1055
|
+
this._onDidChangeTreeData.dispose();
|
|
1056
|
+
}
|
|
1057
|
+
_reRunHistoryItem(item) {
|
|
1058
|
+
this._inputs.delete(item.key);
|
|
1059
|
+
const newPosition = item.anchor.guessedTrackedPosition();
|
|
1060
|
+
let newInput = item.input;
|
|
1061
|
+
// create a new input when having a tracked position which is
|
|
1062
|
+
// different than the original position.
|
|
1063
|
+
if (newPosition && !item.input.location.range.start.isEqual(newPosition)) {
|
|
1064
|
+
newInput = item.input.with(new vscode.Location(item.input.location.uri, newPosition));
|
|
1065
|
+
}
|
|
1066
|
+
this._tree.setInput(newInput);
|
|
1067
|
+
}
|
|
1068
|
+
async add(input) {
|
|
1069
|
+
const doc = await vscode.workspace.openTextDocument(input.location.uri);
|
|
1070
|
+
const anchor = new utils_1.WordAnchor(doc, input.location.range.start);
|
|
1071
|
+
const range = doc.getWordRangeAtPosition(input.location.range.start) ?? doc.getWordRangeAtPosition(input.location.range.start, /[^\s]+/);
|
|
1072
|
+
const word = range ? doc.getText(range) : '???';
|
|
1073
|
+
const item = new HistoryItem(JSON.stringify([range?.start ?? input.location.range.start, input.location.uri, input.title]), word, anchor, input);
|
|
1074
|
+
// use filo-ordering of native maps
|
|
1075
|
+
this._inputs.delete(item.key);
|
|
1076
|
+
this._inputs.set(item.key, item);
|
|
1077
|
+
this._ctxHasHistory.set(true);
|
|
1078
|
+
}
|
|
1079
|
+
clear() {
|
|
1080
|
+
this._inputs.clear();
|
|
1081
|
+
this._ctxHasHistory.set(false);
|
|
1082
|
+
this._onDidChangeTreeData.fire(undefined);
|
|
1083
|
+
}
|
|
1084
|
+
get size() {
|
|
1085
|
+
return this._inputs.size;
|
|
1086
|
+
}
|
|
1087
|
+
// --- tree data provider
|
|
1088
|
+
getTreeItem(item) {
|
|
1089
|
+
const result = new vscode.TreeItem(item.word);
|
|
1090
|
+
result.description = item.description;
|
|
1091
|
+
result.command = { command: '_references-view.showHistoryItem', arguments: [item], title: vscode.l10n.t('Rerun') };
|
|
1092
|
+
result.collapsibleState = vscode.TreeItemCollapsibleState.None;
|
|
1093
|
+
result.contextValue = 'history-item';
|
|
1094
|
+
return result;
|
|
1095
|
+
}
|
|
1096
|
+
getChildren() {
|
|
1097
|
+
return Promise.all([...this._inputs.values()].reverse());
|
|
1098
|
+
}
|
|
1099
|
+
getParent() {
|
|
1100
|
+
return undefined;
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
|
|
1105
|
+
/***/ }),
|
|
1106
|
+
/* 8 */
|
|
1107
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1108
|
+
|
|
1109
|
+
|
|
1110
|
+
/*---------------------------------------------------------------------------------------------
|
|
1111
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
1112
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
1113
|
+
*--------------------------------------------------------------------------------------------*/
|
|
1114
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1115
|
+
exports.EditorHighlights = void 0;
|
|
1116
|
+
const vscode = __webpack_require__(2);
|
|
1117
|
+
class EditorHighlights {
|
|
1118
|
+
constructor(_view, _delegate) {
|
|
1119
|
+
this._view = _view;
|
|
1120
|
+
this._delegate = _delegate;
|
|
1121
|
+
this._decorationType = vscode.window.createTextEditorDecorationType({
|
|
1122
|
+
backgroundColor: new vscode.ThemeColor('editor.findMatchHighlightBackground'),
|
|
1123
|
+
rangeBehavior: vscode.DecorationRangeBehavior.ClosedClosed,
|
|
1124
|
+
overviewRulerLane: vscode.OverviewRulerLane.Center,
|
|
1125
|
+
overviewRulerColor: new vscode.ThemeColor('editor.findMatchHighlightBackground'),
|
|
1126
|
+
});
|
|
1127
|
+
this.disposables = [];
|
|
1128
|
+
this._ignore = new Set();
|
|
1129
|
+
this.disposables.push(vscode.workspace.onDidChangeTextDocument(e => this._ignore.add(e.document.uri.toString())), vscode.window.onDidChangeActiveTextEditor(() => _view.visible && this.update()), _view.onDidChangeVisibility(e => e.visible ? this._show() : this._hide()), _view.onDidChangeSelection(() => {
|
|
1130
|
+
if (_view.visible) {
|
|
1131
|
+
this.update();
|
|
1132
|
+
}
|
|
1133
|
+
}));
|
|
1134
|
+
this._show();
|
|
1135
|
+
}
|
|
1136
|
+
dispose() {
|
|
1137
|
+
vscode.Disposable.from(...this.disposables).dispose();
|
|
1138
|
+
for (const editor of vscode.window.visibleTextEditors) {
|
|
1139
|
+
editor.setDecorations(this._decorationType, []);
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
_show() {
|
|
1143
|
+
const { activeTextEditor: editor } = vscode.window;
|
|
1144
|
+
if (!editor || !editor.viewColumn) {
|
|
1145
|
+
return;
|
|
1146
|
+
}
|
|
1147
|
+
if (this._ignore.has(editor.document.uri.toString())) {
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
const [anchor] = this._view.selection;
|
|
1151
|
+
if (!anchor) {
|
|
1152
|
+
return;
|
|
1153
|
+
}
|
|
1154
|
+
const ranges = this._delegate.getEditorHighlights(anchor, editor.document.uri);
|
|
1155
|
+
if (ranges) {
|
|
1156
|
+
editor.setDecorations(this._decorationType, ranges);
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
_hide() {
|
|
1160
|
+
for (const editor of vscode.window.visibleTextEditors) {
|
|
1161
|
+
editor.setDecorations(this._decorationType, []);
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
update() {
|
|
1165
|
+
this._hide();
|
|
1166
|
+
this._show();
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
exports.EditorHighlights = EditorHighlights;
|
|
1170
|
+
|
|
1171
|
+
|
|
1172
|
+
/***/ }),
|
|
1173
|
+
/* 9 */
|
|
1174
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1175
|
+
|
|
1176
|
+
|
|
1177
|
+
/*---------------------------------------------------------------------------------------------
|
|
1178
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
1179
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
1180
|
+
*--------------------------------------------------------------------------------------------*/
|
|
1181
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1182
|
+
exports.Navigation = void 0;
|
|
1183
|
+
const vscode = __webpack_require__(2);
|
|
1184
|
+
const utils_1 = __webpack_require__(3);
|
|
1185
|
+
class Navigation {
|
|
1186
|
+
constructor(_view) {
|
|
1187
|
+
this._view = _view;
|
|
1188
|
+
this._disposables = [];
|
|
1189
|
+
this._ctxCanNavigate = new utils_1.ContextKey('references-view.canNavigate');
|
|
1190
|
+
this._disposables.push(vscode.commands.registerCommand('references-view.next', () => this.next(false)), vscode.commands.registerCommand('references-view.prev', () => this.previous(false)));
|
|
1191
|
+
}
|
|
1192
|
+
dispose() {
|
|
1193
|
+
vscode.Disposable.from(...this._disposables).dispose();
|
|
1194
|
+
}
|
|
1195
|
+
update(delegate) {
|
|
1196
|
+
this._delegate = delegate;
|
|
1197
|
+
this._ctxCanNavigate.set(Boolean(this._delegate));
|
|
1198
|
+
}
|
|
1199
|
+
_anchor() {
|
|
1200
|
+
if (!this._delegate) {
|
|
1201
|
+
return undefined;
|
|
1202
|
+
}
|
|
1203
|
+
const [sel] = this._view.selection;
|
|
1204
|
+
if (sel) {
|
|
1205
|
+
return sel;
|
|
1206
|
+
}
|
|
1207
|
+
if (!vscode.window.activeTextEditor) {
|
|
1208
|
+
return undefined;
|
|
1209
|
+
}
|
|
1210
|
+
return this._delegate.nearest(vscode.window.activeTextEditor.document.uri, vscode.window.activeTextEditor.selection.active);
|
|
1211
|
+
}
|
|
1212
|
+
_open(loc, preserveFocus) {
|
|
1213
|
+
vscode.commands.executeCommand('vscode.open', loc.uri, {
|
|
1214
|
+
selection: new vscode.Selection(loc.range.start, loc.range.start),
|
|
1215
|
+
preserveFocus
|
|
1216
|
+
});
|
|
1217
|
+
}
|
|
1218
|
+
previous(preserveFocus) {
|
|
1219
|
+
if (!this._delegate) {
|
|
1220
|
+
return;
|
|
1221
|
+
}
|
|
1222
|
+
const item = this._anchor();
|
|
1223
|
+
if (!item) {
|
|
1224
|
+
return;
|
|
1225
|
+
}
|
|
1226
|
+
const newItem = this._delegate.previous(item);
|
|
1227
|
+
const newLocation = this._delegate.location(newItem);
|
|
1228
|
+
if (newLocation) {
|
|
1229
|
+
this._view.reveal(newItem, { select: true, focus: true });
|
|
1230
|
+
this._open(newLocation, preserveFocus);
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
next(preserveFocus) {
|
|
1234
|
+
if (!this._delegate) {
|
|
1235
|
+
return;
|
|
1236
|
+
}
|
|
1237
|
+
const item = this._anchor();
|
|
1238
|
+
if (!item) {
|
|
1239
|
+
return;
|
|
1240
|
+
}
|
|
1241
|
+
const newItem = this._delegate.next(item);
|
|
1242
|
+
const newLocation = this._delegate.location(newItem);
|
|
1243
|
+
if (newLocation) {
|
|
1244
|
+
this._view.reveal(newItem, { select: true, focus: true });
|
|
1245
|
+
this._open(newLocation, preserveFocus);
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
exports.Navigation = Navigation;
|
|
1250
|
+
|
|
1251
|
+
|
|
1252
|
+
/***/ }),
|
|
1253
|
+
/* 10 */
|
|
1254
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1255
|
+
|
|
1256
|
+
|
|
1257
|
+
/*---------------------------------------------------------------------------------------------
|
|
1258
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
1259
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
1260
|
+
*--------------------------------------------------------------------------------------------*/
|
|
1261
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1262
|
+
exports.register = void 0;
|
|
1263
|
+
const vscode = __webpack_require__(2);
|
|
1264
|
+
const utils_1 = __webpack_require__(3);
|
|
1265
|
+
const model_1 = __webpack_require__(11);
|
|
1266
|
+
function register(tree, context) {
|
|
1267
|
+
const direction = new RichTypesDirection(context.workspaceState, "subtypes" /* TypeHierarchyDirection.Subtypes */);
|
|
1268
|
+
function showTypeHierarchy() {
|
|
1269
|
+
if (vscode.window.activeTextEditor) {
|
|
1270
|
+
const input = new model_1.TypesTreeInput(new vscode.Location(vscode.window.activeTextEditor.document.uri, vscode.window.activeTextEditor.selection.active), direction.value);
|
|
1271
|
+
tree.setInput(input);
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
function setTypeHierarchyDirection(value, anchor) {
|
|
1275
|
+
direction.value = value;
|
|
1276
|
+
let newInput;
|
|
1277
|
+
const oldInput = tree.getInput();
|
|
1278
|
+
if (anchor instanceof model_1.TypeItem) {
|
|
1279
|
+
newInput = new model_1.TypesTreeInput(new vscode.Location(anchor.item.uri, anchor.item.selectionRange.start), direction.value);
|
|
1280
|
+
}
|
|
1281
|
+
else if (anchor instanceof vscode.Location) {
|
|
1282
|
+
newInput = new model_1.TypesTreeInput(anchor, direction.value);
|
|
1283
|
+
}
|
|
1284
|
+
else if (oldInput instanceof model_1.TypesTreeInput) {
|
|
1285
|
+
newInput = new model_1.TypesTreeInput(oldInput.location, direction.value);
|
|
1286
|
+
}
|
|
1287
|
+
if (newInput) {
|
|
1288
|
+
tree.setInput(newInput);
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
context.subscriptions.push(vscode.commands.registerCommand('references-view.showTypeHierarchy', showTypeHierarchy), vscode.commands.registerCommand('references-view.showSupertypes', (item) => setTypeHierarchyDirection("supertypes" /* TypeHierarchyDirection.Supertypes */, item)), vscode.commands.registerCommand('references-view.showSubtypes', (item) => setTypeHierarchyDirection("subtypes" /* TypeHierarchyDirection.Subtypes */, item)), vscode.commands.registerCommand('references-view.removeTypeItem', removeTypeItem));
|
|
1292
|
+
}
|
|
1293
|
+
exports.register = register;
|
|
1294
|
+
function removeTypeItem(item) {
|
|
1295
|
+
if (item instanceof model_1.TypeItem) {
|
|
1296
|
+
item.remove();
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
class RichTypesDirection {
|
|
1300
|
+
constructor(_mem, _value = "subtypes" /* TypeHierarchyDirection.Subtypes */) {
|
|
1301
|
+
this._mem = _mem;
|
|
1302
|
+
this._value = _value;
|
|
1303
|
+
this._ctxMode = new utils_1.ContextKey('references-view.typeHierarchyMode');
|
|
1304
|
+
const raw = _mem.get(RichTypesDirection._key);
|
|
1305
|
+
if (typeof raw === 'string') {
|
|
1306
|
+
this.value = raw;
|
|
1307
|
+
}
|
|
1308
|
+
else {
|
|
1309
|
+
this.value = _value;
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
get value() {
|
|
1313
|
+
return this._value;
|
|
1314
|
+
}
|
|
1315
|
+
set value(value) {
|
|
1316
|
+
this._value = value;
|
|
1317
|
+
this._ctxMode.set(value);
|
|
1318
|
+
this._mem.update(RichTypesDirection._key, value);
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
RichTypesDirection._key = 'references-view.typeHierarchyMode';
|
|
1322
|
+
|
|
1323
|
+
|
|
1324
|
+
/***/ }),
|
|
1325
|
+
/* 11 */
|
|
1326
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1327
|
+
|
|
1328
|
+
|
|
1329
|
+
/*---------------------------------------------------------------------------------------------
|
|
1330
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
1331
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
1332
|
+
*--------------------------------------------------------------------------------------------*/
|
|
1333
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1334
|
+
exports.TypeItem = exports.TypesTreeInput = void 0;
|
|
1335
|
+
const vscode = __webpack_require__(2);
|
|
1336
|
+
const utils_1 = __webpack_require__(3);
|
|
1337
|
+
class TypesTreeInput {
|
|
1338
|
+
constructor(location, direction) {
|
|
1339
|
+
this.location = location;
|
|
1340
|
+
this.direction = direction;
|
|
1341
|
+
this.contextValue = 'typeHierarchy';
|
|
1342
|
+
this.title = direction === "supertypes" /* TypeHierarchyDirection.Supertypes */
|
|
1343
|
+
? vscode.l10n.t('Supertypes Of')
|
|
1344
|
+
: vscode.l10n.t('Subtypes Of');
|
|
1345
|
+
}
|
|
1346
|
+
async resolve() {
|
|
1347
|
+
const items = await Promise.resolve(vscode.commands.executeCommand('vscode.prepareTypeHierarchy', this.location.uri, this.location.range.start));
|
|
1348
|
+
const model = new TypesModel(this.direction, items ?? []);
|
|
1349
|
+
const provider = new TypeItemDataProvider(model);
|
|
1350
|
+
if (model.roots.length === 0) {
|
|
1351
|
+
return;
|
|
1352
|
+
}
|
|
1353
|
+
return {
|
|
1354
|
+
provider,
|
|
1355
|
+
get message() { return model.roots.length === 0 ? vscode.l10n.t('No results.') : undefined; },
|
|
1356
|
+
navigation: model,
|
|
1357
|
+
highlights: model,
|
|
1358
|
+
dnd: model,
|
|
1359
|
+
dispose() {
|
|
1360
|
+
provider.dispose();
|
|
1361
|
+
}
|
|
1362
|
+
};
|
|
1363
|
+
}
|
|
1364
|
+
with(location) {
|
|
1365
|
+
return new TypesTreeInput(location, this.direction);
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
exports.TypesTreeInput = TypesTreeInput;
|
|
1369
|
+
class TypeItem {
|
|
1370
|
+
constructor(model, item, parent) {
|
|
1371
|
+
this.model = model;
|
|
1372
|
+
this.item = item;
|
|
1373
|
+
this.parent = parent;
|
|
1374
|
+
}
|
|
1375
|
+
remove() {
|
|
1376
|
+
this.model.remove(this);
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
exports.TypeItem = TypeItem;
|
|
1380
|
+
class TypesModel {
|
|
1381
|
+
constructor(direction, items) {
|
|
1382
|
+
this.direction = direction;
|
|
1383
|
+
this.roots = [];
|
|
1384
|
+
this._onDidChange = new vscode.EventEmitter();
|
|
1385
|
+
this.onDidChange = this._onDidChange.event;
|
|
1386
|
+
this.roots = items.map(item => new TypeItem(this, item, undefined));
|
|
1387
|
+
}
|
|
1388
|
+
async _resolveTypes(currentType) {
|
|
1389
|
+
if (this.direction === "supertypes" /* TypeHierarchyDirection.Supertypes */) {
|
|
1390
|
+
const types = await vscode.commands.executeCommand('vscode.provideSupertypes', currentType.item);
|
|
1391
|
+
return types ? types.map(item => new TypeItem(this, item, currentType)) : [];
|
|
1392
|
+
}
|
|
1393
|
+
else {
|
|
1394
|
+
const types = await vscode.commands.executeCommand('vscode.provideSubtypes', currentType.item);
|
|
1395
|
+
return types ? types.map(item => new TypeItem(this, item, currentType)) : [];
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
async getTypeChildren(item) {
|
|
1399
|
+
if (!item.children) {
|
|
1400
|
+
item.children = await this._resolveTypes(item);
|
|
1401
|
+
}
|
|
1402
|
+
return item.children;
|
|
1403
|
+
}
|
|
1404
|
+
// -- dnd
|
|
1405
|
+
getDragUri(item) {
|
|
1406
|
+
return (0, utils_1.asResourceUrl)(item.item.uri, item.item.range);
|
|
1407
|
+
}
|
|
1408
|
+
// -- navigation
|
|
1409
|
+
location(currentType) {
|
|
1410
|
+
return new vscode.Location(currentType.item.uri, currentType.item.range);
|
|
1411
|
+
}
|
|
1412
|
+
nearest(uri, _position) {
|
|
1413
|
+
return this.roots.find(item => item.item.uri.toString() === uri.toString()) ?? this.roots[0];
|
|
1414
|
+
}
|
|
1415
|
+
next(from) {
|
|
1416
|
+
return this._move(from, true) ?? from;
|
|
1417
|
+
}
|
|
1418
|
+
previous(from) {
|
|
1419
|
+
return this._move(from, false) ?? from;
|
|
1420
|
+
}
|
|
1421
|
+
_move(item, fwd) {
|
|
1422
|
+
if (item.children?.length) {
|
|
1423
|
+
return fwd ? item.children[0] : (0, utils_1.tail)(item.children);
|
|
1424
|
+
}
|
|
1425
|
+
const array = this.roots.includes(item) ? this.roots : item.parent?.children;
|
|
1426
|
+
if (array?.length) {
|
|
1427
|
+
const idx = array.indexOf(item);
|
|
1428
|
+
const delta = fwd ? 1 : -1;
|
|
1429
|
+
return array[idx + delta + array.length % array.length];
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
// --- highlights
|
|
1433
|
+
getEditorHighlights(currentType, uri) {
|
|
1434
|
+
return currentType.item.uri.toString() === uri.toString() ? [currentType.item.selectionRange] : undefined;
|
|
1435
|
+
}
|
|
1436
|
+
remove(item) {
|
|
1437
|
+
const isInRoot = this.roots.includes(item);
|
|
1438
|
+
const siblings = isInRoot ? this.roots : item.parent?.children;
|
|
1439
|
+
if (siblings) {
|
|
1440
|
+
(0, utils_1.del)(siblings, item);
|
|
1441
|
+
this._onDidChange.fire(this);
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
class TypeItemDataProvider {
|
|
1446
|
+
constructor(_model) {
|
|
1447
|
+
this._model = _model;
|
|
1448
|
+
this._emitter = new vscode.EventEmitter();
|
|
1449
|
+
this.onDidChangeTreeData = this._emitter.event;
|
|
1450
|
+
this._modelListener = _model.onDidChange(e => this._emitter.fire(e instanceof TypeItem ? e : undefined));
|
|
1451
|
+
}
|
|
1452
|
+
dispose() {
|
|
1453
|
+
this._emitter.dispose();
|
|
1454
|
+
this._modelListener.dispose();
|
|
1455
|
+
}
|
|
1456
|
+
getTreeItem(element) {
|
|
1457
|
+
const item = new vscode.TreeItem(element.item.name);
|
|
1458
|
+
item.description = element.item.detail;
|
|
1459
|
+
item.contextValue = 'type-item';
|
|
1460
|
+
item.iconPath = (0, utils_1.getThemeIcon)(element.item.kind);
|
|
1461
|
+
item.command = {
|
|
1462
|
+
command: 'vscode.open',
|
|
1463
|
+
title: vscode.l10n.t('Open Type'),
|
|
1464
|
+
arguments: [
|
|
1465
|
+
element.item.uri,
|
|
1466
|
+
{ selection: element.item.selectionRange.with({ end: element.item.selectionRange.start }) }
|
|
1467
|
+
]
|
|
1468
|
+
};
|
|
1469
|
+
item.collapsibleState = vscode.TreeItemCollapsibleState.Collapsed;
|
|
1470
|
+
return item;
|
|
1471
|
+
}
|
|
1472
|
+
getChildren(element) {
|
|
1473
|
+
return element
|
|
1474
|
+
? this._model.getTypeChildren(element)
|
|
1475
|
+
: this._model.roots;
|
|
1476
|
+
}
|
|
1477
|
+
getParent(element) {
|
|
1478
|
+
return element.parent;
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
|
|
1483
|
+
/***/ })
|
|
1484
|
+
/******/ ]);
|
|
1485
|
+
/************************************************************************/
|
|
1486
|
+
/******/ // The module cache
|
|
1487
|
+
/******/ var __webpack_module_cache__ = {};
|
|
1488
|
+
/******/
|
|
1489
|
+
/******/ // The require function
|
|
1490
|
+
/******/ function __webpack_require__(moduleId) {
|
|
1491
|
+
/******/ // Check if module is in cache
|
|
1492
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
1493
|
+
/******/ if (cachedModule !== undefined) {
|
|
1494
|
+
/******/ return cachedModule.exports;
|
|
1495
|
+
/******/ }
|
|
1496
|
+
/******/ // Create a new module (and put it into the cache)
|
|
1497
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
1498
|
+
/******/ // no module.id needed
|
|
1499
|
+
/******/ // no module.loaded needed
|
|
1500
|
+
/******/ exports: {}
|
|
1501
|
+
/******/ };
|
|
1502
|
+
/******/
|
|
1503
|
+
/******/ // Execute the module function
|
|
1504
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
1505
|
+
/******/
|
|
1506
|
+
/******/ // Return the exports of the module
|
|
1507
|
+
/******/ return module.exports;
|
|
1508
|
+
/******/ }
|
|
1509
|
+
/******/
|
|
1510
|
+
/************************************************************************/
|
|
1511
|
+
var __webpack_exports__ = {};
|
|
1512
|
+
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
|
1513
|
+
(() => {
|
|
1514
|
+
var exports = __webpack_exports__;
|
|
1515
|
+
|
|
1516
|
+
/*---------------------------------------------------------------------------------------------
|
|
1517
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
1518
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
1519
|
+
*--------------------------------------------------------------------------------------------*/
|
|
1520
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1521
|
+
exports.activate = void 0;
|
|
1522
|
+
const calls = __webpack_require__(1);
|
|
1523
|
+
const references = __webpack_require__(5);
|
|
1524
|
+
const tree_1 = __webpack_require__(7);
|
|
1525
|
+
const types = __webpack_require__(10);
|
|
1526
|
+
function activate(context) {
|
|
1527
|
+
const tree = new tree_1.SymbolsTree();
|
|
1528
|
+
references.register(tree, context);
|
|
1529
|
+
calls.register(tree, context);
|
|
1530
|
+
types.register(tree, context);
|
|
1531
|
+
function setInput(input) {
|
|
1532
|
+
tree.setInput(input);
|
|
1533
|
+
}
|
|
1534
|
+
function getInput() {
|
|
1535
|
+
return tree.getInput();
|
|
1536
|
+
}
|
|
1537
|
+
return { setInput, getInput };
|
|
1538
|
+
}
|
|
1539
|
+
exports.activate = activate;
|
|
1540
|
+
|
|
1541
|
+
})();
|
|
1542
|
+
|
|
1543
|
+
var __webpack_export_target__ = exports;
|
|
1544
|
+
for(var i in __webpack_exports__) __webpack_export_target__[i] = __webpack_exports__[i];
|
|
1545
|
+
if(__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, "__esModule", { value: true });
|
|
1546
|
+
/******/ })()
|
|
1547
|
+
;
|
|
1548
|
+
//# sourceMappingURL=extension.js.map
|