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

fixes #32379

上级 062a9183
......@@ -16,7 +16,7 @@ import { wireCancellationToken } from 'vs/base/common/async';
import { CancellationToken } from 'vs/base/common/cancellation';
import { Position as EditorPosition } from 'vs/editor/common/core/position';
import { Range as EditorRange } from 'vs/editor/common/core/range';
import { ExtHostContext, MainThreadLanguageFeaturesShape, ExtHostLanguageFeaturesShape, IColorFormatMap } from '../node/extHost.protocol';
import { ExtHostContext, MainThreadLanguageFeaturesShape, ExtHostLanguageFeaturesShape, IRawColorFormatMap } from '../node/extHost.protocol';
import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry';
import { LanguageConfiguration } from 'vs/editor/common/modes/languageConfiguration';
import { IHeapService } from './mainThreadHeapService';
......@@ -29,7 +29,7 @@ export class MainThreadLanguageFeatures extends MainThreadLanguageFeaturesShape
private _heapService: IHeapService;
private _modeService: IModeService;
private _registrations: { [handle: number]: IDisposable; } = Object.create(null);
private _formatters: Map<number, modes.IColorFormatter>;
private _formatters: Map<number, ColorFormatter>;
constructor(
@IThreadService threadService: IThreadService,
......@@ -40,7 +40,7 @@ export class MainThreadLanguageFeatures extends MainThreadLanguageFeaturesShape
this._proxy = threadService.get(ExtHostContext.ExtHostLanguageFeatures);
this._heapService = heapService;
this._modeService = modeService;
this._formatters = new Map<number, modes.IColorFormatter>();
this._formatters = new Map<number, ColorFormatter>();
}
$unregister(handle: number): TPromise<any> {
......@@ -278,8 +278,13 @@ export class MainThreadLanguageFeatures extends MainThreadLanguageFeaturesShape
return wireCancellationToken(token, proxy.$provideDocumentColors(handle, model.uri))
.then(documentColors => {
return documentColors.map(documentColor => {
const formatters = documentColor.availableFormats
.map(f => this._formatters.get(f));
const formatters = documentColor.availableFormats.map(f => {
if (typeof f === 'number') {
return this._formatters.get(f);
} else {
return new CombinedColorFormatter(this._formatters.get(f[0]), this._formatters.get(f[1]));
}
});
const [red, green, blue, alpha] = documentColor.color;
const color = {
......@@ -302,20 +307,8 @@ export class MainThreadLanguageFeatures extends MainThreadLanguageFeaturesShape
return TPromise.as(null);
}
$registerColorFormats(formats: IColorFormatMap): TPromise<any> {
formats.forEach(f => {
const raw = f[1];
let formatter: modes.IColorFormatter;
if (typeof raw === 'string') {
formatter = new ColorFormatter(raw);
} else {
formatter = new CombinedColorFormatter(new ColorFormatter(raw[0]), new ColorFormatter(raw[1]));
}
this._formatters.set(f[0], formatter);
});
$registerColorFormats(formats: IRawColorFormatMap): TPromise<any> {
formats.forEach(f => this._formatters.set(f[0], new ColorFormatter(f[1])));
return TPromise.as(null);
}
......
......@@ -230,7 +230,7 @@ export abstract class MainThreadLanguageFeaturesShape {
$registerSuggestSupport(handle: number, selector: vscode.DocumentSelector, triggerCharacters: string[]): TPromise<any> { throw ni(); }
$registerSignatureHelpProvider(handle: number, selector: vscode.DocumentSelector, triggerCharacter: string[]): TPromise<any> { throw ni(); }
$registerDocumentLinkProvider(handle: number, selector: vscode.DocumentSelector): TPromise<any> { throw ni(); }
$registerColorFormats(formats: IColorFormatMap): TPromise<any> { throw ni(); }
$registerColorFormats(formats: IRawColorFormatMap): TPromise<any> { throw ni(); }
$registerDocumentColorProvider(handle: number, selector: vscode.DocumentSelector): TPromise<any> { throw ni(); }
$setLanguageConfiguration(handle: number, languageId: string, configuration: vscode.LanguageConfiguration): TPromise<any> { throw ni(); }
}
......@@ -466,13 +466,12 @@ export abstract class ExtHostHeapServiceShape {
$onGarbageCollection(ids: number[]): void { throw ni(); }
}
export interface IRawColorInfo {
color: [number, number, number, number | undefined];
availableFormats: number[];
color: [number, number, number, number];
availableFormats: (number | [number, number])[];
range: IRange;
}
export type IRawColorFormat = string | [string, string];
export type IColorFormatMap = [number, IRawColorFormat][];
export type IRawColorFormatMap = [number, string][];
export abstract class ExtHostLanguageFeaturesShape {
$provideDocumentSymbols(handle: number, resource: URI): TPromise<modes.SymbolInformation[]> { throw ni(); }
......
......@@ -19,7 +19,7 @@ import { ExtHostCommands, CommandsConverter } from 'vs/workbench/api/node/extHos
import { ExtHostDiagnostics } from 'vs/workbench/api/node/extHostDiagnostics';
import { IWorkspaceSymbolProvider } from 'vs/workbench/parts/search/common/search';
import { asWinJsPromise } from 'vs/base/common/async';
import { MainContext, MainThreadLanguageFeaturesShape, ExtHostLanguageFeaturesShape, ObjectIdentifier, IRawColorInfo, IColorFormatMap } from './extHost.protocol';
import { MainContext, MainThreadLanguageFeaturesShape, ExtHostLanguageFeaturesShape, ObjectIdentifier, IRawColorInfo, IRawColorFormatMap } from './extHost.protocol';
import { regExpLeadsToEndlessLoop } from 'vs/base/common/strings';
import { IPosition } from 'vs/editor/common/core/position';
import { IRange } from 'vs/editor/common/core/range';
......@@ -668,57 +668,53 @@ class LinkProviderAdapter {
class ColorProviderAdapter {
private _proxy: MainThreadLanguageFeaturesShape;
private _documents: ExtHostDocuments;
private _provider: vscode.DocumentColorProvider;
private _formatStorageMap: Map<vscode.ColorFormat, number>;
private _formatStorageIndex;
private static _colorFormatHandlePool: number = 0;
constructor(proxy: MainThreadLanguageFeaturesShape, documents: ExtHostDocuments, provider: vscode.DocumentColorProvider) {
this._proxy = proxy;
this._documents = documents;
this._provider = provider;
this._formatStorageMap = new Map<vscode.ColorFormat, number>();
this._formatStorageIndex = 0;
}
constructor(
private _proxy: MainThreadLanguageFeaturesShape,
private _documents: ExtHostDocuments,
private _colorFormatCache: Map<string, number>,
private _provider: vscode.DocumentColorProvider
) { }
provideColors(resource: URI): TPromise<IRawColorInfo[]> {
const doc = this._documents.getDocumentData(resource).document;
const colorFormats: IColorFormatMap = [];
const getCachedId = (format: vscode.ColorFormat) => {
let cachedId = this._formatStorageMap.get(format);
if (cachedId === undefined) {
cachedId = this._formatStorageIndex;
this._formatStorageMap.set(format, cachedId);
this._formatStorageIndex += 1;
if (typeof format === 'string') { // Append to format list for registration
colorFormats.push([cachedId, format]);
} else {
colorFormats.push([cachedId, [format.opaque, format.transparent]]);
}
return asWinJsPromise(token => this._provider.provideDocumentColors(doc, token)).then(colors => {
if (!Array.isArray(colors)) {
return [];
}
return cachedId;
};
const newRawColorFormats: IRawColorFormatMap = [];
const getFormatId = (format: string) => {
let id = this._colorFormatCache.get(format);
return asWinJsPromise(token => this._provider.provideDocumentColors(doc, token)).then(colors => {
if (Array.isArray(colors)) {
const colorInfos: IRawColorInfo[] = [];
colors.forEach(ci => {
const availableFormats = ci.availableFormats.map(f => getCachedId(f));
colorInfos.push({
color: [ci.color.red, ci.color.green, ci.color.blue, ci.color.alpha],
availableFormats: availableFormats,
range: TypeConverters.fromRange(ci.range)
});
if (typeof id !== 'number') {
id = ColorProviderAdapter._colorFormatHandlePool++;
this._colorFormatCache.set(format, id);
newRawColorFormats.push([id, format]);
}
return id;
};
const colorInfos: IRawColorInfo[] = colors.map(ci => {
const availableFormats = ci.availableFormats.map(format => {
if (typeof format === 'string') {
return getFormatId(format);
} else {
return [getFormatId(format.opaque), getFormatId(format.transparent)] as [number, number];
}
});
this._proxy.$registerColorFormats(colorFormats);
return colorInfos;
}
return undefined;
return {
color: [ci.color.red, ci.color.green, ci.color.blue, ci.color.alpha] as [number, number, number, number],
availableFormats: availableFormats,
range: TypeConverters.fromRange(ci.range)
};
});
this._proxy.$registerColorFormats(newRawColorFormats);
return colorInfos;
});
}
}
......@@ -738,6 +734,7 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
private _heapService: ExtHostHeapService;
private _diagnostics: ExtHostDiagnostics;
private _adapter = new Map<number, Adapter>();
private _colorFormatCache = new Map<string, number>();
constructor(
threadService: IThreadService,
......@@ -1013,7 +1010,7 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
registerColorProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentColorProvider): vscode.Disposable {
const handle = this._nextHandle();
this._adapter.set(handle, new ColorProviderAdapter(this._proxy, this._documents, provider));
this._adapter.set(handle, new ColorProviderAdapter(this._proxy, this._documents, this._colorFormatCache, provider));
this._proxy.$registerDocumentColorProvider(handle, selector);
return this._createDisposable(handle);
}
......
......@@ -16,7 +16,6 @@ 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 { IRawColorFormat } from "vs/workbench/api/node/extHost.protocol";
export interface PositionLike {
line: number;
......@@ -370,19 +369,6 @@ export namespace DocumentLink {
}
}
export namespace DocumentColorFormat {
export function from(colorFormat: vscode.ColorFormat): IRawColorFormat {
let format: string | [string, string];
if (typeof colorFormat === 'string') {
format = colorFormat;
} else {
format = [colorFormat.opaque, colorFormat.transparent];
}
return format;
}
}
export namespace TextDocumentSaveReason {
export function to(reason: SaveReason): vscode.TextDocumentSaveReason {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册