提交 b9b39fd2 编写于 作者: A Alex Dima

Auto-format the generated monaco-editor.d.ts

上级 b693a851
此差异已折叠。
declare module monaco.editor { declare module monaco.editor {
export function create(domElement: HTMLElement, options: IEditorConstructionOptions, services?: any): ICodeEditor; export function create(domElement: HTMLElement, options: IEditorConstructionOptions, services?: any): ICodeEditor;
export function createDiffEditor(domElement: HTMLElement, options: IDiffEditorConstructionOptions, services?: any): IDiffEditor; export function createDiffEditor(domElement: HTMLElement, options: IDiffEditorConstructionOptions, services?: any): IDiffEditor;
export function createModel(value:string, mode:string|ILanguage|IMode, associatedResource?:any|string): IModel; export function createModel(value:string, mode:string|ILanguage|IMode, associatedResource?:any|string): IModel;
export function getOrCreateMode(modeId: string): TPromise<IMode>; export function getOrCreateMode(modeId: string): TPromise<IMode>;
export function createCustomMode(description:ILanguage): TPromise<IMode>; export function createCustomMode(description:ILanguage): TPromise<IMode>;
export function colorize(text: string, modeId: string, options: IColorizerOptions): TPromise<string>; export function colorize(text: string, modeId: string, options: IColorizerOptions): TPromise<string>;
export function colorizeElement(domNode: HTMLElement, options: IColorizerElementOptions): TPromise<void>; export function colorizeElement(domNode: HTMLElement, options: IColorizerElementOptions): TPromise<void>;
export function colorizeLine(line: string, tokens: ViewLineToken[], tabSize?: number): string; export function colorizeLine(line: string, tokens: ViewLineToken[], tabSize?: number): string;
export function colorizeModelLine(model: IModel, lineNumber: number, tabSize?: number): string; export function colorizeModelLine(model: IModel, lineNumber: number, tabSize?: number): string;
export function registerWorkerParticipant(modeId:string, moduleName:string, ctorName:string): void; export function registerWorkerParticipant(modeId:string, moduleName:string, ctorName:string): void;
export function configureMode(modeId: string, options: any): void; export function configureMode(modeId: string, options: any): void;
export interface IColorizerOptions { export interface IColorizerOptions {
tabSize?: number; tabSize?: number;
} }
...@@ -36,48 +36,49 @@ declare module monaco.editor { ...@@ -36,48 +36,49 @@ declare module monaco.editor {
declare module monaco { declare module monaco {
interface Thenable<R> { interface Thenable<R> {
/** /**
* Attaches callbacks for the resolution and/or rejection of the Promise. * Attaches callbacks for the resolution and/or rejection of the Promise.
* @param onfulfilled The callback to execute when the Promise is resolved. * @param onfulfilled The callback to execute when the Promise is resolved.
* @param onrejected The callback to execute when the Promise is rejected. * @param onrejected The callback to execute when the Promise is rejected.
* @returns A Promise for the completion of which ever callback is executed. * @returns A Promise for the completion of which ever callback is executed.
*/ */
then<TResult>(onfulfilled?: (value: R) => TResult | Thenable<TResult>, onrejected?: (reason: any) => TResult | Thenable<TResult>): Thenable<TResult>; then<TResult>(onfulfilled?: (value: R) => TResult | Thenable<TResult>, onrejected?: (reason: any) => TResult | Thenable<TResult>): Thenable<TResult>;
then<TResult>(onfulfilled?: (value: R) => TResult | Thenable<TResult>, onrejected?: (reason: any) => void): Thenable<TResult>; then<TResult>(onfulfilled?: (value: R) => TResult | Thenable<TResult>, onrejected?: (reason: any) => void): Thenable<TResult>;
} }
export interface IDisposable {
dispose(): void;
}
export interface IDisposable { export interface IEvent<T> {
dispose(): void; (listener: (e: T) => any, thisArg?: any): IDisposable;
} }
export interface IEvent<T> { export class Emitter<T> {
(listener: (e: T) => any, thisArg?: any): IDisposable; constructor();
} event: IEvent<T>;
fire(event?: T): void;
dispose(): void;
}
export class Emitter<T> { #include(vs/base/common/winjs.base.d.ts): TValueCallback, ProgressCallback, TPromise
constructor();
event: IEvent<T>;
fire(event?: T): void;
dispose(): void;
}
#include(vs/base/common/winjs.base.d.ts): TValueCallback, ProgressCallback, TPromise #include(vs/base/common/uri): URI
#include(vs/base/common/uri): URI #include(vs/base/common/eventEmitter): IEmitterEvent, ListenerCallback, IBulkListenerCallback, ListenerUnbind, IEventEmitter
#include(vs/base/common/eventEmitter): IEmitterEvent, ListenerCallback, IBulkListenerCallback, ListenerUnbind, IEventEmitter
#include(vs/base/common/keyCodes): KeyCode, KeyMod #include(vs/base/common/keyCodes): KeyCode, KeyMod
#include(vs/base/common/htmlContent): IHTMLContentElementCode, IHTMLContentElement #include(vs/base/common/htmlContent): IHTMLContentElementCode, IHTMLContentElement
#include(vs/base/common/actions): IAction #include(vs/base/common/actions): IAction
#include(vs/base/browser/keyboardEvent): IKeyboardEvent #include(vs/base/browser/keyboardEvent): IKeyboardEvent
#include(vs/base/browser/mouseEvent): IMouseEvent #include(vs/base/browser/mouseEvent): IMouseEvent
export interface IPlatformServices { export interface IPlatformServices {
} }
export interface IInstantiationService { export interface IInstantiationService {
...@@ -95,21 +96,22 @@ declare module monaco { ...@@ -95,21 +96,22 @@ declare module monaco {
declare module monaco.editor { declare module monaco.editor {
#include(vs/editor/common/modes/monarch/monarchTypes): ILanguage, ILanguageBracket #include(vs/editor/common/modes/monarch/monarchTypes): ILanguage, ILanguageBracket
#include(vs/editor/common/core/modeTransition): ModeTransition #include(vs/editor/common/core/modeTransition): ModeTransition
#include(vs/editor/common/modes): IToken, IModeTransition, ILineContext #include(vs/editor/common/modes): IToken, IModeTransition, ILineContext
export interface IMode { export interface IMode {
} }
#include(vs/base/browser/ui/scrollbar/scrollableElementOptions): ScrollbarVisibility #include(vs/base/browser/ui/scrollbar/scrollableElementOptions): ScrollbarVisibility
#include(vs/editor/common/core/viewLineToken): ViewLineToken
#include(vs/editor/common/core/viewLineToken): ViewLineToken #includeAll(vs/editor/common/editorCommon): KeyCode, KeyMod
#includeAll(vs/editor/common/editorCommon): KeyCode, KeyMod #includeAll(vs/editor/browser/editorBrowser):
#includeAll(vs/editor/browser/editorBrowser):
} }
\ No newline at end of file
...@@ -92,6 +92,52 @@ function getMassagedTopLevelDeclarationText(sourceFile, declaration) { ...@@ -92,6 +92,52 @@ function getMassagedTopLevelDeclarationText(sourceFile, declaration) {
result = result.replace(/export declare/g, 'export'); result = result.replace(/export declare/g, 'export');
return result; return result;
} }
function format(text) {
var options = getDefaultOptions();
// Parse the source text
var sourceFile = ts.createSourceFile('file.ts', text, ts.ScriptTarget.Latest, /*setParentPointers*/ true);
// Get the formatting edits on the input sources
var edits = ts.formatting.formatDocument(sourceFile, getRuleProvider(options), options);
// Apply the edits on the input code
return applyEdits(text, edits);
function getRuleProvider(options) {
// Share this between multiple formatters using the same options.
// This represents the bulk of the space the formatter uses.
var ruleProvider = new ts.formatting.RulesProvider();
ruleProvider.ensureUpToDate(options);
return ruleProvider;
}
function applyEdits(text, edits) {
// Apply edits in reverse on the existing text
var result = text;
for (var i = edits.length - 1; i >= 0; i--) {
var change = edits[i];
var head = result.slice(0, change.span.start);
var tail = result.slice(change.span.start + change.span.length);
result = head + change.newText + tail;
}
return result;
}
function getDefaultOptions() {
return {
IndentSize: 4,
TabSize: 4,
NewLineCharacter: '\r\n',
ConvertTabsToSpaces: true,
IndentStyle: ts.IndentStyle.Block,
InsertSpaceAfterCommaDelimiter: true,
InsertSpaceAfterSemicolonInForStatements: true,
InsertSpaceBeforeAndAfterBinaryOperators: true,
InsertSpaceAfterKeywordsInControlFlowStatements: true,
InsertSpaceAfterFunctionKeywordForAnonymousFunctions: false,
InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false,
InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: true,
PlaceOpenBraceOnNewLineForFunctions: false,
PlaceOpenBraceOnNewLineForControlBlocks: false,
};
}
}
var recipe = fs.readFileSync(path.join(__dirname, './monaco-editor.d.ts.recipe')).toString(); var recipe = fs.readFileSync(path.join(__dirname, './monaco-editor.d.ts.recipe')).toString();
var lines = recipe.split(/\r\n|\n|\r/); var lines = recipe.split(/\r\n|\n|\r/);
var result = []; var result = [];
...@@ -131,4 +177,10 @@ lines.forEach(function (line) { ...@@ -131,4 +177,10 @@ lines.forEach(function (line) {
} }
result.push(line); result.push(line);
}); });
fs.writeFileSync(path.join(__dirname, './monaco-editor.d.ts'), result.join('\n').replace(/\beditorCommon\./g, '').replace(/\bEvent</g, 'IEvent<')); var resultTxt = result.join('\n');
resultTxt = resultTxt.replace(/\beditorCommon\./g, '');
resultTxt = resultTxt.replace(/\bEvent</g, 'IEvent<');
resultTxt = resultTxt.replace(/\bURI\b/g, 'Uri');
resultTxt = format(resultTxt);
resultTxt = resultTxt.replace(/\r\n/g, '\n');
fs.writeFileSync(path.join(__dirname, './monaco-editor.d.ts'), resultTxt);
...@@ -121,6 +121,59 @@ function getMassagedTopLevelDeclarationText(sourceFile:ts.SourceFile, declaratio ...@@ -121,6 +121,59 @@ function getMassagedTopLevelDeclarationText(sourceFile:ts.SourceFile, declaratio
return result; return result;
} }
function format(text:string): string {
let options = getDefaultOptions();
// Parse the source text
let sourceFile = ts.createSourceFile('file.ts', text, ts.ScriptTarget.Latest, /*setParentPointers*/ true);
// Get the formatting edits on the input sources
let edits = (<any>ts).formatting.formatDocument(sourceFile, getRuleProvider(options), options);
// Apply the edits on the input code
return applyEdits(text, edits);
function getRuleProvider(options: ts.FormatCodeOptions) {
// Share this between multiple formatters using the same options.
// This represents the bulk of the space the formatter uses.
let ruleProvider = new (<any>ts).formatting.RulesProvider();
ruleProvider.ensureUpToDate(options);
return ruleProvider;
}
function applyEdits(text: string, edits: ts.TextChange[]): string {
// Apply edits in reverse on the existing text
let result = text;
for (let i = edits.length - 1; i >= 0; i--) {
let change = edits[i];
let head = result.slice(0, change.span.start);
let tail = result.slice(change.span.start + change.span.length)
result = head + change.newText + tail;
}
return result;
}
function getDefaultOptions(): ts.FormatCodeOptions {
return {
IndentSize: 4,
TabSize: 4,
NewLineCharacter: '\r\n',
ConvertTabsToSpaces: true,
IndentStyle: ts.IndentStyle.Block,
InsertSpaceAfterCommaDelimiter: true,
InsertSpaceAfterSemicolonInForStatements: true,
InsertSpaceBeforeAndAfterBinaryOperators: true,
InsertSpaceAfterKeywordsInControlFlowStatements: true,
InsertSpaceAfterFunctionKeywordForAnonymousFunctions: false,
InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false,
InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: true,
PlaceOpenBraceOnNewLineForFunctions: false,
PlaceOpenBraceOnNewLineForControlBlocks: false,
};
}
}
var recipe = fs.readFileSync(path.join(__dirname, './monaco-editor.d.ts.recipe')).toString(); var recipe = fs.readFileSync(path.join(__dirname, './monaco-editor.d.ts.recipe')).toString();
var lines = recipe.split(/\r\n|\n|\r/); var lines = recipe.split(/\r\n|\n|\r/);
...@@ -169,4 +222,13 @@ lines.forEach(line => { ...@@ -169,4 +222,13 @@ lines.forEach(line => {
result.push(line); result.push(line);
}); });
fs.writeFileSync(path.join(__dirname, './monaco-editor.d.ts'), result.join('\n').replace(/\beditorCommon\./g, '').replace(/\bEvent</g, 'IEvent<')); let resultTxt = result.join('\n');
resultTxt = resultTxt.replace(/\beditorCommon\./g, '');
resultTxt = resultTxt.replace(/\bEvent</g, 'IEvent<');
resultTxt = resultTxt.replace(/\bURI\b/g, 'Uri');
resultTxt = format(resultTxt);
resultTxt = resultTxt.replace(/\r\n/g, '\n');
fs.writeFileSync(path.join(__dirname, './monaco-editor.d.ts'), resultTxt);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册