From 3159d3d6c95ba96c4e70da043180f214c0e7a88e Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Mon, 10 Jan 2022 09:07:20 +0100 Subject: [PATCH] Adopt latest `monaco-editor-core` --- CHANGELOG.md | 2 + package-lock.json | 6 +- package.json | 2 +- src/typescript/languageFeatures.ts | 11 ++- website/playground/monaco.d.ts.txt | 149 +++++++++++++++++++++++++---- website/typedoc/monaco.d.ts | 149 +++++++++++++++++++++++++---- 6 files changed, 272 insertions(+), 47 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89bcfa2c..3bd9ae7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ ### Breaking Changes - The binary format for `IEncodedLineTokens` has changed to support strikethrough text. +- `IDiffEditor.getDomNode()` has been renamed to `IDiffEditor.getContainerDomNode()`. +- `InlayHint.text` has been replaced by `InlayHint.label` and `InlayHintsProvider.provideInlayHints` now returns an `InlayHintList`. ## [0.31.1] (14.12.2021) diff --git a/package-lock.json b/package-lock.json index ac330fee..6c87d145 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1159,9 +1159,9 @@ } }, "monaco-editor-core": { - "version": "0.32.0-dev.20211228", - "resolved": "https://registry.npmjs.org/monaco-editor-core/-/monaco-editor-core-0.32.0-dev.20211228.tgz", - "integrity": "sha512-7Cup6hu+EkpjW5Er6nSlSCQEJziJKiddd8vUJ+12Sgloo9KtnirzuoI69KeTYsFRVay8sUgeaZS0Bii0caTqSA==", + "version": "0.32.0-dev.20220110", + "resolved": "https://registry.npmjs.org/monaco-editor-core/-/monaco-editor-core-0.32.0-dev.20220110.tgz", + "integrity": "sha512-XF6xIUAmziM57p+lorG3IXHg0jCuxIL6mqv0WhXcSmtg4oEJFAQy/aT9+3fDbDIyJ+b0oSJga2e38K5PH5ajJQ==", "dev": true }, "mri": { diff --git a/package.json b/package.json index b2ff8076..32fd7619 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "jsdom": "^18.1.0", "jsonc-parser": "^3.0.0", "mocha": "^9.1.3", - "monaco-editor-core": "0.32.0-dev.20211228", + "monaco-editor-core": "0.32.0-dev.20220110", "playwright": "^1.16.3", "prettier": "^2.4.1", "pretty-quick": "^3.1.1", diff --git a/src/typescript/languageFeatures.ts b/src/typescript/languageFeatures.ts index 19050b00..9157877a 100644 --- a/src/typescript/languageFeatures.ts +++ b/src/typescript/languageFeatures.ts @@ -1224,7 +1224,7 @@ export class InlayHintsAdapter extends Adapter implements languages.InlayHintsPr model: editor.ITextModel, range: Range, token: CancellationToken - ): Promise { + ): Promise { const resource = model.uri; const fileName = resource.toString(); const start = model.getOffsetAt({ @@ -1237,18 +1237,19 @@ export class InlayHintsAdapter extends Adapter implements languages.InlayHintsPr }); const worker = await this._worker(resource); if (model.isDisposed()) { - return []; + return null; } - const hints = await worker.provideInlayHints(fileName, start, end); - - return hints.map((hint) => { + const tsHints = await worker.provideInlayHints(fileName, start, end); + const hints: languages.InlayHint[] = tsHints.map((hint) => { return { ...hint, + label: hint.text, position: model.getPositionAt(hint.position), kind: this._convertHintKind(hint.kind) }; }); + return { hints, dispose: () => {} }; } private _convertHintKind(kind?: ts.InlayHintKind) { diff --git a/website/playground/monaco.d.ts.txt b/website/playground/monaco.d.ts.txt index 415cd57a..86df5b53 100644 --- a/website/playground/monaco.d.ts.txt +++ b/website/playground/monaco.d.ts.txt @@ -1506,6 +1506,11 @@ declare namespace monaco.editor { * If there is an `inlineClassName` which affects letter spacing. */ readonly inlineClassNameAffectsLetterSpacing?: boolean; + /** + * This field allows to attach data to this injected text. + * The data can be read when injected texts at a given position are queried. + */ + readonly attachedData?: unknown; } /** @@ -3305,6 +3310,7 @@ declare namespace monaco.editor { */ guides?: IGuidesOptions; unicodeHighlight?: IUnicodeHighlightOptions; + bracketPairColorization?: IBracketPairColorizationOptions; } export interface IDiffEditorBaseOptions { @@ -3379,8 +3385,8 @@ declare namespace monaco.editor { get(id: T): FindComputedEditorOptionValueById; } - export interface IEditorOption { - readonly id: K1; + export interface IEditorOption { + readonly id: K; readonly name: string; defaultValue: V; /** @@ -4541,6 +4547,9 @@ declare namespace monaco.editor { * Render this content widget in a location where it could overflow the editor's view dom node. */ allowEditorOverflow?: boolean; + /** + * Call preventDefault() on mousedown events that target the content widget. + */ suppressMouseDown?: boolean; /** * Get a unique identifier of the content widget. @@ -4678,18 +4687,11 @@ declare namespace monaco.editor { OUTSIDE_EDITOR = 13 } - /** - * Target hit with the mouse in the editor. - */ - export interface IMouseTarget { + export interface IBaseMouseTarget { /** * The target element */ readonly element: Element | null; - /** - * The target type - */ - readonly type: MouseTargetType; /** * The 'approximate' editor position */ @@ -4702,12 +4704,104 @@ declare namespace monaco.editor { * The 'approximate' editor range */ readonly range: Range | null; - /** - * Some extra detail. - */ - readonly detail: any; + } + + export interface IMouseTargetUnknown extends IBaseMouseTarget { + readonly type: MouseTargetType.UNKNOWN; + } + + export interface IMouseTargetTextarea extends IBaseMouseTarget { + readonly type: MouseTargetType.TEXTAREA; + readonly position: null; + readonly range: null; + } + + export interface IMouseTargetMarginData { + readonly isAfterLines: boolean; + readonly glyphMarginLeft: number; + readonly glyphMarginWidth: number; + readonly lineNumbersWidth: number; + readonly offsetX: number; + } + + export interface IMouseTargetMargin extends IBaseMouseTarget { + readonly type: MouseTargetType.GUTTER_GLYPH_MARGIN | MouseTargetType.GUTTER_LINE_NUMBERS | MouseTargetType.GUTTER_LINE_DECORATIONS; + readonly position: Position; + readonly range: Range; + readonly detail: IMouseTargetMarginData; + } + + export interface IMouseTargetViewZoneData { + readonly viewZoneId: string; + readonly positionBefore: Position | null; + readonly positionAfter: Position | null; + readonly position: Position; + readonly afterLineNumber: number; + } + + export interface IMouseTargetViewZone extends IBaseMouseTarget { + readonly type: MouseTargetType.GUTTER_VIEW_ZONE | MouseTargetType.CONTENT_VIEW_ZONE; + readonly position: Position; + readonly range: Range; + readonly detail: IMouseTargetViewZoneData; + } + + export interface IMouseTargetContentTextData { + readonly mightBeForeignElement: boolean; + } + + export interface IMouseTargetContentText extends IBaseMouseTarget { + readonly type: MouseTargetType.CONTENT_TEXT; + readonly position: Position; + readonly range: Range; + readonly detail: IMouseTargetContentTextData; + } + + export interface IMouseTargetContentEmptyData { + readonly isAfterLines: boolean; + readonly horizontalDistanceToText?: number; + } + + export interface IMouseTargetContentEmpty extends IBaseMouseTarget { + readonly type: MouseTargetType.CONTENT_EMPTY; + readonly position: Position; + readonly range: Range; + readonly detail: IMouseTargetContentEmptyData; + } + + export interface IMouseTargetContentWidget extends IBaseMouseTarget { + readonly type: MouseTargetType.CONTENT_WIDGET; + readonly position: null; + readonly range: null; + readonly detail: string; + } + + export interface IMouseTargetOverlayWidget extends IBaseMouseTarget { + readonly type: MouseTargetType.OVERLAY_WIDGET; + readonly position: null; + readonly range: null; + readonly detail: string; + } + + export interface IMouseTargetScrollbar extends IBaseMouseTarget { + readonly type: MouseTargetType.SCROLLBAR; + readonly position: Position; + readonly range: Range; + } + + export interface IMouseTargetOverviewRuler extends IBaseMouseTarget { + readonly type: MouseTargetType.OVERVIEW_RULER; + } + + export interface IMouseTargetOutsideEditor extends IBaseMouseTarget { + readonly type: MouseTargetType.OUTSIDE_EDITOR; } + /** + * Target hit with the mouse in the editor. + */ + export type IMouseTarget = (IMouseTargetUnknown | IMouseTargetTextarea | IMouseTargetMargin | IMouseTargetViewZone | IMouseTargetContentText | IMouseTargetContentEmpty | IMouseTargetContentWidget | IMouseTargetOverlayWidget | IMouseTargetScrollbar | IMouseTargetOverviewRuler | IMouseTargetOutsideEditor); + /** * A mouse event originating from the editor. */ @@ -5041,6 +5135,10 @@ declare namespace monaco.editor { * Get all the decorations on a line (filtering out decorations from other editors). */ getLineDecorations(lineNumber: number): IModelDecoration[] | null; + /** + * Get all the decorations for a range (filtering out decorations from other editors). + */ + getDecorationsInRange(range: Range): IModelDecoration[] | null; /** * All decorations added through this call will get the ownerId of this editor. * @see {@link ITextModel.deltaDecorations} @@ -5149,9 +5247,9 @@ declare namespace monaco.editor { */ export interface IDiffEditor extends IEditor { /** - * @see {@link ICodeEditor.getDomNode} + * @see {@link ICodeEditor.getContainerDomNode} */ - getDomNode(): HTMLElement; + getContainerDomNode(): HTMLElement; /** * An event emitted when the diff information computed by this diff editor has been updated. * @event @@ -5253,7 +5351,7 @@ declare namespace monaco.languages { export function getEncodedLanguageId(languageId: string): number; /** - * An event emitted when a language is first time needed (e.g. a model has it set). + * An event emitted when a language is needed for the first time (e.g. a model has it set). * @event */ export function onLanguage(languageId: string, callback: () => void): IDisposable; @@ -6751,17 +6849,30 @@ declare namespace monaco.languages { Parameter = 2 } + export interface InlayHintLabelPart { + label: string; + collapsible?: boolean; + action?: Command | Location; + } + export interface InlayHint { - text: string; + label: string | InlayHintLabelPart[]; + tooltip?: string | IMarkdownString; position: IPosition; kind: InlayHintKind; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } + export interface InlayHintList { + hints: InlayHint[]; + dispose(): void; + } + export interface InlayHintsProvider { onDidChangeInlayHints?: IEvent; - provideInlayHints(model: editor.ITextModel, range: Range, token: CancellationToken): ProviderResult; + provideInlayHints(model: editor.ITextModel, range: Range, token: CancellationToken): ProviderResult; + resolveInlayHint?(hint: InlayHint, token: CancellationToken): ProviderResult; } export interface SemanticTokensLegend { diff --git a/website/typedoc/monaco.d.ts b/website/typedoc/monaco.d.ts index 415cd57a..86df5b53 100644 --- a/website/typedoc/monaco.d.ts +++ b/website/typedoc/monaco.d.ts @@ -1506,6 +1506,11 @@ declare namespace monaco.editor { * If there is an `inlineClassName` which affects letter spacing. */ readonly inlineClassNameAffectsLetterSpacing?: boolean; + /** + * This field allows to attach data to this injected text. + * The data can be read when injected texts at a given position are queried. + */ + readonly attachedData?: unknown; } /** @@ -3305,6 +3310,7 @@ declare namespace monaco.editor { */ guides?: IGuidesOptions; unicodeHighlight?: IUnicodeHighlightOptions; + bracketPairColorization?: IBracketPairColorizationOptions; } export interface IDiffEditorBaseOptions { @@ -3379,8 +3385,8 @@ declare namespace monaco.editor { get(id: T): FindComputedEditorOptionValueById; } - export interface IEditorOption { - readonly id: K1; + export interface IEditorOption { + readonly id: K; readonly name: string; defaultValue: V; /** @@ -4541,6 +4547,9 @@ declare namespace monaco.editor { * Render this content widget in a location where it could overflow the editor's view dom node. */ allowEditorOverflow?: boolean; + /** + * Call preventDefault() on mousedown events that target the content widget. + */ suppressMouseDown?: boolean; /** * Get a unique identifier of the content widget. @@ -4678,18 +4687,11 @@ declare namespace monaco.editor { OUTSIDE_EDITOR = 13 } - /** - * Target hit with the mouse in the editor. - */ - export interface IMouseTarget { + export interface IBaseMouseTarget { /** * The target element */ readonly element: Element | null; - /** - * The target type - */ - readonly type: MouseTargetType; /** * The 'approximate' editor position */ @@ -4702,12 +4704,104 @@ declare namespace monaco.editor { * The 'approximate' editor range */ readonly range: Range | null; - /** - * Some extra detail. - */ - readonly detail: any; + } + + export interface IMouseTargetUnknown extends IBaseMouseTarget { + readonly type: MouseTargetType.UNKNOWN; + } + + export interface IMouseTargetTextarea extends IBaseMouseTarget { + readonly type: MouseTargetType.TEXTAREA; + readonly position: null; + readonly range: null; + } + + export interface IMouseTargetMarginData { + readonly isAfterLines: boolean; + readonly glyphMarginLeft: number; + readonly glyphMarginWidth: number; + readonly lineNumbersWidth: number; + readonly offsetX: number; + } + + export interface IMouseTargetMargin extends IBaseMouseTarget { + readonly type: MouseTargetType.GUTTER_GLYPH_MARGIN | MouseTargetType.GUTTER_LINE_NUMBERS | MouseTargetType.GUTTER_LINE_DECORATIONS; + readonly position: Position; + readonly range: Range; + readonly detail: IMouseTargetMarginData; + } + + export interface IMouseTargetViewZoneData { + readonly viewZoneId: string; + readonly positionBefore: Position | null; + readonly positionAfter: Position | null; + readonly position: Position; + readonly afterLineNumber: number; + } + + export interface IMouseTargetViewZone extends IBaseMouseTarget { + readonly type: MouseTargetType.GUTTER_VIEW_ZONE | MouseTargetType.CONTENT_VIEW_ZONE; + readonly position: Position; + readonly range: Range; + readonly detail: IMouseTargetViewZoneData; + } + + export interface IMouseTargetContentTextData { + readonly mightBeForeignElement: boolean; + } + + export interface IMouseTargetContentText extends IBaseMouseTarget { + readonly type: MouseTargetType.CONTENT_TEXT; + readonly position: Position; + readonly range: Range; + readonly detail: IMouseTargetContentTextData; + } + + export interface IMouseTargetContentEmptyData { + readonly isAfterLines: boolean; + readonly horizontalDistanceToText?: number; + } + + export interface IMouseTargetContentEmpty extends IBaseMouseTarget { + readonly type: MouseTargetType.CONTENT_EMPTY; + readonly position: Position; + readonly range: Range; + readonly detail: IMouseTargetContentEmptyData; + } + + export interface IMouseTargetContentWidget extends IBaseMouseTarget { + readonly type: MouseTargetType.CONTENT_WIDGET; + readonly position: null; + readonly range: null; + readonly detail: string; + } + + export interface IMouseTargetOverlayWidget extends IBaseMouseTarget { + readonly type: MouseTargetType.OVERLAY_WIDGET; + readonly position: null; + readonly range: null; + readonly detail: string; + } + + export interface IMouseTargetScrollbar extends IBaseMouseTarget { + readonly type: MouseTargetType.SCROLLBAR; + readonly position: Position; + readonly range: Range; + } + + export interface IMouseTargetOverviewRuler extends IBaseMouseTarget { + readonly type: MouseTargetType.OVERVIEW_RULER; + } + + export interface IMouseTargetOutsideEditor extends IBaseMouseTarget { + readonly type: MouseTargetType.OUTSIDE_EDITOR; } + /** + * Target hit with the mouse in the editor. + */ + export type IMouseTarget = (IMouseTargetUnknown | IMouseTargetTextarea | IMouseTargetMargin | IMouseTargetViewZone | IMouseTargetContentText | IMouseTargetContentEmpty | IMouseTargetContentWidget | IMouseTargetOverlayWidget | IMouseTargetScrollbar | IMouseTargetOverviewRuler | IMouseTargetOutsideEditor); + /** * A mouse event originating from the editor. */ @@ -5041,6 +5135,10 @@ declare namespace monaco.editor { * Get all the decorations on a line (filtering out decorations from other editors). */ getLineDecorations(lineNumber: number): IModelDecoration[] | null; + /** + * Get all the decorations for a range (filtering out decorations from other editors). + */ + getDecorationsInRange(range: Range): IModelDecoration[] | null; /** * All decorations added through this call will get the ownerId of this editor. * @see {@link ITextModel.deltaDecorations} @@ -5149,9 +5247,9 @@ declare namespace monaco.editor { */ export interface IDiffEditor extends IEditor { /** - * @see {@link ICodeEditor.getDomNode} + * @see {@link ICodeEditor.getContainerDomNode} */ - getDomNode(): HTMLElement; + getContainerDomNode(): HTMLElement; /** * An event emitted when the diff information computed by this diff editor has been updated. * @event @@ -5253,7 +5351,7 @@ declare namespace monaco.languages { export function getEncodedLanguageId(languageId: string): number; /** - * An event emitted when a language is first time needed (e.g. a model has it set). + * An event emitted when a language is needed for the first time (e.g. a model has it set). * @event */ export function onLanguage(languageId: string, callback: () => void): IDisposable; @@ -6751,17 +6849,30 @@ declare namespace monaco.languages { Parameter = 2 } + export interface InlayHintLabelPart { + label: string; + collapsible?: boolean; + action?: Command | Location; + } + export interface InlayHint { - text: string; + label: string | InlayHintLabelPart[]; + tooltip?: string | IMarkdownString; position: IPosition; kind: InlayHintKind; whitespaceBefore?: boolean; whitespaceAfter?: boolean; } + export interface InlayHintList { + hints: InlayHint[]; + dispose(): void; + } + export interface InlayHintsProvider { onDidChangeInlayHints?: IEvent; - provideInlayHints(model: editor.ITextModel, range: Range, token: CancellationToken): ProviderResult; + provideInlayHints(model: editor.ITextModel, range: Range, token: CancellationToken): ProviderResult; + resolveInlayHint?(hint: InlayHint, token: CancellationToken): ProviderResult; } export interface SemanticTokensLegend {