monaco-editor-core
Version:
A browser based code editor
1,721 lines (1,624 loc) • 255 kB
TypeScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
declare global {
let MonacoEnvironment: Environment | undefined;
}
interface Window {
MonacoEnvironment?: Environment | undefined;
}
export type Thenable<T> = PromiseLike<T>;
export interface Environment {
/**
* Define a global `monaco` symbol.
* This is true by default in AMD and false by default in ESM.
*/
globalAPI?: boolean;
/**
* The base url where the editor sources are found (which contains the vs folder)
*/
baseUrl?: string;
/**
* A web worker factory.
* NOTE: If `getWorker` is defined, `getWorkerUrl` is not invoked.
*/
getWorker?(workerId: string, label: string): Promise<Worker> | Worker;
/**
* Return the location for web worker scripts.
* NOTE: If `getWorker` is defined, `getWorkerUrl` is not invoked.
*/
getWorkerUrl?(workerId: string, label: string): string;
/**
* Create a trusted types policy (same API as window.trustedTypes.createPolicy)
*/
createTrustedTypesPolicy?(
policyName: string,
policyOptions?: ITrustedTypePolicyOptions,
): undefined | ITrustedTypePolicy;
}
export interface ITrustedTypePolicyOptions {
createHTML?: (input: string, ...arguments: any[]) => string;
createScript?: (input: string, ...arguments: any[]) => string;
createScriptURL?: (input: string, ...arguments: any[]) => string;
}
export interface ITrustedTypePolicy {
readonly name: string;
createHTML?(input: string): any;
createScript?(input: string): any;
createScriptURL?(input: string): any;
}
export interface IDisposable {
dispose(): void;
}
export interface IEvent<T> {
(listener: (e: T) => any, thisArg?: any): IDisposable;
}
/**
* A helper that allows to emit and listen to typed events
*/
export class Emitter<T> {
constructor();
readonly event: IEvent<T>;
fire(event: T): void;
dispose(): void;
}
export enum MarkerTag {
Unnecessary = 1,
Deprecated = 2
}
export enum MarkerSeverity {
Hint = 1,
Info = 2,
Warning = 4,
Error = 8
}
export class CancellationTokenSource {
constructor(parent?: CancellationToken);
get token(): CancellationToken;
cancel(): void;
dispose(cancel?: boolean): void;
}
export interface CancellationToken {
/**
* A flag signalling is cancellation has been requested.
*/
readonly isCancellationRequested: boolean;
/**
* An event which fires when cancellation is requested. This event
* only ever fires `once` as cancellation can only happen once. Listeners
* that are registered after cancellation will be called (next event loop run),
* but also only once.
*
* @event
*/
readonly onCancellationRequested: (listener: (e: any) => any, thisArgs?: any, disposables?: IDisposable[]) => IDisposable;
}
/**
* Uniform Resource Identifier (Uri) http://tools.ietf.org/html/rfc3986.
* This class is a simple parser which creates the basic component parts
* (http://tools.ietf.org/html/rfc3986#section-3) with minimal validation
* and encoding.
*
* ```txt
* foo://example.com:8042/over/there?name=ferret#nose
* \_/ \______________/\_________/ \_________/ \__/
* | | | | |
* scheme authority path query fragment
* | _____________________|__
* / \ / \
* urn:example:animal:ferret:nose
* ```
*/
export class Uri implements UriComponents {
static isUri(thing: any): thing is Uri;
/**
* scheme is the 'http' part of 'http://www.example.com/some/path?query#fragment'.
* The part before the first colon.
*/
readonly scheme: string;
/**
* authority is the 'www.example.com' part of 'http://www.example.com/some/path?query#fragment'.
* The part between the first double slashes and the next slash.
*/
readonly authority: string;
/**
* path is the '/some/path' part of 'http://www.example.com/some/path?query#fragment'.
*/
readonly path: string;
/**
* query is the 'query' part of 'http://www.example.com/some/path?query#fragment'.
*/
readonly query: string;
/**
* fragment is the 'fragment' part of 'http://www.example.com/some/path?query#fragment'.
*/
readonly fragment: string;
/**
* Returns a string representing the corresponding file system path of this Uri.
* Will handle UNC paths, normalizes windows drive letters to lower-case, and uses the
* platform specific path separator.
*
* * Will *not* validate the path for invalid characters and semantics.
* * Will *not* look at the scheme of this Uri.
* * The result shall *not* be used for display purposes but for accessing a file on disk.
*
*
* The *difference* to `Uri#path` is the use of the platform specific separator and the handling
* of UNC paths. See the below sample of a file-uri with an authority (UNC path).
*
* ```ts
const u = Uri.parse('file://server/c$/folder/file.txt')
u.authority === 'server'
u.path === '/shares/c$/file.txt'
u.fsPath === '\\server\c$\folder\file.txt'
```
*
* Using `Uri#path` to read a file (using fs-apis) would not be enough because parts of the path,
* namely the server name, would be missing. Therefore `Uri#fsPath` exists - it's sugar to ease working
* with URIs that represent files on disk (`file` scheme).
*/
get fsPath(): string;
with(change: {
scheme?: string;
authority?: string | null;
path?: string | null;
query?: string | null;
fragment?: string | null;
}): Uri;
/**
* Creates a new Uri from a string, e.g. `http://www.example.com/some/path`,
* `file:///usr/home`, or `scheme:with/path`.
*
* @param value A string which represents an Uri (see `Uri#toString`).
*/
static parse(value: string, _strict?: boolean): Uri;
/**
* Creates a new Uri from a file system path, e.g. `c:\my\files`,
* `/usr/home`, or `\\server\share\some\path`.
*
* The *difference* between `Uri#parse` and `Uri#file` is that the latter treats the argument
* as path, not as stringified-uri. E.g. `Uri.file(path)` is **not the same as**
* `Uri.parse('file://' + path)` because the path might contain characters that are
* interpreted (# and ?). See the following sample:
* ```ts
const good = Uri.file('/coding/c#/project1');
good.scheme === 'file';
good.path === '/coding/c#/project1';
good.fragment === '';
const bad = Uri.parse('file://' + '/coding/c#/project1');
bad.scheme === 'file';
bad.path === '/coding/c'; // path is now broken
bad.fragment === '/project1';
```
*
* @param path A file system path (see `Uri#fsPath`)
*/
static file(path: string): Uri;
/**
* Creates new Uri from uri components.
*
* Unless `strict` is `true` the scheme is defaults to be `file`. This function performs
* validation and should be used for untrusted uri components retrieved from storage,
* user input, command arguments etc
*/
static from(components: UriComponents, strict?: boolean): Uri;
/**
* Join a Uri path with path fragments and normalizes the resulting path.
*
* @param uri The input Uri.
* @param pathFragment The path fragment to add to the Uri path.
* @returns The resulting Uri.
*/
static joinPath(uri: Uri, ...pathFragment: string[]): Uri;
/**
* Creates a string representation for this Uri. It's guaranteed that calling
* `Uri.parse` with the result of this function creates an Uri which is equal
* to this Uri.
*
* * The result shall *not* be used for display purposes but for externalization or transport.
* * The result will be encoded using the percentage encoding and encoding happens mostly
* ignore the scheme-specific encoding rules.
*
* @param skipEncoding Do not encode the result, default is `false`
*/
toString(skipEncoding?: boolean): string;
toJSON(): UriComponents;
/**
* A helper function to revive URIs.
*
* **Note** that this function should only be used when receiving Uri#toJSON generated data
* and that it doesn't do any validation. Use {@link Uri.from} when received "untrusted"
* uri components such as command arguments or data from storage.
*
* @param data The Uri components or Uri to revive.
* @returns The revived Uri or undefined or null.
*/
static revive(data: UriComponents | Uri): Uri;
static revive(data: UriComponents | Uri | undefined): Uri | undefined;
static revive(data: UriComponents | Uri | null): Uri | null;
static revive(data: UriComponents | Uri | undefined | null): Uri | undefined | null;
}
export interface UriComponents {
scheme: string;
authority?: string;
path?: string;
query?: string;
fragment?: string;
}
/**
* Virtual Key Codes, the value does not hold any inherent meaning.
* Inspired somewhat from https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
* But these are "more general", as they should work across browsers & OS`s.
*/
export enum KeyCode {
DependsOnKbLayout = -1,
/**
* Placed first to cover the 0 value of the enum.
*/
Unknown = 0,
Backspace = 1,
Tab = 2,
Enter = 3,
Shift = 4,
Ctrl = 5,
Alt = 6,
PauseBreak = 7,
CapsLock = 8,
Escape = 9,
Space = 10,
PageUp = 11,
PageDown = 12,
End = 13,
Home = 14,
LeftArrow = 15,
UpArrow = 16,
RightArrow = 17,
DownArrow = 18,
Insert = 19,
Delete = 20,
Digit0 = 21,
Digit1 = 22,
Digit2 = 23,
Digit3 = 24,
Digit4 = 25,
Digit5 = 26,
Digit6 = 27,
Digit7 = 28,
Digit8 = 29,
Digit9 = 30,
KeyA = 31,
KeyB = 32,
KeyC = 33,
KeyD = 34,
KeyE = 35,
KeyF = 36,
KeyG = 37,
KeyH = 38,
KeyI = 39,
KeyJ = 40,
KeyK = 41,
KeyL = 42,
KeyM = 43,
KeyN = 44,
KeyO = 45,
KeyP = 46,
KeyQ = 47,
KeyR = 48,
KeyS = 49,
KeyT = 50,
KeyU = 51,
KeyV = 52,
KeyW = 53,
KeyX = 54,
KeyY = 55,
KeyZ = 56,
Meta = 57,
ContextMenu = 58,
F1 = 59,
F2 = 60,
F3 = 61,
F4 = 62,
F5 = 63,
F6 = 64,
F7 = 65,
F8 = 66,
F9 = 67,
F10 = 68,
F11 = 69,
F12 = 70,
F13 = 71,
F14 = 72,
F15 = 73,
F16 = 74,
F17 = 75,
F18 = 76,
F19 = 77,
F20 = 78,
F21 = 79,
F22 = 80,
F23 = 81,
F24 = 82,
NumLock = 83,
ScrollLock = 84,
/**
* Used for miscellaneous characters; it can vary by keyboard.
* For the US standard keyboard, the ';:' key
*/
Semicolon = 85,
/**
* For any country/region, the '+' key
* For the US standard keyboard, the '=+' key
*/
Equal = 86,
/**
* For any country/region, the ',' key
* For the US standard keyboard, the ',<' key
*/
Comma = 87,
/**
* For any country/region, the '-' key
* For the US standard keyboard, the '-_' key
*/
Minus = 88,
/**
* For any country/region, the '.' key
* For the US standard keyboard, the '.>' key
*/
Period = 89,
/**
* Used for miscellaneous characters; it can vary by keyboard.
* For the US standard keyboard, the '/?' key
*/
Slash = 90,
/**
* Used for miscellaneous characters; it can vary by keyboard.
* For the US standard keyboard, the '`~' key
*/
Backquote = 91,
/**
* Used for miscellaneous characters; it can vary by keyboard.
* For the US standard keyboard, the '[{' key
*/
BracketLeft = 92,
/**
* Used for miscellaneous characters; it can vary by keyboard.
* For the US standard keyboard, the '\|' key
*/
Backslash = 93,
/**
* Used for miscellaneous characters; it can vary by keyboard.
* For the US standard keyboard, the ']}' key
*/
BracketRight = 94,
/**
* Used for miscellaneous characters; it can vary by keyboard.
* For the US standard keyboard, the ''"' key
*/
Quote = 95,
/**
* Used for miscellaneous characters; it can vary by keyboard.
*/
OEM_8 = 96,
/**
* Either the angle bracket key or the backslash key on the RT 102-key keyboard.
*/
IntlBackslash = 97,
Numpad0 = 98,// VK_NUMPAD0, 0x60, Numeric keypad 0 key
Numpad1 = 99,// VK_NUMPAD1, 0x61, Numeric keypad 1 key
Numpad2 = 100,// VK_NUMPAD2, 0x62, Numeric keypad 2 key
Numpad3 = 101,// VK_NUMPAD3, 0x63, Numeric keypad 3 key
Numpad4 = 102,// VK_NUMPAD4, 0x64, Numeric keypad 4 key
Numpad5 = 103,// VK_NUMPAD5, 0x65, Numeric keypad 5 key
Numpad6 = 104,// VK_NUMPAD6, 0x66, Numeric keypad 6 key
Numpad7 = 105,// VK_NUMPAD7, 0x67, Numeric keypad 7 key
Numpad8 = 106,// VK_NUMPAD8, 0x68, Numeric keypad 8 key
Numpad9 = 107,// VK_NUMPAD9, 0x69, Numeric keypad 9 key
NumpadMultiply = 108,// VK_MULTIPLY, 0x6A, Multiply key
NumpadAdd = 109,// VK_ADD, 0x6B, Add key
NUMPAD_SEPARATOR = 110,// VK_SEPARATOR, 0x6C, Separator key
NumpadSubtract = 111,// VK_SUBTRACT, 0x6D, Subtract key
NumpadDecimal = 112,// VK_DECIMAL, 0x6E, Decimal key
NumpadDivide = 113,// VK_DIVIDE, 0x6F,
/**
* Cover all key codes when IME is processing input.
*/
KEY_IN_COMPOSITION = 114,
ABNT_C1 = 115,// Brazilian (ABNT) Keyboard
ABNT_C2 = 116,// Brazilian (ABNT) Keyboard
AudioVolumeMute = 117,
AudioVolumeUp = 118,
AudioVolumeDown = 119,
BrowserSearch = 120,
BrowserHome = 121,
BrowserBack = 122,
BrowserForward = 123,
MediaTrackNext = 124,
MediaTrackPrevious = 125,
MediaStop = 126,
MediaPlayPause = 127,
LaunchMediaPlayer = 128,
LaunchMail = 129,
LaunchApp2 = 130,
/**
* VK_CLEAR, 0x0C, CLEAR key
*/
Clear = 131,
/**
* Placed last to cover the length of the enum.
* Please do not depend on this value!
*/
MAX_VALUE = 132
}
export class KeyMod {
static readonly CtrlCmd: number;
static readonly Shift: number;
static readonly Alt: number;
static readonly WinCtrl: number;
static chord(firstPart: number, secondPart: number): number;
}
export interface IMarkdownString {
readonly value: string;
readonly isTrusted?: boolean | MarkdownStringTrustedOptions;
readonly supportThemeIcons?: boolean;
readonly supportHtml?: boolean;
readonly baseUri?: UriComponents;
uris?: {
[href: string]: UriComponents;
};
}
export interface MarkdownStringTrustedOptions {
readonly enabledCommands: readonly string[];
}
export interface IKeyboardEvent {
readonly _standardKeyboardEventBrand: true;
readonly browserEvent: KeyboardEvent;
readonly target: HTMLElement;
readonly ctrlKey: boolean;
readonly shiftKey: boolean;
readonly altKey: boolean;
readonly metaKey: boolean;
readonly altGraphKey: boolean;
readonly keyCode: KeyCode;
readonly code: string;
equals(keybinding: number): boolean;
preventDefault(): void;
stopPropagation(): void;
}
export interface IMouseEvent {
readonly browserEvent: MouseEvent;
readonly leftButton: boolean;
readonly middleButton: boolean;
readonly rightButton: boolean;
readonly buttons: number;
readonly target: HTMLElement;
readonly detail: number;
readonly posx: number;
readonly posy: number;
readonly ctrlKey: boolean;
readonly shiftKey: boolean;
readonly altKey: boolean;
readonly metaKey: boolean;
readonly timestamp: number;
preventDefault(): void;
stopPropagation(): void;
}
export interface IScrollEvent {
readonly scrollTop: number;
readonly scrollLeft: number;
readonly scrollWidth: number;
readonly scrollHeight: number;
readonly scrollTopChanged: boolean;
readonly scrollLeftChanged: boolean;
readonly scrollWidthChanged: boolean;
readonly scrollHeightChanged: boolean;
}
/**
* A position in the editor. This interface is suitable for serialization.
*/
export interface IPosition {
/**
* line number (starts at 1)
*/
readonly lineNumber: number;
/**
* column (the first character in a line is between column 1 and column 2)
*/
readonly column: number;
}
/**
* A position in the editor.
*/
export class Position {
/**
* line number (starts at 1)
*/
readonly lineNumber: number;
/**
* column (the first character in a line is between column 1 and column 2)
*/
readonly column: number;
constructor(lineNumber: number, column: number);
/**
* Create a new position from this position.
*
* @param newLineNumber new line number
* @param newColumn new column
*/
with(newLineNumber?: number, newColumn?: number): Position;
/**
* Derive a new position from this position.
*
* @param deltaLineNumber line number delta
* @param deltaColumn column delta
*/
delta(deltaLineNumber?: number, deltaColumn?: number): Position;
/**
* Test if this position equals other position
*/
equals(other: IPosition): boolean;
/**
* Test if position `a` equals position `b`
*/
static equals(a: IPosition | null, b: IPosition | null): boolean;
/**
* Test if this position is before other position.
* If the two positions are equal, the result will be false.
*/
isBefore(other: IPosition): boolean;
/**
* Test if position `a` is before position `b`.
* If the two positions are equal, the result will be false.
*/
static isBefore(a: IPosition, b: IPosition): boolean;
/**
* Test if this position is before other position.
* If the two positions are equal, the result will be true.
*/
isBeforeOrEqual(other: IPosition): boolean;
/**
* Test if position `a` is before position `b`.
* If the two positions are equal, the result will be true.
*/
static isBeforeOrEqual(a: IPosition, b: IPosition): boolean;
/**
* A function that compares positions, useful for sorting
*/
static compare(a: IPosition, b: IPosition): number;
/**
* Clone this position.
*/
clone(): Position;
/**
* Convert to a human-readable representation.
*/
toString(): string;
/**
* Create a `Position` from an `IPosition`.
*/
static lift(pos: IPosition): Position;
/**
* Test if `obj` is an `IPosition`.
*/
static isIPosition(obj: any): obj is IPosition;
toJSON(): IPosition;
}
/**
* A range in the editor. This interface is suitable for serialization.
*/
export interface IRange {
/**
* Line number on which the range starts (starts at 1).
*/
readonly startLineNumber: number;
/**
* Column on which the range starts in line `startLineNumber` (starts at 1).
*/
readonly startColumn: number;
/**
* Line number on which the range ends.
*/
readonly endLineNumber: number;
/**
* Column on which the range ends in line `endLineNumber`.
*/
readonly endColumn: number;
}
/**
* A range in the editor. (startLineNumber,startColumn) is <= (endLineNumber,endColumn)
*/
export class Range {
/**
* Line number on which the range starts (starts at 1).
*/
readonly startLineNumber: number;
/**
* Column on which the range starts in line `startLineNumber` (starts at 1).
*/
readonly startColumn: number;
/**
* Line number on which the range ends.
*/
readonly endLineNumber: number;
/**
* Column on which the range ends in line `endLineNumber`.
*/
readonly endColumn: number;
constructor(startLineNumber: number, startColumn: number, endLineNumber: number, endColumn: number);
/**
* Test if this range is empty.
*/
isEmpty(): boolean;
/**
* Test if `range` is empty.
*/
static isEmpty(range: IRange): boolean;
/**
* Test if position is in this range. If the position is at the edges, will return true.
*/
containsPosition(position: IPosition): boolean;
/**
* Test if `position` is in `range`. If the position is at the edges, will return true.
*/
static containsPosition(range: IRange, position: IPosition): boolean;
/**
* Test if range is in this range. If the range is equal to this range, will return true.
*/
containsRange(range: IRange): boolean;
/**
* Test if `otherRange` is in `range`. If the ranges are equal, will return true.
*/
static containsRange(range: IRange, otherRange: IRange): boolean;
/**
* Test if `range` is strictly in this range. `range` must start after and end before this range for the result to be true.
*/
strictContainsRange(range: IRange): boolean;
/**
* Test if `otherRange` is strictly in `range` (must start after, and end before). If the ranges are equal, will return false.
*/
static strictContainsRange(range: IRange, otherRange: IRange): boolean;
/**
* A reunion of the two ranges.
* The smallest position will be used as the start point, and the largest one as the end point.
*/
plusRange(range: IRange): Range;
/**
* A reunion of the two ranges.
* The smallest position will be used as the start point, and the largest one as the end point.
*/
static plusRange(a: IRange, b: IRange): Range;
/**
* A intersection of the two ranges.
*/
intersectRanges(range: IRange): Range | null;
/**
* A intersection of the two ranges.
*/
static intersectRanges(a: IRange, b: IRange): Range | null;
/**
* Test if this range equals other.
*/
equalsRange(other: IRange | null | undefined): boolean;
/**
* Test if range `a` equals `b`.
*/
static equalsRange(a: IRange | null | undefined, b: IRange | null | undefined): boolean;
/**
* Return the end position (which will be after or equal to the start position)
*/
getEndPosition(): Position;
/**
* Return the end position (which will be after or equal to the start position)
*/
static getEndPosition(range: IRange): Position;
/**
* Return the start position (which will be before or equal to the end position)
*/
getStartPosition(): Position;
/**
* Return the start position (which will be before or equal to the end position)
*/
static getStartPosition(range: IRange): Position;
/**
* Transform to a user presentable string representation.
*/
toString(): string;
/**
* Create a new range using this range's start position, and using endLineNumber and endColumn as the end position.
*/
setEndPosition(endLineNumber: number, endColumn: number): Range;
/**
* Create a new range using this range's end position, and using startLineNumber and startColumn as the start position.
*/
setStartPosition(startLineNumber: number, startColumn: number): Range;
/**
* Create a new empty range using this range's start position.
*/
collapseToStart(): Range;
/**
* Create a new empty range using this range's start position.
*/
static collapseToStart(range: IRange): Range;
/**
* Create a new empty range using this range's end position.
*/
collapseToEnd(): Range;
/**
* Create a new empty range using this range's end position.
*/
static collapseToEnd(range: IRange): Range;
/**
* Moves the range by the given amount of lines.
*/
delta(lineCount: number): Range;
static fromPositions(start: IPosition, end?: IPosition): Range;
/**
* Create a `Range` from an `IRange`.
*/
static lift(range: undefined | null): null;
static lift(range: IRange): Range;
static lift(range: IRange | undefined | null): Range | null;
/**
* Test if `obj` is an `IRange`.
*/
static isIRange(obj: any): obj is IRange;
/**
* Test if the two ranges are touching in any way.
*/
static areIntersectingOrTouching(a: IRange, b: IRange): boolean;
/**
* Test if the two ranges are intersecting. If the ranges are touching it returns true.
*/
static areIntersecting(a: IRange, b: IRange): boolean;
/**
* A function that compares ranges, useful for sorting ranges
* It will first compare ranges on the startPosition and then on the endPosition
*/
static compareRangesUsingStarts(a: IRange | null | undefined, b: IRange | null | undefined): number;
/**
* A function that compares ranges, useful for sorting ranges
* It will first compare ranges on the endPosition and then on the startPosition
*/
static compareRangesUsingEnds(a: IRange, b: IRange): number;
/**
* Test if the range spans multiple lines.
*/
static spansMultipleLines(range: IRange): boolean;
toJSON(): IRange;
}
/**
* A selection in the editor.
* The selection is a range that has an orientation.
*/
export interface ISelection {
/**
* The line number on which the selection has started.
*/
readonly selectionStartLineNumber: number;
/**
* The column on `selectionStartLineNumber` where the selection has started.
*/
readonly selectionStartColumn: number;
/**
* The line number on which the selection has ended.
*/
readonly positionLineNumber: number;
/**
* The column on `positionLineNumber` where the selection has ended.
*/
readonly positionColumn: number;
}
/**
* A selection in the editor.
* The selection is a range that has an orientation.
*/
export class Selection extends Range {
/**
* The line number on which the selection has started.
*/
readonly selectionStartLineNumber: number;
/**
* The column on `selectionStartLineNumber` where the selection has started.
*/
readonly selectionStartColumn: number;
/**
* The line number on which the selection has ended.
*/
readonly positionLineNumber: number;
/**
* The column on `positionLineNumber` where the selection has ended.
*/
readonly positionColumn: number;
constructor(selectionStartLineNumber: number, selectionStartColumn: number, positionLineNumber: number, positionColumn: number);
/**
* Transform to a human-readable representation.
*/
toString(): string;
/**
* Test if equals other selection.
*/
equalsSelection(other: ISelection): boolean;
/**
* Test if the two selections are equal.
*/
static selectionsEqual(a: ISelection, b: ISelection): boolean;
/**
* Get directions (LTR or RTL).
*/
getDirection(): SelectionDirection;
/**
* Create a new selection with a different `positionLineNumber` and `positionColumn`.
*/
setEndPosition(endLineNumber: number, endColumn: number): Selection;
/**
* Get the position at `positionLineNumber` and `positionColumn`.
*/
getPosition(): Position;
/**
* Get the position at the start of the selection.
*/
getSelectionStart(): Position;
/**
* Create a new selection with a different `selectionStartLineNumber` and `selectionStartColumn`.
*/
setStartPosition(startLineNumber: number, startColumn: number): Selection;
/**
* Create a `Selection` from one or two positions
*/
static fromPositions(start: IPosition, end?: IPosition): Selection;
/**
* Creates a `Selection` from a range, given a direction.
*/
static fromRange(range: Range, direction: SelectionDirection): Selection;
/**
* Create a `Selection` from an `ISelection`.
*/
static liftSelection(sel: ISelection): Selection;
/**
* `a` equals `b`.
*/
static selectionsArrEqual(a: ISelection[], b: ISelection[]): boolean;
/**
* Test if `obj` is an `ISelection`.
*/
static isISelection(obj: any): obj is ISelection;
/**
* Create with a direction.
*/
static createWithDirection(startLineNumber: number, startColumn: number, endLineNumber: number, endColumn: number, direction: SelectionDirection): Selection;
}
/**
* The direction of a selection.
*/
export enum SelectionDirection {
/**
* The selection starts above where it ends.
*/
LTR = 0,
/**
* The selection starts below where it ends.
*/
RTL = 1
}
export class Token {
readonly offset: number;
readonly type: string;
readonly language: string;
_tokenBrand: void;
constructor(offset: number, type: string, language: string);
toString(): string;
}
export namespace editor {
/**
* Create a new editor under `domElement`.
* `domElement` should be empty (not contain other dom nodes).
* The editor will read the size of `domElement`.
*/
export function create(domElement: HTMLElement, options?: IStandaloneEditorConstructionOptions, override?: IEditorOverrideServices): IStandaloneCodeEditor;
/**
* Emitted when an editor is created.
* Creating a diff editor might cause this listener to be invoked with the two editors.
* @event
*/
export function onDidCreateEditor(listener: (codeEditor: ICodeEditor) => void): IDisposable;
/**
* Emitted when an diff editor is created.
* @event
*/
export function onDidCreateDiffEditor(listener: (diffEditor: IDiffEditor) => void): IDisposable;
/**
* Get all the created editors.
*/
export function getEditors(): readonly ICodeEditor[];
/**
* Get all the created diff editors.
*/
export function getDiffEditors(): readonly IDiffEditor[];
/**
* Create a new diff editor under `domElement`.
* `domElement` should be empty (not contain other dom nodes).
* The editor will read the size of `domElement`.
*/
export function createDiffEditor(domElement: HTMLElement, options?: IStandaloneDiffEditorConstructionOptions, override?: IEditorOverrideServices): IStandaloneDiffEditor;
export function createMultiFileDiffEditor(domElement: HTMLElement, override?: IEditorOverrideServices): any;
/**
* Description of a command contribution
*/
export interface ICommandDescriptor {
/**
* An unique identifier of the contributed command.
*/
id: string;
/**
* Callback that will be executed when the command is triggered.
*/
run: ICommandHandler;
}
/**
* Add a command.
*/
export function addCommand(descriptor: ICommandDescriptor): IDisposable;
/**
* Add an action to all editors.
*/
export function addEditorAction(descriptor: IActionDescriptor): IDisposable;
/**
* A keybinding rule.
*/
export interface IKeybindingRule {
keybinding: number;
command?: string | null;
commandArgs?: any;
when?: string | null;
}
/**
* Add a keybinding rule.
*/
export function addKeybindingRule(rule: IKeybindingRule): IDisposable;
/**
* Add keybinding rules.
*/
export function addKeybindingRules(rules: IKeybindingRule[]): IDisposable;
/**
* Create a new editor model.
* You can specify the language that should be set for this model or let the language be inferred from the `uri`.
*/
export function createModel(value: string, language?: string, uri?: Uri): ITextModel;
/**
* Change the language for a model.
*/
export function setModelLanguage(model: ITextModel, mimeTypeOrLanguageId: string): void;
/**
* Set the markers for a model.
*/
export function setModelMarkers(model: ITextModel, owner: string, markers: IMarkerData[]): void;
/**
* Remove all markers of an owner.
*/
export function removeAllMarkers(owner: string): void;
/**
* Get markers for owner and/or resource
*
* @returns list of markers
*/
export function getModelMarkers(filter: {
owner?: string;
resource?: Uri;
take?: number;
}): IMarker[];
/**
* Emitted when markers change for a model.
* @event
*/
export function onDidChangeMarkers(listener: (e: readonly Uri[]) => void): IDisposable;
/**
* Get the model that has `uri` if it exists.
*/
export function getModel(uri: Uri): ITextModel | null;
/**
* Get all the created models.
*/
export function getModels(): ITextModel[];
/**
* Emitted when a model is created.
* @event
*/
export function onDidCreateModel(listener: (model: ITextModel) => void): IDisposable;
/**
* Emitted right before a model is disposed.
* @event
*/
export function onWillDisposeModel(listener: (model: ITextModel) => void): IDisposable;
/**
* Emitted when a different language is set to a model.
* @event
*/
export function onDidChangeModelLanguage(listener: (e: {
readonly model: ITextModel;
readonly oldLanguage: string;
}) => void): IDisposable;
/**
* Create a new web worker that has model syncing capabilities built in.
* Specify an AMD module to load that will `create` an object that will be proxied.
*/
export function createWebWorker<T extends object>(opts: IWebWorkerOptions): MonacoWebWorker<T>;
/**
* Colorize the contents of `domNode` using attribute `data-lang`.
*/
export function colorizeElement(domNode: HTMLElement, options: IColorizerElementOptions): Promise<void>;
/**
* Colorize `text` using language `languageId`.
*/
export function colorize(text: string, languageId: string, options: IColorizerOptions): Promise<string>;
/**
* Colorize a line in a model.
*/
export function colorizeModelLine(model: ITextModel, lineNumber: number, tabSize?: number): string;
/**
* Tokenize `text` using language `languageId`
*/
export function tokenize(text: string, languageId: string): Token[][];
/**
* Define a new theme or update an existing theme.
*/
export function defineTheme(themeName: string, themeData: IStandaloneThemeData): void;
/**
* Switches to a theme.
*/
export function setTheme(themeName: string): void;
/**
* Clears all cached font measurements and triggers re-measurement.
*/
export function remeasureFonts(): void;
/**
* Register a command.
*/
export function registerCommand(id: string, handler: (accessor: any, ...args: any[]) => void): IDisposable;
export interface ILinkOpener {
open(resource: Uri): boolean | Promise<boolean>;
}
/**
* Registers a handler that is called when a link is opened in any editor. The handler callback should return `true` if the link was handled and `false` otherwise.
* The handler that was registered last will be called first when a link is opened.
*
* Returns a disposable that can unregister the opener again.
*/
export function registerLinkOpener(opener: ILinkOpener): IDisposable;
/**
* Represents an object that can handle editor open operations (e.g. when "go to definition" is called
* with a resource other than the current model).
*/
export interface ICodeEditorOpener {
/**
* Callback that is invoked when a resource other than the current model should be opened (e.g. when "go to definition" is called).
* The callback should return `true` if the request was handled and `false` otherwise.
* @param source The code editor instance that initiated the request.
* @param resource The Uri of the resource that should be opened.
* @param selectionOrPosition An optional position or selection inside the model corresponding to `resource` that can be used to set the cursor.
*/
openCodeEditor(source: ICodeEditor, resource: Uri, selectionOrPosition?: IRange | IPosition): boolean | Promise<boolean>;
}
/**
* Registers a handler that is called when a resource other than the current model should be opened in the editor (e.g. "go to definition").
* The handler callback should return `true` if the request was handled and `false` otherwise.
*
* Returns a disposable that can unregister the opener again.
*
* If no handler is registered the default behavior is to do nothing for models other than the currently attached one.
*/
export function registerEditorOpener(opener: ICodeEditorOpener): IDisposable;
export type BuiltinTheme = 'vs' | 'vs-dark' | 'hc-black' | 'hc-light';
export interface IStandaloneThemeData {
base: BuiltinTheme;
inherit: boolean;
rules: ITokenThemeRule[];
encodedTokensColors?: string[];
colors: IColors;
}
export type IColors = {
[colorId: string]: string;
};
export interface ITokenThemeRule {
token: string;
foreground?: string;
background?: string;
fontStyle?: string;
}
/**
* A web worker that can provide a proxy to an arbitrary file.
*/
export interface MonacoWebWorker<T> {
/**
* Terminate the web worker, thus invalidating the returned proxy.
*/
dispose(): void;
/**
* Get a proxy to the arbitrary loaded code.
*/
getProxy(): Promise<T>;
/**
* Synchronize (send) the models at `resources` to the web worker,
* making them available in the monaco.worker.getMirrorModels().
*/
withSyncedResources(resources: Uri[]): Promise<T>;
}
export interface IWebWorkerOptions {
/**
* The AMD moduleId to load.
* It should export a function `create` that should return the exported proxy.
*/
moduleId: string;
/**
* The data to send over when calling create on the module.
*/
createData?: any;
/**
* A label to be used to identify the web worker for debugging purposes.
*/
label?: string;
/**
* An object that can be used by the web worker to make calls back to the main thread.
*/
host?: any;
/**
* Keep idle models.
* Defaults to false, which means that idle models will stop syncing after a while.
*/
keepIdleModels?: boolean;
}
/**
* Description of an action contribution
*/
export interface IActionDescriptor {
/**
* An unique identifier of the contributed action.
*/
id: string;
/**
* A label of the action that will be presented to the user.
*/
label: string;
/**
* Precondition rule. The value should be a [context key expression](https://code.visualstudio.com/docs/getstarted/keybindings#_when-clause-contexts).
*/
precondition?: string;
/**
* An array of keybindings for the action.
*/
keybindings?: number[];
/**
* The keybinding rule (condition on top of precondition).
*/
keybindingContext?: string;
/**
* Control if the action should show up in the context menu and where.
* The context menu of the editor has these default:
* navigation - The navigation group comes first in all cases.
* 1_modification - This group comes next and contains commands that modify your code.
* 9_cutcopypaste - The last default group with the basic editing commands.
* You can also create your own group.
* Defaults to null (don't show in context menu).
*/
contextMenuGroupId?: string;
/**
* Control the order in the context menu group.
*/
contextMenuOrder?: number;
/**
* Method that will be executed when the action is triggered.
* @param editor The editor instance is passed in as a convenience
*/
run(editor: ICodeEditor, ...args: any[]): void | Promise<void>;
}
/**
* Options which apply for all editors.
*/
export interface IGlobalEditorOptions {
/**
* The number of spaces a tab is equal to.
* This setting is overridden based on the file contents when `detectIndentation` is on.
* Defaults to 4.
*/
tabSize?: number;
/**
* Insert spaces when pressing `Tab`.
* This setting is overridden based on the file contents when `detectIndentation` is on.
* Defaults to true.
*/
insertSpaces?: boolean;
/**
* Controls whether `tabSize` and `insertSpaces` will be automatically detected when a file is opened based on the file contents.
* Defaults to true.
*/
detectIndentation?: boolean;
/**
* Remove trailing auto inserted whitespace.
* Defaults to true.
*/
trimAutoWhitespace?: boolean;
/**
* Special handling for large files to disable certain memory intensive features.
* Defaults to true.
*/
largeFileOptimizations?: boolean;
/**
* Controls whether completions should be computed based on words in the document.
* Defaults to true.
*/
wordBasedSuggestions?: 'off' | 'currentDocument' | 'matchingDocuments' | 'allDocuments';
/**
* Controls whether word based completions should be included from opened documents of the same language or any language.
*/
wordBasedSuggestionsOnlySameLanguage?: boolean;
/**
* Controls whether the semanticHighlighting is shown for the languages that support it.
* true: semanticHighlighting is enabled for all themes
* false: semanticHighlighting is disabled for all themes
* 'configuredByTheme': semanticHighlighting is controlled by the current color theme's semanticHighlighting setting.
* Defaults to 'byTheme'.
*/
'semanticHighlighting.enabled'?: true | false | 'configuredByTheme';
/**
* Keep peek editors open even when double-clicking their content or when hitting `Escape`.
* Defaults to false.
*/
stablePeek?: boolean;
/**
* Lines above this length will not be tokenized for performance reasons.
* Defaults to 20000.
*/
maxTokenizationLineLength?: number;
/**
* Theme to be used for rendering.
* The current out-of-the-box available themes are: 'vs' (default), 'vs-dark', 'hc-black', 'hc-light'.
* You can create custom themes via `monaco.editor.defineTheme`.
* To switch a theme, use `monaco.editor.setTheme`.
* **NOTE**: The theme might be overwritten if the OS is in high contrast mode, unless `autoDetectHighContrast` is set to false.
*/
theme?: string;
/**
* If enabled, will automatically change to high contrast theme if the OS is using a high contrast theme.
* Defaults to true.
*/
autoDetectHighContrast?: boolean;
}
/**
* The options to create an editor.
*/
export interface IStandaloneEditorConstructionOptions extends IEditorConstructionOptions, IGlobalEditorOptions {
/**
* The initial model associated with this code editor.
*/
model?: ITextModel | null;
/**
* The initial value of the auto created model in the editor.
* To not automatically create a model, use `model: null`.
*/
value?: string;
/**
* The initial language of the auto created model in the editor.
* To not automatically create a model, use `model: null`.
*/
language?: string;
/**
* Initial theme to be used for rendering.
* The current out-of-the-box available themes are: 'vs' (default), 'vs-dark', 'hc-black', 'hc-light.
* You can create custom themes via `monaco.editor.defineTheme`.
* To switch a theme, use `monaco.editor.setTheme`.
* **NOTE**: The theme might be overwritten if the OS is in high contrast mode, unless `autoDetectHighContrast` is set to false.
*/
theme?: string;
/**
* If enabled, will automatically change to high contrast theme if the OS is using a high contrast theme.
* Defaults to true.
*/
autoDetectHighContrast?: boolean;
/**
* An URL to open when Ctrl+H (Windows and Linux) or Cmd+H (OSX) is pressed in
* the accessibility help dialog in the editor.
*
* Defaults to "https://go.microsoft.com/fwlink/?linkid=852450"
*/
accessibilityHelpUrl?: string;
/**
* Container element to use for ARIA messages.
* Defaults to document.body.
*/
ariaContainerElement?: HTMLElement;
}
/**
* The options to create a diff editor.
*/
export interface IStandaloneDiffEditorConstructionOptions extends IDiffEditorConstructionOptions {
/**
* Initial theme to be used for rendering.
* The current out-of-the-box available themes are: 'vs' (default), 'vs-dark', 'hc-black', 'hc-light.
* You can create custom themes via `monaco.editor.defineTheme`.
* To switch a theme, use `monaco.editor.setTheme`.
* **NOTE**: The theme might be overwritten if the OS is in high contrast mode, unless `autoDetectHighContrast` is set to false.
*/
theme?: string;
/**
* If enabled, will automatically change to high contrast theme if the OS is using a high contrast theme.
* Defaults to true.
*/
autoDetectHighContrast?: boolean;
}
export interface IStandaloneCodeEditor extends ICodeEditor {
updateOptions(newOptions: IEditorOptions & IGlobalEditorOptions): void;
addCommand(keybinding: number, handler: ICommandHandler, context?: string): string | null;
createContextKey<T extends ContextKeyValue = ContextKeyValue>(key: string, defaultValue: T): IContextKey<T>;
addAction(descriptor: IActionDescriptor): IDisposable;
}
export interface IStandaloneDiffEditor extends IDiffEditor {
addCommand(keybinding: number, handler: ICommandHandler, context?: string): string | null;
createContextKey<T extends ContextKeyValue = ContextKeyValue>(key: string, defaultValue: T): IContextKey<T>;
addAction(descriptor: IActionDescriptor): IDisposable;
getOriginalEditor(): IStandaloneCodeEditor;
getModifiedEditor(): IStandaloneCodeEditor;
}
export interface ICommandHandler {
(...args: any[]): void;
}
export interface ILocalizedString {
original: string;
value: string;
}
export interface ICommandMetadata {
readonly description: ILocalizedString | string;
}
export interface IContextKey<T extends ContextKeyValue = ContextKeyValue> {
set(value: T): void;
reset(): void;
get(): T | undefined;
}
export type ContextKeyValue = null | undefined | boolean | number | string | Array<null | undefined | boolean | number | string> | Record<string, null | undefined | boolean | number | string>;
export interface IEditorOverrideServices {
[index: string]: any;
}
export interface IMarker {
owner: string;
resource: Uri;
severity: MarkerSeverity;
code?: string | {
value: string;
target: Uri;
};
message: string;
source?: string;
startLineNumber: number;
startColumn: number;
endLineNumber: number;
endColumn: number;
modelVersionId?: number;
relatedInformation?: IRelatedInformation[];
tags?: MarkerTag[];
}
/**
* A structure defining a problem/warning/etc.
*/
export interface IMarkerData {
code?: string | {
value: string;
target: Uri;
};
severity: MarkerSeverity;
message: string;
source?: string;
startLineNumber: number;
startColumn: number;
endLineNumber: number;
endColumn: number;
modelVersionId?: number;
relatedInformation?: IRelatedInformation[];
tags?: MarkerTag[];
}
/**
*
*/
export interface IRelatedInformation {
resource: Uri;
message: string;
startLineNumber: number;
startColumn: number;
endLineNumber: number;
endColumn: number;
}
export interface IColorizerOptions {
tabSize?: number;
}
export interface IColorizerElementOptions extends IColorizerOptions {
theme?: string;
mimeType?: string;
}
export enum ScrollbarVisibility {
Auto = 1,
Hidden = 2,
Visible = 3
}
export interface ThemeColor {
id: string;
}
/**
* A single edit operation, that acts as a simple replace.
* i.e. Replace text at `range` with `text` in model.
*/
export interface ISingleEditOperation {
/**
* The range to replace. This can be empty to emulate a simple insert.
*/
range: IRange;
/**
* The text to replace with. This can be null to emulate a simple delete.
*/
text: string | null;
/**
* This indicates that this operation has "insert" semantics.
* i.e. forceMoveMarkers = true => if `range` is collapsed, all markers at the position will be moved.
*/
forceMoveMarkers?: boolean;
}
/**
* Word inside a model.
*/
export interface IWordAtPosition {
/**
* The word.
*/
readonly word: string;
/**
* The column where the word starts.
*/
readonly startColumn: number;
/**
* The column where the word ends.
*/
readonly endColumn: number;
}
/**
* Vertical Lane in the overview ruler of the editor.
*/
export enum OverviewRulerLane {
Left = 1,
Center = 2,
Right = 4,
Full = 7
}
/**
* Vertical Lane in the glyph margin of the editor.
*/
export enum GlyphMarginLane {
Left = 1,
Center = 2,
Right = 3
}
export interface IGlyphMarginLanesModel {
/**
* The number of lanes that should be rendered in the editor.
*/
readonly requiredLanes: number;
/**
* Gets the lanes that should be rendered starting at a given line number.
*/
getLanesAtLine(lineNumber: number): GlyphMarginLane[];
/**
* Resets the model and ensures it can contain at least `maxLine` lines.
*/
reset(maxLine: number): void;
/**
* Registers that a lane should be visible at the Range in the model.
* @param persist - if true, notes that the lane should always be visible,
* even on lines where there's no specific request for that lane.
*/
push(lane: GlyphMarginLane, range: Range, persist?: boolean): void;
}
/**
* Position in the minimap to render the decoration.
*/
export enum MinimapPosition {
Inline = 1,
Gutter = 2
}
/**
* Section header style.
*/
export enum MinimapSectionHeaderStyle {
Normal = 1,
Underlined = 2
}
export interface IDecorationOptions {
/**
* CSS color to render.
* e.g.: rgba(100, 100, 100, 0.5) or a color from the color registry
*/
color: string | ThemeColor | undefined;
/**
* CSS color to render.
* e.g.: rgba(100, 100, 100, 0.5) or a color from the color registry
*/
darkColor?: string | ThemeColor;
}
export interface IModelDecorationGlyphMarginOptions {
/**
* The position in the glyph margin.
*/
position: GlyphMarginLane;
/**
* Whether the glyph margin lane in {@link position} should be rendered even
* outside of this decoration's range.
*/
persistLane?: boolean;
}
/**
* Options for rendering a model decoration in the overview ruler.
*/
export interface IModelDecorationOverviewRulerOptions extends IDecorationOptions {
/**
* The position in the overview ruler.
*/
position: OverviewRulerLane;
}
/**
* Options for rendering a model decoration in the minimap.
*/
export interface IModelDecorationMinimapOptions extends IDecorationOptions {
/**
* The position in the minimap.
*/
position: MinimapPosition;
/**
* If the decoration is for a section header, which header style.
*/
sectionHeaderStyle?: MinimapSectionHeaderStyle | null;
/**
* If the decoration is for a section header, the header text.
*/
sectionHeaderText?: string | null;
}
/**
* Options for a model decoration.
*/
export interface IModelDecorationOptions {
/**
* Customize the growing behavior of the decoration when typing at the edges of the decoration.
* Defaults to TrackedRangeStickiness.AlwaysGrowsWhenTypingAtEdges
*/
stickiness?: TrackedRangeStickiness;
/**
* CSS class name describing the decoration.
*/
className?: string | null;
/**
* Indicates whether the decoration should span across the entire line when it continues onto the next line.
*/
shouldFillLineOnLineBreak?: boolean | null;
blockClassName?: string | null;
/**
* Indicates if this block should be rendered after the last line.
* In this case, the range must be empty and set to the last line.
*/
blockIsAfterEnd?: boolean | null;
blockDoesNotCollapse?: boolean | null;
blockPadding?: [top: number, right: number, bottom: number, left: number] | null;
/**
* Message to be rendered when hovering over the glyph margin decoration.
*/
glyphMarginHoverMessage?: IMarkdownString | IMarkdownString[] | null;
/**
* Array of MarkdownString to render as the decoration message.
*/
hoverMessage?: IMarkdownString | IMarkdownString[] | null;
/**
* Array of MarkdownString to render as the line number message.
*/
lineNumberHoverMessage?: IMarkdownString | IMarkdownString[] | null;
/**
* Should the decoration expand to encompass a whole line.
*/
isWholeLine?: boolean;
/**
* Always render the decoration (even when the range it encompasses is collapsed).
*/
showIfCollapsed?: boolean;
/**
* Specifies the st