提交 b275fc78 编写于 作者: J Joao Moreno

introduce IColorDecorationExtraOptions

clean up monaco.d.ts
上级 7efa9545
...@@ -25,7 +25,6 @@ import * as editorOptions from 'vs/editor/common/config/editorOptions'; ...@@ -25,7 +25,6 @@ import * as editorOptions from 'vs/editor/common/config/editorOptions';
import { ICursorPositionChangedEvent, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents'; import { ICursorPositionChangedEvent, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
import { ICursors, CursorConfiguration } from 'vs/editor/common/controller/cursorCommon'; import { ICursors, CursorConfiguration } from 'vs/editor/common/controller/cursorCommon';
import { ThemeColor } from 'vs/platform/theme/common/themeService'; import { ThemeColor } from 'vs/platform/theme/common/themeService';
import { Color } from 'vs/base/common/color';
/** /**
* Vertical Lane in the overview ruler of the editor. * Vertical Lane in the overview ruler of the editor.
...@@ -62,12 +61,6 @@ export interface IModelDecorationOverviewRulerOptions { ...@@ -62,12 +61,6 @@ export interface IModelDecorationOverviewRulerOptions {
position: OverviewRulerLane; position: OverviewRulerLane;
} }
export type IColorFormat = string | { opaque: string, transparent: string };
export interface IColorInfo {
color: Color;
format: IColorFormat;
availableFormats: IColorFormat[];
}
/** /**
* Options for a model decoration. * Options for a model decoration.
*/ */
...@@ -89,10 +82,6 @@ export interface IModelDecorationOptions { ...@@ -89,10 +82,6 @@ export interface IModelDecorationOptions {
* Array of MarkedString to render as the decoration message. * Array of MarkedString to render as the decoration message.
*/ */
hoverMessage?: MarkedString | MarkedString[]; hoverMessage?: MarkedString | MarkedString[];
/**
* Color with mode to render in the color picker.
*/
colorInfo?: IColorInfo;
/** /**
* Should the decoration expand to encompass a whole line. * Should the decoration expand to encompass a whole line.
*/ */
......
...@@ -879,15 +879,23 @@ export class ModelDecorationOverviewRulerOptions implements editorCommon.IModelD ...@@ -879,15 +879,23 @@ export class ModelDecorationOverviewRulerOptions implements editorCommon.IModelD
let lastStaticId = 0; let lastStaticId = 0;
// TODO@Joao
// This was introduced to solve the color problem.
// We don't want to expose colors in decorations, although
// we piggyback on decorations to implement colors in the model.
export interface IModelDecorationExtraOptions {
__extraOptions?: any;
}
export class ModelDecorationOptions implements editorCommon.IModelDecorationOptions { export class ModelDecorationOptions implements editorCommon.IModelDecorationOptions {
public static EMPTY: ModelDecorationOptions; public static EMPTY: ModelDecorationOptions;
public static register(options: editorCommon.IModelDecorationOptions): ModelDecorationOptions { public static register(options: editorCommon.IModelDecorationOptions & IModelDecorationExtraOptions): ModelDecorationOptions {
return new ModelDecorationOptions(++lastStaticId, options); return new ModelDecorationOptions(++lastStaticId, options);
} }
public static createDynamic(options: editorCommon.IModelDecorationOptions): ModelDecorationOptions { public static createDynamic(options: editorCommon.IModelDecorationOptions & IModelDecorationExtraOptions): ModelDecorationOptions {
return new ModelDecorationOptions(0, options); return new ModelDecorationOptions(0, options);
} }
...@@ -895,7 +903,6 @@ export class ModelDecorationOptions implements editorCommon.IModelDecorationOpti ...@@ -895,7 +903,6 @@ export class ModelDecorationOptions implements editorCommon.IModelDecorationOpti
readonly stickiness: editorCommon.TrackedRangeStickiness; readonly stickiness: editorCommon.TrackedRangeStickiness;
readonly className: string; readonly className: string;
readonly hoverMessage: MarkedString | MarkedString[]; readonly hoverMessage: MarkedString | MarkedString[];
readonly colorInfo: editorCommon.IColorInfo;
readonly glyphMarginHoverMessage: MarkedString | MarkedString[]; readonly glyphMarginHoverMessage: MarkedString | MarkedString[];
readonly isWholeLine: boolean; readonly isWholeLine: boolean;
readonly showIfCollapsed: boolean; readonly showIfCollapsed: boolean;
...@@ -906,13 +913,13 @@ export class ModelDecorationOptions implements editorCommon.IModelDecorationOpti ...@@ -906,13 +913,13 @@ export class ModelDecorationOptions implements editorCommon.IModelDecorationOpti
readonly inlineClassName: string; readonly inlineClassName: string;
readonly beforeContentClassName: string; readonly beforeContentClassName: string;
readonly afterContentClassName: string; readonly afterContentClassName: string;
readonly extraOptions: any;
private constructor(staticId: number, options: editorCommon.IModelDecorationOptions) { private constructor(staticId: number, options: editorCommon.IModelDecorationOptions & IModelDecorationExtraOptions) {
this.staticId = staticId; this.staticId = staticId;
this.stickiness = options.stickiness || editorCommon.TrackedRangeStickiness.AlwaysGrowsWhenTypingAtEdges; this.stickiness = options.stickiness || editorCommon.TrackedRangeStickiness.AlwaysGrowsWhenTypingAtEdges;
this.className = options.className ? cleanClassName(options.className) : strings.empty; this.className = options.className ? cleanClassName(options.className) : strings.empty;
this.hoverMessage = options.hoverMessage || []; this.hoverMessage = options.hoverMessage || [];
this.colorInfo = options.colorInfo || undefined;
this.glyphMarginHoverMessage = options.glyphMarginHoverMessage || strings.empty; this.glyphMarginHoverMessage = options.glyphMarginHoverMessage || strings.empty;
this.isWholeLine = options.isWholeLine || false; this.isWholeLine = options.isWholeLine || false;
this.showIfCollapsed = options.showIfCollapsed || false; this.showIfCollapsed = options.showIfCollapsed || false;
...@@ -923,6 +930,10 @@ export class ModelDecorationOptions implements editorCommon.IModelDecorationOpti ...@@ -923,6 +930,10 @@ export class ModelDecorationOptions implements editorCommon.IModelDecorationOpti
this.inlineClassName = options.inlineClassName ? cleanClassName(options.inlineClassName) : strings.empty; this.inlineClassName = options.inlineClassName ? cleanClassName(options.inlineClassName) : strings.empty;
this.beforeContentClassName = options.beforeContentClassName ? cleanClassName(options.beforeContentClassName) : strings.empty; this.beforeContentClassName = options.beforeContentClassName ? cleanClassName(options.beforeContentClassName) : strings.empty;
this.afterContentClassName = options.afterContentClassName ? cleanClassName(options.afterContentClassName) : strings.empty; this.afterContentClassName = options.afterContentClassName ? cleanClassName(options.afterContentClassName) : strings.empty;
if (options.__extraOptions) {
this.extraOptions = options.__extraOptions;
}
} }
public equals(other: ModelDecorationOptions): boolean { public equals(other: ModelDecorationOptions): boolean {
...@@ -944,6 +955,7 @@ export class ModelDecorationOptions implements editorCommon.IModelDecorationOpti ...@@ -944,6 +955,7 @@ export class ModelDecorationOptions implements editorCommon.IModelDecorationOpti
&& markedStringsEquals(this.hoverMessage, other.hoverMessage) && markedStringsEquals(this.hoverMessage, other.hoverMessage)
&& markedStringsEquals(this.glyphMarginHoverMessage, other.glyphMarginHoverMessage) && markedStringsEquals(this.glyphMarginHoverMessage, other.glyphMarginHoverMessage)
&& this.overviewRuler.equals(other.overviewRuler) && this.overviewRuler.equals(other.overviewRuler)
&& this.extraOptions === other.extraOptions
); );
} }
} }
......
...@@ -156,7 +156,7 @@ export interface IState { ...@@ -156,7 +156,7 @@ export interface IState {
* A hover represents additional information for a symbol or word. Hovers are * A hover represents additional information for a symbol or word. Hovers are
* rendered in a tooltip-like widget. * rendered in a tooltip-like widget.
*/ */
export interface MarkedStringHover { export interface Hover {
/** /**
* The contents of this hover. * The contents of this hover.
*/ */
...@@ -170,21 +170,6 @@ export interface MarkedStringHover { ...@@ -170,21 +170,6 @@ export interface MarkedStringHover {
range: IRange; range: IRange;
} }
// TODO@michel documentation
export interface ColorHover {
color: Color;
format: IColorFormat;
availableFormats: IColorFormat[];
/**
* The range to which this hover applies. When missing, the
* editor will use the range at the current position or the
* current position itself.
*/
range: IRange;
}
export type Hover = MarkedStringHover | ColorHover;
/** /**
* The hover provider interface defines the contract between extensions and * The hover provider interface defines the contract between extensions and
* the [hover](https://code.visualstudio.com/docs/editor/intellisense)-feature. * the [hover](https://code.visualstudio.com/docs/editor/intellisense)-feature.
......
...@@ -3,16 +3,17 @@ ...@@ -3,16 +3,17 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { ICommonCodeEditor, IEditorContribution, IModelDecorationsChangeAccessor, IModelDeltaDecoration } from "vs/editor/common/editorCommon"; import { ICommonCodeEditor, IEditorContribution, IModelDecorationsChangeAccessor, IModelDeltaDecoration } from 'vs/editor/common/editorCommon';
import { editorContribution } from "vs/editor/browser/editorBrowserExtensions"; import { editorContribution } from 'vs/editor/browser/editorBrowserExtensions';
import { ICodeEditor } from "vs/editor/browser/editorBrowser"; import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { IDisposable, dispose } from "vs/base/common/lifecycle"; import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { registerThemingParticipant } from "vs/platform/theme/common/themeService"; import { registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { editorWidgetBackground, editorWidgetBorder } from "vs/platform/theme/common/colorRegistry"; import { editorWidgetBackground, editorWidgetBorder } from 'vs/platform/theme/common/colorRegistry';
import { ColorProviderRegistry, IColorInfo } from "vs/editor/common/modes"; import { ColorProviderRegistry, IColorInfo } from 'vs/editor/common/modes';
import { TPromise } from "vs/base/common/winjs.base"; import { TPromise } from 'vs/base/common/winjs.base';
import { getColors } from "vs/editor/contrib/colorPicker/common/colorPicker"; import { getColors } from 'vs/editor/contrib/colorPicker/common/colorPicker';
import { IRange } from "vs/editor/common/core/range"; import { IRange } from 'vs/editor/common/core/range';
import { IColorDecorationExtraOptions } from '../common/color';
@editorContribution @editorContribution
export class ColorPicker implements IEditorContribution { export class ColorPicker implements IEditorContribution {
...@@ -111,18 +112,16 @@ export class ColorPicker implements IEditorContribution { ...@@ -111,18 +112,16 @@ export class ColorPicker implements IEditorContribution {
endColumn: c.range.endColumn endColumn: c.range.endColumn
}; };
const decoration = { const extraOptions: IColorDecorationExtraOptions = {
range: range, color: c.color,
options: { format: c.format,
colorInfo: { availableFormats: c.availableFormats
color: c.color,
format: c.format,
availableFormats: c.availableFormats
}
}
}; };
newDecorations.push(decoration); // TODO@Joao
const options = { __extraOptions: extraOptions } as any;
newDecorations.push({ range, options });
} }
this.currentDecorations = changeAccessor.deltaDecorations(this.currentDecorations, newDecorations); this.currentDecorations = changeAccessor.deltaDecorations(this.currentDecorations, newDecorations);
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IColorFormat } from 'vs/editor/common/modes';
import { Color } from 'vs/base/common/color';
export interface IColorDecorationExtraOptions {
readonly color: Color;
readonly format: IColorFormat;
readonly availableFormats: IColorFormat[];
}
export function isColorDecorationOptions(options: any): options is IColorDecorationExtraOptions {
return !!(options && (options as any).color);
}
\ No newline at end of file
...@@ -12,25 +12,38 @@ import { TPromise } from 'vs/base/common/winjs.base'; ...@@ -12,25 +12,38 @@ import { TPromise } from 'vs/base/common/winjs.base';
import { renderMarkedString } from 'vs/base/browser/htmlContentRenderer'; import { renderMarkedString } from 'vs/base/browser/htmlContentRenderer';
import { IOpenerService, NullOpenerService } from 'vs/platform/opener/common/opener'; import { IOpenerService, NullOpenerService } from 'vs/platform/opener/common/opener';
import { IModeService } from 'vs/editor/common/services/modeService'; import { IModeService } from 'vs/editor/common/services/modeService';
import { Range } from 'vs/editor/common/core/range'; import { IRange, Range } from 'vs/editor/common/core/range';
import { Position } from 'vs/editor/common/core/position'; import { Position } from 'vs/editor/common/core/position';
import { HoverProviderRegistry, Hover } from 'vs/editor/common/modes'; import { HoverProviderRegistry, Hover, IColorFormat } from 'vs/editor/common/modes';
import { tokenizeToString } from 'vs/editor/common/modes/textToHtmlTokenizer'; import { tokenizeToString } from 'vs/editor/common/modes/textToHtmlTokenizer';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { getHover, isColorHover } from '../common/hover'; import { getHover } from '../common/hover';
import { HoverOperation, IHoverComputer } from './hoverOperation'; import { HoverOperation, IHoverComputer } from './hoverOperation';
import { ContentHoverWidget } from './hoverWidgets'; import { ContentHoverWidget } from './hoverWidgets';
import { textToMarkedString, MarkedString } from 'vs/base/common/htmlContent'; import { textToMarkedString, MarkedString } from 'vs/base/common/htmlContent';
import { ModelDecorationOptions } from 'vs/editor/common/model/textModelWithDecorations'; import { ModelDecorationOptions } from 'vs/editor/common/model/textModelWithDecorations';
import { ColorPickerModel } from "vs/editor/contrib/colorPicker/browser/colorPickerModel"; import { ColorPickerModel } from "vs/editor/contrib/colorPicker/browser/colorPickerModel";
import { ColorPickerWidget } from "vs/editor/contrib/colorPicker/browser/colorPickerWidget"; import { ColorPickerWidget } from "vs/editor/contrib/colorPicker/browser/colorPickerWidget";
import { IColorInfo } from 'vs/editor/common/editorCommon'; import { isColorDecorationOptions } from 'vs/editor/contrib/colorPicker/common/color';
import { ColorFormatter } from "vs/editor/contrib/colorPicker/common/colorFormatter"; import { ColorFormatter } from 'vs/editor/contrib/colorPicker/common/colorFormatter';
import { Color } from 'vs/base/common/color';
class ColorHover {
constructor(
public readonly range: IRange,
public readonly color: Color,
public readonly format: IColorFormat,
public readonly availableFormats: IColorFormat[]
) { }
}
type HoverPart = Hover | ColorHover;
class ModesContentComputer implements IHoverComputer<Hover[]> { class ModesContentComputer implements IHoverComputer<HoverPart[]> {
private _editor: ICodeEditor; private _editor: ICodeEditor;
private _result: Hover[]; private _result: HoverPart[];
private _range: Range; private _range: Range;
constructor(editor: ICodeEditor) { constructor(editor: ICodeEditor) {
...@@ -47,7 +60,7 @@ class ModesContentComputer implements IHoverComputer<Hover[]> { ...@@ -47,7 +60,7 @@ class ModesContentComputer implements IHoverComputer<Hover[]> {
this._result = []; this._result = [];
} }
computeAsync(): TPromise<Hover[]> { computeAsync(): TPromise<HoverPart[]> {
const model = this._editor.getModel(); const model = this._editor.getModel();
if (!HoverProviderRegistry.has(model)) { if (!HoverProviderRegistry.has(model)) {
...@@ -60,7 +73,7 @@ class ModesContentComputer implements IHoverComputer<Hover[]> { ...@@ -60,7 +73,7 @@ class ModesContentComputer implements IHoverComputer<Hover[]> {
)); ));
} }
computeSync(): Hover[] { computeSync(): HoverPart[] {
const lineNumber = this._range.startLineNumber; const lineNumber = this._range.startLineNumber;
if (lineNumber > this._editor.getModel().getLineCount()) { if (lineNumber > this._editor.getModel().getLineCount()) {
...@@ -68,7 +81,7 @@ class ModesContentComputer implements IHoverComputer<Hover[]> { ...@@ -68,7 +81,7 @@ class ModesContentComputer implements IHoverComputer<Hover[]> {
return []; return [];
} }
const hasHoverContent = (contents: MarkedString | MarkedString[] | IColorInfo) => { const hasHoverContent = (contents: MarkedString | MarkedString[]) => {
return contents && (!Array.isArray(contents) || (<MarkedString[]>contents).length > 0); return contents && (!Array.isArray(contents) || (<MarkedString[]>contents).length > 0);
}; };
...@@ -79,45 +92,49 @@ class ModesContentComputer implements IHoverComputer<Hover[]> { ...@@ -79,45 +92,49 @@ class ModesContentComputer implements IHoverComputer<Hover[]> {
const startColumn = (d.range.startLineNumber === lineNumber) ? d.range.startColumn : 1; const startColumn = (d.range.startLineNumber === lineNumber) ? d.range.startColumn : 1;
const endColumn = (d.range.endLineNumber === lineNumber) ? d.range.endColumn : maxColumn; const endColumn = (d.range.endLineNumber === lineNumber) ? d.range.endColumn : maxColumn;
if (startColumn > this._range.startColumn || this._range.endColumn > endColumn || (!hasHoverContent(d.options.hoverMessage) && !hasHoverContent(d.options.colorInfo))) { if (startColumn > this._range.startColumn || this._range.endColumn > endColumn) {
return null; return null;
} }
const range = new Range(this._range.startLineNumber, startColumn, this._range.startLineNumber, endColumn); const range = new Range(this._range.startLineNumber, startColumn, this._range.startLineNumber, endColumn);
let contents: MarkedString[];
if (d.options.hoverMessage) { // TOOD@Joao
if (Array.isArray(d.options.hoverMessage)) { const options = d.options as any;
contents = [...d.options.hoverMessage]; const extraOptions = options && options.extraOptions;
} else {
contents = [d.options.hoverMessage]; if (isColorDecorationOptions(extraOptions)) {
console.log('found color!');
const { color, format, availableFormats } = extraOptions;
return new ColorHover(range, color, format, availableFormats);
} else {
if (!hasHoverContent(d.options.hoverMessage)) {
return null;
} }
}
const colorInfo = d.options.colorInfo; let contents: MarkedString[];
if (colorInfo) { if (d.options.hoverMessage) {
return { if (Array.isArray(d.options.hoverMessage)) {
color: colorInfo.color, contents = [...d.options.hoverMessage];
format: colorInfo.format, } else {
availableFormats: colorInfo.availableFormats, contents = [d.options.hoverMessage];
range: range, }
}; }
}
return { contents, range }; return { contents, range };
}
}); });
return result.filter(d => !!d); return result.filter(d => !!d);
} }
onResult(result: Hover[], isFromSynchronousComputation: boolean): void { onResult(result: HoverPart[], isFromSynchronousComputation: boolean): void {
// Always put synchronous messages before asynchronous ones // Always put synchronous messages before asynchronous ones
if (isFromSynchronousComputation) { if (isFromSynchronousComputation) {
this._result = result.concat(this._result.sort((a, b) => { this._result = result.concat(this._result.sort((a, b) => {
if (isColorHover(a)) { // sort picker messages at to the top if (a instanceof ColorHover) { // sort picker messages at to the top
return -1; return -1;
} else if (isColorHover(b)) { } else if (b instanceof ColorHover) {
return 1; return 1;
} }
return 0; return 0;
...@@ -127,15 +144,15 @@ class ModesContentComputer implements IHoverComputer<Hover[]> { ...@@ -127,15 +144,15 @@ class ModesContentComputer implements IHoverComputer<Hover[]> {
} }
} }
getResult(): Hover[] { getResult(): HoverPart[] {
return this._result.slice(0); return this._result.slice(0);
} }
getResultWithLoadingMessage(): Hover[] { getResultWithLoadingMessage(): HoverPart[] {
return this._result.slice(0).concat([this._getLoadingMessage()]); return this._result.slice(0).concat([this._getLoadingMessage()]);
} }
private _getLoadingMessage(): Hover { private _getLoadingMessage(): HoverPart {
return { return {
range: this._range, range: this._range,
contents: [textToMarkedString(nls.localize('modesContentHover.loading', "Loading..."))] contents: [textToMarkedString(nls.localize('modesContentHover.loading', "Loading..."))]
...@@ -147,10 +164,10 @@ export class ModesContentHoverWidget extends ContentHoverWidget { ...@@ -147,10 +164,10 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
static ID = 'editor.contrib.modesContentHoverWidget'; static ID = 'editor.contrib.modesContentHoverWidget';
private _messages: Hover[]; private _messages: HoverPart[];
private _lastRange: Range; private _lastRange: Range;
private _computer: ModesContentComputer; private _computer: ModesContentComputer;
private _hoverOperation: HoverOperation<Hover[]>; private _hoverOperation: HoverOperation<HoverPart[]>;
private _highlightDecorations: string[]; private _highlightDecorations: string[];
private _isChangingDecorations: boolean; private _isChangingDecorations: boolean;
private _openerService: IOpenerService; private _openerService: IOpenerService;
...@@ -169,9 +186,9 @@ export class ModesContentHoverWidget extends ContentHoverWidget { ...@@ -169,9 +186,9 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
this._hoverOperation = new HoverOperation( this._hoverOperation = new HoverOperation(
this._computer, this._computer,
(result: Hover[]) => this._withResult(result, true), result => this._withResult(result, true),
null, null,
(result: any) => this._withResult(result, false) result => this._withResult(result, false)
); );
} }
...@@ -209,7 +226,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget { ...@@ -209,7 +226,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
if (this._showAtPosition.lineNumber !== range.startLineNumber) { if (this._showAtPosition.lineNumber !== range.startLineNumber) {
this.hide(); this.hide();
} else { } else {
var filteredMessages: Hover[] = []; var filteredMessages: HoverPart[] = [];
for (var i = 0, len = this._messages.length; i < len; i++) { for (var i = 0, len = this._messages.length; i < len; i++) {
var msg = this._messages[i]; var msg = this._messages[i];
var rng = msg.range; var rng = msg.range;
...@@ -244,7 +261,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget { ...@@ -244,7 +261,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
} }
} }
_withResult(result: Hover[], complete: boolean): void { private _withResult(result: HoverPart[], complete: boolean): void {
this._messages = result; this._messages = result;
if (this._lastRange && this._messages.length > 0) { if (this._lastRange && this._messages.length > 0) {
...@@ -254,7 +271,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget { ...@@ -254,7 +271,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
} }
} }
private _renderMessages(renderRange: Range, messages: Hover[]): void { private _renderMessages(renderRange: Range, messages: HoverPart[]): void {
// update column from which to show // update column from which to show
var renderColumn = Number.MAX_VALUE, var renderColumn = Number.MAX_VALUE,
...@@ -269,7 +286,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget { ...@@ -269,7 +286,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
renderColumn = Math.min(renderColumn, msg.range.startColumn); renderColumn = Math.min(renderColumn, msg.range.startColumn);
highlightRange = Range.plusRange(highlightRange, msg.range); highlightRange = Range.plusRange(highlightRange, msg.range);
if (!isColorHover(msg)) { if (!(msg instanceof ColorHover)) {
msg.contents msg.contents
.filter(contents => !!contents) .filter(contents => !!contents)
.forEach(contents => { .forEach(contents => {
......
...@@ -10,14 +10,10 @@ import { onUnexpectedExternalError } from 'vs/base/common/errors'; ...@@ -10,14 +10,10 @@ import { onUnexpectedExternalError } from 'vs/base/common/errors';
import { TPromise } from 'vs/base/common/winjs.base'; import { TPromise } from 'vs/base/common/winjs.base';
import { IReadOnlyModel } from 'vs/editor/common/editorCommon'; import { IReadOnlyModel } from 'vs/editor/common/editorCommon';
import { CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions'; import { CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions';
import { Hover, HoverProviderRegistry, ColorHover } from 'vs/editor/common/modes'; import { Hover, HoverProviderRegistry } from 'vs/editor/common/modes';
import { asWinJsPromise } from 'vs/base/common/async'; import { asWinJsPromise } from 'vs/base/common/async';
import { Position } from 'vs/editor/common/core/position'; import { Position } from 'vs/editor/common/core/position';
export function isColorHover(hover: Hover): hover is ColorHover {
return !!(hover as any).color;
}
export function getHover(model: IReadOnlyModel, position: Position): TPromise<Hover[]> { export function getHover(model: IReadOnlyModel, position: Position): TPromise<Hover[]> {
const supports = HoverProviderRegistry.ordered(model); const supports = HoverProviderRegistry.ordered(model);
...@@ -29,7 +25,7 @@ export function getHover(model: IReadOnlyModel, position: Position): TPromise<Ho ...@@ -29,7 +25,7 @@ export function getHover(model: IReadOnlyModel, position: Position): TPromise<Ho
}).then((result) => { }).then((result) => {
if (result) { if (result) {
let hasRange = (typeof result.range !== 'undefined'); let hasRange = (typeof result.range !== 'undefined');
let hasHtmlContent = !isColorHover(result) && (typeof result.contents !== 'undefined' && result.contents && result.contents.length > 0); let hasHtmlContent = typeof result.contents !== 'undefined' && result.contents && result.contents.length > 0;
if (hasRange && hasHtmlContent) { if (hasRange && hasHtmlContent) {
values[idx] = result; values[idx] = result;
} }
......
...@@ -1121,17 +1121,6 @@ declare module monaco.editor { ...@@ -1121,17 +1121,6 @@ declare module monaco.editor {
position: OverviewRulerLane; position: OverviewRulerLane;
} }
export type IColorFormat = string | {
opaque: string;
transparent: string;
};
export interface IColorInfo {
color: Color;
format: IColorFormat;
availableFormats: IColorFormat[];
}
/** /**
* Options for a model decoration. * Options for a model decoration.
*/ */
...@@ -1153,10 +1142,6 @@ declare module monaco.editor { ...@@ -1153,10 +1142,6 @@ declare module monaco.editor {
* Array of MarkedString to render as the decoration message. * Array of MarkedString to render as the decoration message.
*/ */
hoverMessage?: MarkedString | MarkedString[]; hoverMessage?: MarkedString | MarkedString[];
/**
* Color with mode to render in the color picker.
*/
colorInfo?: IColorInfo;
/** /**
* Should the decoration expand to encompass a whole line. * Should the decoration expand to encompass a whole line.
*/ */
...@@ -4437,7 +4422,7 @@ declare module monaco.languages { ...@@ -4437,7 +4422,7 @@ declare module monaco.languages {
* A hover represents additional information for a symbol or word. Hovers are * A hover represents additional information for a symbol or word. Hovers are
* rendered in a tooltip-like widget. * rendered in a tooltip-like widget.
*/ */
export interface MarkedStringHover { export interface Hover {
/** /**
* The contents of this hover. * The contents of this hover.
*/ */
...@@ -4450,20 +4435,6 @@ declare module monaco.languages { ...@@ -4450,20 +4435,6 @@ declare module monaco.languages {
range: IRange; range: IRange;
} }
export interface ColorHover {
color: Color;
format: IColorFormat;
availableFormats: IColorFormat[];
/**
* The range to which this hover applies. When missing, the
* editor will use the range at the current position or the
* current position itself.
*/
range: IRange;
}
export type Hover = MarkedStringHover | ColorHover;
/** /**
* The hover provider interface defines the contract between extensions and * The hover provider interface defines the contract between extensions and
* the [hover](https://code.visualstudio.com/docs/editor/intellisense)-feature. * the [hover](https://code.visualstudio.com/docs/editor/intellisense)-feature.
......
...@@ -16,7 +16,7 @@ import { SaveReason } from 'vs/workbench/services/textfile/common/textfiles'; ...@@ -16,7 +16,7 @@ import { SaveReason } from 'vs/workbench/services/textfile/common/textfiles';
import { IPosition } from 'vs/editor/common/core/position'; import { IPosition } from 'vs/editor/common/core/position';
import { IRange } from 'vs/editor/common/core/range'; import { IRange } from 'vs/editor/common/core/range';
import { ISelection } from 'vs/editor/common/core/selection'; import { ISelection } from 'vs/editor/common/core/selection';
import { IColorInfo } from "vs/workbench/api/node/extHost.protocol"; import { IColorInfo } from 'vs/workbench/api/node/extHost.protocol';
export interface PositionLike { export interface PositionLike {
line: number; line: number;
...@@ -254,14 +254,14 @@ export const location = { ...@@ -254,14 +254,14 @@ export const location = {
} }
}; };
export function fromHover(hover: vscode.Hover): modes.MarkedStringHover { export function fromHover(hover: vscode.Hover): modes.Hover {
return <modes.MarkedStringHover>{ return <modes.Hover>{
range: fromRange(hover.range), range: fromRange(hover.range),
contents: hover.contents contents: hover.contents
}; };
} }
export function toHover(info: modes.MarkedStringHover): types.Hover { export function toHover(info: modes.Hover): types.Hover {
return new types.Hover(info.contents, toRange(info.range)); return new types.Hover(info.contents, toRange(info.range));
} }
......
...@@ -26,7 +26,7 @@ import { IHeapService } from 'vs/workbench/api/electron-browser/mainThreadHeapSe ...@@ -26,7 +26,7 @@ import { IHeapService } from 'vs/workbench/api/electron-browser/mainThreadHeapSe
import { ExtHostDocuments } from 'vs/workbench/api/node/extHostDocuments'; import { ExtHostDocuments } from 'vs/workbench/api/node/extHostDocuments';
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/node/extHostDocumentsAndEditors'; import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/node/extHostDocumentsAndEditors';
import { getDocumentSymbols } from 'vs/editor/contrib/quickOpen/common/quickOpen'; import { getDocumentSymbols } from 'vs/editor/contrib/quickOpen/common/quickOpen';
import { DocumentSymbolProviderRegistry, DocumentHighlightKind, MarkedStringHover } from 'vs/editor/common/modes'; import { DocumentSymbolProviderRegistry, DocumentHighlightKind, Hover } from 'vs/editor/common/modes';
import { getCodeLensData } from 'vs/editor/contrib/codelens/browser/codelens'; import { getCodeLensData } from 'vs/editor/contrib/codelens/browser/codelens';
import { getDefinitionsAtPosition, getImplementationsAtPosition, getTypeDefinitionsAtPosition } from 'vs/editor/contrib/goToDeclaration/browser/goToDeclaration'; import { getDefinitionsAtPosition, getImplementationsAtPosition, getTypeDefinitionsAtPosition } from 'vs/editor/contrib/goToDeclaration/browser/goToDeclaration';
import { getHover } from 'vs/editor/contrib/hover/common/hover'; import { getHover } from 'vs/editor/contrib/hover/common/hover';
...@@ -440,7 +440,7 @@ suite('ExtHostLanguageFeatures', function () { ...@@ -440,7 +440,7 @@ suite('ExtHostLanguageFeatures', function () {
return threadService.sync().then(() => { return threadService.sync().then(() => {
return getHover(model, new EditorPosition(1, 1)).then(value => { return getHover(model, new EditorPosition(1, 1)).then(value => {
assert.equal(value.length, 2); assert.equal(value.length, 2);
let [first, second] = value as MarkedStringHover[]; let [first, second] = value as Hover[];
assert.equal(first.contents[0], 'registered second'); assert.equal(first.contents[0], 'registered second');
assert.equal(second.contents[0], 'registered first'); assert.equal(second.contents[0], 'registered first');
}); });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册