提交 561cd050 编写于 作者: A Alex Dima

Bring in monaco.d.ts into the /src/ folder such that editor API can be...

Bring in monaco.d.ts into the /src/ folder such that editor API can be typechecked to be exported correctly
上级 a2fd5725
......@@ -26,7 +26,7 @@ var eolFilter = [
'!**/node_modules/**',
'!**/fixtures/**',
'!**/*.{svg,exe,png,scpt,bat,cmd,cur,ttf,woff,eot}',
'!build/{lib,tslintRules}/**/*.js'
'!build/{lib,monaco,tslintRules}/**/*.js'
];
var indentationFilter = [
......@@ -37,6 +37,7 @@ var indentationFilter = [
'!**/*.yml',
'!**/lib/**',
'!**/*.d.ts',
'!**/*.d.ts.recipe',
'!extensions/typescript/server/**',
'!test/assert.js',
'!**/package.json',
......
......@@ -7,7 +7,6 @@
// SET VSCODE_BUILD_DECLARATION_FILES=1
// run gulp watch once
import fs = require('fs');
import ts = require('typescript');
import path = require('path');
......@@ -25,11 +24,21 @@ function moduleIdToPath(moduleId:string): string {
}
var SOURCE_FILE_MAP: {[moduleId:string]:ts.SourceFile;} = {};
let 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 fileContents: string;
try {
fileContents = fs.readFileSync(filePath).toString();
} catch (err) {
console.error('======================================================================');
console.error('=> Have you compiled (gulp watch) with env variable VSCODE_BUILD_DECLARATION_FILES=1 ?');
console.error('======================================================================');
throw err;
}
let sourceFile = ts.createSourceFile(filePath, fileContents, ts.ScriptTarget.ES5);
SOURCE_FILE_MAP[moduleId] = sourceFile;
......@@ -227,10 +236,6 @@ function format(text:string): string {
}
}
var recipe = fs.readFileSync(path.join(__dirname, './monaco-editor.d.ts.recipe')).toString();
var lines = recipe.split(/\r\n|\n|\r/);
var result = [];
function createReplacer(data:string): (str:string)=>string {
data = data || '';
let rawDirectives = data.split(';');
......@@ -256,77 +261,95 @@ function createReplacer(data:string): (str:string)=>string {
};
}
lines.forEach(line => {
export function generateDeclarationFile(recipe:string): string {
let lines = recipe.split(/\r\n|\n|\r/);
let result = [];
let m1 = line.match(/^\s*#include\(([^;)]*)(;[^)]*)?\)\:(.*)$/);
if (m1) {
console.log('HANDLING META: ' + line);
let moduleId = m1[1];
let sourceFile = getSourceFile(moduleId);
let replacer = createReplacer(m1[2]);
lines.forEach(line => {
let typeNames = m1[3].split(/,/);
typeNames.forEach((typeName) => {
typeName = typeName.trim();
if (typeName.length === 0) {
return;
}
let declaration = getTopLevelDeclaration(sourceFile, typeName);
result.push(replacer(getMassagedTopLevelDeclarationText(sourceFile, declaration)));
});
return;
}
let m1 = line.match(/^\s*#include\(([^;)]*)(;[^)]*)?\)\:(.*)$/);
if (m1) {
console.log('HANDLING META: ' + line);
let moduleId = m1[1];
let sourceFile = getSourceFile(moduleId);
let m2 = line.match(/^\s*#includeAll\(([^;)]*)(;[^)]*)?\)\:(.*)$/);
if (m2) {
console.log('HANDLING META: ' + line);
let moduleId = m2[1];
let sourceFile = getSourceFile(moduleId);
let replacer = createReplacer(m2[2]);
let typeNames = m2[3].split(/,/);
let typesToExcludeMap: {[typeName:string]:boolean;} = {};
let typesToExcludeArr: string[] = [];
typeNames.forEach((typeName) => {
typeName = typeName.trim();
if (typeName.length === 0) {
return;
}
typesToExcludeMap[typeName] = true;
typesToExcludeArr.push(typeName);
});
let replacer = createReplacer(m1[2]);
let typeNames = m1[3].split(/,/);
typeNames.forEach((typeName) => {
typeName = typeName.trim();
if (typeName.length === 0) {
return;
}
let declaration = getTopLevelDeclaration(sourceFile, typeName);
result.push(replacer(getMassagedTopLevelDeclarationText(sourceFile, declaration)));
});
return;
}
getAllTopLevelDeclarations(sourceFile).forEach((declaration) => {
if (isDeclaration(declaration)) {
if (typesToExcludeMap[declaration.name.text]) {
let m2 = line.match(/^\s*#includeAll\(([^;)]*)(;[^)]*)?\)\:(.*)$/);
if (m2) {
console.log('HANDLING META: ' + line);
let moduleId = m2[1];
let sourceFile = getSourceFile(moduleId);
let replacer = createReplacer(m2[2]);
let typeNames = m2[3].split(/,/);
let typesToExcludeMap: {[typeName:string]:boolean;} = {};
let typesToExcludeArr: string[] = [];
typeNames.forEach((typeName) => {
typeName = typeName.trim();
if (typeName.length === 0) {
return;
}
} else {
// node is ts.VariableStatement
let nodeText = getNodeText(sourceFile, declaration);
for (let i = 0; i < typesToExcludeArr.length; i++) {
if (nodeText.indexOf(typesToExcludeArr[i]) >= 0) {
typesToExcludeMap[typeName] = true;
typesToExcludeArr.push(typeName);
});
getAllTopLevelDeclarations(sourceFile).forEach((declaration) => {
if (isDeclaration(declaration)) {
if (typesToExcludeMap[declaration.name.text]) {
return;
}
} else {
// node is ts.VariableStatement
let nodeText = getNodeText(sourceFile, declaration);
for (let i = 0; i < typesToExcludeArr.length; i++) {
if (nodeText.indexOf(typesToExcludeArr[i]) >= 0) {
return;
}
}
}
}
result.push(replacer(getMassagedTopLevelDeclarationText(sourceFile, declaration)));
});
return;
}
result.push(replacer(getMassagedTopLevelDeclarationText(sourceFile, declaration)));
});
return;
}
result.push(line);
});
let resultTxt = result.join('\n');
resultTxt = resultTxt.replace(/\bURI\b/g, 'Uri');
resultTxt = resultTxt.replace(/\bEvent</g, 'IEvent<');
resultTxt = resultTxt.replace(/\bTPromise</g, 'Promise<');
resultTxt = format(resultTxt);
resultTxt = resultTxt.replace(/\r\n/g, '\n');
return resultTxt;
}
result.push(line);
});
const RECIPE_PATH = path.join(__dirname, './monaco.d.ts.recipe');
let recipe = fs.readFileSync(RECIPE_PATH).toString();
let result = generateDeclarationFile(recipe);
let resultTxt = result.join('\n');
resultTxt = resultTxt.replace(/\bURI\b/g, 'Uri');
resultTxt = resultTxt.replace(/\bEvent</g, 'IEvent<');
resultTxt = resultTxt.replace(/\bTPromise</g, 'Promise<');
const DECLARATION_PATH = path.join(__dirname, '../../src/vs/monaco.d.ts');
fs.writeFileSync(DECLARATION_PATH, result);
resultTxt = format(resultTxt);
// let result = generateDeclarationFile
resultTxt = resultTxt.replace(/\r\n/g, '\n');
// var recipe = fs.readFileSync(path.join(__dirname, './monaco-editor.d.ts.recipe')).toString();
fs.writeFileSync(path.join(__dirname, './monaco-editor.d.ts'), resultTxt);
// fs.writeFileSync(path.join(__dirname, './monaco-editor.d.ts'), resultTxt);
......@@ -17,7 +17,6 @@ declare module monaco.languages {
#include(vs/editor/common/modes/supports/richEditSupport): CommentRule, IRichLanguageConfiguration
#include(vs/editor/common/modes/supports/onEnter): IIndentationRules, IOnEnterRegExpRules
#include(vs/editor/common/modes/supports/electricCharacter): IBracketElectricCharacterContribution, IDocComment
#include(vs/editor/common/modes/supports/characterPair): ICharacterPairContribution
#includeAll(vs/editor/common/modes;editorCommon.IRange=>IRange;editorCommon.IPosition=>IPosition;editorCommon.=>editor.;IToken2=>IToken;ILineTokens2=>ILineTokens;IState2=>IState):
#include(vs/editor/common/services/modeService): ILanguageExtensionPoint
......
......@@ -327,7 +327,7 @@ export function colorizeModelLine(model:IModel, lineNumber:number, tabSize:numbe
/**
* @internal
*/
export function createMonacoEditorAPI()/*: typeof monaco.editor*/ {
export function createMonacoEditorAPI(): typeof monaco.editor {
return {
// methods
create: create,
......@@ -377,7 +377,6 @@ export function createMonacoEditorAPI()/*: typeof monaco.editor*/ {
// vars
EditorType: editorCommon.EditorType,
EventType: editorCommon.EventType,
Handler: editorCommon.Handler,
// consts
......
......@@ -339,7 +339,7 @@ export function registerStandaloneSchema(uri:string, schema:IJSONSchema) {
/**
* @internal
*/
export function createMonacoLanguagesAPI()/*: typeof monaco.languages*/ {
export function createMonacoLanguagesAPI(): typeof monaco.languages {
return {
// provider methods
setLanguageConfiguration: setLanguageConfiguration,
......
......@@ -214,7 +214,7 @@ export function create(): IRequestHandler {
return standaloneWorker;
}
function createMonacoWorkerAPI()/*: typeof monaco.worker*/ {
function createMonacoWorkerAPI(): typeof monaco.worker {
return {
get mirrorModels () {
return standaloneWorker.getModels();
......
......@@ -16,7 +16,7 @@ import {CancellationTokenSource} from 'vs/base/common/cancellation';
import Severity from 'vs/base/common/severity';
import URI from 'vs/base/common/uri';
export function createMonacoBaseAPI()/*: typeof monaco*/ {
export function createMonacoBaseAPI(): typeof monaco {
return {
editor: undefined,
worker: undefined,
......
......@@ -106,8 +106,9 @@ declare module monaco.languages {
wordPattern?: RegExp;
indentationRules?: IIndentationRules;
onEnterRules?: IOnEnterRegExpRules[];
autoClosingPairs?: IAutoClosingPairConditional[];
surroundingPairs?: IAutoClosingPair[];
__electricCharacterSupport?: IBracketElectricCharacterContribution;
__characterPairSupport?: ICharacterPairContribution;
}
export interface IIndentationRules {
......@@ -139,11 +140,6 @@ declare module monaco.languages {
close?: string;
}
export interface ICharacterPairContribution {
autoClosingPairs: IAutoClosingPairConditional[];
surroundingPairs?: IAutoClosingPair[];
}
export interface IMode {
getId(): string;
}
......@@ -610,12 +606,13 @@ declare module monaco {
* invalid characters and semantics. Will *not* look at the scheme of this Uri.
*/
fsPath: string;
with(scheme: string, authority: string, path: string, query: string, fragment: string): Uri;
withScheme(value: string): Uri;
withAuthority(value: string): Uri;
withPath(value: string): Uri;
withQuery(value: string): Uri;
withFragment(value: string): Uri;
with(change: {
scheme?: string;
authority?: string;
path?: string;
query?: string;
fragment?: string;
}): Uri;
static parse(value: string): Uri;
static file(path: string): Uri;
static create(scheme?: string, authority?: string, path?: string, query?: string, fragment?: string): Uri;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册