From d5b5ce14f44b84cc6fa6017d6e6d009b80868fe0 Mon Sep 17 00:00:00 2001 From: Sebastian Pahnke Date: Mon, 7 Oct 2019 12:09:31 +0200 Subject: [PATCH 1/5] Add support to ignore certain diagnostics --- src/languageFeatures.ts | 1 + src/monaco.d.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/languageFeatures.ts b/src/languageFeatures.ts index 7dc0d1de..659b346c 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); 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 { From 933c7faef2f9ee4aae3788e6b268a8eb71ea0688 Mon Sep 17 00:00:00 2001 From: Sebastian Pahnke Date: Mon, 7 Oct 2019 13:37:40 +0200 Subject: [PATCH 2/5] Support diagnostics of type unnecessary --- src/languageFeatures.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/languageFeatures.ts b/src/languageFeatures.ts index 7dc0d1de..510fec79 100644 --- a/src/languageFeatures.ts +++ b/src/languageFeatures.ts @@ -200,7 +200,8 @@ 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] : [] }; } From 8b18d160dbd3a0c6ab9bb73504bc2872a00d2dad Mon Sep 17 00:00:00 2001 From: Sebastian Pahnke Date: Mon, 7 Oct 2019 14:33:21 +0200 Subject: [PATCH 3/5] Provide related information to diagnostics --- src/languageFeatures.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/languageFeatures.ts b/src/languageFeatures.ts index 7dc0d1de..1ea08991 100644 --- a/src/languageFeatures.ts +++ b/src/languageFeatures.ts @@ -200,10 +200,31 @@ export class DiagnosticsAdapter extends Adapter { endLineNumber, endColumn, message: flattenDiagnosticMessageText(diag.messageText, '\n'), - code: diag.code.toString() + code: diag.code.toString(), + 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 From 99f7b1185ccdb86ceb01e74b431b74f912fb89e9 Mon Sep 17 00:00:00 2001 From: Elizabeth Craig Date: Sat, 26 Oct 2019 00:29:21 -0700 Subject: [PATCH 4/5] Remove another require call --- scripts/importTypescript.js | 16 +++++++++++++++- src/lib/typescriptServices-amd.js | 4 +++- src/lib/typescriptServices.js | 4 +++- src/lib/typescriptServicesMetadata.ts | 2 +- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/scripts/importTypescript.js b/scripts/importTypescript.js index cade4cb2..85820b59 100644 --- a/scripts/importTypescript.js +++ b/scripts/importTypescript.js @@ -34,10 +34,24 @@ 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... + // Eliminate more require() calls... tsServices = ( tsServices.replace(/return require\(fileNameToRequire\);/, `// MONACOCHANGE\n return undefined;\n // END MONACOCHANGE`) ); + tsServices = tsServices.replace(/^( +)etwModule = require\(.*$/m, '$1// MONACOCHANGE\n$1etwModule = 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/lib/typescriptServices-amd.js b/src/lib/typescriptServices-amd.js index 3b949170..79c50264 100644 --- a/src/lib/typescriptServices-amd.js +++ b/src/lib/typescriptServices-amd.js @@ -2417,7 +2417,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"); // tslint:disable-line:no-implicit-dependencies + // MONACOCHANGE + etwModule = undefined; + // END MONACOCHANGE } catch (e) { etwModule = undefined; diff --git a/src/lib/typescriptServices.js b/src/lib/typescriptServices.js index 98b7558f..5c60255c 100644 --- a/src/lib/typescriptServices.js +++ b/src/lib/typescriptServices.js @@ -2417,7 +2417,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"); // tslint:disable-line:no-implicit-dependencies + // MONACOCHANGE + etwModule = undefined; + // END MONACOCHANGE } catch (e) { etwModule = undefined; diff --git a/src/lib/typescriptServicesMetadata.ts b/src/lib/typescriptServicesMetadata.ts index 433e642e..ce50d807 100644 --- a/src/lib/typescriptServicesMetadata.ts +++ b/src/lib/typescriptServicesMetadata.ts @@ -1 +1 @@ -export const typescriptVersion = "3.5.1"; +export const typescriptVersion = "3.6.2"; From a3a6f7981a46e381c5c7387a65fdf62fd27bad01 Mon Sep 17 00:00:00 2001 From: Elizabeth Craig Date: Sat, 26 Oct 2019 00:43:57 -0700 Subject: [PATCH 5/5] Generate and publish typings for package --- src/tsconfig.esm.json | 1 + src/tsconfig.json | 1 + 2 files changed, 2 insertions(+) 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",