Merge from master

This commit is contained in:
Raj Musuku
2019-02-21 17:56:04 -08:00
parent 5a146e34fa
commit 666ae11639
11482 changed files with 119352 additions and 255574 deletions

View File

@@ -3,14 +3,12 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import 'vs/css!./goToDefinitionMouse';
import * as nls from 'vs/nls';
import { Throttler } from 'vs/base/common/async';
import { createCancelablePromise, CancelablePromise } from 'vs/base/common/async';
import { CancellationToken } from 'vs/base/common/cancellation';
import { onUnexpectedError } from 'vs/base/common/errors';
import { MarkdownString } from 'vs/base/common/htmlContent';
import { TPromise } from 'vs/base/common/winjs.base';
import { IModeService } from 'vs/editor/common/services/modeService';
import { Range } from 'vs/editor/common/core/range';
import * as editorCommon from 'vs/editor/common/editorCommon';
@@ -25,7 +23,7 @@ import { editorActiveLinkForeground } from 'vs/platform/theme/common/colorRegist
import { EditorState, CodeEditorStateFlag } from 'vs/editor/browser/core/editorState';
import { DefinitionAction, DefinitionActionConfig } from './goToDefinitionCommands';
import { ClickLinkGesture, ClickLinkMouseEvent, ClickLinkKeyboardEvent } from 'vs/editor/contrib/goToDefinition/clickLinkGesture';
import { IWordAtPosition, IModelDeltaDecoration, ITextModel } from 'vs/editor/common/model';
import { IWordAtPosition, IModelDeltaDecoration, ITextModel, IFoundBracket } from 'vs/editor/common/model';
import { Position } from 'vs/editor/common/core/position';
class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorContribution {
@@ -37,7 +35,7 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
private toUnhook: IDisposable[];
private decorations: string[];
private currentWordUnderMouse: IWordAtPosition;
private throttler: Throttler;
private previousPromise: CancelablePromise<DefinitionLink[]>;
constructor(
editor: ICodeEditor,
@@ -47,7 +45,7 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
this.toUnhook = [];
this.decorations = [];
this.editor = editor;
this.throttler = new Throttler();
this.previousPromise = null;
let linkGesture = new ClickLinkGesture(editor);
this.toUnhook.push(linkGesture);
@@ -58,7 +56,7 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
this.toUnhook.push(linkGesture.onExecute((mouseEvent: ClickLinkMouseEvent) => {
if (this.isEnabled(mouseEvent)) {
this.gotoDefinition(mouseEvent.target, mouseEvent.hasSideBySideModifier).done(() => {
this.gotoDefinition(mouseEvent.target, mouseEvent.hasSideBySideModifier).then(() => {
this.removeDecorations();
}, (error: Error) => {
this.removeDecorations();
@@ -75,6 +73,12 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
}
private startFindDefinition(mouseEvent: ClickLinkMouseEvent, withKey?: ClickLinkKeyboardEvent): void {
// check if we are active and on a content widget
if (mouseEvent.target.type === MouseTargetType.CONTENT_WIDGET && this.decorations.length > 0) {
return;
}
if (!this.isEnabled(mouseEvent, withKey)) {
this.currentWordUnderMouse = null;
this.removeDecorations();
@@ -100,12 +104,14 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
// 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.wrap<DefinitionLink[]>(null);
if (this.previousPromise) {
this.previousPromise.cancel();
this.previousPromise = null;
}
}).then(results => {
this.previousPromise = createCancelablePromise(token => this.findDefinition(mouseEvent.target, token));
this.previousPromise.then(results => {
if (!results || !results.length || !state.validate(this.editor)) {
this.removeDecorations();
return;
@@ -137,7 +143,8 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
const { object: { textEditorModel } } = ref;
const { startLineNumber } = result.range;
if (textEditorModel.getLineMaxColumn(startLineNumber) === 0) {
if (startLineNumber < 1 || startLineNumber > textEditorModel.getLineCount()) {
// invalid range
ref.dispose();
return;
}
@@ -153,12 +160,12 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
this.addDecoration(
wordRange,
new MarkdownString().appendCodeblock(this.modeService.getModeIdByFilenameOrFirstLine(textEditorModel.uri.fsPath), previewValue)
new MarkdownString().appendCodeblock(this.modeService.getModeIdByFilepathOrFirstLine(textEditorModel.uri.fsPath), previewValue)
);
ref.dispose();
});
}
}).done(undefined, onUnexpectedError);
}).then(undefined, onUnexpectedError);
}
private getPreviewValue(textEditorModel: ITextModel, startLineNumber: number) {
@@ -204,7 +211,7 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
private getPreviewRangeBasedOnBrackets(textEditorModel: ITextModel, startLineNumber: number) {
const maxLineNumber = Math.min(textEditorModel.getLineCount(), startLineNumber + GotoDefinitionWithMouseEditorContribution.MAX_SOURCE_PREVIEW_LINES);
const brackets = [];
const brackets: IFoundBracket[] = [];
let ignoreFirstEmpty = true;
let currentBracket = textEditorModel.findNextBracket(new Position(startLineNumber, 1));
@@ -269,21 +276,21 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
private isEnabled(mouseEvent: ClickLinkMouseEvent, withKey?: ClickLinkKeyboardEvent): boolean {
return this.editor.getModel() &&
mouseEvent.isNoneOrSingleMouseDown &&
mouseEvent.target.type === MouseTargetType.CONTENT_TEXT &&
(mouseEvent.target.type === MouseTargetType.CONTENT_TEXT) &&
(mouseEvent.hasTriggerModifier || (withKey && withKey.keyCodeIsTriggerKey)) &&
DefinitionProviderRegistry.has(this.editor.getModel());
}
private findDefinition(target: IMouseTarget): TPromise<DefinitionLink[]> {
private findDefinition(target: IMouseTarget, token: CancellationToken): Thenable<DefinitionLink[]> {
const model = this.editor.getModel();
if (!model) {
return TPromise.as(null);
return Promise.resolve(null);
}
return getDefinitionsAtPosition(model, target.position);
return getDefinitionsAtPosition(model, target.position, token);
}
private gotoDefinition(target: IMouseTarget, sideBySide: boolean): TPromise<any> {
private gotoDefinition(target: IMouseTarget, sideBySide: boolean): Thenable<any> {
this.editor.setPosition(target.position);
const action = new DefinitionAction(new DefinitionActionConfig(sideBySide, false, true, false), { alias: undefined, label: undefined, id: undefined, precondition: undefined });
return this.editor.invokeWithinContext(accessor => action.run(accessor, this.editor));
@@ -301,7 +308,7 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
registerEditorContribution(GotoDefinitionWithMouseEditorContribution);
registerThemingParticipant((theme, collector) => {
let activeLinkForeground = theme.getColor(editorActiveLinkForeground);
const activeLinkForeground = theme.getColor(editorActiveLinkForeground);
if (activeLinkForeground) {
collector.addRule(`.monaco-editor .goto-definition-link { color: ${activeLinkForeground} !important; }`);
}