-
Notifications
You must be signed in to change notification settings - Fork 28k
/
goToDeclaration.ts
627 lines (530 loc) · 22 KB
/
goToDeclaration.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import 'vs/css!./goToDeclaration';
import * as nls from 'vs/nls';
import { Throttler } from 'vs/base/common/async';
import { onUnexpectedError } from 'vs/base/common/errors';
import { alert } from 'vs/base/browser/ui/aria/aria';
import { MarkedString } from 'vs/base/common/htmlContent';
import { KeyCode, KeyMod, KeyChord } from 'vs/base/common/keyCodes';
import * as platform from 'vs/base/common/platform';
import Severity from 'vs/base/common/severity';
import { TPromise } from 'vs/base/common/winjs.base';
import * as browser from 'vs/base/browser/browser';
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { IEditorService } from 'vs/platform/editor/common/editor';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IMessageService } from 'vs/platform/message/common/message';
import { Range } from 'vs/editor/common/core/range';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { editorAction, IActionOptions, ServicesAccessor, EditorAction } from 'vs/editor/common/editorCommonExtensions';
import { Location, DefinitionProviderRegistry } from 'vs/editor/common/modes';
import { ICodeEditor, IEditorMouseEvent, IMouseTarget, MouseTargetType } from 'vs/editor/browser/editorBrowser';
import { editorContribution } from 'vs/editor/browser/editorBrowserExtensions';
import { getDefinitionsAtPosition, getImplementationsAtPosition, getTypeDefinitionsAtPosition } from 'vs/editor/contrib/goToDeclaration/common/goToDeclaration';
import { ReferencesController } from 'vs/editor/contrib/referenceSearch/browser/referencesController';
import { ReferencesModel } from 'vs/editor/contrib/referenceSearch/browser/referencesModel';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { PeekContext } from 'vs/editor/contrib/zoneWidget/browser/peekViewWidget';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { ITextModelResolverService } from 'vs/editor/common/services/resolverService';
import { MessageController } from './messageController';
import * as corePosition from 'vs/editor/common/core/position';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
import { registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { editorActiveLinkForeground } from 'vs/platform/theme/common/colorRegistry';
import { EditorState, CodeEditorStateFlag } from 'vs/editor/common/core/editorState';
export class DefinitionActionConfig {
constructor(
public openToSide = false,
public openInPeek = false,
public filterCurrent = true
) {
//
}
}
export class DefinitionAction extends EditorAction {
private _configuration: DefinitionActionConfig;
constructor(configuration: DefinitionActionConfig, opts: IActionOptions) {
super(opts);
this._configuration = configuration;
}
public run(accessor: ServicesAccessor, editor: editorCommon.ICommonCodeEditor): TPromise<void> {
const messageService = accessor.get(IMessageService);
const editorService = accessor.get(IEditorService);
let model = editor.getModel();
let pos = editor.getPosition();
return this.getDeclarationsAtPosition(model, pos).then(references => {
// * remove falsy references
// * remove reference at the current pos
let result: Location[] = [];
for (let i = 0; i < references.length; i++) {
let reference = references[i];
if (!reference || !reference.range) {
continue;
}
let { uri, range } = reference;
if (!this._configuration.filterCurrent
|| uri.toString() !== model.uri.toString()
|| !Range.containsPosition(range, pos)) {
result.push({
uri,
range
});
}
}
if (result.length === 0) {
const info = model.getWordAtPosition(pos);
MessageController.get(editor).showMessage(this.getNoResultFoundMessage(info), pos);
return;
}
return this._onResult(editorService, editor, new ReferencesModel(result));
}, (err) => {
// report an error
messageService.show(Severity.Error, err);
return false;
});
}
protected getDeclarationsAtPosition(model: editorCommon.IModel, position: corePosition.Position): TPromise<Location[]> {
return getDefinitionsAtPosition(model, position);
}
protected getNoResultFoundMessage(info?: editorCommon.IWordAtPosition): string {
return info && info.word
? nls.localize('noResultWord', "No definition found for '{0}'", info.word)
: nls.localize('generic.noResults', "No definition found");
}
protected getMetaTitle(model: ReferencesModel): string {
return model.references.length > 1 && nls.localize('meta.title', " – {0} definitions", model.references.length);
}
private _onResult(editorService: IEditorService, editor: editorCommon.ICommonCodeEditor, model: ReferencesModel) {
const msg = model.getAriaMessage();
alert(msg);
if (this._configuration.openInPeek) {
this._openInPeek(editorService, editor, model);
} else {
let next = model.nearestReference(editor.getModel().uri, editor.getPosition());
this._openReference(editorService, next, this._configuration.openToSide).then(editor => {
if (editor && model.references.length > 1) {
this._openInPeek(editorService, editor, model);
} else {
model.dispose();
}
});
}
}
private _openReference(editorService: IEditorService, reference: Location, sideBySide: boolean): TPromise<editorCommon.ICommonCodeEditor> {
let { uri, range } = reference;
return editorService.openEditor({
resource: uri,
options: {
selection: Range.collapseToStart(range),
revealIfVisible: !sideBySide
}
}, sideBySide).then(editor => {
return editor && <editorCommon.IEditor>editor.getControl();
});
}
private _openInPeek(editorService: IEditorService, target: editorCommon.ICommonCodeEditor, model: ReferencesModel) {
let controller = ReferencesController.get(target);
if (controller) {
controller.toggleWidget(target.getSelection(), TPromise.as(model), {
getMetaTitle: (model) => {
return this.getMetaTitle(model);
},
onGoto: (reference) => {
controller.closeWidget();
return this._openReference(editorService, reference, false);
}
});
} else {
model.dispose();
}
}
}
const goToDeclarationKb = platform.isWeb
? KeyMod.CtrlCmd | KeyCode.F12
: KeyCode.F12;
@editorAction
export class GoToDefinitionAction extends DefinitionAction {
public static ID = 'editor.action.goToDeclaration';
constructor() {
super(new DefinitionActionConfig(), {
id: GoToDefinitionAction.ID,
label: nls.localize('actions.goToDecl.label', "Go to Definition"),
alias: 'Go to Definition',
precondition: ContextKeyExpr.and(
EditorContextKeys.hasDefinitionProvider,
EditorContextKeys.isInEmbeddedEditor.toNegated()),
kbOpts: {
kbExpr: EditorContextKeys.textFocus,
primary: goToDeclarationKb
},
menuOpts: {
group: 'navigation',
order: 1.1
}
});
}
}
@editorAction
export class OpenDefinitionToSideAction extends DefinitionAction {
public static ID = 'editor.action.openDeclarationToTheSide';
constructor() {
super(new DefinitionActionConfig(true), {
id: OpenDefinitionToSideAction.ID,
label: nls.localize('actions.goToDeclToSide.label', "Open Definition to the Side"),
alias: 'Open Definition to the Side',
precondition: ContextKeyExpr.and(
EditorContextKeys.hasDefinitionProvider,
EditorContextKeys.isInEmbeddedEditor.toNegated()),
kbOpts: {
kbExpr: EditorContextKeys.textFocus,
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, goToDeclarationKb)
}
});
}
}
@editorAction
export class PeekDefinitionAction extends DefinitionAction {
constructor() {
super(new DefinitionActionConfig(void 0, true, false), {
id: 'editor.action.previewDeclaration',
label: nls.localize('actions.previewDecl.label', "Peek Definition"),
alias: 'Peek Definition',
precondition: ContextKeyExpr.and(
EditorContextKeys.hasDefinitionProvider,
PeekContext.notInPeekEditor,
EditorContextKeys.isInEmbeddedEditor.toNegated()),
kbOpts: {
kbExpr: EditorContextKeys.textFocus,
primary: KeyMod.Alt | KeyCode.F12,
linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.F10 }
},
menuOpts: {
group: 'navigation',
order: 1.2
}
});
}
}
export class ImplementationAction extends DefinitionAction {
protected getDeclarationsAtPosition(model: editorCommon.IModel, position: corePosition.Position): TPromise<Location[]> {
return getImplementationsAtPosition(model, position);
}
protected getNoResultFoundMessage(info?: editorCommon.IWordAtPosition): string {
return info && info.word
? nls.localize('goToImplementation.noResultWord', "No implementation found for '{0}'", info.word)
: nls.localize('goToImplementation.generic.noResults', "No implementation found");
}
protected getMetaTitle(model: ReferencesModel): string {
return model.references.length > 1 && nls.localize('meta.implementations.title', " – {0} implementations", model.references.length);
}
}
@editorAction
export class GoToImplementationAction extends ImplementationAction {
public static ID = 'editor.action.goToImplementation';
constructor() {
super(new DefinitionActionConfig(), {
id: GoToImplementationAction.ID,
label: nls.localize('actions.goToImplementation.label', "Go to Implementation"),
alias: 'Go to Implementation',
precondition: ContextKeyExpr.and(
EditorContextKeys.hasImplementationProvider,
EditorContextKeys.isInEmbeddedEditor.toNegated()),
kbOpts: {
kbExpr: EditorContextKeys.textFocus,
primary: KeyMod.CtrlCmd | KeyCode.F12
},
menuOpts: {
group: 'navigation',
order: 1.3
}
});
}
}
@editorAction
export class PeekImplementationAction extends ImplementationAction {
public static ID = 'editor.action.peekImplementation';
constructor() {
super(new DefinitionActionConfig(false, true, false), {
id: PeekImplementationAction.ID,
label: nls.localize('actions.peekImplementation.label', "Peek Implementation"),
alias: 'Peek Implementation',
precondition: ContextKeyExpr.and(
EditorContextKeys.hasImplementationProvider,
EditorContextKeys.isInEmbeddedEditor.toNegated()),
kbOpts: {
kbExpr: EditorContextKeys.textFocus,
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.F12
}
});
}
}
export class TypeDefinitionAction extends DefinitionAction {
protected getDeclarationsAtPosition(model: editorCommon.IModel, position: corePosition.Position): TPromise<Location[]> {
return getTypeDefinitionsAtPosition(model, position);
}
protected getNoResultFoundMessage(info?: editorCommon.IWordAtPosition): string {
return info && info.word
? nls.localize('goToTypeDefinition.noResultWord', "No type definition found for '{0}'", info.word)
: nls.localize('goToTypeDefinition.generic.noResults', "No type definition found");
}
protected getMetaTitle(model: ReferencesModel): string {
return model.references.length > 1 && nls.localize('meta.typeDefinitions.title', " – {0} type definitions", model.references.length);
}
}
@editorAction
export class GoToTypeDefintionAction extends TypeDefinitionAction {
public static ID = 'editor.action.goToTypeDefinition';
constructor() {
super(new DefinitionActionConfig(), {
id: GoToTypeDefintionAction.ID,
label: nls.localize('actions.goToTypeDefinition.label', "Go to Type Definition"),
alias: 'Go to Type Definition',
precondition: ContextKeyExpr.and(
EditorContextKeys.hasTypeDefinitionProvider,
EditorContextKeys.isInEmbeddedEditor.toNegated()),
kbOpts: {
kbExpr: EditorContextKeys.textFocus,
primary: 0
},
menuOpts: {
group: 'navigation',
order: 1.4
}
});
}
}
@editorAction
export class PeekTypeDefinitionAction extends TypeDefinitionAction {
public static ID = 'editor.action.peekTypeDefinition';
constructor() {
super(new DefinitionActionConfig(false, true, false), {
id: PeekTypeDefinitionAction.ID,
label: nls.localize('actions.peekTypeDefinition.label', "Peek Type Definition"),
alias: 'Peek Type Definition',
precondition: ContextKeyExpr.and(
EditorContextKeys.hasTypeDefinitionProvider,
EditorContextKeys.isInEmbeddedEditor.toNegated()),
kbOpts: {
kbExpr: EditorContextKeys.textFocus,
primary: 0
}
});
}
}
// --- Editor Contribution to goto definition using the mouse and a modifier key
@editorContribution
class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorContribution {
private static ID = 'editor.contrib.gotodefinitionwithmouse';
static TRIGGER_MODIFIER = platform.isMacintosh ? 'metaKey' : 'ctrlKey';
static TRIGGER_SIDEBYSIDE_KEY_VALUE = KeyCode.Alt;
static TRIGGER_KEY_VALUE = platform.isMacintosh ? KeyCode.Meta : KeyCode.Ctrl;
static MAX_SOURCE_PREVIEW_LINES = 8;
private editor: ICodeEditor;
private toUnhook: IDisposable[];
private decorations: string[];
private currentWordUnderMouse: editorCommon.IWordAtPosition;
private throttler: Throttler;
private lastMouseMoveEvent: IEditorMouseEvent;
private hasTriggerKeyOnMouseDown: boolean;
constructor(
editor: ICodeEditor,
@ITextModelResolverService private textModelResolverService: ITextModelResolverService,
@IModeService private modeService: IModeService
) {
this.toUnhook = [];
this.decorations = [];
this.editor = editor;
this.throttler = new Throttler();
this.toUnhook.push(this.editor.onMouseDown((e: IEditorMouseEvent) => this.onEditorMouseDown(e)));
this.toUnhook.push(this.editor.onMouseUp((e: IEditorMouseEvent) => this.onEditorMouseUp(e)));
this.toUnhook.push(this.editor.onMouseMove((e: IEditorMouseEvent) => this.onEditorMouseMove(e)));
this.toUnhook.push(this.editor.onMouseDrag(() => this.resetHandler()));
this.toUnhook.push(this.editor.onKeyDown((e: IKeyboardEvent) => this.onEditorKeyDown(e)));
this.toUnhook.push(this.editor.onKeyUp((e: IKeyboardEvent) => this.onEditorKeyUp(e)));
this.toUnhook.push(this.editor.onDidChangeCursorSelection((e) => this.onDidChangeCursorSelection(e)));
this.toUnhook.push(this.editor.onDidChangeModel((e) => this.resetHandler()));
this.toUnhook.push(this.editor.onDidChangeModelContent(() => this.resetHandler()));
this.toUnhook.push(this.editor.onDidScrollChange((e) => {
if (e.scrollTopChanged || e.scrollLeftChanged) {
this.resetHandler();
}
}));
}
private onDidChangeCursorSelection(e: ICursorSelectionChangedEvent): void {
if (e.selection && e.selection.startColumn !== e.selection.endColumn) {
this.resetHandler(); // immediately stop this feature if the user starts to select (https://github.com/Microsoft/vscode/issues/7827)
}
}
private onEditorMouseMove(mouseEvent: IEditorMouseEvent, withKey?: IKeyboardEvent): void {
this.lastMouseMoveEvent = mouseEvent;
this.startFindDefinition(mouseEvent, withKey);
}
private startFindDefinition(mouseEvent: IEditorMouseEvent, withKey?: IKeyboardEvent): void {
if (!this.isEnabled(mouseEvent, withKey)) {
this.currentWordUnderMouse = null;
this.removeDecorations();
return;
}
// Find word at mouse position
let position = mouseEvent.target.position;
let word = position ? this.editor.getModel().getWordAtPosition(position) : null;
if (!word) {
this.currentWordUnderMouse = null;
this.removeDecorations();
return;
}
// Return early if word at position is still the same
if (this.currentWordUnderMouse && this.currentWordUnderMouse.startColumn === word.startColumn && this.currentWordUnderMouse.endColumn === word.endColumn && this.currentWordUnderMouse.word === word.word) {
return;
}
this.currentWordUnderMouse = word;
// Find definition and decorate word if found
let state = new EditorState(this.editor, CodeEditorStateFlag.Position | CodeEditorStateFlag.Value | CodeEditorStateFlag.Selection | CodeEditorStateFlag.Scroll);
this.throttler.queue(() => {
return state.validate(this.editor)
? this.findDefinition(mouseEvent.target)
: TPromise.as<Location[]>(null);
}).then(results => {
if (!results || !results.length || !state.validate(this.editor)) {
this.removeDecorations();
return;
}
// Multiple results
if (results.length > 1) {
this.addDecoration(new Range(position.lineNumber, word.startColumn, position.lineNumber, word.endColumn), nls.localize('multipleResults', "Click to show {0} definitions.", results.length));
}
// Single result
else {
let result = results[0];
if (!result.uri) {
return;
}
this.textModelResolverService.createModelReference(result.uri).then(ref => {
if (!ref.object || !ref.object.textEditorModel) {
ref.dispose();
return;
}
const { object: { textEditorModel } } = ref;
const { startLineNumber } = result.range;
if (textEditorModel.getLineMaxColumn(startLineNumber) === 0) {
ref.dispose();
return;
}
const startIndent = textEditorModel.getLineFirstNonWhitespaceColumn(startLineNumber);
const maxLineNumber = Math.min(textEditorModel.getLineCount(), startLineNumber + GotoDefinitionWithMouseEditorContribution.MAX_SOURCE_PREVIEW_LINES);
let endLineNumber = startLineNumber + 1;
let minIndent = startIndent;
for (; endLineNumber < maxLineNumber; endLineNumber++) {
let endIndent = textEditorModel.getLineFirstNonWhitespaceColumn(endLineNumber);
minIndent = Math.min(minIndent, endIndent);
if (startIndent === endIndent) {
break;
}
}
const previewRange = new Range(startLineNumber, 1, endLineNumber + 1, 1);
const value = textEditorModel.getValueInRange(previewRange).replace(new RegExp(`^\\s{${minIndent - 1}}`, 'gm'), '').trim();
this.addDecoration(new Range(position.lineNumber, word.startColumn, position.lineNumber, word.endColumn), {
language: this.modeService.getModeIdByFilenameOrFirstLine(textEditorModel.uri.fsPath),
value
});
ref.dispose();
});
}
}).done(undefined, onUnexpectedError);
}
private addDecoration(range: Range, hoverMessage: MarkedString): void {
const newDecorations: editorCommon.IModelDeltaDecoration = {
range: range,
options: {
inlineClassName: 'goto-definition-link',
hoverMessage
}
};
this.decorations = this.editor.deltaDecorations(this.decorations, [newDecorations]);
}
private removeDecorations(): void {
if (this.decorations.length > 0) {
this.decorations = this.editor.deltaDecorations(this.decorations, []);
}
}
private onEditorKeyDown(e: IKeyboardEvent): void {
if (
this.lastMouseMoveEvent && (
e.keyCode === GotoDefinitionWithMouseEditorContribution.TRIGGER_KEY_VALUE || // User just pressed Ctrl/Cmd (normal goto definition)
e.keyCode === GotoDefinitionWithMouseEditorContribution.TRIGGER_SIDEBYSIDE_KEY_VALUE && e[GotoDefinitionWithMouseEditorContribution.TRIGGER_MODIFIER] // User pressed Ctrl/Cmd+Alt (goto definition to the side)
)
) {
this.startFindDefinition(this.lastMouseMoveEvent, e);
} else if (e[GotoDefinitionWithMouseEditorContribution.TRIGGER_MODIFIER]) {
this.removeDecorations(); // remove decorations if user holds another key with ctrl/cmd to prevent accident goto declaration
}
}
private resetHandler(): void {
this.lastMouseMoveEvent = null;
this.hasTriggerKeyOnMouseDown = false;
this.removeDecorations();
}
private onEditorMouseDown(mouseEvent: IEditorMouseEvent): void {
// We need to record if we had the trigger key on mouse down because someone might select something in the editor
// holding the mouse down and then while mouse is down start to press Ctrl/Cmd to start a copy operation and then
// release the mouse button without wanting to do the navigation.
// With this flag we prevent goto definition if the mouse was down before the trigger key was pressed.
this.hasTriggerKeyOnMouseDown = !!mouseEvent.event[GotoDefinitionWithMouseEditorContribution.TRIGGER_MODIFIER];
}
private onEditorMouseUp(mouseEvent: IEditorMouseEvent): void {
if (this.isEnabled(mouseEvent) && this.hasTriggerKeyOnMouseDown) {
this.gotoDefinition(mouseEvent.target, mouseEvent.event.altKey).done(() => {
this.removeDecorations();
}, (error: Error) => {
this.removeDecorations();
onUnexpectedError(error);
});
}
}
private onEditorKeyUp(e: IKeyboardEvent): void {
if (e.keyCode === GotoDefinitionWithMouseEditorContribution.TRIGGER_KEY_VALUE) {
this.removeDecorations();
this.currentWordUnderMouse = null;
}
}
private isEnabled(mouseEvent: IEditorMouseEvent, withKey?: IKeyboardEvent): boolean {
return this.editor.getModel() &&
(browser.isIE || mouseEvent.event.detail <= 1) && // IE does not support event.detail properly
mouseEvent.target.type === MouseTargetType.CONTENT_TEXT &&
(mouseEvent.event[GotoDefinitionWithMouseEditorContribution.TRIGGER_MODIFIER] || (withKey && withKey.keyCode === GotoDefinitionWithMouseEditorContribution.TRIGGER_KEY_VALUE)) &&
DefinitionProviderRegistry.has(this.editor.getModel());
}
private findDefinition(target: IMouseTarget): TPromise<Location[]> {
let model = this.editor.getModel();
if (!model) {
return TPromise.as(null);
}
return getDefinitionsAtPosition(this.editor.getModel(), target.position);
}
private gotoDefinition(target: IMouseTarget, sideBySide: boolean): TPromise<any> {
const targetAction = sideBySide
? OpenDefinitionToSideAction.ID
: GoToDefinitionAction.ID;
// just run the corresponding action
this.editor.setPosition(target.position);
return this.editor.getAction(targetAction).run();
}
public getId(): string {
return GotoDefinitionWithMouseEditorContribution.ID;
}
public dispose(): void {
this.toUnhook = dispose(this.toUnhook);
}
}
registerThemingParticipant((theme, collector) => {
let activeLinkForeground = theme.getColor(editorActiveLinkForeground);
if (activeLinkForeground) {
collector.addRule(`.monaco-editor.${theme.selector} .goto-definition-link { color: ${activeLinkForeground} !important; }`);
}
});