提交 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';
import { ICursorPositionChangedEvent, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
import { ICursors, CursorConfiguration } from 'vs/editor/common/controller/cursorCommon';
import { ThemeColor } from 'vs/platform/theme/common/themeService';
import { Color } from 'vs/base/common/color';
/**
* Vertical Lane in the overview ruler of the editor.
......@@ -62,12 +61,6 @@ export interface IModelDecorationOverviewRulerOptions {
position: OverviewRulerLane;
}
export type IColorFormat = string | { opaque: string, transparent: string };
export interface IColorInfo {
color: Color;
format: IColorFormat;
availableFormats: IColorFormat[];
}
/**
* Options for a model decoration.
*/
......@@ -89,10 +82,6 @@ export interface IModelDecorationOptions {
* Array of MarkedString to render as the decoration message.
*/
hoverMessage?: MarkedString | MarkedString[];
/**
* Color with mode to render in the color picker.
*/
colorInfo?: IColorInfo;
/**
* Should the decoration expand to encompass a whole line.
*/
......
......@@ -879,15 +879,23 @@ export class ModelDecorationOverviewRulerOptions implements editorCommon.IModelD
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 {
public static EMPTY: ModelDecorationOptions;
public static register(options: editorCommon.IModelDecorationOptions): ModelDecorationOptions {
public static register(options: editorCommon.IModelDecorationOptions & IModelDecorationExtraOptions): ModelDecorationOptions {
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);
}
......@@ -895,7 +903,6 @@ export class ModelDecorationOptions implements editorCommon.IModelDecorationOpti
readonly stickiness: editorCommon.TrackedRangeStickiness;
readonly className: string;
readonly hoverMessage: MarkedString | MarkedString[];
readonly colorInfo: editorCommon.IColorInfo;
readonly glyphMarginHoverMessage: MarkedString | MarkedString[];
readonly isWholeLine: boolean;
readonly showIfCollapsed: boolean;
......@@ -906,13 +913,13 @@ export class ModelDecorationOptions implements editorCommon.IModelDecorationOpti
readonly inlineClassName: string;
readonly beforeContentClassName: 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.stickiness = options.stickiness || editorCommon.TrackedRangeStickiness.AlwaysGrowsWhenTypingAtEdges;
this.className = options.className ? cleanClassName(options.className) : strings.empty;
this.hoverMessage = options.hoverMessage || [];
this.colorInfo = options.colorInfo || undefined;
this.glyphMarginHoverMessage = options.glyphMarginHoverMessage || strings.empty;
this.isWholeLine = options.isWholeLine || false;
this.showIfCollapsed = options.showIfCollapsed || false;
......@@ -923,6 +930,10 @@ export class ModelDecorationOptions implements editorCommon.IModelDecorationOpti
this.inlineClassName = options.inlineClassName ? cleanClassName(options.inlineClassName) : strings.empty;
this.beforeContentClassName = options.beforeContentClassName ? cleanClassName(options.beforeContentClassName) : strings.empty;
this.afterContentClassName = options.afterContentClassName ? cleanClassName(options.afterContentClassName) : strings.empty;
if (options.__extraOptions) {
this.extraOptions = options.__extraOptions;
}
}
public equals(other: ModelDecorationOptions): boolean {
......@@ -944,6 +955,7 @@ export class ModelDecorationOptions implements editorCommon.IModelDecorationOpti
&& markedStringsEquals(this.hoverMessage, other.hoverMessage)
&& markedStringsEquals(this.glyphMarginHoverMessage, other.glyphMarginHoverMessage)
&& this.overviewRuler.equals(other.overviewRuler)
&& this.extraOptions === other.extraOptions
);
}
}
......
......@@ -156,7 +156,7 @@ export interface IState {
* A hover represents additional information for a symbol or word. Hovers are
* rendered in a tooltip-like widget.
*/
export interface MarkedStringHover {
export interface Hover {
/**
* The contents of this hover.
*/
......@@ -170,21 +170,6 @@ export interface MarkedStringHover {
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](https://code.visualstudio.com/docs/editor/intellisense)-feature.
......
......@@ -3,16 +3,17 @@
* 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 { editorContribution } from "vs/editor/browser/editorBrowserExtensions";
import { ICodeEditor } from "vs/editor/browser/editorBrowser";
import { IDisposable, dispose } from "vs/base/common/lifecycle";
import { registerThemingParticipant } from "vs/platform/theme/common/themeService";
import { editorWidgetBackground, editorWidgetBorder } from "vs/platform/theme/common/colorRegistry";
import { ColorProviderRegistry, IColorInfo } from "vs/editor/common/modes";
import { TPromise } from "vs/base/common/winjs.base";
import { getColors } from "vs/editor/contrib/colorPicker/common/colorPicker";
import { IRange } from "vs/editor/common/core/range";
import { ICommonCodeEditor, IEditorContribution, IModelDecorationsChangeAccessor, IModelDeltaDecoration } from 'vs/editor/common/editorCommon';
import { editorContribution } from 'vs/editor/browser/editorBrowserExtensions';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { editorWidgetBackground, editorWidgetBorder } from 'vs/platform/theme/common/colorRegistry';
import { ColorProviderRegistry, IColorInfo } from 'vs/editor/common/modes';
import { TPromise } from 'vs/base/common/winjs.base';
import { getColors } from 'vs/editor/contrib/colorPicker/common/colorPicker';
import { IRange } from 'vs/editor/common/core/range';
import { IColorDecorationExtraOptions } from '../common/color';
@editorContribution
export class ColorPicker implements IEditorContribution {
......@@ -111,18 +112,16 @@ export class ColorPicker implements IEditorContribution {
endColumn: c.range.endColumn
};
const decoration = {
range: range,
options: {
colorInfo: {
const extraOptions: IColorDecorationExtraOptions = {
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);
......
/*---------------------------------------------------------------------------------------------
* 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';
import { renderMarkedString } from 'vs/base/browser/htmlContentRenderer';
import { IOpenerService, NullOpenerService } from 'vs/platform/opener/common/opener';
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 { 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 { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { getHover, isColorHover } from '../common/hover';
import { getHover } from '../common/hover';
import { HoverOperation, IHoverComputer } from './hoverOperation';
import { ContentHoverWidget } from './hoverWidgets';
import { textToMarkedString, MarkedString } from 'vs/base/common/htmlContent';
import { ModelDecorationOptions } from 'vs/editor/common/model/textModelWithDecorations';
import { ColorPickerModel } from "vs/editor/contrib/colorPicker/browser/colorPickerModel";
import { ColorPickerWidget } from "vs/editor/contrib/colorPicker/browser/colorPickerWidget";
import { IColorInfo } from 'vs/editor/common/editorCommon';
import { ColorFormatter } from "vs/editor/contrib/colorPicker/common/colorFormatter";
import { isColorDecorationOptions } from 'vs/editor/contrib/colorPicker/common/color';
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 _result: Hover[];
private _result: HoverPart[];
private _range: Range;
constructor(editor: ICodeEditor) {
......@@ -47,7 +60,7 @@ class ModesContentComputer implements IHoverComputer<Hover[]> {
this._result = [];
}
computeAsync(): TPromise<Hover[]> {
computeAsync(): TPromise<HoverPart[]> {
const model = this._editor.getModel();
if (!HoverProviderRegistry.has(model)) {
......@@ -60,7 +73,7 @@ class ModesContentComputer implements IHoverComputer<Hover[]> {
));
}
computeSync(): Hover[] {
computeSync(): HoverPart[] {
const lineNumber = this._range.startLineNumber;
if (lineNumber > this._editor.getModel().getLineCount()) {
......@@ -68,7 +81,7 @@ class ModesContentComputer implements IHoverComputer<Hover[]> {
return [];
}
const hasHoverContent = (contents: MarkedString | MarkedString[] | IColorInfo) => {
const hasHoverContent = (contents: MarkedString | MarkedString[]) => {
return contents && (!Array.isArray(contents) || (<MarkedString[]>contents).length > 0);
};
......@@ -79,11 +92,25 @@ class ModesContentComputer implements IHoverComputer<Hover[]> {
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 || (!hasHoverContent(d.options.hoverMessage) && !hasHoverContent(d.options.colorInfo))) {
if (startColumn > this._range.startColumn || this._range.endColumn > endColumn) {
return null;
}
const range = new Range(this._range.startLineNumber, startColumn, this._range.startLineNumber, endColumn);
// TOOD@Joao
const options = d.options as any;
const extraOptions = options && options.extraOptions;
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;
}
let contents: MarkedString[];
if (d.options.hoverMessage) {
......@@ -94,30 +121,20 @@ class ModesContentComputer implements IHoverComputer<Hover[]> {
}
}
const colorInfo = d.options.colorInfo;
if (colorInfo) {
return {
color: colorInfo.color,
format: colorInfo.format,
availableFormats: colorInfo.availableFormats,
range: range,
};
}
return { contents, range };
}
});
return result.filter(d => !!d);
}
onResult(result: Hover[], isFromSynchronousComputation: boolean): void {
onResult(result: HoverPart[], isFromSynchronousComputation: boolean): void {
// Always put synchronous messages before asynchronous ones
if (isFromSynchronousComputation) {
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;
} else if (isColorHover(b)) {
} else if (b instanceof ColorHover) {
return 1;
}
return 0;
......@@ -127,15 +144,15 @@ class ModesContentComputer implements IHoverComputer<Hover[]> {
}
}
getResult(): Hover[] {
getResult(): HoverPart[] {
return this._result.slice(0);
}
getResultWithLoadingMessage(): Hover[] {
getResultWithLoadingMessage(): HoverPart[] {
return this._result.slice(0).concat([this._getLoadingMessage()]);
}
private _getLoadingMessage(): Hover {
private _getLoadingMessage(): HoverPart {
return {
range: this._range,
contents: [textToMarkedString(nls.localize('modesContentHover.loading', "Loading..."))]
......@@ -147,10 +164,10 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
static ID = 'editor.contrib.modesContentHoverWidget';
private _messages: Hover[];
private _messages: HoverPart[];
private _lastRange: Range;
private _computer: ModesContentComputer;
private _hoverOperation: HoverOperation<Hover[]>;
private _hoverOperation: HoverOperation<HoverPart[]>;
private _highlightDecorations: string[];
private _isChangingDecorations: boolean;
private _openerService: IOpenerService;
......@@ -169,9 +186,9 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
this._hoverOperation = new HoverOperation(
this._computer,
(result: Hover[]) => this._withResult(result, true),
result => this._withResult(result, true),
null,
(result: any) => this._withResult(result, false)
result => this._withResult(result, false)
);
}
......@@ -209,7 +226,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
if (this._showAtPosition.lineNumber !== range.startLineNumber) {
this.hide();
} else {
var filteredMessages: Hover[] = [];
var filteredMessages: HoverPart[] = [];
for (var i = 0, len = this._messages.length; i < len; i++) {
var msg = this._messages[i];
var rng = msg.range;
......@@ -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;
if (this._lastRange && this._messages.length > 0) {
......@@ -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
var renderColumn = Number.MAX_VALUE,
......@@ -269,7 +286,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
renderColumn = Math.min(renderColumn, msg.range.startColumn);
highlightRange = Range.plusRange(highlightRange, msg.range);
if (!isColorHover(msg)) {
if (!(msg instanceof ColorHover)) {
msg.contents
.filter(contents => !!contents)
.forEach(contents => {
......
......@@ -10,14 +10,10 @@ import { onUnexpectedExternalError } from 'vs/base/common/errors';
import { TPromise } from 'vs/base/common/winjs.base';
import { IReadOnlyModel } from 'vs/editor/common/editorCommon';
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 { 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[]> {
const supports = HoverProviderRegistry.ordered(model);
......@@ -29,7 +25,7 @@ export function getHover(model: IReadOnlyModel, position: Position): TPromise<Ho
}).then((result) => {
if (result) {
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) {
values[idx] = result;
}
......
......@@ -1121,17 +1121,6 @@ declare module monaco.editor {
position: OverviewRulerLane;
}
export type IColorFormat = string | {
opaque: string;
transparent: string;
};
export interface IColorInfo {
color: Color;
format: IColorFormat;
availableFormats: IColorFormat[];
}
/**
* Options for a model decoration.
*/
......@@ -1153,10 +1142,6 @@ declare module monaco.editor {
* Array of MarkedString to render as the decoration message.
*/
hoverMessage?: MarkedString | MarkedString[];
/**
* Color with mode to render in the color picker.
*/
colorInfo?: IColorInfo;
/**
* Should the decoration expand to encompass a whole line.
*/
......@@ -4437,7 +4422,7 @@ declare module monaco.languages {
* A hover represents additional information for a symbol or word. Hovers are
* rendered in a tooltip-like widget.
*/
export interface MarkedStringHover {
export interface Hover {
/**
* The contents of this hover.
*/
......@@ -4450,20 +4435,6 @@ declare module monaco.languages {
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](https://code.visualstudio.com/docs/editor/intellisense)-feature.
......
......@@ -16,7 +16,7 @@ import { SaveReason } from 'vs/workbench/services/textfile/common/textfiles';
import { IPosition } from 'vs/editor/common/core/position';
import { IRange } from 'vs/editor/common/core/range';
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 {
line: number;
......@@ -254,14 +254,14 @@ export const location = {
}
};
export function fromHover(hover: vscode.Hover): modes.MarkedStringHover {
return <modes.MarkedStringHover>{
export function fromHover(hover: vscode.Hover): modes.Hover {
return <modes.Hover>{
range: fromRange(hover.range),
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));
}
......
......@@ -26,7 +26,7 @@ import { IHeapService } from 'vs/workbench/api/electron-browser/mainThreadHeapSe
import { ExtHostDocuments } from 'vs/workbench/api/node/extHostDocuments';
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/node/extHostDocumentsAndEditors';
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 { getDefinitionsAtPosition, getImplementationsAtPosition, getTypeDefinitionsAtPosition } from 'vs/editor/contrib/goToDeclaration/browser/goToDeclaration';
import { getHover } from 'vs/editor/contrib/hover/common/hover';
......@@ -440,7 +440,7 @@ suite('ExtHostLanguageFeatures', function () {
return threadService.sync().then(() => {
return getHover(model, new EditorPosition(1, 1)).then(value => {
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(second.contents[0], 'registered first');
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册