diff --git a/scripts/importTypescript.js b/scripts/importTypescript.js index cade4cb2..d1e42d22 100644 --- a/scripts/importTypescript.js +++ b/scripts/importTypescript.js @@ -19,7 +19,7 @@ const TYPESCRIPT_LIB_DESTINATION = path.join(__dirname, '../src/lib'); importLibs(); const npmLsOutput = JSON.parse(child_process.execSync("npm ls typescript --depth=0 --json=true").toString()); - const typeScriptDependencyVersion = npmLsOutput.dependencies.typescript.version; + const typeScriptDependencyVersion = '3.5.1';//npmLsOutput.dependencies.typescript.version; fs.writeFileSync( path.join(TYPESCRIPT_LIB_DESTINATION, 'typescriptServicesMetadata.ts'), @@ -34,10 +34,22 @@ const TYPESCRIPT_LIB_DESTINATION = path.join(__dirname, '../src/lib'); tsServices.replace(/\n ts\.sys =([^]*)\n \}\)\(\);/m, `\n // MONACOCHANGE\n ts.sys = undefined;\n // END MONACOCHANGE`) ); - // Eliminate another require() call... - tsServices = ( - tsServices.replace(/return require\(fileNameToRequire\);/, `// MONACOCHANGE\n return undefined;\n // END MONACOCHANGE`) - ); + // Eliminate more require() calls... + tsServices = tsServices.replace(/^( +)etwModule = require\(.*$/m, '$1// MONACOCHANGE\n$1etwModule = undefined;\n$1// END MONACOCHANGE'); + tsServices = tsServices.replace(/^( +)var result = ts\.sys\.require\(.*$/m, '$1// MONACOCHANGE\n$1var result = undefined;\n$1// END MONACOCHANGE'); + + // Flag any new require calls (outside comments) so they can be corrected preemptively. + // To avoid missing cases (or using an even more complex regex), temporarily remove comments + // about require() and then check for lines actually calling require(). + // \/[*/] matches the start of a comment (single or multi-line). + // ^\s+\*[^/] matches (presumably) a later line of a multi-line comment. + const tsServicesNoCommentedRequire = tsServices.replace(/(\/[*/]|^\s+\*[^/]).*\brequire\(.*/gm, ''); + const linesWithRequire = tsServicesNoCommentedRequire.match(/^.*?\brequire\(.*$/gm); + if (linesWithRequire && linesWithRequire.length) { + console.error('Found new require() calls on the following lines. These should be removed to avoid breaking webpack builds.\n'); + console.error(linesWithRequire.join('\n')); + process.exit(1); + } // Make sure process.args don't get called in the browser, this // should only happen in TS 2.6.2 diff --git a/src/languageFeatures.ts b/src/languageFeatures.ts index 7dc0d1de..da5e4207 100644 --- a/src/languageFeatures.ts +++ b/src/languageFeatures.ts @@ -181,6 +181,7 @@ export class DiagnosticsAdapter extends Adapter { } const markers = diagnostics .reduce((p, c) => c.concat(p), []) + .filter(d => (this._defaults.getDiagnosticsOptions().diagnosticCodesToIgnore || []).indexOf(d.code) === -1) .map(d => this._convertDiagnostics(resource, d)); monaco.editor.setModelMarkers(monaco.editor.getModel(resource), this._selector, markers); @@ -200,10 +201,32 @@ export class DiagnosticsAdapter extends Adapter { endLineNumber, endColumn, message: flattenDiagnosticMessageText(diag.messageText, '\n'), - code: diag.code.toString() + code: diag.code.toString(), + tags: diag.reportsUnnecessary ? [monaco.MarkerTag.Unnecessary] : [], + relatedInformation: this._convertRelatedInformation(resource, diag.relatedInformation), }; } + private _convertRelatedInformation(resource: Uri, relatedInformation?: ts.DiagnosticRelatedInformation[]): monaco.editor.IRelatedInformation[] { + if (relatedInformation === undefined) + return undefined; + + return relatedInformation.map(info => { + const relatedResource = info.file === undefined ? resource : monaco.Uri.parse(info.file.fileName); + const { lineNumber: startLineNumber, column: startColumn } = this._offsetToPosition(relatedResource, info.start); + const { lineNumber: endLineNumber, column: endColumn } = this._offsetToPosition(relatedResource, info.start + info.length); + + return { + resource: relatedResource, + startLineNumber, + startColumn, + endLineNumber, + endColumn, + message: flattenDiagnosticMessageText(info.messageText, '\n') + }; + }); + } + private _tsDiagnosticCategoryToMarkerSeverity(category: ts.DiagnosticCategory): monaco.MarkerSeverity { switch (category) { case ts.DiagnosticCategory.Error: return monaco.MarkerSeverity.Error diff --git a/src/lib/typescriptServices-amd.js b/src/lib/typescriptServices-amd.js index f9b12bf1..8cbc099e 100644 --- a/src/lib/typescriptServices-amd.js +++ b/src/lib/typescriptServices-amd.js @@ -2349,7 +2349,9 @@ var ts; try { if (ts.sys && ts.sys.require) { var basePath = ts.getDirectoryPath(ts.resolvePath(ts.sys.getExecutingFilePath())); - var result = ts.sys.require(basePath, "./compiler-debug"); + // MONACOCHANGE + var result = undefined; + // END MONACOCHANGE if (!result.error) { result.module.init(ts); extendedDebugModule = result.module; @@ -2515,7 +2517,9 @@ var ts; try { // require() will throw an exception if the module is not installed // It may also return undefined if not installed properly - etwModule = require("@microsoft/typescript-etw"); + // MONACOCHANGE + etwModule = undefined; + // END MONACOCHANGE } catch (e) { etwModule = undefined; diff --git a/src/lib/typescriptServices.js b/src/lib/typescriptServices.js index ce4e12a9..47543b59 100644 --- a/src/lib/typescriptServices.js +++ b/src/lib/typescriptServices.js @@ -2349,7 +2349,9 @@ var ts; try { if (ts.sys && ts.sys.require) { var basePath = ts.getDirectoryPath(ts.resolvePath(ts.sys.getExecutingFilePath())); - var result = ts.sys.require(basePath, "./compiler-debug"); + // MONACOCHANGE + var result = undefined; + // END MONACOCHANGE if (!result.error) { result.module.init(ts); extendedDebugModule = result.module; @@ -2515,7 +2517,9 @@ var ts; try { // require() will throw an exception if the module is not installed // It may also return undefined if not installed properly - etwModule = require("@microsoft/typescript-etw"); + // MONACOCHANGE + etwModule = undefined; + // END MONACOCHANGE } catch (e) { etwModule = undefined; diff --git a/src/lib/typescriptServicesMetadata.ts b/src/lib/typescriptServicesMetadata.ts index c2d37d7c..433e642e 100644 --- a/src/lib/typescriptServicesMetadata.ts +++ b/src/lib/typescriptServicesMetadata.ts @@ -1 +1 @@ -export const typescriptVersion = "3.7.2"; +export const typescriptVersion = "3.5.1"; diff --git a/src/monaco.d.ts b/src/monaco.d.ts index 8aa58804..7d50e7ab 100644 --- a/src/monaco.d.ts +++ b/src/monaco.d.ts @@ -129,6 +129,7 @@ declare module monaco.languages.typescript { noSemanticValidation?: boolean; noSyntaxValidation?: boolean; noSuggestionDiagnostics?: boolean; + diagnosticCodesToIgnore?: number[]; } export interface LanguageServiceDefaults { diff --git a/src/tsconfig.esm.json b/src/tsconfig.esm.json index 6efc6a00..d6085367 100644 --- a/src/tsconfig.esm.json +++ b/src/tsconfig.esm.json @@ -2,6 +2,7 @@ "compilerOptions": { "module": "esnext", "moduleResolution": "node", + "declaration": true, "outDir": "../release/esm", "target": "es5", "lib": [ diff --git a/src/tsconfig.json b/src/tsconfig.json index 778087ca..2dbccb11 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -3,6 +3,7 @@ "module": "amd", "moduleResolution": "node", "outDir": "../release/dev", + "declaration": true, "target": "es5", "lib": [ "dom",