diff --git a/build/lib/compilation.js b/build/lib/compilation.js index fb311e14a01eead7c874bc44fdb5ac7a65316e97..c1a4fac020cd4fdaecc02d2f592c977475c4e407 100644 --- a/build/lib/compilation.js +++ b/build/lib/compilation.js @@ -89,7 +89,6 @@ function compileTask(src, out, build) { .pipe(generator.stream) .pipe(compile()) .pipe(gulp.dest(out)); - // .pipe(src !== 'src' ? es.through() : monacodtsTask(out, false)); }; } exports.compileTask = compileTask; diff --git a/build/lib/compilation.ts b/build/lib/compilation.ts index 30d03c069cb0dbd0779ebe6e06231df5a668c21c..936cf40f682b0d25fbaa253261bd7831383b930d 100644 --- a/build/lib/compilation.ts +++ b/build/lib/compilation.ts @@ -106,7 +106,6 @@ export function compileTask(src: string, out: string, build: boolean): () => Nod .pipe(generator.stream) .pipe(compile()) .pipe(gulp.dest(out)); - // .pipe(src !== 'src' ? es.through() : monacodtsTask(out, false)); }; } diff --git a/build/monaco/api.js b/build/monaco/api.js index 8b1319690814ab3eff56ffe6886c3b44c5c9cbe2..7bf66ac5d7de54de507efe80ff9d7370c0edf1a3 100644 --- a/build/monaco/api.js +++ b/build/monaco/api.js @@ -162,13 +162,109 @@ function getMassagedTopLevelDeclarationText(sourceFile, declaration, importName, result = result.replace(/export declare/g, 'export'); return result; } -function format(text) { +function format(text, endl) { + const REALLY_FORMAT = false; + text = preformat(text, endl); + if (!REALLY_FORMAT) { + return text; + } // 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 = ts.formatting.formatDocument(sourceFile, getRuleProvider(tsfmt), tsfmt); // Apply the edits on the input code return applyEdits(text, edits); + function countParensCurly(text) { + let cnt = 0; + for (let i = 0; i < text.length; i++) { + if (text.charAt(i) === '(' || text.charAt(i) === '{') { + cnt++; + } + if (text.charAt(i) === ')' || text.charAt(i) === '}') { + cnt--; + } + } + return cnt; + } + function repeatStr(s, cnt) { + let r = ''; + for (let i = 0; i < cnt; i++) { + r += s; + } + return r; + } + function preformat(text, endl) { + let lines = text.split(endl); + let inComment = false; + let inCommentDeltaIndent = 0; + let indent = 0; + for (let i = 0; i < lines.length; i++) { + let line = lines[i].replace(/\s$/, ''); + let repeat = false; + let lineIndent = 0; + do { + repeat = false; + if (line.substring(0, 4) === ' ') { + line = line.substring(4); + lineIndent++; + repeat = true; + } + if (line.charAt(0) === '\t') { + line = line.substring(1); + lineIndent++; + repeat = true; + } + } while (repeat); + if (line.length === 0) { + continue; + } + if (inComment) { + if (/\*\//.test(line)) { + inComment = false; + } + lines[i] = repeatStr('\t', lineIndent + inCommentDeltaIndent) + line; + continue; + } + if (/\/\*/.test(line)) { + inComment = true; + inCommentDeltaIndent = indent - lineIndent; + lines[i] = repeatStr('\t', indent) + line; + continue; + } + const cnt = countParensCurly(line); + let shouldUnindentAfter = false; + let shouldUnindentBefore = false; + if (cnt < 0) { + if (/[({]/.test(line)) { + shouldUnindentAfter = true; + } + else { + shouldUnindentBefore = true; + } + } + else if (cnt === 0) { + shouldUnindentBefore = /^\}/.test(line); + } + let shouldIndentAfter = false; + if (cnt > 0) { + shouldIndentAfter = true; + } + else if (cnt === 0) { + shouldIndentAfter = /{$/.test(line); + } + if (shouldUnindentBefore) { + indent--; + } + lines[i] = repeatStr('\t', indent) + line; + if (shouldUnindentAfter) { + indent--; + } + if (shouldIndentAfter) { + indent++; + } + } + return lines.join(endl); + } function getRuleProvider(options) { // Share this between multiple formatters using the same options. // This represents the bulk of the space the formatter uses. @@ -293,7 +389,7 @@ function generateDeclarationFile(recipe, sourceFileGetter) { let resultTxt = result.join(endl); resultTxt = resultTxt.replace(/\bURI\b/g, 'Uri'); resultTxt = resultTxt.replace(/\bEvent 0) { + shouldIndentAfter = true; + } else if (cnt === 0) { + shouldIndentAfter = /{$/.test(line); + } + + if (shouldUnindentBefore) { + indent--; + } + + lines[i] = repeatStr('\t', indent) + line; + + if (shouldUnindentAfter) { + indent--; + } + if (shouldIndentAfter) { + indent++; + } + } + return lines.join(endl); + } + function getRuleProvider(options: ts.FormatCodeSettings) { // Share this between multiple formatters using the same options. // This represents the bulk of the space the formatter uses. @@ -353,7 +457,7 @@ function generateDeclarationFile(recipe: string, sourceFileGetter: SourceFileGet resultTxt = resultTxt.replace(/\bURI\b/g, 'Uri'); resultTxt = resultTxt.replace(/\bEvent