Merge VS Code 1.31.1 (#4283)

This commit is contained in:
Matt Irvine
2019-03-15 13:09:45 -07:00
committed by GitHub
parent 7d31575149
commit 86bac90001
1716 changed files with 53308 additions and 48375 deletions

View File

@@ -36,6 +36,14 @@
margin: 8px 0;
}
.monaco-editor-hover hr {
margin-top: 4px;
margin-bottom: -6px;
margin-left: -10px;
margin-right: -10px;
height: 1px;
}
.monaco-editor-hover p:first-child,
.monaco-editor-hover ul:first-child {
margin-top: 0;

View File

@@ -8,7 +8,6 @@ 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 * as platform from 'vs/base/common/platform';
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,6 +24,7 @@ import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegis
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { editorHoverBackground, editorHoverBorder, editorHoverHighlight, textCodeBlockBackground, textLinkForeground } from 'vs/platform/theme/common/colorRegistry';
import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { IMarkerDecorationsService } from 'vs/editor/common/services/markersDecorationService';
export class ModesHoverController implements IEditorContribution {
@@ -62,6 +62,7 @@ export class ModesHoverController implements IEditorContribution {
constructor(private readonly _editor: ICodeEditor,
@IOpenerService private readonly _openerService: IOpenerService,
@IModeService private readonly _modeService: IModeService,
@IMarkerDecorationsService private readonly _markerDecorationsService: IMarkerDecorationsService,
@IThemeService private readonly _themeService: IThemeService
) {
this._toUnhook = [];
@@ -146,18 +147,17 @@ export class ModesHoverController implements IEditorContribution {
private _onEditorMouseMove(mouseEvent: IEditorMouseEvent): void {
// const this._editor.getConfiguration().contribInfo.hover.sticky;
let targetType = mouseEvent.target.type;
const hasStopKey = (platform.isMacintosh ? mouseEvent.event.metaKey : mouseEvent.event.ctrlKey);
if (this._isMouseDown && this._hoverClicked && this.contentWidget.isColorPickerVisible()) {
return;
}
if (this._isHoverSticky && targetType === MouseTargetType.CONTENT_WIDGET && mouseEvent.target.detail === ModesContentHoverWidget.ID && !hasStopKey) {
if (this._isHoverSticky && targetType === MouseTargetType.CONTENT_WIDGET && mouseEvent.target.detail === ModesContentHoverWidget.ID) {
// mouse moved on top of content hover widget
return;
}
if (this._isHoverSticky && targetType === MouseTargetType.OVERLAY_WIDGET && mouseEvent.target.detail === ModesGlyphHoverWidget.ID && !hasStopKey) {
if (this._isHoverSticky && targetType === MouseTargetType.OVERLAY_WIDGET && mouseEvent.target.detail === ModesGlyphHoverWidget.ID) {
// mouse moved on top of overlay hover widget
return;
}
@@ -174,13 +174,13 @@ export class ModesHoverController implements IEditorContribution {
if (targetType === MouseTargetType.CONTENT_TEXT) {
this.glyphWidget.hide();
if (this._isHoverEnabled) {
if (this._isHoverEnabled && mouseEvent.target.range) {
this.contentWidget.startShowingAt(mouseEvent.target.range, HoverStartMode.Delayed, false);
}
} else if (targetType === MouseTargetType.GUTTER_GLYPH_MARGIN) {
this.contentWidget.hide();
if (this._isHoverEnabled) {
if (this._isHoverEnabled && mouseEvent.target.position) {
this.glyphWidget.startShowingAt(mouseEvent.target.position.lineNumber);
}
} else {
@@ -206,7 +206,7 @@ export class ModesHoverController implements IEditorContribution {
private _createHoverWidget() {
const renderer = new MarkdownRenderer(this._editor, this._modeService, this._openerService);
this._contentWidget = new ModesContentHoverWidget(this._editor, renderer, this._themeService);
this._contentWidget = new ModesContentHoverWidget(this._editor, renderer, this._markerDecorationsService, this._themeService, this._openerService);
this._glyphWidget = new ModesGlyphHoverWidget(this._editor, renderer);
}
@@ -224,11 +224,9 @@ export class ModesHoverController implements IEditorContribution {
if (this._glyphWidget) {
this._glyphWidget.dispose();
this._glyphWidget = null;
}
if (this._contentWidget) {
this._contentWidget.dispose();
this._contentWidget = null;
}
}
}
@@ -256,6 +254,9 @@ class ShowHoverAction extends EditorAction {
}
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
if (!editor.hasModel()) {
return;
}
let controller = ModesHoverController.get(editor);
if (!controller) {
return;
@@ -283,6 +284,8 @@ registerThemingParticipant((theme, collector) => {
if (hoverBorder) {
collector.addRule(`.monaco-editor .monaco-editor-hover { border: 1px solid ${hoverBorder}; }`);
collector.addRule(`.monaco-editor .monaco-editor-hover .hover-row:not(:first-child):not(:empty) { border-top: 1px solid ${hoverBorder.transparent(0.5)}; }`);
collector.addRule(`.monaco-editor .monaco-editor-hover hr { border-top: 1px solid ${hoverBorder.transparent(0.5)}; }`);
collector.addRule(`.monaco-editor .monaco-editor-hover hr { border-bottom: 0px solid ${hoverBorder.transparent(0.5)}; }`);
}
const link = theme.getColor(textLinkForeground);
if (link) {

View File

@@ -84,7 +84,7 @@ export class ContentHoverWidget extends Widget implements editorBrowser.IContent
return this._containerDomNode;
}
public showAt(position: Position, range: Range, focus: boolean): void {
public showAt(position: Position, range: Range | null, focus: boolean): void {
// Position has changed
this._showAtPosition = position;
this._showAtRange = range;

View File

@@ -13,7 +13,7 @@ import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { Position } from 'vs/editor/common/core/position';
import { IRange, Range } from 'vs/editor/common/core/range';
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
import { DocumentColorProvider, Hover, HoverProviderRegistry, IColor } from 'vs/editor/common/modes';
import { DocumentColorProvider, Hover as MarkdownHover, HoverProviderRegistry, IColor } from 'vs/editor/common/modes';
import { getColorPresentations } from 'vs/editor/contrib/colorPicker/color';
import { ColorDetector } from 'vs/editor/contrib/colorPicker/colorDetector';
import { ColorPickerModel } from 'vs/editor/contrib/colorPicker/colorPickerModel';
@@ -23,6 +23,13 @@ import { HoverOperation, HoverStartMode, IHoverComputer } from 'vs/editor/contri
import { ContentHoverWidget } from 'vs/editor/contrib/hover/hoverWidgets';
import { MarkdownRenderer } from 'vs/editor/contrib/markdown/markdownRenderer';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { coalesce, isNonEmptyArray } from 'vs/base/common/arrays';
import { IMarker, IMarkerData } from 'vs/platform/markers/common/markers';
import { basename } from 'vs/base/common/paths';
import { IMarkerDecorationsService } from 'vs/editor/common/services/markersDecorationService';
import { onUnexpectedError } from 'vs/base/common/errors';
import { IOpenerService, NullOpenerService } from 'vs/platform/opener/common/opener';
const $ = dom.$;
class ColorHover {
@@ -34,7 +41,15 @@ class ColorHover {
) { }
}
type HoverPart = Hover | ColorHover;
class MarkerHover {
constructor(
public readonly range: IRange,
public readonly marker: IMarker,
) { }
}
type HoverPart = MarkdownHover | ColorHover | MarkerHover;
class ModesContentComputer implements IHoverComputer<HoverPart[]> {
@@ -42,7 +57,10 @@ class ModesContentComputer implements IHoverComputer<HoverPart[]> {
private _result: HoverPart[];
private _range: Range | null;
constructor(editor: ICodeEditor) {
constructor(
editor: ICodeEditor,
private _markerDecorationsService: IMarkerDecorationsService
) {
this._editor = editor;
this._range = null;
}
@@ -78,6 +96,7 @@ class ModesContentComputer implements IHoverComputer<HoverPart[]> {
return [];
}
const model = this._editor.getModel();
const lineNumber = this._range.startLineNumber;
if (lineNumber > this._editor.getModel().getLineCount()) {
@@ -86,19 +105,25 @@ class ModesContentComputer implements IHoverComputer<HoverPart[]> {
}
const colorDetector = ColorDetector.get(this._editor);
const maxColumn = this._editor.getModel().getLineMaxColumn(lineNumber);
const maxColumn = model.getLineMaxColumn(lineNumber);
const lineDecorations = this._editor.getLineDecorations(lineNumber);
let didFindColor = false;
const result = lineDecorations.map(d => {
const hoverRange = this._range;
const result = lineDecorations.map((d): HoverPart | null => {
const startColumn = (d.range.startLineNumber === lineNumber) ? d.range.startColumn : 1;
const endColumn = (d.range.endLineNumber === lineNumber) ? d.range.endColumn : maxColumn;
if (startColumn > this._range.startColumn || this._range.endColumn > endColumn) {
if (startColumn > hoverRange.startColumn || hoverRange.endColumn > endColumn) {
return null;
}
const range = new Range(this._range.startLineNumber, startColumn, this._range.startLineNumber, endColumn);
const range = new Range(hoverRange.startLineNumber, startColumn, hoverRange.startLineNumber, endColumn);
const marker = this._markerDecorationsService.getMarker(model, d);
if (marker) {
return new MarkerHover(range, marker);
}
const colorData = colorDetector.getColorData(d.range.getStartPosition());
if (!didFindColor && colorData) {
@@ -111,7 +136,7 @@ class ModesContentComputer implements IHoverComputer<HoverPart[]> {
return null;
}
let contents: IMarkdownString[];
let contents: IMarkdownString[] = [];
if (d.options.hoverMessage) {
if (Array.isArray(d.options.hoverMessage)) {
@@ -125,7 +150,7 @@ class ModesContentComputer implements IHoverComputer<HoverPart[]> {
}
});
return result.filter(d => !!d);
return coalesce(result);
}
onResult(result: HoverPart[], isFromSynchronousComputation: boolean): void {
@@ -154,7 +179,7 @@ class ModesContentComputer implements IHoverComputer<HoverPart[]> {
private _getLoadingMessage(): HoverPart {
return {
range: this._range,
range: this._range || undefined,
contents: [new MarkdownString().appendText(nls.localize('modesContentHover.loading', "Loading..."))]
};
}
@@ -179,13 +204,15 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
constructor(
editor: ICodeEditor,
markdownRenderer: MarkdownRenderer,
private readonly _themeService: IThemeService
markerDecorationsService: IMarkerDecorationsService,
private readonly _themeService: IThemeService,
private readonly _openerService: IOpenerService | null = NullOpenerService,
) {
super(ModesContentHoverWidget.ID, editor);
this._messages = [];
this._lastRange = null;
this._computer = new ModesContentComputer(this._editor);
this._computer = new ModesContentComputer(this._editor, markerDecorationsService);
this._highlightDecorations = [];
this._isChangingDecorations = false;
@@ -248,14 +275,14 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
// The range might have changed, but the hover is visible
// Instead of hiding it completely, filter out messages that are still in the new range and
// kick off a new computation
if (this._showAtPosition.lineNumber !== range.startLineNumber) {
if (!this._showAtPosition || this._showAtPosition.lineNumber !== range.startLineNumber) {
this.hide();
} else {
let filteredMessages: HoverPart[] = [];
for (let i = 0, len = this._messages.length; i < len; i++) {
const msg = this._messages[i];
const rng = msg.range;
if (rng.startColumn <= range.startColumn && rng.endColumn >= range.endColumn) {
if (rng && rng.startColumn <= range.startColumn && rng.endColumn >= range.endColumn) {
filteredMessages.push(msg);
}
}
@@ -311,7 +338,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
// update column from which to show
let renderColumn = Number.MAX_VALUE;
let highlightRange = Range.lift(messages[0].range);
let highlightRange: Range | null = messages[0].range ? Range.lift(messages[0].range) : null;
let fragment = document.createDocumentFragment();
let isEmptyHoverContent = true;
@@ -323,24 +350,19 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
}
renderColumn = Math.min(renderColumn, msg.range.startColumn);
highlightRange = Range.plusRange(highlightRange, msg.range);
highlightRange = highlightRange ? Range.plusRange(highlightRange, msg.range) : Range.lift(msg.range);
if (!(msg instanceof ColorHover)) {
msg.contents
.filter(contents => !isEmptyMarkdownString(contents))
.forEach(contents => {
const renderedContents = this._markdownRenderer.render(contents);
markdownDisposeable = renderedContents;
fragment.appendChild($('div.hover-row', null, renderedContents.element));
isEmptyHoverContent = false;
});
} else {
if (msg instanceof ColorHover) {
containColorPicker = true;
const { red, green, blue, alpha } = msg.color;
const rgba = new RGBA(red * 255, green * 255, blue * 255, alpha);
const color = new Color(rgba);
if (!this._editor.hasModel()) {
return;
}
const editorModel = this._editor.getModel();
let range = new Range(msg.range.startLineNumber, msg.range.startColumn, msg.range.endLineNumber, msg.range.endColumn);
let colorInfo = { range: msg.range, color: msg.color };
@@ -350,7 +372,11 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
const widget = new ColorPickerWidget(fragment, model, this._editor.getConfiguration().pixelRatio, this._themeService);
getColorPresentations(editorModel, colorInfo, msg.provider, CancellationToken.None).then(colorPresentations => {
model.colorPresentations = colorPresentations;
model.colorPresentations = colorPresentations || [];
if (!this._editor.hasModel()) {
// gone...
return;
}
const originalText = this._editor.getModel().getValueInRange(msg.range);
model.guessColorPresentation(color, originalText);
@@ -393,7 +419,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
alpha: color.rgba.a
}
}, msg.provider, CancellationToken.None).then((colorPresentations) => {
model.colorPresentations = colorPresentations;
model.colorPresentations = colorPresentations || [];
});
};
@@ -409,6 +435,20 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
this.renderDisposable = combinedDisposable([colorListener, colorChangeListener, widget, markdownDisposeable]);
});
} else {
if (msg instanceof MarkerHover) {
isEmptyHoverContent = false;
fragment.appendChild($('div.hover-row', undefined, this.renderMarkerHover(msg)));
} else {
msg.contents
.filter(contents => !isEmptyMarkdownString(contents))
.forEach(contents => {
const renderedContents = this._markdownRenderer.render(contents);
markdownDisposeable = renderedContents;
fragment.appendChild($('div.hover-row', undefined, renderedContents.element));
isEmptyHoverContent = false;
});
}
}
});
@@ -420,13 +460,50 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
}
this._isChangingDecorations = true;
this._highlightDecorations = this._editor.deltaDecorations(this._highlightDecorations, [{
this._highlightDecorations = this._editor.deltaDecorations(this._highlightDecorations, highlightRange ? [{
range: highlightRange,
options: ModesContentHoverWidget._DECORATION_OPTIONS
}]);
}] : []);
this._isChangingDecorations = false;
}
private renderMarkerHover(markerHover: MarkerHover): HTMLElement {
const hoverElement = $('div');
const { source, message, code, relatedInformation } = markerHover.marker;
const messageElement = dom.append(hoverElement, $('span'));
messageElement.style.whiteSpace = 'pre-wrap';
messageElement.innerText = message.trim();
this._editor.applyFontInfo(messageElement);
if (source || code) {
const detailsElement = dom.append(hoverElement, $('span'));
detailsElement.style.opacity = '0.6';
detailsElement.style.paddingLeft = '6px';
detailsElement.innerText = source && code ? `${source}(${code})` : `(${code})`;
}
if (isNonEmptyArray(relatedInformation)) {
const listElement = dom.append(hoverElement, $('ul'));
for (const { message, resource, startLineNumber, startColumn } of relatedInformation) {
const item = dom.append(listElement, $('li'));
const a = dom.append(item, $('a'));
a.innerText = `${basename(resource.path)}(${startLineNumber}, ${startColumn})`;
a.style.cursor = 'pointer';
a.onclick = e => {
e.stopPropagation();
e.preventDefault();
if (this._openerService) {
this._openerService.open(resource.with({ fragment: `${startLineNumber},${startColumn}` })).catch(onUnexpectedError);
}
};
const messageElement = dom.append<HTMLAnchorElement>(item, $('span'));
messageElement.innerText = `: ${message}`;
}
}
return hoverElement;
}
private static readonly _DECORATION_OPTIONS = ModelDecorationOptions.register({
className: 'hoverHighlight'
});
@@ -439,10 +516,13 @@ function hoverContentsEquals(first: HoverPart[], second: HoverPart[]): boolean {
for (let i = 0; i < first.length; i++) {
const firstElement = first[i];
const secondElement = second[i];
if (firstElement instanceof ColorHover) {
if (firstElement instanceof MarkerHover && secondElement instanceof MarkerHover) {
return IMarkerData.makeKey(firstElement.marker) === IMarkerData.makeKey(secondElement.marker);
}
if (firstElement instanceof ColorHover || secondElement instanceof ColorHover) {
return false;
}
if (secondElement instanceof ColorHover) {
if (firstElement instanceof MarkerHover || secondElement instanceof MarkerHover) {
return false;
}
if (!markedStringsEquals(firstElement.contents, secondElement.contents)) {

View File

@@ -43,28 +43,25 @@ class MarginComputer implements IHoverComputer<IHoverMessage[]> {
};
};
let lineDecorations = this._editor.getLineDecorations(this._lineNumber);
const lineDecorations = this._editor.getLineDecorations(this._lineNumber);
let result: IHoverMessage[] = [];
const result: IHoverMessage[] = [];
if (!lineDecorations) {
return result;
}
for (let i = 0, len = lineDecorations.length; i < len; i++) {
let d = lineDecorations[i];
for (const d of lineDecorations) {
if (!d.options.glyphMarginClassName) {
continue;
}
const hoverMessage = d.options.glyphMarginHoverMessage;
if (!hoverMessage || isEmptyMarkdownString(hoverMessage)) {
continue;
}
if (Array.isArray(hoverMessage)) {
result = result.concat(hoverMessage.map(toHoverMessage));
result.push(...hoverMessage.map(toHoverMessage));
} else {
result.push(toHoverMessage(hoverMessage));
}