debt - add some XYZ.isXYZ methods to the ext host types.
This commit is contained in:
parent
64e3c01410
commit
fbbb9061bc
3 changed files with 56 additions and 6 deletions
|
@ -39,6 +39,20 @@ function encodeNoop(str: string): string {
|
|||
*/
|
||||
export default class URI {
|
||||
|
||||
static isUri(thing: any): thing is URI {
|
||||
if (thing instanceof URI) {
|
||||
return true;
|
||||
}
|
||||
if (!thing) {
|
||||
return false;
|
||||
}
|
||||
return typeof (<URI>thing).authority === 'string'
|
||||
&& typeof (<URI>thing).fragment === 'string'
|
||||
&& typeof (<URI>thing).path === 'string'
|
||||
&& typeof (<URI>thing).query === 'string'
|
||||
&& typeof (<URI>thing).scheme === 'string';
|
||||
}
|
||||
|
||||
private static _empty = '';
|
||||
private static _slash = '/';
|
||||
private static _regexp = /^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/;
|
||||
|
|
1
src/vs/monaco.d.ts
vendored
1
src/vs/monaco.d.ts
vendored
|
@ -111,6 +111,7 @@ declare module monaco {
|
|||
*
|
||||
*/
|
||||
export class Uri {
|
||||
static isUri(thing: any): thing is Uri;
|
||||
constructor();
|
||||
/**
|
||||
* scheme is the 'http' part of 'http://www.msft.com/some/path?query#fragment'.
|
||||
|
|
|
@ -63,7 +63,7 @@ export class Position {
|
|||
return result;
|
||||
}
|
||||
|
||||
static is(other: any): other is Position {
|
||||
static isPosition(other: any): other is Position {
|
||||
if (!other) {
|
||||
return false;
|
||||
}
|
||||
|
@ -206,15 +206,15 @@ export class Position {
|
|||
|
||||
export class Range {
|
||||
|
||||
static is(thing: any): thing is Range {
|
||||
static isRange(thing: any): thing is Range {
|
||||
if (thing instanceof Range) {
|
||||
return true;
|
||||
}
|
||||
if (!thing) {
|
||||
return false;
|
||||
}
|
||||
return Position.is((<Range>thing).start)
|
||||
&& Position.is((<Range>thing.end));
|
||||
return Position.isPosition((<Range>thing).start)
|
||||
&& Position.isPosition((<Range>thing.end));
|
||||
}
|
||||
|
||||
protected _start: Position;
|
||||
|
@ -319,7 +319,7 @@ export class Range {
|
|||
if (!startOrChange) {
|
||||
start = this.start;
|
||||
|
||||
} else if (Position.is(startOrChange)) {
|
||||
} else if (Position.isPosition(startOrChange)) {
|
||||
start = startOrChange;
|
||||
|
||||
} else {
|
||||
|
@ -340,6 +340,19 @@ export class Range {
|
|||
|
||||
export class Selection extends Range {
|
||||
|
||||
static isSelection(thing: any): thing is Selection {
|
||||
if (thing instanceof Selection) {
|
||||
return true;
|
||||
}
|
||||
if (!thing) {
|
||||
return false;
|
||||
}
|
||||
return Range.isRange(thing)
|
||||
&& Position.isPosition((<Selection>thing).anchor)
|
||||
&& Position.isPosition((<Selection>thing).active)
|
||||
&& typeof (<Selection>thing).isReversed === 'boolean';
|
||||
}
|
||||
|
||||
private _anchor: Position;
|
||||
|
||||
public get anchor(): Position {
|
||||
|
@ -392,6 +405,17 @@ export class Selection extends Range {
|
|||
|
||||
export class TextEdit {
|
||||
|
||||
static isTextEdit(thing: any): thing is TextEdit {
|
||||
if (thing instanceof TextEdit) {
|
||||
return true;
|
||||
}
|
||||
if (!thing) {
|
||||
return false;
|
||||
}
|
||||
return Range.isRange((<TextEdit>thing))
|
||||
&& typeof (<TextEdit>thing).newText === 'string';
|
||||
}
|
||||
|
||||
static replace(range: Range, newText: string): TextEdit {
|
||||
return new TextEdit(range, newText);
|
||||
}
|
||||
|
@ -506,6 +530,17 @@ export enum DiagnosticSeverity {
|
|||
|
||||
export class Location {
|
||||
|
||||
static isLocation(thing: any): thing is Location {
|
||||
if (thing instanceof Location) {
|
||||
return true;
|
||||
}
|
||||
if (!thing) {
|
||||
return false;
|
||||
}
|
||||
return Range.isRange((<Location>thing).range)
|
||||
&& URI.isUri((<Location>thing).uri);
|
||||
}
|
||||
|
||||
uri: URI;
|
||||
range: Range;
|
||||
|
||||
|
@ -791,7 +826,7 @@ export class DocumentLink {
|
|||
if (!(target instanceof URI)) {
|
||||
throw illegalArgument('target');
|
||||
}
|
||||
if (!Range.is(range) || range.isEmpty) {
|
||||
if (!Range.isRange(range) || range.isEmpty) {
|
||||
throw illegalArgument('range');
|
||||
}
|
||||
this.range = range;
|
||||
|
|
Loading…
Reference in a new issue