Merge remote-tracking branch 'origin/main' into 4_3_dev

This commit is contained in:
Alex Dima 2021-06-03 17:22:37 +02:00
commit ebdc056429
No known key found for this signature in database
GPG key ID: 6E58D7B045760DA0
10 changed files with 166 additions and 57 deletions

41
SECURITY.md Normal file
View file

@ -0,0 +1,41 @@
<!-- BEGIN MICROSOFT SECURITY.MD V0.0.5 BLOCK -->
## Security
Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](<https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)>), please report it to us as described below.
## Reporting Security Issues
**Please do not report security vulnerabilities through public GitHub issues.**
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report).
If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc).
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
- Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
- Full paths of source file(s) related to the manifestation of the issue
- The location of the affected source code (tag/branch/commit or direct URL)
- Any special configuration required to reproduce the issue
- Step-by-step instructions to reproduce the issue
- Proof-of-concept or exploit code (if possible)
- Impact of the issue, including how an attacker might exploit the issue
This information will help us triage your report more quickly.
If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://microsoft.com/msrc/bounty) page for more details about our active programs.
## Preferred Languages
We prefer all communications to be in English.
## Policy
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd).
<!-- END MICROSOFT SECURITY.MD BLOCK -->

5
monaco.d.ts vendored
View file

@ -143,6 +143,11 @@ declare namespace monaco.languages.typescript {
noSemanticValidation?: boolean; noSemanticValidation?: boolean;
noSyntaxValidation?: boolean; noSyntaxValidation?: boolean;
noSuggestionDiagnostics?: boolean; noSuggestionDiagnostics?: boolean;
/**
* Limit diagnostic computation to only visible files.
* Defaults to false.
*/
onlyVisible?: boolean;
diagnosticCodesToIgnore?: number[]; diagnosticCodesToIgnore?: number[];
} }
export interface WorkerOptions { export interface WorkerOptions {

20
package-lock.json generated
View file

@ -1,6 +1,6 @@
{ {
"name": "monaco-typescript", "name": "monaco-typescript",
"version": "4.3.1", "version": "4.4.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -237,15 +237,15 @@
} }
}, },
"monaco-editor-core": { "monaco-editor-core": {
"version": "0.23.0", "version": "0.24.0",
"resolved": "https://registry.npmjs.org/monaco-editor-core/-/monaco-editor-core-0.23.0.tgz", "resolved": "https://registry.npmjs.org/monaco-editor-core/-/monaco-editor-core-0.24.0.tgz",
"integrity": "sha512-1LHVpCHp+FErFdUjwzal1muTe+hUkR5CfXAxzua//eHB31bHdWVe15OJPEPS3/rxmfQtl9wZqJdHi4FcGz2zog==", "integrity": "sha512-WJAzpNYEaJp8Z7crIAiLCVln1zZdo4cFXCRuhTDN4A3tz6IK2NOXAtTOZ9iLKBTtd6eitZJ2Q1Fx8JN8rN3fWw==",
"dev": true "dev": true
}, },
"monaco-languages": { "monaco-languages": {
"version": "2.3.0", "version": "2.4.0",
"resolved": "https://registry.npmjs.org/monaco-languages/-/monaco-languages-2.3.0.tgz", "resolved": "https://registry.npmjs.org/monaco-languages/-/monaco-languages-2.4.0.tgz",
"integrity": "sha512-gER/vKpIUH2kKhWEWRDojMuI6cm4S7Dl9jSYNFUfToOB8uIxoWSZUJCm2FH+ECnUZmnLs6O2fNONKQQ6JCoa/g==", "integrity": "sha512-63ZMAPgqBylS0kyC22QSKJWJmCRcwM7dWql1xtt9R7mCfzszfIIViSTiJ5vDSnzj0lH0aZh8OJggh/uZY6Vgnw==",
"dev": true "dev": true
}, },
"monaco-plugin-helpers": { "monaco-plugin-helpers": {
@ -461,9 +461,9 @@
} }
}, },
"typescript": { "typescript": {
"version": "4.2.3", "version": "4.2.4",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.3.tgz", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.4.tgz",
"integrity": "sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw==", "integrity": "sha512-V+evlYHZnQkaz8TRBuxTA92yZBPotr5H+WhQ7bD3hZUndx5tGOa1fuCgeSjxAzM1RiN5IzvadIXTVefuuwZCRg==",
"dev": true "dev": true
}, },
"which": { "which": {

View file

@ -1,6 +1,6 @@
{ {
"name": "monaco-typescript", "name": "monaco-typescript",
"version": "4.3.1", "version": "4.4.0",
"description": "TypeScript and JavaScript language support for Monaco Editor", "description": "TypeScript and JavaScript language support for Monaco Editor",
"scripts": { "scripts": {
"compile-amd": "mcopy ./src/lib/typescriptServices-amd.js ./out/amd/lib/typescriptServices.js && tsc -p ./src/tsconfig.json", "compile-amd": "mcopy ./src/lib/typescriptServices-amd.js ./out/amd/lib/typescriptServices.js && tsc -p ./src/tsconfig.json",
@ -25,14 +25,14 @@
"devDependencies": { "devDependencies": {
"@typescript/vfs": "^1.3.4", "@typescript/vfs": "^1.3.4",
"husky": "^5.1.3", "husky": "^5.1.3",
"monaco-editor-core": "^0.23.0", "monaco-editor-core": "^0.24.0",
"monaco-languages": "^2.3.0", "monaco-languages": "^2.4.0",
"monaco-plugin-helpers": "^1.0.3", "monaco-plugin-helpers": "^1.0.3",
"prettier": "^2.2.1", "prettier": "^2.2.1",
"pretty-quick": "^3.1.0", "pretty-quick": "^3.1.0",
"requirejs": "^2.3.6", "requirejs": "^2.3.6",
"terser": "^5.6.0", "terser": "^5.6.0",
"typescript": "^4.2.3" "typescript": "^4.2.4"
}, },
"husky": { "husky": {
"hooks": { "hooks": {

View file

@ -7,7 +7,8 @@
import { import {
Diagnostic, Diagnostic,
DiagnosticRelatedInformation, DiagnosticRelatedInformation,
LanguageServiceDefaults LanguageServiceDefaults,
typescriptDefaults
} from './monaco.contribution'; } from './monaco.contribution';
import type * as ts from './lib/typescriptServices'; import type * as ts from './lib/typescriptServices';
import type { TypeScriptWorker } from './tsWorker'; import type { TypeScriptWorker } from './tsWorker';
@ -163,6 +164,15 @@ enum DiagnosticCategory {
Message = 3 Message = 3
} }
/**
* temporary interface until the editor API exposes
* `IModel.isAttachedToEditor` and `IModel.onDidChangeAttached`
*/
interface IInternalEditorModel extends editor.IModel {
onDidChangeAttached(listener: () => void): IDisposable;
isAttachedToEditor(): boolean;
}
export class DiagnosticsAdapter extends Adapter { export class DiagnosticsAdapter extends Adapter {
private _disposables: IDisposable[] = []; private _disposables: IDisposable[] = [];
private _listener: { [uri: string]: IDisposable } = Object.create(null); private _listener: { [uri: string]: IDisposable } = Object.create(null);
@ -175,25 +185,52 @@ export class DiagnosticsAdapter extends Adapter {
) { ) {
super(worker); super(worker);
const onModelAdd = (model: editor.IModel): void => { const onModelAdd = (model: IInternalEditorModel): void => {
if (model.getModeId() !== _selector) { if (model.getModeId() !== _selector) {
return; return;
} }
const maybeValidate = () => {
const { onlyVisible } = this._defaults.getDiagnosticsOptions();
if (onlyVisible) {
if (model.isAttachedToEditor()) {
this._doValidate(model);
}
} else {
this._doValidate(model);
}
};
let handle: number; let handle: number;
const changeSubscription = model.onDidChangeContent(() => { const changeSubscription = model.onDidChangeContent(() => {
clearTimeout(handle); clearTimeout(handle);
handle = setTimeout(() => this._doValidate(model), 500); handle = setTimeout(maybeValidate, 500);
});
const visibleSubscription = model.onDidChangeAttached(() => {
const { onlyVisible } = this._defaults.getDiagnosticsOptions();
if (onlyVisible) {
if (model.isAttachedToEditor()) {
// this model is now attached to an editor
// => compute diagnostics
maybeValidate();
} else {
// this model is no longer attached to an editor
// => clear existing diagnostics
editor.setModelMarkers(model, this._selector, []);
}
}
}); });
this._listener[model.uri.toString()] = { this._listener[model.uri.toString()] = {
dispose() { dispose() {
changeSubscription.dispose(); changeSubscription.dispose();
visibleSubscription.dispose();
clearTimeout(handle); clearTimeout(handle);
} }
}; };
this._doValidate(model); maybeValidate();
}; };
const onModelRemoved = (model: editor.IModel): void => { const onModelRemoved = (model: editor.IModel): void => {
@ -205,12 +242,12 @@ export class DiagnosticsAdapter extends Adapter {
} }
}; };
this._disposables.push(editor.onDidCreateModel(onModelAdd)); this._disposables.push(editor.onDidCreateModel((model) => onModelAdd(<IInternalEditorModel>model)));
this._disposables.push(editor.onWillDisposeModel(onModelRemoved)); this._disposables.push(editor.onWillDisposeModel(onModelRemoved));
this._disposables.push( this._disposables.push(
editor.onDidChangeModelLanguage((event) => { editor.onDidChangeModelLanguage((event) => {
onModelRemoved(event.model); onModelRemoved(event.model);
onModelAdd(event.model); onModelAdd(<IInternalEditorModel>event.model);
}) })
); );
@ -226,13 +263,13 @@ export class DiagnosticsAdapter extends Adapter {
// redo diagnostics when options change // redo diagnostics when options change
for (const model of editor.getModels()) { for (const model of editor.getModels()) {
onModelRemoved(model); onModelRemoved(model);
onModelAdd(model); onModelAdd(<IInternalEditorModel>model);
} }
}; };
this._disposables.push(this._defaults.onDidChange(recomputeDiagostics)); this._disposables.push(this._defaults.onDidChange(recomputeDiagostics));
this._disposables.push(this._defaults.onDidExtraLibsChange(recomputeDiagostics)); this._disposables.push(this._defaults.onDidExtraLibsChange(recomputeDiagostics));
editor.getModels().forEach(onModelAdd); editor.getModels().forEach((model) => onModelAdd(<IInternalEditorModel>model));
} }
public dispose(): void { public dispose(): void {
@ -753,6 +790,17 @@ export class DefinitionAdapter extends Adapter {
uri: uri, uri: uri,
range: this._textSpanToRange(refModel, entry.textSpan) range: this._textSpanToRange(refModel, entry.textSpan)
}); });
} else {
const matchedLibFile = typescriptDefaults.getExtraLibs()[entry.fileName]
if (matchedLibFile) {
const libModel = editor.createModel(matchedLibFile.content, 'typescript', uri);
return {
uri: uri,
range: this._textSpanToRange(libModel, entry.textSpan)
}
}
} }
} }
return result; return result;

View file

@ -293,7 +293,7 @@ var ts;
// The following is baselined as a literal template type without intervention // The following is baselined as a literal template type without intervention
/** The version of the TypeScript compiler release */ /** The version of the TypeScript compiler release */
// eslint-disable-next-line @typescript-eslint/no-inferrable-types // eslint-disable-next-line @typescript-eslint/no-inferrable-types
ts.version = "4.2.3"; ts.version = "4.2.4";
/* @internal */ /* @internal */
var Comparison; var Comparison;
(function (Comparison) { (function (Comparison) {
@ -46611,7 +46611,9 @@ var ts;
var result = new Type(checker, flags); var result = new Type(checker, flags);
typeCount++; typeCount++;
result.id = typeCount; result.id = typeCount;
typeCatalog.push(result); if (ts.tracing) {
typeCatalog.push(result);
}
return result; return result;
} }
function createOriginType(flags) { function createOriginType(flags) {
@ -148422,7 +148424,7 @@ var ts;
}; };
SignatureObject.prototype.getJsDocTags = function () { SignatureObject.prototype.getJsDocTags = function () {
if (this.jsDocTags === undefined) { if (this.jsDocTags === undefined) {
this.jsDocTags = this.declaration ? getJsDocTags([this.declaration], this.checker) : []; this.jsDocTags = this.declaration ? getJsDocTagsOfSignature(this.declaration, this.checker) : [];
} }
return this.jsDocTags; return this.jsDocTags;
}; };
@ -148436,15 +148438,13 @@ var ts;
function hasJSDocInheritDocTag(node) { function hasJSDocInheritDocTag(node) {
return ts.getJSDocTags(node).some(function (tag) { return tag.tagName.text === "inheritDoc"; }); return ts.getJSDocTags(node).some(function (tag) { return tag.tagName.text === "inheritDoc"; });
} }
function getJsDocTags(declarations, checker) { function getJsDocTagsOfSignature(declaration, checker) {
var tags = ts.JsDoc.getJsDocTagsFromDeclarations(declarations); var tags = ts.JsDoc.getJsDocTagsFromDeclarations([declaration]);
if (tags.length === 0 || declarations.some(hasJSDocInheritDocTag)) { if (tags.length === 0 || hasJSDocInheritDocTag(declaration)) {
ts.forEachUnique(declarations, function (declaration) { var inheritedTags = findBaseOfDeclaration(checker, declaration, function (symbol) { var _a; return ((_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a.length) === 1 ? symbol.getJsDocTags() : undefined; });
var inheritedTags = findBaseOfDeclaration(checker, declaration, function (symbol) { return symbol.getJsDocTags(); }); if (inheritedTags) {
if (inheritedTags) { tags = __spreadArray(__spreadArray([], inheritedTags), tags);
tags = __spreadArray(__spreadArray([], inheritedTags), tags); }
}
});
} }
return tags; return tags;
} }

View file

@ -293,7 +293,7 @@ var ts;
// The following is baselined as a literal template type without intervention // The following is baselined as a literal template type without intervention
/** The version of the TypeScript compiler release */ /** The version of the TypeScript compiler release */
// eslint-disable-next-line @typescript-eslint/no-inferrable-types // eslint-disable-next-line @typescript-eslint/no-inferrable-types
ts.version = "4.2.3"; ts.version = "4.2.4";
/* @internal */ /* @internal */
var Comparison; var Comparison;
(function (Comparison) { (function (Comparison) {
@ -46611,7 +46611,9 @@ var ts;
var result = new Type(checker, flags); var result = new Type(checker, flags);
typeCount++; typeCount++;
result.id = typeCount; result.id = typeCount;
typeCatalog.push(result); if (ts.tracing) {
typeCatalog.push(result);
}
return result; return result;
} }
function createOriginType(flags) { function createOriginType(flags) {
@ -148422,7 +148424,7 @@ var ts;
}; };
SignatureObject.prototype.getJsDocTags = function () { SignatureObject.prototype.getJsDocTags = function () {
if (this.jsDocTags === undefined) { if (this.jsDocTags === undefined) {
this.jsDocTags = this.declaration ? getJsDocTags([this.declaration], this.checker) : []; this.jsDocTags = this.declaration ? getJsDocTagsOfSignature(this.declaration, this.checker) : [];
} }
return this.jsDocTags; return this.jsDocTags;
}; };
@ -148436,15 +148438,13 @@ var ts;
function hasJSDocInheritDocTag(node) { function hasJSDocInheritDocTag(node) {
return ts.getJSDocTags(node).some(function (tag) { return tag.tagName.text === "inheritDoc"; }); return ts.getJSDocTags(node).some(function (tag) { return tag.tagName.text === "inheritDoc"; });
} }
function getJsDocTags(declarations, checker) { function getJsDocTagsOfSignature(declaration, checker) {
var tags = ts.JsDoc.getJsDocTagsFromDeclarations(declarations); var tags = ts.JsDoc.getJsDocTagsFromDeclarations([declaration]);
if (tags.length === 0 || declarations.some(hasJSDocInheritDocTag)) { if (tags.length === 0 || hasJSDocInheritDocTag(declaration)) {
ts.forEachUnique(declarations, function (declaration) { var inheritedTags = findBaseOfDeclaration(checker, declaration, function (symbol) { var _a; return ((_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a.length) === 1 ? symbol.getJsDocTags() : undefined; });
var inheritedTags = findBaseOfDeclaration(checker, declaration, function (symbol) { return symbol.getJsDocTags(); }); if (inheritedTags) {
if (inheritedTags) { tags = __spreadArray(__spreadArray([], inheritedTags), tags);
tags = __spreadArray(__spreadArray([], inheritedTags), tags); }
}
});
} }
return tags; return tags;
} }

View file

@ -2,4 +2,4 @@
// **NOTE**: Do not edit directly! This file is generated using `npm run import-typescript` // **NOTE**: Do not edit directly! This file is generated using `npm run import-typescript`
// //
export const typescriptVersion = "4.2.3"; export const typescriptVersion = "4.2.4";

View file

@ -156,6 +156,11 @@ export interface DiagnosticsOptions {
noSemanticValidation?: boolean; noSemanticValidation?: boolean;
noSyntaxValidation?: boolean; noSyntaxValidation?: boolean;
noSuggestionDiagnostics?: boolean; noSuggestionDiagnostics?: boolean;
/**
* Limit diagnostic computation to only visible files.
* Defaults to false.
*/
onlyVisible?: boolean;
diagnosticCodesToIgnore?: number[]; diagnosticCodesToIgnore?: number[];
} }
@ -616,13 +621,13 @@ export const typescriptVersion: string = tsversion;
export const typescriptDefaults: LanguageServiceDefaults = new LanguageServiceDefaultsImpl( export const typescriptDefaults: LanguageServiceDefaults = new LanguageServiceDefaultsImpl(
{ allowNonTsExtensions: true, target: ScriptTarget.Latest }, { allowNonTsExtensions: true, target: ScriptTarget.Latest },
{ noSemanticValidation: false, noSyntaxValidation: false }, { noSemanticValidation: false, noSyntaxValidation: false, onlyVisible: false },
{} {}
); );
export const javascriptDefaults: LanguageServiceDefaults = new LanguageServiceDefaultsImpl( export const javascriptDefaults: LanguageServiceDefaults = new LanguageServiceDefaultsImpl(
{ allowNonTsExtensions: true, allowJs: true, target: ScriptTarget.Latest }, { allowNonTsExtensions: true, allowJs: true, target: ScriptTarget.Latest },
{ noSemanticValidation: true, noSyntaxValidation: false }, { noSemanticValidation: true, noSyntaxValidation: false, onlyVisible: false },
{} {}
); );

View file

@ -8,6 +8,7 @@ import * as ts from './lib/typescriptServices';
import { libFileMap } from './lib/lib'; import { libFileMap } from './lib/lib';
import { import {
Diagnostic, Diagnostic,
DiagnosticRelatedInformation,
IExtraLibs, IExtraLibs,
TypeScriptWorker as ITypeScriptWorker TypeScriptWorker as ITypeScriptWorker
} from './monaco.contribution'; } from './monaco.contribution';
@ -177,17 +178,26 @@ export class TypeScriptWorker implements ts.LanguageServiceHost, ITypeScriptWork
// --- language features // --- language features
private static clearFiles(diagnostics: ts.Diagnostic[]): Diagnostic[] { private static clearFiles(tsDiagnostics: ts.Diagnostic[]): Diagnostic[] {
// Clear the `file` field, which cannot be JSON'yfied because it // Clear the `file` field, which cannot be JSON'yfied because it
// contains cyclic data structures, except for the `fileName` // contains cyclic data structures, except for the `fileName`
// property. // property.
diagnostics.forEach((diag: Diagnostic) => { // Do a deep clone so we don't mutate the ts.Diagnostic object (see https://github.com/microsoft/monaco-editor/issues/2392)
diag.file = diag.file ? { fileName: diag.file.fileName } : undefined; const diagnostics: Diagnostic[] = [];
diag.relatedInformation?.forEach( for (const tsDiagnostic of tsDiagnostics) {
(diag2) => (diag2.file = diag2.file ? { fileName: diag2.file.fileName } : undefined) const diagnostic: Diagnostic = { ...tsDiagnostic };
); diagnostic.file = diagnostic.file ? { fileName: diagnostic.file.fileName } : undefined;
}); if (tsDiagnostic.relatedInformation) {
return <Diagnostic[]>diagnostics; diagnostic.relatedInformation = [];
for (const tsRelatedDiagnostic of tsDiagnostic.relatedInformation) {
const relatedDiagnostic: DiagnosticRelatedInformation = { ...tsRelatedDiagnostic };
relatedDiagnostic.file = relatedDiagnostic.file ? { fileName: relatedDiagnostic.file.fileName } : undefined
diagnostic.relatedInformation.push(relatedDiagnostic);
}
}
diagnostics.push(diagnostic);
}
return diagnostics;
} }
async getSyntacticDiagnostics(fileName: string): Promise<Diagnostic[]> { async getSyntacticDiagnostics(fileName: string): Promise<Diagnostic[]> {