mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 18:49:00 +01:00
debt - add some XYZ.isXYZ methods to the ext host types.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user