Просмотр исходного кода

Adopt latest `monaco-editor-core`

Alex Dima 3 лет назад
Родитель
Сommit
3159d3d6c9
6 измененных файлов с 272 добавлено и 47 удалено
  1. 2 0
      CHANGELOG.md
  2. 3 3
      package-lock.json
  3. 1 1
      package.json
  4. 6 5
      src/typescript/languageFeatures.ts
  5. 130 19
      website/playground/monaco.d.ts.txt
  6. 130 19
      website/typedoc/monaco.d.ts

+ 2 - 0
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)
 

+ 3 - 3
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": {

+ 1 - 1
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",

+ 6 - 5
src/typescript/languageFeatures.ts

@@ -1224,7 +1224,7 @@ export class InlayHintsAdapter extends Adapter implements languages.InlayHintsPr
 		model: editor.ITextModel,
 		range: Range,
 		token: CancellationToken
-	): Promise<languages.InlayHint[]> {
+	): Promise<languages.InlayHintList | null> {
 		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) {

+ 130 - 19
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<T extends EditorOption>(id: T): FindComputedEditorOptionValueById<T>;
     }
 
-    export interface IEditorOption<K1 extends EditorOption, V> {
-        readonly id: K1;
+    export interface IEditorOption<K extends EditorOption, V> {
+        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<void>;
-        provideInlayHints(model: editor.ITextModel, range: Range, token: CancellationToken): ProviderResult<InlayHint[]>;
+        provideInlayHints(model: editor.ITextModel, range: Range, token: CancellationToken): ProviderResult<InlayHintList>;
+        resolveInlayHint?(hint: InlayHint, token: CancellationToken): ProviderResult<InlayHint>;
     }
 
     export interface SemanticTokensLegend {

+ 130 - 19
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<T extends EditorOption>(id: T): FindComputedEditorOptionValueById<T>;
     }
 
-    export interface IEditorOption<K1 extends EditorOption, V> {
-        readonly id: K1;
+    export interface IEditorOption<K extends EditorOption, V> {
+        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<void>;
-        provideInlayHints(model: editor.ITextModel, range: Range, token: CancellationToken): ProviderResult<InlayHint[]>;
+        provideInlayHints(model: editor.ITextModel, range: Range, token: CancellationToken): ProviderResult<InlayHintList>;
+        resolveInlayHint?(hint: InlayHint, token: CancellationToken): ProviderResult<InlayHint>;
     }
 
     export interface SemanticTokensLegend {