mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-23 00:22:56 +01:00
Adopt native promises
This commit is contained in:
parent
f70f178c03
commit
da22aff470
5 changed files with 15 additions and 19 deletions
|
|
@ -10,7 +10,6 @@ import { LanguageServiceDefaultsImpl } from './monaco.contribution';
|
||||||
import * as languageFeatures from './languageFeatures';
|
import * as languageFeatures from './languageFeatures';
|
||||||
import { createTokenizationSupport } from './tokenization';
|
import { createTokenizationSupport } from './tokenization';
|
||||||
|
|
||||||
import Promise = monaco.Promise;
|
|
||||||
import Uri = monaco.Uri;
|
import Uri = monaco.Uri;
|
||||||
import IDisposable = monaco.IDisposable;
|
import IDisposable = monaco.IDisposable;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import Promise = monaco.Promise;
|
|
||||||
import Thenable = monaco.Thenable;
|
import Thenable = monaco.Thenable;
|
||||||
import IWorkerContext = monaco.worker.IWorkerContext;
|
import IWorkerContext = monaco.worker.IWorkerContext;
|
||||||
|
|
||||||
|
|
@ -17,10 +16,10 @@ if (typeof fetch !== 'undefined'){
|
||||||
}
|
}
|
||||||
|
|
||||||
class PromiseAdapter<T> implements jsonService.Thenable<T> {
|
class PromiseAdapter<T> implements jsonService.Thenable<T> {
|
||||||
private wrapped: monaco.Promise<T>;
|
private wrapped: Promise<T>;
|
||||||
|
|
||||||
constructor(executor: (resolve: (value?: T | jsonService.Thenable<T>) => void, reject: (reason?: any) => void) => void) {
|
constructor(executor: (resolve: (value?: T | jsonService.Thenable<T>) => void, reject: (reason?: any) => void) => void) {
|
||||||
this.wrapped = new monaco.Promise<T>(executor);
|
this.wrapped = new Promise<T>(executor);
|
||||||
}
|
}
|
||||||
public then<TResult>(onfulfilled?: (value: T) => TResult | jsonService.Thenable<TResult>, onrejected?: (reason: any) => void): jsonService.Thenable<TResult> {
|
public then<TResult>(onfulfilled?: (value: T) => TResult | jsonService.Thenable<TResult>, onrejected?: (reason: any) => void): jsonService.Thenable<TResult> {
|
||||||
let thenable: jsonService.Thenable<T> = this.wrapped;
|
let thenable: jsonService.Thenable<T> = this.wrapped;
|
||||||
|
|
@ -30,13 +29,13 @@ class PromiseAdapter<T> implements jsonService.Thenable<T> {
|
||||||
return this.wrapped;
|
return this.wrapped;
|
||||||
}
|
}
|
||||||
public static resolve<T>(v: T | Thenable<T>): jsonService.Thenable<T> {
|
public static resolve<T>(v: T | Thenable<T>): jsonService.Thenable<T> {
|
||||||
return <monaco.Thenable<T>>monaco.Promise.as(v);
|
return <monaco.Thenable<T>>Promise.resolve(v);
|
||||||
}
|
}
|
||||||
public static reject<T>(v: T): jsonService.Thenable<T> {
|
public static reject<T>(v: T): jsonService.Thenable<T> {
|
||||||
return monaco.Promise.wrapError(<any>v);
|
return Promise.reject(<any>v);
|
||||||
}
|
}
|
||||||
public static all<T>(values: jsonService.Thenable<T>[]): jsonService.Thenable<T[]> {
|
public static all<T>(values: jsonService.Thenable<T>[]): jsonService.Thenable<T[]> {
|
||||||
return monaco.Promise.join(values);
|
return Promise.all(values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,7 +63,7 @@ export class JSONWorker {
|
||||||
let jsonDocument = this._languageService.parseJSONDocument(document);
|
let jsonDocument = this._languageService.parseJSONDocument(document);
|
||||||
return this._languageService.doValidation(document, jsonDocument);
|
return this._languageService.doValidation(document, jsonDocument);
|
||||||
}
|
}
|
||||||
return Promise.as([]);
|
return Promise.resolve([]);
|
||||||
}
|
}
|
||||||
doComplete(uri: string, position: ls.Position): Thenable<ls.CompletionList> {
|
doComplete(uri: string, position: ls.Position): Thenable<ls.CompletionList> {
|
||||||
let document = this._getTextDocument(uri);
|
let document = this._getTextDocument(uri);
|
||||||
|
|
@ -82,33 +81,33 @@ export class JSONWorker {
|
||||||
format(uri: string, range: ls.Range, options: ls.FormattingOptions): Thenable<ls.TextEdit[]> {
|
format(uri: string, range: ls.Range, options: ls.FormattingOptions): Thenable<ls.TextEdit[]> {
|
||||||
let document = this._getTextDocument(uri);
|
let document = this._getTextDocument(uri);
|
||||||
let textEdits = this._languageService.format(document, range, options);
|
let textEdits = this._languageService.format(document, range, options);
|
||||||
return Promise.as(textEdits);
|
return Promise.resolve(textEdits);
|
||||||
}
|
}
|
||||||
resetSchema(uri: string): Thenable<boolean> {
|
resetSchema(uri: string): Thenable<boolean> {
|
||||||
return Promise.as(this._languageService.resetSchema(uri));
|
return Promise.resolve(this._languageService.resetSchema(uri));
|
||||||
}
|
}
|
||||||
findDocumentSymbols(uri: string): Thenable<ls.SymbolInformation[]> {
|
findDocumentSymbols(uri: string): Thenable<ls.SymbolInformation[]> {
|
||||||
let document = this._getTextDocument(uri);
|
let document = this._getTextDocument(uri);
|
||||||
let jsonDocument = this._languageService.parseJSONDocument(document);
|
let jsonDocument = this._languageService.parseJSONDocument(document);
|
||||||
let symbols = this._languageService.findDocumentSymbols(document, jsonDocument);
|
let symbols = this._languageService.findDocumentSymbols(document, jsonDocument);
|
||||||
return Promise.as(symbols);
|
return Promise.resolve(symbols);
|
||||||
}
|
}
|
||||||
findDocumentColors(uri: string): Thenable<ls.ColorInformation[]> {
|
findDocumentColors(uri: string): Thenable<ls.ColorInformation[]> {
|
||||||
let document = this._getTextDocument(uri);
|
let document = this._getTextDocument(uri);
|
||||||
let stylesheet = this._languageService.parseJSONDocument(document);
|
let stylesheet = this._languageService.parseJSONDocument(document);
|
||||||
let colorSymbols = this._languageService.findDocumentColors(document, stylesheet);
|
let colorSymbols = this._languageService.findDocumentColors(document, stylesheet);
|
||||||
return Promise.as(colorSymbols);
|
return Promise.resolve(colorSymbols);
|
||||||
}
|
}
|
||||||
getColorPresentations(uri: string, color: ls.Color, range: ls.Range): Thenable<ls.ColorPresentation[]> {
|
getColorPresentations(uri: string, color: ls.Color, range: ls.Range): Thenable<ls.ColorPresentation[]> {
|
||||||
let document = this._getTextDocument(uri);
|
let document = this._getTextDocument(uri);
|
||||||
let stylesheet = this._languageService.parseJSONDocument(document);
|
let stylesheet = this._languageService.parseJSONDocument(document);
|
||||||
let colorPresentations = this._languageService.getColorPresentations(document, stylesheet, color, range);
|
let colorPresentations = this._languageService.getColorPresentations(document, stylesheet, color, range);
|
||||||
return Promise.as(colorPresentations);
|
return Promise.resolve(colorPresentations);
|
||||||
}
|
}
|
||||||
provideFoldingRanges(uri: string, context?: { rangeLimit?: number; }): Thenable<ls.FoldingRange[]> {
|
provideFoldingRanges(uri: string, context?: { rangeLimit?: number; }): Thenable<ls.FoldingRange[]> {
|
||||||
let document = this._getTextDocument(uri);
|
let document = this._getTextDocument(uri);
|
||||||
let ranges = this._languageService.getFoldingRanges(document, context);
|
let ranges = this._languageService.getFoldingRanges(document, context);
|
||||||
return Promise.as(ranges);
|
return Promise.resolve(ranges);
|
||||||
}
|
}
|
||||||
private _getTextDocument(uri: string): ls.TextDocument {
|
private _getTextDocument(uri: string): ls.TextDocument {
|
||||||
let models = this._ctx.getMirrorModels();
|
let models = this._ctx.getMirrorModels();
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ import Position = monaco.Position;
|
||||||
import Range = monaco.Range;
|
import Range = monaco.Range;
|
||||||
import IRange = monaco.IRange;
|
import IRange = monaco.IRange;
|
||||||
import Thenable = monaco.Thenable;
|
import Thenable = monaco.Thenable;
|
||||||
import Promise = monaco.Promise;
|
|
||||||
import CancellationToken = monaco.CancellationToken;
|
import CancellationToken = monaco.CancellationToken;
|
||||||
import IDisposable = monaco.IDisposable;
|
import IDisposable = monaco.IDisposable;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -61,8 +61,8 @@ monaco.languages.json = createAPI();
|
||||||
|
|
||||||
// --- Registration to monaco editor ---
|
// --- Registration to monaco editor ---
|
||||||
|
|
||||||
function getMode(): monaco.Promise<typeof mode> {
|
function getMode(): Promise<typeof mode> {
|
||||||
return monaco.Promise.wrap(import('./jsonMode'))
|
return import('./jsonMode');
|
||||||
}
|
}
|
||||||
|
|
||||||
monaco.languages.register({
|
monaco.languages.register({
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@
|
||||||
import { LanguageServiceDefaultsImpl } from './monaco.contribution';
|
import { LanguageServiceDefaultsImpl } from './monaco.contribution';
|
||||||
import { JSONWorker } from './jsonWorker';
|
import { JSONWorker } from './jsonWorker';
|
||||||
|
|
||||||
import Promise = monaco.Promise;
|
|
||||||
import IDisposable = monaco.IDisposable;
|
import IDisposable = monaco.IDisposable;
|
||||||
import Uri = monaco.Uri;
|
import Uri = monaco.Uri;
|
||||||
|
|
||||||
|
|
@ -74,7 +73,7 @@ export class WorkerManager {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this._client = this._worker.getProxy();
|
this._client = <Promise<JSONWorker>><any>this._worker.getProxy();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._client;
|
return this._client;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue