mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 19:18:59 +01:00
fixes #32379
This commit is contained in:
@@ -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));
|
||||
if (typeof id !== 'number') {
|
||||
id = ColorProviderAdapter._colorFormatHandlePool++;
|
||||
this._colorFormatCache.set(format, id);
|
||||
newRawColorFormats.push([id, format]);
|
||||
}
|
||||
|
||||
colorInfos.push({
|
||||
color: [ci.color.red, ci.color.green, ci.color.blue, ci.color.alpha],
|
||||
availableFormats: availableFormats,
|
||||
range: TypeConverters.fromRange(ci.range)
|
||||
});
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user