Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973 (#6381)

* Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973

* disable strict null check
This commit is contained in:
Anthony Dresser
2019-07-15 22:35:46 -07:00
committed by GitHub
parent f720ec642f
commit 0b7e7ddbf9
2406 changed files with 59140 additions and 35464 deletions

View File

@@ -29,6 +29,7 @@
.monaco-editor-hover .markdown-hover > .hover-contents:not(.code-hover-contents) {
max-width: 500px;
word-wrap: break-word;
}
.monaco-editor-hover p,

View File

@@ -7,7 +7,7 @@ import 'vs/css!./hover';
import * as nls from 'vs/nls';
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { KeyChord, KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import { IEmptyContentData } from 'vs/editor/browser/controller/mouseTarget';
import { ICodeEditor, IEditorMouseEvent, MouseTargetType } from 'vs/editor/browser/editorBrowser';
import { EditorAction, ServicesAccessor, registerEditorAction, registerEditorContribution } from 'vs/editor/browser/editorExtensions';
@@ -25,16 +25,13 @@ import { editorHoverBackground, editorHoverBorder, editorHoverHighlight, textCod
import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { IMarkerDecorationsService } from 'vs/editor/common/services/markersDecorationService';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IBulkEditService } from 'vs/editor/browser/services/bulkEditService';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility';
export class ModesHoverController implements IEditorContribution {
private static readonly ID = 'editor.contrib.hover';
private _toUnhook: IDisposable[];
private readonly _toUnhook = new DisposableStore();
private readonly _didChangeConfigurationHandler: IDisposable;
private _contentWidget: ModesContentHoverWidget;
@@ -68,13 +65,8 @@ export class ModesHoverController implements IEditorContribution {
@IModeService private readonly _modeService: IModeService,
@IMarkerDecorationsService private readonly _markerDecorationsService: IMarkerDecorationsService,
@IKeybindingService private readonly _keybindingService: IKeybindingService,
@IContextMenuService private readonly _contextMenuService: IContextMenuService,
@IBulkEditService private readonly _bulkEditService: IBulkEditService,
@ICommandService private readonly _commandService: ICommandService,
@IThemeService private readonly _themeService: IThemeService
) {
this._toUnhook = [];
this._isMouseDown = false;
this._hoverClicked = false;
@@ -96,22 +88,22 @@ export class ModesHoverController implements IEditorContribution {
this._isHoverEnabled = hoverOpts.enabled;
this._isHoverSticky = hoverOpts.sticky;
if (this._isHoverEnabled) {
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.onKeyDown((e: IKeyboardEvent) => this._onKeyDown(e)));
this._toUnhook.push(this._editor.onDidChangeModelDecorations(() => this._onModelDecorationsChanged()));
this._toUnhook.add(this._editor.onMouseDown((e: IEditorMouseEvent) => this._onEditorMouseDown(e)));
this._toUnhook.add(this._editor.onMouseUp((e: IEditorMouseEvent) => this._onEditorMouseUp(e)));
this._toUnhook.add(this._editor.onMouseMove((e: IEditorMouseEvent) => this._onEditorMouseMove(e)));
this._toUnhook.add(this._editor.onKeyDown((e: IKeyboardEvent) => this._onKeyDown(e)));
this._toUnhook.add(this._editor.onDidChangeModelDecorations(() => this._onModelDecorationsChanged()));
} else {
this._toUnhook.push(this._editor.onMouseMove(hideWidgetsEventHandler));
this._toUnhook.add(this._editor.onMouseMove(hideWidgetsEventHandler));
}
this._toUnhook.push(this._editor.onMouseLeave(hideWidgetsEventHandler));
this._toUnhook.push(this._editor.onDidChangeModel(hideWidgetsEventHandler));
this._toUnhook.push(this._editor.onDidScrollChange((e: IScrollEvent) => this._onEditorScrollChanged(e)));
this._toUnhook.add(this._editor.onMouseLeave(hideWidgetsEventHandler));
this._toUnhook.add(this._editor.onDidChangeModel(hideWidgetsEventHandler));
this._toUnhook.add(this._editor.onDidScrollChange((e: IScrollEvent) => this._onEditorScrollChanged(e)));
}
private _unhookEvents(): void {
this._toUnhook = dispose(this._toUnhook);
this._toUnhook.clear();
}
private _onModelDecorationsChanged(): void {
@@ -213,7 +205,7 @@ export class ModesHoverController implements IEditorContribution {
}
private _createHoverWidget() {
this._contentWidget = new ModesContentHoverWidget(this._editor, this._markerDecorationsService, this._themeService, this._keybindingService, this._contextMenuService, this._bulkEditService, this._commandService, this._modeService, this._openerService);
this._contentWidget = new ModesContentHoverWidget(this._editor, this._markerDecorationsService, this._themeService, this._keybindingService, this._modeService, this._openerService);
this._glyphWidget = new ModesGlyphHoverWidget(this._editor, this._modeService, this._openerService);
}
@@ -227,6 +219,7 @@ export class ModesHoverController implements IEditorContribution {
public dispose(): void {
this._unhookEvents();
this._toUnhook.dispose();
this._didChangeConfigurationHandler.dispose();
if (this._glyphWidget) {

View File

@@ -8,7 +8,6 @@ import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { DomScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement';
import { Widget } from 'vs/base/browser/ui/widget';
import { KeyCode } from 'vs/base/common/keyCodes';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import * as editorBrowser from 'vs/editor/browser/editorBrowser';
import { IConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions';
import { Position } from 'vs/editor/common/core/position';
@@ -25,7 +24,6 @@ export class ContentHoverWidget extends Widget implements editorBrowser.IContent
protected _showAtRange: Range | null;
private _stoleFocus: boolean;
private readonly scrollbar: DomScrollableElement;
private disposables: IDisposable[] = [];
// Editor.IContentWidget.allowEditorOverflow
public allowEditorOverflow = true;
@@ -53,7 +51,7 @@ export class ContentHoverWidget extends Widget implements editorBrowser.IContent
this._domNode.className = 'monaco-editor-hover-content';
this.scrollbar = new DomScrollableElement(this._domNode, {});
this.disposables.push(this.scrollbar);
this._register(this.scrollbar);
this._containerDomNode.appendChild(this.scrollbar.getDomNode());
this.onkeydown(this._containerDomNode, (e: IKeyboardEvent) => {
@@ -129,7 +127,6 @@ export class ContentHoverWidget extends Widget implements editorBrowser.IContent
public dispose(): void {
this._editor.removeContentWidget(this);
this.disposables = dispose(this.disposables);
super.dispose();
}

View File

@@ -8,7 +8,7 @@ import * as dom from 'vs/base/browser/dom';
import { CancellationToken } from 'vs/base/common/cancellation';
import { Color, RGBA } from 'vs/base/common/color';
import { IMarkdownString, MarkdownString, isEmptyMarkdownString, markedStringsEquals } from 'vs/base/common/htmlContent';
import { Disposable, IDisposable, combinedDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { IDisposable, toDisposable, DisposableStore, combinedDisposable, MutableDisposable } from 'vs/base/common/lifecycle';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { Position } from 'vs/editor/common/core/position';
import { IRange, Range } from 'vs/editor/common/core/range';
@@ -31,13 +31,9 @@ import { onUnexpectedError } from 'vs/base/common/errors';
import { IOpenerService, NullOpenerService } from 'vs/platform/opener/common/opener';
import { MarkerController, NextMarkerAction } from 'vs/editor/contrib/gotoError/gotoError';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IBulkEditService } from 'vs/editor/browser/services/bulkEditService';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { CancelablePromise, createCancelablePromise } from 'vs/base/common/async';
import { getCodeActions } from 'vs/editor/contrib/codeAction/codeAction';
import { applyCodeAction, QuickFixAction } from 'vs/editor/contrib/codeAction/codeActionCommands';
import { Action } from 'vs/base/common/actions';
import { getCodeActions, CodeActionSet } from 'vs/editor/contrib/codeAction/codeAction';
import { QuickFixAction, QuickFixController } from 'vs/editor/contrib/codeAction/codeActionCommands';
import { CodeActionKind } from 'vs/editor/contrib/codeAction/codeActionTrigger';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IIdentifiedSingleEditOperation } from 'vs/editor/common/model';
@@ -200,16 +196,13 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
private _shouldFocus: boolean;
private _colorPicker: ColorPickerWidget | null;
private renderDisposable: IDisposable = Disposable.None;
private readonly renderDisposable = this._register(new MutableDisposable<IDisposable>());
constructor(
editor: ICodeEditor,
markerDecorationsService: IMarkerDecorationsService,
private readonly _themeService: IThemeService,
private readonly _keybindingService: IKeybindingService,
private readonly _contextMenuService: IContextMenuService,
private readonly _bulkEditService: IBulkEditService,
private readonly _commandService: ICommandService,
private readonly _modeService: IModeService,
private readonly _openerService: IOpenerService | null = NullOpenerService,
) {
@@ -243,8 +236,6 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
}
dispose(): void {
this.renderDisposable.dispose();
this.renderDisposable = Disposable.None;
this._hoverOperation.cancel();
super.dispose();
}
@@ -312,8 +303,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
this._isChangingDecorations = true;
this._highlightDecorations = this._editor.deltaDecorations(this._highlightDecorations, []);
this._isChangingDecorations = false;
this.renderDisposable.dispose();
this.renderDisposable = Disposable.None;
this.renderDisposable.clear();
this._colorPicker = null;
}
@@ -345,7 +335,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
let isEmptyHoverContent = true;
let containColorPicker = false;
let markdownDisposeables: IDisposable[] = [];
const markdownDisposeables = new DisposableStore();
const markerMessages: MarkerHover[] = [];
messages.forEach((msg) => {
if (!msg.range) {
@@ -436,7 +426,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
this.updateContents(fragment);
this._colorPicker.layout();
this.renderDisposable = combinedDisposable([colorListener, colorChangeListener, widget, ...markdownDisposeables]);
this.renderDisposable.value = combinedDisposable(colorListener, colorChangeListener, widget, markdownDisposeables);
});
} else {
if (msg instanceof MarkerHover) {
@@ -448,15 +438,14 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
.forEach(contents => {
const markdownHoverElement = $('div.hover-row.markdown-hover');
const hoverContentsElement = dom.append(markdownHoverElement, $('div.hover-contents'));
const renderer = new MarkdownRenderer(this._editor, this._modeService, this._openerService);
markdownDisposeables.push(renderer.onDidRenderCodeBlock(() => {
const renderer = markdownDisposeables.add(new MarkdownRenderer(this._editor, this._modeService, this._openerService));
markdownDisposeables.add(renderer.onDidRenderCodeBlock(() => {
hoverContentsElement.className = 'hover-contents code-hover-contents';
this.onContentsChange();
}));
const renderedContents = renderer.render(contents);
const renderedContents = markdownDisposeables.add(renderer.render(contents));
hoverContentsElement.appendChild(renderedContents.element);
fragment.appendChild(markdownHoverElement);
markdownDisposeables.push(renderedContents);
isEmptyHoverContent = false;
});
}
@@ -526,24 +515,10 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
private renderMarkerStatusbar(markerHover: MarkerHover): HTMLElement {
const hoverElement = $('div.hover-row.status-bar');
const disposables: IDisposable[] = [];
const disposables = new DisposableStore();
const actionsElement = dom.append(hoverElement, $('div.actions'));
disposables.push(this.renderAction(actionsElement, {
label: nls.localize('quick fixes', "Quick Fix..."),
commandId: QuickFixAction.Id,
run: async (target) => {
const codeActionsPromise = this.getCodeActions(markerHover.marker);
disposables.push(toDisposable(() => codeActionsPromise.cancel()));
const actions = await codeActionsPromise;
const elementPosition = dom.getDomNodePagePosition(target);
this._contextMenuService.showContextMenu({
getAnchor: () => ({ x: elementPosition.left + 6, y: elementPosition.top + elementPosition.height + 6 }),
getActions: () => actions
});
}
}));
if (markerHover.marker.severity === MarkerSeverity.Error || markerHover.marker.severity === MarkerSeverity.Warning || markerHover.marker.severity === MarkerSeverity.Info) {
disposables.push(this.renderAction(actionsElement, {
disposables.add(this.renderAction(actionsElement, {
label: nls.localize('peek problem', "Peek Problem"),
commandId: NextMarkerAction.ID,
run: () => {
@@ -553,24 +528,61 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
}
}));
}
this.renderDisposable = combinedDisposable(disposables);
const quickfixPlaceholderElement = dom.append(actionsElement, $('div'));
quickfixPlaceholderElement.style.opacity = '0';
quickfixPlaceholderElement.style.transition = 'opacity 0.2s';
setTimeout(() => quickfixPlaceholderElement.style.opacity = '1', 200);
quickfixPlaceholderElement.textContent = nls.localize('checkingForQuickFixes', "Checking for quick fixes...");
disposables.add(toDisposable(() => quickfixPlaceholderElement.remove()));
const codeActionsPromise = this.getCodeActions(markerHover.marker);
disposables.add(toDisposable(() => codeActionsPromise.cancel()));
codeActionsPromise.then(actions => {
quickfixPlaceholderElement.style.transition = '';
quickfixPlaceholderElement.style.opacity = '1';
if (!actions.actions.length) {
actions.dispose();
quickfixPlaceholderElement.textContent = nls.localize('noQuickFixes', "No quick fixes available");
return;
}
quickfixPlaceholderElement.remove();
let showing = false;
disposables.add(toDisposable(() => {
if (!showing) {
actions.dispose();
}
}));
disposables.add(this.renderAction(actionsElement, {
label: nls.localize('quick fixes', "Quick Fix..."),
commandId: QuickFixAction.Id,
run: (target) => {
showing = true;
const controller = QuickFixController.get(this._editor);
const elementPosition = dom.getDomNodePagePosition(target);
controller.showCodeActions(actions, {
x: elementPosition.left + 6,
y: elementPosition.top + elementPosition.height + 6
});
}
}));
});
this.renderDisposable.value = disposables;
return hoverElement;
}
private getCodeActions(marker: IMarker): CancelablePromise<Action[]> {
return createCancelablePromise(async cancellationToken => {
const codeActions = await getCodeActions(this._editor.getModel()!, new Range(marker.startLineNumber, marker.startColumn, marker.endLineNumber, marker.endColumn), { type: 'manual', filter: { kind: CodeActionKind.QuickFix } }, cancellationToken);
if (codeActions.actions.length) {
return codeActions.actions.map(codeAction => new Action(
codeAction.command ? codeAction.command.id : codeAction.title,
codeAction.title,
undefined,
true,
() => applyCodeAction(codeAction, this._bulkEditService, this._commandService)));
}
return [
new Action('', nls.localize('editor.action.quickFix.noneMessage', "No code actions available"))
];
private getCodeActions(marker: IMarker): CancelablePromise<CodeActionSet> {
return createCancelablePromise(cancellationToken => {
return getCodeActions(
this._editor.getModel()!,
new Range(marker.startLineNumber, marker.startColumn, marker.endLineNumber, marker.endColumn),
{ type: 'manual', filter: { kind: CodeActionKind.QuickFix } },
cancellationToken);
});
}

View File

@@ -5,7 +5,7 @@
import { $ } from 'vs/base/browser/dom';
import { IMarkdownString, isEmptyMarkdownString } from 'vs/base/common/htmlContent';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { HoverOperation, HoverStartMode, IHoverComputer } from 'vs/editor/contrib/hover/hoverOperation';
import { GlyphHoverWidget } from 'vs/editor/contrib/hover/hoverWidgets';
@@ -91,7 +91,7 @@ export class ModesGlyphHoverWidget extends GlyphHoverWidget {
private readonly _markdownRenderer: MarkdownRenderer;
private readonly _computer: MarginComputer;
private readonly _hoverOperation: HoverOperation<IHoverMessage[]>;
private _renderDisposeables: IDisposable[];
private readonly _renderDisposeables = this._register(new DisposableStore());
constructor(
editor: ICodeEditor,
@@ -102,7 +102,7 @@ export class ModesGlyphHoverWidget extends GlyphHoverWidget {
this._lastLineNumber = -1;
this._markdownRenderer = new MarkdownRenderer(this._editor, modeService, openerService);
this._markdownRenderer = this._register(new MarkdownRenderer(this._editor, modeService, openerService));
this._computer = new MarginComputer(this._editor);
this._hoverOperation = new HoverOperation(
@@ -116,7 +116,6 @@ export class ModesGlyphHoverWidget extends GlyphHoverWidget {
}
public dispose(): void {
this._renderDisposeables = dispose(this._renderDisposeables);
this._hoverOperation.cancel();
super.dispose();
}
@@ -163,16 +162,15 @@ export class ModesGlyphHoverWidget extends GlyphHoverWidget {
}
private _renderMessages(lineNumber: number, messages: IHoverMessage[]): void {
dispose(this._renderDisposeables);
this._renderDisposeables = [];
this._renderDisposeables.clear();
const fragment = document.createDocumentFragment();
messages.forEach((msg) => {
for (const msg of messages) {
const renderedContents = this._markdownRenderer.render(msg.value);
this._renderDisposeables.push(renderedContents);
this._renderDisposeables.add(renderedContents);
fragment.appendChild($('div.hover-row', undefined, renderedContents.element));
});
}
this.updateContents(fragment);
this.showAt(lineNumber);