提交 0519a269 编写于 作者: A Alex Dima

First cut at monaco editor d.ts auto-generation

上级 9812161a
......@@ -74,6 +74,21 @@
"request": "launch",
"program": "${workspaceRoot}/src/vs/languages/css/common/buildscripts/generate_browserjs.js",
"stopOnEntry": false
},
{
"name": "Debug monaco",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/build/lib/monaco.js",
"stopOnEntry": false,
"args": [
],
"cwd": "${workspaceRoot}/build/lib"
// ,
// "port": 5870,
// "sourceMaps": true,
// "outDir": "${workspaceRoot}/out"
}
]
}
\ No newline at end of file
此差异已折叠。
declare module monaco {
interface Thenable<R> {
/**
* Attaches callbacks for the resolution and/or rejection of the Promise.
* @param onfulfilled The callback to execute when the Promise is resolved.
* @param onrejected The callback to execute when the Promise is rejected.
* @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) => void): Thenable<TResult>;
}
export interface Event<T> {
(listener: (e: T) => any): IDisposable;
}
export class Emitter<T> {
constructor();
event: Event<T>;
fire(event?: T): void;
dispose(): void;
}
export interface IDisposable {
dispose(): void;
}
#include(vs/base/common/uri): URI
#include(vs/base/common/winjs.base.d.ts): TValueCallback, ProgressCallback, TPromise
}
declare module monaco.editor {
export function create(domElement: HTMLElement, options: IEditorConstructionOptions, services?: any): ICodeEditor;
export function createDiffEditor(domElement: HTMLElement, options: IDiffEditorConstructionOptions, services?: any): IDiffEditor;
export function createModel(value:string, mode:string|IMonarchLanguage|IMode, associatedResource?:any|string): IModel;
export function getOrCreateMode(modeId: string): TPromise<IMode>;
export function createCustomMode(description:IMonarchLanguage): TPromise<IMode>;
export function colorize(text: string, modeId: string, options: IColorizerOptions): TPromise<string>;
export function colorizeElement(domNode: HTMLElement, options: IColorizerElementOptions): TPromise<void>;
export function colorizeLine(line: string, tokens: Editor.ILineToken[], tabSize?: number): string;
export function colorizeModelLine(model: Editor.IModel, lineNumber: number, tabSize?: number): string;
export function registerWorkerParticipant(modeId:string, moduleName:string, ctorName:string): void;
export function configureMode(modeId: string, options: any): void;
#include(vs/base/browser/ui/scrollbar/scrollableElementOptions): ScrollbarVisibility
#include(vs/base/common/htmlContent): IHTMLContentElementCode, IHTMLContentElement
#include(vs/editor/common/modes): ILineContext, IMode, IModeTransition, IToken
#includeAll(vs/editor/common/editorCommon):
#includeAll(vs/editor/browser/editorBrowser):
}
\ No newline at end of file
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
"use strict";
// PREREQUISITE:
// SET VSCODE_BUILD_DECLARATION_FILES=1
// run gulp watch once
var fs = require('fs');
var ts = require('typescript');
var path = require('path');
var SRC = path.join(__dirname, '../../src');
var OUT = path.join(__dirname, '../../out');
function moduleIdToPath(moduleId) {
if (/\.d\.ts/.test(moduleId)) {
return path.join(SRC, moduleId);
}
return path.join(OUT, moduleId) + '.d.ts';
}
var SOURCE_FILE_MAP = {};
function getSourceFile(moduleId) {
if (!SOURCE_FILE_MAP[moduleId]) {
var filePath = moduleIdToPath(moduleId);
var fileContents = fs.readFileSync(filePath).toString();
var sourceFile = ts.createSourceFile(filePath, fileContents, ts.ScriptTarget.ES5);
SOURCE_FILE_MAP[moduleId] = sourceFile;
}
return SOURCE_FILE_MAP[moduleId];
}
function visitTopLevelDeclarations(sourceFile, visitor) {
var stop = false;
var visit = function (node) {
if (stop) {
return;
}
switch (node.kind) {
case ts.SyntaxKind.InterfaceDeclaration:
case ts.SyntaxKind.EnumDeclaration:
case ts.SyntaxKind.ClassDeclaration:
stop = visitor(node);
break;
}
if (stop) {
return;
}
ts.forEachChild(node, visit);
};
visit(sourceFile);
}
function getAllTopLevelDeclarations(sourceFile) {
var all = [];
visitTopLevelDeclarations(sourceFile, function (node) {
all.push(node);
return false /*continue*/;
});
return all;
}
function getTopLevelDeclaration(sourceFile, typeName) {
var result = null;
visitTopLevelDeclarations(sourceFile, function (node) {
if (node.name.text === typeName) {
result = node;
return true /*stop*/;
}
return false /*continue*/;
});
return result;
}
function getNodeText(sourceFile, node) {
return sourceFile.getFullText().substring(node.pos, node.end);
}
function getMassagedTopLevelDeclarationText(sourceFile, declaration) {
var result = getNodeText(sourceFile, declaration);
result = result.replace(/export default/g, 'export');
result = result.replace(/export declare/g, 'export');
return result;
}
var recipe = fs.readFileSync(path.join(__dirname, './monaco-editor.d.ts.recipe')).toString();
var lines = recipe.split(/\r\n|\n|\r/);
var result = [];
lines.forEach(function (line) {
var m1 = line.match(/^\s*#include\(([^\)]*)\)\:(.*)$/);
if (m1) {
var moduleId = m1[1];
var sourceFile_1 = getSourceFile(moduleId);
var typeNames = m1[2].split(/,/);
typeNames.forEach(function (typeName) {
typeName = typeName.trim();
if (typeName.length === 0) {
return;
}
var declaration = getTopLevelDeclaration(sourceFile_1, typeName);
result.push(getMassagedTopLevelDeclarationText(sourceFile_1, declaration));
});
return;
}
var m2 = line.match(/^\s*#includeAll\(([^\)]*)\)\:(.*)$/);
if (m2) {
var moduleId = m2[1];
var sourceFile_2 = getSourceFile(moduleId);
var typeNames = m2[2].split(/,/);
var typesToExclude_1 = {};
typeNames.forEach(function (typeName) {
typeName = typeName.trim();
if (typeName.length === 0) {
return;
}
typesToExclude_1[typeName] = true;
});
getAllTopLevelDeclarations(sourceFile_2).forEach(function (declaration) {
result.push(getMassagedTopLevelDeclarationText(sourceFile_2, declaration));
});
return;
}
result.push(line);
});
fs.writeFileSync(path.join(__dirname, './monaco-editor.d.ts'), result.join('\n'));
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
// PREREQUISITE:
// SET VSCODE_BUILD_DECLARATION_FILES=1
// run gulp watch once
import fs = require('fs');
import ts = require('typescript');
import path = require('path');
const SRC = path.join(__dirname, '../../src');
const OUT = path.join(__dirname, '../../out');
function moduleIdToPath(moduleId:string): string {
if (/\.d\.ts/.test(moduleId)) {
return path.join(SRC, moduleId);
}
return path.join(OUT, moduleId) + '.d.ts';
}
var SOURCE_FILE_MAP: {[moduleId:string]:ts.SourceFile;} = {};
function getSourceFile(moduleId:string): ts.SourceFile {
if (!SOURCE_FILE_MAP[moduleId]) {
let filePath = moduleIdToPath(moduleId);
let fileContents = fs.readFileSync(filePath).toString();
let sourceFile = ts.createSourceFile(filePath, fileContents, ts.ScriptTarget.ES5);
SOURCE_FILE_MAP[moduleId] = sourceFile;
}
return SOURCE_FILE_MAP[moduleId];
}
type TypeScriptTypeDeclaration = ts.InterfaceDeclaration | ts.EnumDeclaration | ts.ClassDeclaration;
function visitTopLevelDeclarations(sourceFile:ts.SourceFile, visitor:(node:TypeScriptTypeDeclaration)=>boolean): void {
let stop = false;
let visit = (node: ts.Node): void => {
if (stop) {
return;
}
switch (node.kind) {
case ts.SyntaxKind.InterfaceDeclaration:
case ts.SyntaxKind.EnumDeclaration:
case ts.SyntaxKind.ClassDeclaration:
stop = visitor(<TypeScriptTypeDeclaration>node);
break;
}
if (stop) {
return;
}
ts.forEachChild(node, visit);
};
visit(sourceFile);
}
function getAllTopLevelDeclarations(sourceFile:ts.SourceFile): TypeScriptTypeDeclaration[] {
let all:TypeScriptTypeDeclaration[] = [];
visitTopLevelDeclarations(sourceFile, (node) => {
all.push(node);
return false /*continue*/;
});
return all;
}
function getTopLevelDeclaration(sourceFile:ts.SourceFile, typeName:string): TypeScriptTypeDeclaration {
let result:TypeScriptTypeDeclaration = null;
visitTopLevelDeclarations(sourceFile, (node) => {
if (node.name.text === typeName) {
result = node;
return true /*stop*/;
}
return false /*continue*/;
});
return result;
}
function getNodeText(sourceFile:ts.SourceFile, node:ts.Node): string {
return sourceFile.getFullText().substring(node.pos, node.end);
}
function getMassagedTopLevelDeclarationText(sourceFile:ts.SourceFile, declaration: TypeScriptTypeDeclaration): string {
let result = getNodeText(sourceFile, declaration);
result = result.replace(/export default/g, 'export');
result = result.replace(/export declare/g, 'export');
return result;
}
var recipe = fs.readFileSync(path.join(__dirname, './monaco-editor.d.ts.recipe')).toString();
var lines = recipe.split(/\r\n|\n|\r/);
var result = [];
lines.forEach(line => {
let m1 = line.match(/^\s*#include\(([^\)]*)\)\:(.*)$/);
if (m1) {
let moduleId = m1[1];
let sourceFile = getSourceFile(moduleId);
let typeNames = m1[2].split(/,/);
typeNames.forEach((typeName) => {
typeName = typeName.trim();
if (typeName.length === 0) {
return;
}
let declaration = getTopLevelDeclaration(sourceFile, typeName);
result.push(getMassagedTopLevelDeclarationText(sourceFile, declaration));
});
return;
}
let m2 = line.match(/^\s*#includeAll\(([^\)]*)\)\:(.*)$/);
if (m2) {
let moduleId = m2[1];
let sourceFile = getSourceFile(moduleId);
let typeNames = m2[2].split(/,/);
let typesToExclude: {[typeName:string]:boolean;} = {};
typeNames.forEach((typeName) => {
typeName = typeName.trim();
if (typeName.length === 0) {
return;
}
typesToExclude[typeName] = true;
});
getAllTopLevelDeclarations(sourceFile).forEach((declaration) => {
result.push(getMassagedTopLevelDeclarationText(sourceFile, declaration));
});
return;
}
result.push(line);
});
fs.writeFileSync(path.join(__dirname, './monaco-editor.d.ts'), result.join('\n'));
......@@ -25,10 +25,12 @@ var sourcemaps = require('gulp-sourcemaps');
var _ = require('underscore');
var assign = require('object-assign');
var quiet = !!process.env['VSCODE_BUILD_QUIET'];
var declaration = !!proces.env['VSCODE_BUILD_DECLARATION_FILES'];
var rootDir = path.join(__dirname, 'src');
var tsOptions = {
target: 'ES5',
declaration: declaration,
module: 'amd',
verbose: !quiet,
preserveConstEnums: true,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册