Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/microsoft/vscode.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Dima <alexdima@microsoft.com>2016-06-10 19:40:23 +0300
committerAlex Dima <alexdima@microsoft.com>2016-06-10 19:40:32 +0300
commit8fd51f85b99158addb59c0ce66ce8709e7029ccb (patch)
treecd4cd53adf9aef306b89be7f5e091e9fc1ff71f2
parentac9567ee476ff02c72741ac02a1b75a2fca84bdf (diff)
Generate monaco.d.ts continuously and check it in build
-rw-r--r--build/monaco/README.md7
-rw-r--r--build/monaco/api.js634
-rw-r--r--build/monaco/api.ts106
-rw-r--r--gulpfile.js73
-rw-r--r--src/vs/monaco.d.ts30
5 files changed, 518 insertions, 332 deletions
diff --git a/build/monaco/README.md b/build/monaco/README.md
index 064b9dda1d3..3acbb4eebdb 100644
--- a/build/monaco/README.md
+++ b/build/monaco/README.md
@@ -2,12 +2,7 @@
## Generate monaco.d.ts
-* Generate `.d.ts` files from our modules
- * kill `gulp watch` if you have it running
- * `SET VSCODE_BUILD_DECLARATION_FILES=1`
- * run `gulp watch`
-* `node build/lib/api`
-* validate that the file is generated ok and that everything compiles
+* The `monaco.d.ts` is now automatically generated when running `gulp watch`
## Bump version
diff --git a/build/monaco/api.js b/build/monaco/api.js
index 70dc1547ab5..77974bcc142 100644
--- a/build/monaco/api.js
+++ b/build/monaco/api.js
@@ -1,292 +1,342 @@
-/*---------------------------------------------------------------------------------------------
- * 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 = void 0;
- try {
- fileContents = fs.readFileSync(filePath).toString();
- }
- catch (err) {
- console.error('=========================================================================');
- console.error('=> Have you compiled with env variable VSCODE_BUILD_DECLARATION_FILES=1 ?');
- console.error('=========================================================================');
- throw err;
- }
- var sourceFile = ts.createSourceFile(filePath, fileContents, ts.ScriptTarget.ES5);
- SOURCE_FILE_MAP[moduleId] = sourceFile;
- }
- return SOURCE_FILE_MAP[moduleId];
-}
-function isDeclaration(a) {
- return (a.kind === ts.SyntaxKind.InterfaceDeclaration
- || a.kind === ts.SyntaxKind.EnumDeclaration
- || a.kind === ts.SyntaxKind.ClassDeclaration
- || a.kind === ts.SyntaxKind.TypeAliasDeclaration
- || a.kind === ts.SyntaxKind.FunctionDeclaration
- || a.kind === ts.SyntaxKind.ModuleDeclaration);
-}
-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:
- case ts.SyntaxKind.VariableStatement:
- case ts.SyntaxKind.TypeAliasDeclaration:
- case ts.SyntaxKind.FunctionDeclaration:
- case ts.SyntaxKind.ModuleDeclaration:
- stop = visitor(node);
- }
- // if (node.kind !== ts.SyntaxKind.SourceFile) {
- // if (getNodeText(sourceFile, node).indexOf('SymbolKind') >= 0) {
- // console.log('FOUND TEXT IN NODE: ' + ts.SyntaxKind[node.kind]);
- // console.log(getNodeText(sourceFile, node));
- // }
- // }
- if (stop) {
- return;
- }
- ts.forEachChild(node, visit);
- };
- visit(sourceFile);
-}
-function getAllTopLevelDeclarations(sourceFile) {
- var all = [];
- visitTopLevelDeclarations(sourceFile, function (node) {
- if (node.kind === ts.SyntaxKind.InterfaceDeclaration || node.kind === ts.SyntaxKind.ClassDeclaration || node.kind === ts.SyntaxKind.ModuleDeclaration) {
- var interfaceDeclaration = node;
- var triviaStart = interfaceDeclaration.pos;
- var triviaEnd = interfaceDeclaration.name.pos;
- var triviaText = getNodeText(sourceFile, { pos: triviaStart, end: triviaEnd });
- // // let nodeText = getNodeText(sourceFile, node);
- // if (getNodeText(sourceFile, node).indexOf('SymbolKind') >= 0) {
- // console.log('TRIVIA: ', triviaText);
- // }
- if (triviaText.indexOf('@internal') === -1) {
- all.push(node);
- }
- }
- else {
- var nodeText = getNodeText(sourceFile, node);
- if (nodeText.indexOf('@internal') === -1) {
- all.push(node);
- }
- }
- return false /*continue*/;
- });
- return all;
-}
-function getTopLevelDeclaration(sourceFile, typeName) {
- var result = null;
- visitTopLevelDeclarations(sourceFile, function (node) {
- if (isDeclaration(node)) {
- if (node.name.text === typeName) {
- result = node;
- return true /*stop*/;
- }
- return false /*continue*/;
- }
- // node is ts.VariableStatement
- if (getNodeText(sourceFile, node).indexOf(typeName) >= 0) {
- result = node;
- return true /*stop*/;
- }
- return false /*continue*/;
- });
- if (result === null) {
- console.log('COULD NOT FIND ' + typeName + '!');
- }
- return result;
-}
-function getNodeText(sourceFile, node) {
- return sourceFile.getFullText().substring(node.pos, node.end);
-}
-function getMassagedTopLevelDeclarationText(sourceFile, declaration) {
- var result = getNodeText(sourceFile, declaration);
- // if (result.indexOf('MonacoWorker') >= 0) {
- // console.log('here!');
- // // console.log(ts.SyntaxKind[declaration.kind]);
- // }
- if (declaration.kind === ts.SyntaxKind.InterfaceDeclaration || declaration.kind === ts.SyntaxKind.ClassDeclaration) {
- var interfaceDeclaration = declaration;
- var members = interfaceDeclaration.members;
- members.forEach(function (member) {
- try {
- var memberText = getNodeText(sourceFile, member);
- if (memberText.indexOf('@internal') >= 0 || memberText.indexOf('private') >= 0) {
- // console.log('BEFORE: ', result);
- result = result.replace(memberText, '');
- }
- }
- catch (err) {
- }
- });
- }
- result = result.replace(/export default/g, 'export');
- result = result.replace(/export declare/g, 'export');
- 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,
- };
- }
-}
-function createReplacer(data) {
- data = data || '';
- var rawDirectives = data.split(';');
- var directives = [];
- rawDirectives.forEach(function (rawDirective) {
- if (rawDirective.length === 0) {
- return;
- }
- var pieces = rawDirective.split('=>');
- var findStr = pieces[0];
- var replaceStr = pieces[1];
- findStr = findStr.replace(/[\-\\\{\}\*\+\?\|\^\$\.\,\[\]\(\)\#\s]/g, '\\$&');
- findStr = '\\b' + findStr + '\\b';
- directives.push([new RegExp(findStr, 'g'), replaceStr]);
- });
- return function (str) {
- for (var i = 0; i < directives.length; i++) {
- str = str.replace(directives[i][0], directives[i][1]);
- }
- return str;
- };
-}
-function generateDeclarationFile(recipe) {
- var lines = recipe.split(/\r\n|\n|\r/);
- var result = [];
- lines.forEach(function (line) {
- var m1 = line.match(/^\s*#include\(([^;)]*)(;[^)]*)?\)\:(.*)$/);
- if (m1) {
- console.log('HANDLING META: ' + line);
- var moduleId = m1[1];
- var sourceFile_1 = getSourceFile(moduleId);
- var replacer_1 = createReplacer(m1[2]);
- var typeNames = m1[3].split(/,/);
- typeNames.forEach(function (typeName) {
- typeName = typeName.trim();
- if (typeName.length === 0) {
- return;
- }
- var declaration = getTopLevelDeclaration(sourceFile_1, typeName);
- result.push(replacer_1(getMassagedTopLevelDeclarationText(sourceFile_1, declaration)));
- });
- return;
- }
- var m2 = line.match(/^\s*#includeAll\(([^;)]*)(;[^)]*)?\)\:(.*)$/);
- if (m2) {
- console.log('HANDLING META: ' + line);
- var moduleId = m2[1];
- var sourceFile_2 = getSourceFile(moduleId);
- var replacer_2 = createReplacer(m2[2]);
- var typeNames = m2[3].split(/,/);
- var typesToExcludeMap_1 = {};
- var typesToExcludeArr_1 = [];
- typeNames.forEach(function (typeName) {
- typeName = typeName.trim();
- if (typeName.length === 0) {
- return;
- }
- typesToExcludeMap_1[typeName] = true;
- typesToExcludeArr_1.push(typeName);
- });
- getAllTopLevelDeclarations(sourceFile_2).forEach(function (declaration) {
- if (isDeclaration(declaration)) {
- if (typesToExcludeMap_1[declaration.name.text]) {
- return;
- }
- }
- else {
- // node is ts.VariableStatement
- var nodeText = getNodeText(sourceFile_2, declaration);
- for (var i = 0; i < typesToExcludeArr_1.length; i++) {
- if (nodeText.indexOf(typesToExcludeArr_1[i]) >= 0) {
- return;
- }
- }
- }
- result.push(replacer_2(getMassagedTopLevelDeclarationText(sourceFile_2, declaration)));
- });
- return;
- }
- result.push(line);
- });
- var 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;
-}
-exports.generateDeclarationFile = generateDeclarationFile;
-var RECIPE_PATH = path.join(__dirname, './monaco.d.ts.recipe');
-var recipe = fs.readFileSync(RECIPE_PATH).toString();
-var result = generateDeclarationFile(recipe);
-var DECLARATION_PATH = path.join(__dirname, '../../src/vs/monaco.d.ts');
-fs.writeFileSync(DECLARATION_PATH, result);
+/*---------------------------------------------------------------------------------------------
+ * Copyright (c) Microsoft Corporation. All rights reserved.
+ * Licensed under the MIT License. See License.txt in the project root for license information.
+ *--------------------------------------------------------------------------------------------*/
+"use strict";
+var fs = require('fs');
+var ts = require('typescript');
+var path = require('path');
+var util = require('gulp-util');
+function log(message) {
+ var rest = [];
+ for (var _i = 1; _i < arguments.length; _i++) {
+ rest[_i - 1] = arguments[_i];
+ }
+ util.log.apply(util, [util.colors.cyan('[monaco.d.ts]'), message].concat(rest));
+}
+var SRC = path.join(__dirname, '../../src');
+var OUT_ROOT = path.join(__dirname, '../../');
+var RECIPE_PATH = path.join(__dirname, './monaco.d.ts.recipe');
+var DECLARATION_PATH = path.join(__dirname, '../../src/vs/monaco.d.ts');
+var CURRENT_PROCESSING_RULE = '';
+function logErr(message) {
+ var rest = [];
+ for (var _i = 1; _i < arguments.length; _i++) {
+ rest[_i - 1] = arguments[_i];
+ }
+ util.log(util.colors.red('[monaco.d.ts]'), 'WHILE HANDLING RULE: ', CURRENT_PROCESSING_RULE);
+ util.log.apply(util, [util.colors.red('[monaco.d.ts]'), message].concat(rest));
+}
+function moduleIdToPath(out, moduleId) {
+ if (/\.d\.ts/.test(moduleId)) {
+ return path.join(SRC, moduleId);
+ }
+ return path.join(OUT_ROOT, out, moduleId) + '.d.ts';
+}
+var SOURCE_FILE_MAP = {};
+function getSourceFile(out, moduleId) {
+ if (!SOURCE_FILE_MAP[moduleId]) {
+ var filePath = moduleIdToPath(out, moduleId);
+ var fileContents = void 0;
+ try {
+ fileContents = fs.readFileSync(filePath).toString();
+ }
+ catch (err) {
+ logErr('CANNOT FIND FILE ' + filePath);
+ return null;
+ }
+ var sourceFile = ts.createSourceFile(filePath, fileContents, ts.ScriptTarget.ES5);
+ SOURCE_FILE_MAP[moduleId] = sourceFile;
+ }
+ return SOURCE_FILE_MAP[moduleId];
+}
+function isDeclaration(a) {
+ return (a.kind === ts.SyntaxKind.InterfaceDeclaration
+ || a.kind === ts.SyntaxKind.EnumDeclaration
+ || a.kind === ts.SyntaxKind.ClassDeclaration
+ || a.kind === ts.SyntaxKind.TypeAliasDeclaration
+ || a.kind === ts.SyntaxKind.FunctionDeclaration
+ || a.kind === ts.SyntaxKind.ModuleDeclaration);
+}
+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:
+ case ts.SyntaxKind.VariableStatement:
+ case ts.SyntaxKind.TypeAliasDeclaration:
+ case ts.SyntaxKind.FunctionDeclaration:
+ case ts.SyntaxKind.ModuleDeclaration:
+ stop = visitor(node);
+ }
+ // if (node.kind !== ts.SyntaxKind.SourceFile) {
+ // if (getNodeText(sourceFile, node).indexOf('SymbolKind') >= 0) {
+ // console.log('FOUND TEXT IN NODE: ' + ts.SyntaxKind[node.kind]);
+ // console.log(getNodeText(sourceFile, node));
+ // }
+ // }
+ if (stop) {
+ return;
+ }
+ ts.forEachChild(node, visit);
+ };
+ visit(sourceFile);
+}
+function getAllTopLevelDeclarations(sourceFile) {
+ var all = [];
+ visitTopLevelDeclarations(sourceFile, function (node) {
+ if (node.kind === ts.SyntaxKind.InterfaceDeclaration || node.kind === ts.SyntaxKind.ClassDeclaration || node.kind === ts.SyntaxKind.ModuleDeclaration) {
+ var interfaceDeclaration = node;
+ var triviaStart = interfaceDeclaration.pos;
+ var triviaEnd = interfaceDeclaration.name.pos;
+ var triviaText = getNodeText(sourceFile, { pos: triviaStart, end: triviaEnd });
+ // // let nodeText = getNodeText(sourceFile, node);
+ // if (getNodeText(sourceFile, node).indexOf('SymbolKind') >= 0) {
+ // console.log('TRIVIA: ', triviaText);
+ // }
+ if (triviaText.indexOf('@internal') === -1) {
+ all.push(node);
+ }
+ }
+ else {
+ var nodeText = getNodeText(sourceFile, node);
+ if (nodeText.indexOf('@internal') === -1) {
+ all.push(node);
+ }
+ }
+ return false /*continue*/;
+ });
+ return all;
+}
+function getTopLevelDeclaration(sourceFile, typeName) {
+ var result = null;
+ visitTopLevelDeclarations(sourceFile, function (node) {
+ if (isDeclaration(node)) {
+ if (node.name.text === typeName) {
+ result = node;
+ return true /*stop*/;
+ }
+ return false /*continue*/;
+ }
+ // node is ts.VariableStatement
+ if (getNodeText(sourceFile, node).indexOf(typeName) >= 0) {
+ 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);
+ // if (result.indexOf('MonacoWorker') >= 0) {
+ // console.log('here!');
+ // // console.log(ts.SyntaxKind[declaration.kind]);
+ // }
+ if (declaration.kind === ts.SyntaxKind.InterfaceDeclaration || declaration.kind === ts.SyntaxKind.ClassDeclaration) {
+ var interfaceDeclaration = declaration;
+ var members = interfaceDeclaration.members;
+ members.forEach(function (member) {
+ try {
+ var memberText = getNodeText(sourceFile, member);
+ if (memberText.indexOf('@internal') >= 0 || memberText.indexOf('private') >= 0) {
+ // console.log('BEFORE: ', result);
+ result = result.replace(memberText, '');
+ }
+ }
+ catch (err) {
+ }
+ });
+ }
+ result = result.replace(/export default/g, 'export');
+ result = result.replace(/export declare/g, 'export');
+ 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
+ };
+ }
+}
+function createReplacer(data) {
+ data = data || '';
+ var rawDirectives = data.split(';');
+ var directives = [];
+ rawDirectives.forEach(function (rawDirective) {
+ if (rawDirective.length === 0) {
+ return;
+ }
+ var pieces = rawDirective.split('=>');
+ var findStr = pieces[0];
+ var replaceStr = pieces[1];
+ findStr = findStr.replace(/[\-\\\{\}\*\+\?\|\^\$\.\,\[\]\(\)\#\s]/g, '\\$&');
+ findStr = '\\b' + findStr + '\\b';
+ directives.push([new RegExp(findStr, 'g'), replaceStr]);
+ });
+ return function (str) {
+ for (var i = 0; i < directives.length; i++) {
+ str = str.replace(directives[i][0], directives[i][1]);
+ }
+ return str;
+ };
+}
+function generateDeclarationFile(out, recipe) {
+ var lines = recipe.split(/\r\n|\n|\r/);
+ var result = [];
+ lines.forEach(function (line) {
+ var m1 = line.match(/^\s*#include\(([^;)]*)(;[^)]*)?\)\:(.*)$/);
+ if (m1) {
+ CURRENT_PROCESSING_RULE = line;
+ var moduleId = m1[1];
+ var sourceFile_1 = getSourceFile(out, moduleId);
+ if (!sourceFile_1) {
+ return;
+ }
+ var replacer_1 = createReplacer(m1[2]);
+ var typeNames = m1[3].split(/,/);
+ typeNames.forEach(function (typeName) {
+ typeName = typeName.trim();
+ if (typeName.length === 0) {
+ return;
+ }
+ var declaration = getTopLevelDeclaration(sourceFile_1, typeName);
+ if (!declaration) {
+ logErr('Cannot find type ' + typeName);
+ return;
+ }
+ result.push(replacer_1(getMassagedTopLevelDeclarationText(sourceFile_1, declaration)));
+ });
+ return;
+ }
+ var m2 = line.match(/^\s*#includeAll\(([^;)]*)(;[^)]*)?\)\:(.*)$/);
+ if (m2) {
+ CURRENT_PROCESSING_RULE = line;
+ var moduleId = m2[1];
+ var sourceFile_2 = getSourceFile(out, moduleId);
+ if (!sourceFile_2) {
+ return;
+ }
+ var replacer_2 = createReplacer(m2[2]);
+ var typeNames = m2[3].split(/,/);
+ var typesToExcludeMap_1 = {};
+ var typesToExcludeArr_1 = [];
+ typeNames.forEach(function (typeName) {
+ typeName = typeName.trim();
+ if (typeName.length === 0) {
+ return;
+ }
+ typesToExcludeMap_1[typeName] = true;
+ typesToExcludeArr_1.push(typeName);
+ });
+ getAllTopLevelDeclarations(sourceFile_2).forEach(function (declaration) {
+ if (isDeclaration(declaration)) {
+ if (typesToExcludeMap_1[declaration.name.text]) {
+ return;
+ }
+ }
+ else {
+ // node is ts.VariableStatement
+ var nodeText = getNodeText(sourceFile_2, declaration);
+ for (var i = 0; i < typesToExcludeArr_1.length; i++) {
+ if (nodeText.indexOf(typesToExcludeArr_1[i]) >= 0) {
+ return;
+ }
+ }
+ }
+ result.push(replacer_2(getMassagedTopLevelDeclarationText(sourceFile_2, declaration)));
+ });
+ return;
+ }
+ result.push(line);
+ });
+ var 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;
+}
+function getFilesToWatch(out) {
+ var recipe = fs.readFileSync(RECIPE_PATH).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];
+ result.push(moduleIdToPath(out, moduleId));
+ return;
+ }
+ var m2 = line.match(/^\s*#includeAll\(([^;)]*)(;[^)]*)?\)\:(.*)$/);
+ if (m2) {
+ var moduleId = m2[1];
+ result.push(moduleIdToPath(out, moduleId));
+ return;
+ }
+ });
+ return result;
+}
+exports.getFilesToWatch = getFilesToWatch;
+function run(out) {
+ log('Starting monaco.d.ts generation');
+ SOURCE_FILE_MAP = {};
+ var recipe = fs.readFileSync(RECIPE_PATH).toString();
+ var result = generateDeclarationFile(out, recipe);
+ var currentContent = fs.readFileSync(DECLARATION_PATH).toString();
+ log('Finished monaco.d.ts generation');
+ return {
+ content: result,
+ filePath: DECLARATION_PATH,
+ isTheSame: currentContent === result
+ };
+}
+exports.run = run;
diff --git a/build/monaco/api.ts b/build/monaco/api.ts
index 46a70018deb..44e619e8588 100644
--- a/build/monaco/api.ts
+++ b/build/monaco/api.ts
@@ -3,40 +3,44 @@
* 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');
+var util = require('gulp-util');
+function log(message: any, ...rest: any[]): void {
+ util.log(util.colors.cyan('[monaco.d.ts]'), message, ...rest);
+}
const SRC = path.join(__dirname, '../../src');
-const OUT = path.join(__dirname, '../../out');
+const OUT_ROOT = path.join(__dirname, '../../');
+const RECIPE_PATH = path.join(__dirname, './monaco.d.ts.recipe');
+const DECLARATION_PATH = path.join(__dirname, '../../src/vs/monaco.d.ts');
+var CURRENT_PROCESSING_RULE = '';
+function logErr(message: any, ...rest: any[]): void {
+ util.log(util.colors.red('[monaco.d.ts]'), 'WHILE HANDLING RULE: ', CURRENT_PROCESSING_RULE);
+ util.log(util.colors.red('[monaco.d.ts]'), message, ...rest);
+}
-function moduleIdToPath(moduleId:string): string {
+function moduleIdToPath(out:string, moduleId:string): string {
if (/\.d\.ts/.test(moduleId)) {
return path.join(SRC, moduleId);
}
- return path.join(OUT, moduleId) + '.d.ts';
+ return path.join(OUT_ROOT, out, moduleId) + '.d.ts';
}
-
let SOURCE_FILE_MAP: {[moduleId:string]:ts.SourceFile;} = {};
-function getSourceFile(moduleId:string): ts.SourceFile {
+function getSourceFile(out:string, moduleId:string): ts.SourceFile {
if (!SOURCE_FILE_MAP[moduleId]) {
- let filePath = moduleIdToPath(moduleId);
+ let filePath = moduleIdToPath(out, moduleId);
let fileContents: string;
try {
fileContents = fs.readFileSync(filePath).toString();
} catch (err) {
- console.error('=========================================================================');
- console.error('=> Have you compiled with env variable VSCODE_BUILD_DECLARATION_FILES=1 ?');
- console.error('=========================================================================');
- throw err;
+ logErr('CANNOT FIND FILE ' + filePath);
+ return null;
}
let sourceFile = ts.createSourceFile(filePath, fileContents, ts.ScriptTarget.ES5);
@@ -142,9 +146,6 @@ function getTopLevelDeclaration(sourceFile:ts.SourceFile, typeName:string): TSTo
}
return false /*continue*/;
});
- if (result === null) {
- console.log('COULD NOT FIND ' + typeName + '!');
- }
return result;
}
@@ -261,7 +262,7 @@ function createReplacer(data:string): (str:string)=>string {
};
}
-export function generateDeclarationFile(recipe:string): string {
+function generateDeclarationFile(out:string, recipe:string): string {
let lines = recipe.split(/\r\n|\n|\r/);
let result = [];
@@ -270,9 +271,12 @@ export function generateDeclarationFile(recipe:string): string {
let m1 = line.match(/^\s*#include\(([^;)]*)(;[^)]*)?\)\:(.*)$/);
if (m1) {
- console.log('HANDLING META: ' + line);
+ CURRENT_PROCESSING_RULE = line;
let moduleId = m1[1];
- let sourceFile = getSourceFile(moduleId);
+ let sourceFile = getSourceFile(out, moduleId);
+ if (!sourceFile) {
+ return;
+ }
let replacer = createReplacer(m1[2]);
@@ -283,6 +287,10 @@ export function generateDeclarationFile(recipe:string): string {
return;
}
let declaration = getTopLevelDeclaration(sourceFile, typeName);
+ if (!declaration) {
+ logErr('Cannot find type ' + typeName);
+ return;
+ }
result.push(replacer(getMassagedTopLevelDeclarationText(sourceFile, declaration)));
});
return;
@@ -290,9 +298,12 @@ export function generateDeclarationFile(recipe:string): string {
let m2 = line.match(/^\s*#includeAll\(([^;)]*)(;[^)]*)?\)\:(.*)$/);
if (m2) {
- console.log('HANDLING META: ' + line);
+ CURRENT_PROCESSING_RULE = line;
let moduleId = m2[1];
- let sourceFile = getSourceFile(moduleId);
+ let sourceFile = getSourceFile(out, moduleId);
+ if (!sourceFile) {
+ return;
+ }
let replacer = createReplacer(m2[2]);
@@ -341,9 +352,50 @@ export function generateDeclarationFile(recipe:string): string {
return resultTxt;
}
-const RECIPE_PATH = path.join(__dirname, './monaco.d.ts.recipe');
-let recipe = fs.readFileSync(RECIPE_PATH).toString();
-let result = generateDeclarationFile(recipe);
+export function getFilesToWatch(out:string): string[] {
+ let recipe = fs.readFileSync(RECIPE_PATH).toString();
+ let lines = recipe.split(/\r\n|\n|\r/);
+ let result = [];
-const DECLARATION_PATH = path.join(__dirname, '../../src/vs/monaco.d.ts');
-fs.writeFileSync(DECLARATION_PATH, result);
+ lines.forEach(line => {
+
+ let m1 = line.match(/^\s*#include\(([^;)]*)(;[^)]*)?\)\:(.*)$/);
+ if (m1) {
+ let moduleId = m1[1];
+ result.push(moduleIdToPath(out, moduleId));
+ return;
+ }
+
+ let m2 = line.match(/^\s*#includeAll\(([^;)]*)(;[^)]*)?\)\:(.*)$/);
+ if (m2) {
+ let moduleId = m2[1];
+ result.push(moduleIdToPath(out, moduleId));
+ return;
+ }
+ });
+
+ return result;
+}
+
+export interface IMonacoDeclarationResult {
+ content: string;
+ filePath: string;
+ isTheSame: boolean;
+}
+
+export function run(out:string): IMonacoDeclarationResult {
+ log('Starting monaco.d.ts generation');
+ SOURCE_FILE_MAP = {};
+
+ let recipe = fs.readFileSync(RECIPE_PATH).toString();
+ let result = generateDeclarationFile(out, recipe);
+
+ let currentContent = fs.readFileSync(DECLARATION_PATH).toString();
+ log('Finished monaco.d.ts generation');
+
+ return {
+ content: result,
+ filePath: DECLARATION_PATH,
+ isTheSame: currentContent === result
+ };
+}
diff --git a/gulpfile.js b/gulpfile.js
index 571ef7bfbe1..3b3a997c746 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -25,12 +25,13 @@ var sourcemaps = require('gulp-sourcemaps');
var _ = require('underscore');
var assign = require('object-assign');
var quiet = !!process.env['VSCODE_BUILD_QUIET'];
-var declaration = !!process.env['VSCODE_BUILD_DECLARATION_FILES'];
+var monacodts = require('./build/monaco/api');
+var fs = require('fs');
var rootDir = path.join(__dirname, 'src');
var tsOptions = {
target: 'ES5',
- declaration: declaration,
+ declaration: true,
module: 'amd',
verbose: !quiet,
preserveConstEnums: true,
@@ -50,9 +51,8 @@ function createCompile(build, emitError) {
return function (token) {
var utf8Filter = filter('**/test/**/*utf8*', { restore: true });
- var tsFilter = filter([
- '**/*.ts'
- ], { restore: true });
+ var tsFilter = filter(['**/*.ts'], { restore: true });
+ var noDeclarationsFilter = filter(['**/*', '!**/*.d.ts'], { restore: true });
var input = es.through();
var output = input
@@ -62,7 +62,9 @@ function createCompile(build, emitError) {
.pipe(tsFilter)
.pipe(util.loadSourcemaps())
.pipe(ts(token))
+ .pipe(noDeclarationsFilter)
.pipe(build ? nls() : es.through())
+ .pipe(noDeclarationsFilter.restore)
.pipe(sourcemaps.write('.', {
addComment: false,
includeContent: !!build,
@@ -83,7 +85,8 @@ function compileTask(out, build) {
return src
.pipe(compile())
- .pipe(gulp.dest(out));
+ .pipe(gulp.dest(out))
+ .pipe(monacodtsTask(out, false));
};
}
@@ -96,10 +99,66 @@ function watchTask(out, build) {
return watchSrc
.pipe(util.incremental(compile, src, true))
- .pipe(gulp.dest(out));
+ .pipe(gulp.dest(out))
+ .pipe(monacodtsTask(out, true));
};
}
+function monacodtsTask(out, isWatch) {
+
+ var filesToWatchMap = {};
+ monacodts.getFilesToWatch(out).forEach(function(filePath) {
+ filesToWatchMap[path.normalize(filePath)] = true;
+ });
+
+ var timer = -1;
+
+ var runSoon = function(howSoon) {
+ if (timer !== -1) {
+ clearTimeout(timer);
+ timer = -1;
+ }
+ timer = setTimeout(function() {
+ timer = -1;
+ runNow();
+ }, howSoon);
+ };
+
+ var runNow = function() {
+ if (timer !== -1) {
+ clearTimeout(timer);
+ timer = -1;
+ }
+ var result = monacodts.run(out);
+ if (!result.isTheSame) {
+ if (isWatch) {
+ fs.writeFileSync(result.filePath, result.content);
+ } else {
+ resultStream.emit('error', 'monaco.d.ts is no longer up to date. Please run gulp watch and commit the new file.');
+ }
+ }
+ };
+
+ if (isWatch) {
+ watch('build/monaco/*').pipe(es.through(function() {
+ runSoon(500);
+ }));
+ }
+
+ var resultStream = es.through(function(data) {
+ var filePath = path.normalize(data.path);
+ if (filesToWatchMap[filePath]) {
+ runSoon(5000);
+ }
+ this.emit('data', data);
+ }, function(end) {
+ runNow();
+ this.emit('end');
+ });
+
+ return resultStream;
+}
+
// Fast compile for development time
gulp.task('clean-client', util.rimraf('out'));
gulp.task('compile-client', ['clean-client'], compileTask('out', false));
diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts
index fce53070a08..ee23f09bc72 100644
--- a/src/vs/monaco.d.ts
+++ b/src/vs/monaco.d.ts
@@ -1271,6 +1271,14 @@ declare module monaco.editor {
* to have a background color decoration.
*/
inlineClassName?: string;
+ /**
+ * If set, the decoration will be rendered before the text with this CSS class name.
+ */
+ beforeContentClassName?: string;
+ /**
+ * If set, the decoration will be rendered after the text with this CSS class name.
+ */
+ afterContentClassName?: string;
}
/**
@@ -2677,6 +2685,28 @@ declare module monaco.editor {
restoreViewState?(state: any): void;
}
+ export interface IContentDecorationRenderOptions {
+ contentText?: string;
+ contentIconPath?: string;
+ border?: string;
+ textDecoration?: string;
+ color?: string;
+ backgroundColor?: string;
+ margin?: string;
+ width?: string;
+ height?: string;
+ }
+
+ export interface IThemeDecorationInstanceRenderOptions {
+ before?: IContentDecorationRenderOptions;
+ after?: IContentDecorationRenderOptions;
+ }
+
+ export interface IDecorationInstanceRenderOptions extends IThemeDecorationInstanceRenderOptions {
+ light?: IThemeDecorationInstanceRenderOptions;
+ dark?: IThemeDecorationInstanceRenderOptions;
+ }
+
export interface ICommonCodeEditor extends IEditor {
onDidChangeModel(listener: (e: IModelChangedEvent) => void): IDisposable;
onDidChangeModelDecorations(listener: (e: IModelDecorationsChangedEvent) => void): IDisposable;