mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 19:18:59 +01:00
type converter, use namespace for Range
This commit is contained in:
@@ -392,7 +392,7 @@ export class ExtHostApiCommands {
|
||||
};
|
||||
return this._commands.executeCommand<IRawColorInfo[]>('_executeDocumentColorProvider', args).then(result => {
|
||||
if (result) {
|
||||
return result.map(ci => ({ range: typeConverters.toRange(ci.range), color: typeConverters.Color.to(ci.color) }));
|
||||
return result.map(ci => ({ range: typeConverters.Range.to(ci.range), color: typeConverters.Color.to(ci.color) }));
|
||||
}
|
||||
return [];
|
||||
});
|
||||
@@ -402,7 +402,7 @@ export class ExtHostApiCommands {
|
||||
const args = {
|
||||
resource: context.uri,
|
||||
color: typeConverters.Color.from(color),
|
||||
range: typeConverters.fromRange(context.range),
|
||||
range: typeConverters.Range.from(context.range),
|
||||
};
|
||||
return this._commands.executeCommand<modes.IColorPresentation[]>('_executeColorPresentationProvider', args).then(result => {
|
||||
if (result) {
|
||||
@@ -427,7 +427,7 @@ export class ExtHostApiCommands {
|
||||
private _executeCodeActionProvider(resource: URI, range: types.Range): Thenable<(vscode.CodeAction | vscode.Command)[]> {
|
||||
const args = {
|
||||
resource,
|
||||
range: typeConverters.fromRange(range)
|
||||
range: typeConverters.Range.from(range)
|
||||
};
|
||||
return this._commands.executeCommand<CustomCodeAction[]>('_executeCodeActionProvider', args)
|
||||
.then(tryMapWith(codeAction => {
|
||||
@@ -454,7 +454,7 @@ export class ExtHostApiCommands {
|
||||
return this._commands.executeCommand<modes.ICodeLensSymbol[]>('_executeCodeLensProvider', args)
|
||||
.then(tryMapWith(item => {
|
||||
return new types.CodeLens(
|
||||
typeConverters.toRange(item.range),
|
||||
typeConverters.Range.to(item.range),
|
||||
this._commands.converter.fromInternal(item.command));
|
||||
}));
|
||||
|
||||
@@ -466,17 +466,17 @@ export class ExtHostApiCommands {
|
||||
options
|
||||
};
|
||||
return this._commands.executeCommand<ISingleEditOperation[]>('_executeFormatDocumentProvider', args)
|
||||
.then(tryMapWith(edit => new types.TextEdit(typeConverters.toRange(edit.range), edit.text)));
|
||||
.then(tryMapWith(edit => new types.TextEdit(typeConverters.Range.to(edit.range), edit.text)));
|
||||
}
|
||||
|
||||
private _executeFormatRangeProvider(resource: URI, range: types.Range, options: vscode.FormattingOptions): Thenable<vscode.TextEdit[]> {
|
||||
const args = {
|
||||
resource,
|
||||
range: typeConverters.fromRange(range),
|
||||
range: typeConverters.Range.from(range),
|
||||
options
|
||||
};
|
||||
return this._commands.executeCommand<ISingleEditOperation[]>('_executeFormatRangeProvider', args)
|
||||
.then(tryMapWith(edit => new types.TextEdit(typeConverters.toRange(edit.range), edit.text)));
|
||||
.then(tryMapWith(edit => new types.TextEdit(typeConverters.Range.to(edit.range), edit.text)));
|
||||
}
|
||||
|
||||
private _executeFormatOnTypeProvider(resource: URI, position: types.Position, ch: string, options: vscode.FormattingOptions): Thenable<vscode.TextEdit[]> {
|
||||
@@ -487,7 +487,7 @@ export class ExtHostApiCommands {
|
||||
options
|
||||
};
|
||||
return this._commands.executeCommand<ISingleEditOperation[]>('_executeFormatOnTypeProvider', args)
|
||||
.then(tryMapWith(edit => new types.TextEdit(typeConverters.toRange(edit.range), edit.text)));
|
||||
.then(tryMapWith(edit => new types.TextEdit(typeConverters.Range.to(edit.range), edit.text)));
|
||||
}
|
||||
|
||||
private _executeDocumentLinkProvider(resource: URI): Thenable<vscode.DocumentLink[]> {
|
||||
|
||||
@@ -95,7 +95,7 @@ export class ExtHostCommands implements ExtHostCommandsShape {
|
||||
return extHostTypeConverter.fromPosition(value);
|
||||
}
|
||||
if (value instanceof extHostTypes.Range) {
|
||||
return extHostTypeConverter.fromRange(value);
|
||||
return extHostTypeConverter.Range.from(value);
|
||||
}
|
||||
if (value instanceof extHostTypes.Location) {
|
||||
return extHostTypeConverter.location.from(value);
|
||||
|
||||
@@ -10,7 +10,7 @@ import { sequence, always } from 'vs/base/common/async';
|
||||
import { illegalState } from 'vs/base/common/errors';
|
||||
import { ExtHostDocumentSaveParticipantShape, MainThreadTextEditorsShape, ResourceTextEditDto } from 'vs/workbench/api/node/extHost.protocol';
|
||||
import { TextEdit } from 'vs/workbench/api/node/extHostTypes';
|
||||
import { fromRange, TextDocumentSaveReason, EndOfLine } from 'vs/workbench/api/node/extHostTypeConverters';
|
||||
import { Range, TextDocumentSaveReason, EndOfLine } from 'vs/workbench/api/node/extHostTypeConverters';
|
||||
import { ExtHostDocuments } from 'vs/workbench/api/node/extHostDocuments';
|
||||
import { SaveReason } from 'vs/workbench/services/textfile/common/textfiles';
|
||||
import * as vscode from 'vscode';
|
||||
@@ -151,7 +151,7 @@ export class ExtHostDocumentSaveParticipant implements ExtHostDocumentSavePartic
|
||||
if (Array.isArray(value) && (<vscode.TextEdit[]>value).every(e => e instanceof TextEdit)) {
|
||||
for (const { newText, newEol, range } of value) {
|
||||
resourceEdit.edits.push({
|
||||
range: range && fromRange(range),
|
||||
range: range && Range.from(range),
|
||||
text: newText,
|
||||
eol: EndOfLine.from(newEol)
|
||||
});
|
||||
|
||||
@@ -136,7 +136,7 @@ export class ExtHostDocuments implements ExtHostDocumentsShape {
|
||||
document: data.document,
|
||||
contentChanges: events.changes.map((change) => {
|
||||
return {
|
||||
range: TypeConverters.toRange(change.range),
|
||||
range: TypeConverters.Range.to(change.range),
|
||||
rangeOffset: change.rangeOffset,
|
||||
rangeLength: change.rangeLength,
|
||||
text: change.text
|
||||
|
||||
@@ -97,7 +97,7 @@ export class ExtHostDocumentsAndEditors implements ExtHostDocumentsAndEditorsSha
|
||||
documentData,
|
||||
data.selections.map(typeConverters.Selection.to),
|
||||
data.options,
|
||||
data.visibleRanges.map(typeConverters.toRange),
|
||||
data.visibleRanges.map(typeConverters.Range.to),
|
||||
typeConverters.toViewColumn(data.editorPosition)
|
||||
);
|
||||
this._editors.set(data.id, editor);
|
||||
|
||||
@@ -74,7 +74,7 @@ class CodeLensAdapter {
|
||||
return lenses.map(lens => {
|
||||
const id = this._heapService.keep(lens);
|
||||
return ObjectIdentifier.mixin({
|
||||
range: typeConvert.fromRange(lens.range),
|
||||
range: typeConvert.Range.from(lens.range),
|
||||
command: this._commands.toInternal(lens.command)
|
||||
}, id);
|
||||
});
|
||||
@@ -230,7 +230,7 @@ class DocumentHighlightAdapter {
|
||||
|
||||
private static _convertDocumentHighlight(documentHighlight: vscode.DocumentHighlight): modes.DocumentHighlight {
|
||||
return {
|
||||
range: typeConvert.fromRange(documentHighlight.range),
|
||||
range: typeConvert.Range.from(documentHighlight.range),
|
||||
kind: documentHighlight.kind
|
||||
};
|
||||
}
|
||||
@@ -275,7 +275,7 @@ class CodeActionAdapter {
|
||||
provideCodeActions(resource: URI, range: IRange, context: modes.CodeActionContext): TPromise<CodeActionDto[]> {
|
||||
|
||||
const doc = this._documents.getDocumentData(resource).document;
|
||||
const ran = <vscode.Range>typeConvert.toRange(range);
|
||||
const ran = <vscode.Range>typeConvert.Range.to(range);
|
||||
const allDiagnostics: vscode.Diagnostic[] = [];
|
||||
|
||||
for (const diagnostic of this._diagnostics.getDiagnostics(resource)) {
|
||||
@@ -363,7 +363,7 @@ class RangeFormattingAdapter {
|
||||
provideDocumentRangeFormattingEdits(resource: URI, range: IRange, options: modes.FormattingOptions): TPromise<ISingleEditOperation[]> {
|
||||
|
||||
const { document } = this._documents.getDocumentData(resource);
|
||||
const ran = typeConvert.toRange(range);
|
||||
const ran = typeConvert.Range.to(range);
|
||||
|
||||
return asWinJsPromise(token => this._provider.provideDocumentRangeFormattingEdits(document, ran, <any>options, token)).then(value => {
|
||||
if (Array.isArray(value)) {
|
||||
@@ -533,7 +533,7 @@ class RenameAdapter {
|
||||
console.warn('INVALID rename location: range must contain position');
|
||||
return undefined;
|
||||
}
|
||||
return { range: typeConvert.fromRange(range), text };
|
||||
return { range: typeConvert.Range.from(range), text };
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -792,7 +792,7 @@ class ColorProviderAdapter {
|
||||
const colorInfos: IRawColorInfo[] = colors.map(ci => {
|
||||
return {
|
||||
color: typeConvert.Color.from(ci.color),
|
||||
range: typeConvert.fromRange(ci.range)
|
||||
range: typeConvert.Range.from(ci.range)
|
||||
};
|
||||
});
|
||||
|
||||
@@ -802,7 +802,7 @@ class ColorProviderAdapter {
|
||||
|
||||
provideColorPresentations(resource: URI, raw: IRawColorInfo): TPromise<modes.IColorPresentation[]> {
|
||||
const document = this._documents.getDocumentData(resource).document;
|
||||
const range = typeConvert.toRange(raw.range);
|
||||
const range = typeConvert.Range.to(raw.range);
|
||||
const color = typeConvert.Color.to(raw.color);
|
||||
return asWinJsPromise(token => this._provider.provideColorPresentations(color, { document, range }, token)).then(value => {
|
||||
return value.map(typeConvert.ColorPresentation.from);
|
||||
|
||||
@@ -467,7 +467,7 @@ export class ExtHostTextEditor implements vscode.TextEditor {
|
||||
this._runOnProxy(
|
||||
() => this._proxy.$tryRevealRange(
|
||||
this._id,
|
||||
TypeConverters.fromRange(range),
|
||||
TypeConverters.Range.from(range),
|
||||
(revealType || TextEditorRevealType.Default)
|
||||
)
|
||||
);
|
||||
@@ -530,7 +530,7 @@ export class ExtHostTextEditor implements vscode.TextEditor {
|
||||
// prepare data for serialization
|
||||
let edits: ISingleEditOperation[] = editData.edits.map((edit) => {
|
||||
return {
|
||||
range: TypeConverters.fromRange(edit.range),
|
||||
range: TypeConverters.Range.from(edit.range),
|
||||
text: edit.text,
|
||||
forceMoveMarkers: edit.forceMoveMarkers
|
||||
};
|
||||
@@ -550,19 +550,19 @@ export class ExtHostTextEditor implements vscode.TextEditor {
|
||||
let ranges: IRange[];
|
||||
|
||||
if (!where || (Array.isArray(where) && where.length === 0)) {
|
||||
ranges = this._selections.map(TypeConverters.fromRange);
|
||||
ranges = this._selections.map(TypeConverters.Range.from);
|
||||
|
||||
} else if (where instanceof Position) {
|
||||
const { lineNumber, column } = TypeConverters.fromPosition(where);
|
||||
ranges = [{ startLineNumber: lineNumber, startColumn: column, endLineNumber: lineNumber, endColumn: column }];
|
||||
|
||||
} else if (where instanceof Range) {
|
||||
ranges = [TypeConverters.fromRange(where)];
|
||||
ranges = [TypeConverters.Range.from(where)];
|
||||
} else {
|
||||
ranges = [];
|
||||
for (const posOrRange of where) {
|
||||
if (posOrRange instanceof Range) {
|
||||
ranges.push(TypeConverters.fromRange(posOrRange));
|
||||
ranges.push(TypeConverters.Range.from(posOrRange));
|
||||
} else {
|
||||
const { lineNumber, column } = TypeConverters.fromPosition(posOrRange);
|
||||
ranges.push({ startLineNumber: lineNumber, startColumn: column, endLineNumber: lineNumber, endColumn: column });
|
||||
|
||||
@@ -68,7 +68,7 @@ export class ExtHostEditors implements ExtHostEditorsShape {
|
||||
options = {
|
||||
position: TypeConverters.fromViewColumn(columnOrOptions.viewColumn),
|
||||
preserveFocus: columnOrOptions.preserveFocus,
|
||||
selection: typeof columnOrOptions.selection === 'object' ? TypeConverters.fromRange(columnOrOptions.selection) : undefined,
|
||||
selection: typeof columnOrOptions.selection === 'object' ? TypeConverters.Range.from(columnOrOptions.selection) : undefined,
|
||||
pinned: typeof columnOrOptions.preview === 'boolean' ? !columnOrOptions.preview : undefined
|
||||
};
|
||||
} else {
|
||||
@@ -127,7 +127,7 @@ export class ExtHostEditors implements ExtHostEditorsShape {
|
||||
textEditor._acceptSelections(selections);
|
||||
}
|
||||
if (data.visibleRanges) {
|
||||
const visibleRanges = data.visibleRanges.map(TypeConverters.toRange);
|
||||
const visibleRanges = data.visibleRanges.map(TypeConverters.Range.to);
|
||||
textEditor._acceptVisibleRanges(visibleRanges);
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ export class ExtHostEditors implements ExtHostEditorsShape {
|
||||
});
|
||||
}
|
||||
if (data.visibleRanges) {
|
||||
const visibleRanges = data.visibleRanges.map(TypeConverters.toRange);
|
||||
const visibleRanges = data.visibleRanges.map(TypeConverters.Range.to);
|
||||
this._onDidChangeTextEditorVisibleRanges.fire({
|
||||
textEditor,
|
||||
visibleRanges
|
||||
|
||||
@@ -55,26 +55,28 @@ export namespace Selection {
|
||||
};
|
||||
}
|
||||
}
|
||||
export namespace Range {
|
||||
|
||||
export function fromRange(range: RangeLike): IRange {
|
||||
if (!range) {
|
||||
return undefined;
|
||||
export function from(range: RangeLike): IRange {
|
||||
if (!range) {
|
||||
return undefined;
|
||||
}
|
||||
let { start, end } = range;
|
||||
return {
|
||||
startLineNumber: start.line + 1,
|
||||
startColumn: start.character + 1,
|
||||
endLineNumber: end.line + 1,
|
||||
endColumn: end.character + 1
|
||||
};
|
||||
}
|
||||
let { start, end } = range;
|
||||
return {
|
||||
startLineNumber: start.line + 1,
|
||||
startColumn: start.character + 1,
|
||||
endLineNumber: end.line + 1,
|
||||
endColumn: end.character + 1
|
||||
};
|
||||
}
|
||||
|
||||
export function toRange(range: IRange): types.Range {
|
||||
if (!range) {
|
||||
return undefined;
|
||||
export function to(range: IRange): types.Range {
|
||||
if (!range) {
|
||||
return undefined;
|
||||
}
|
||||
let { startLineNumber, startColumn, endLineNumber, endColumn } = range;
|
||||
return new types.Range(startLineNumber - 1, startColumn - 1, endLineNumber - 1, endColumn - 1);
|
||||
}
|
||||
let { startLineNumber, startColumn, endLineNumber, endColumn } = range;
|
||||
return new types.Range(startLineNumber - 1, startColumn - 1, endLineNumber - 1, endColumn - 1);
|
||||
}
|
||||
|
||||
export function toPosition(position: IPosition): types.Position {
|
||||
@@ -87,7 +89,7 @@ export function fromPosition(position: types.Position): IPosition {
|
||||
|
||||
export function fromDiagnostic(value: vscode.Diagnostic): IMarkerData {
|
||||
return {
|
||||
...fromRange(value.range),
|
||||
...Range.from(value.range),
|
||||
message: value.message,
|
||||
source: value.source,
|
||||
code: String(value.code),
|
||||
@@ -98,14 +100,14 @@ export function fromDiagnostic(value: vscode.Diagnostic): IMarkerData {
|
||||
|
||||
export function fromDiagnosticRelatedInformation(value: types.DiagnosticRelatedInformation): IRelatedInformation {
|
||||
return {
|
||||
...fromRange(value.location.range),
|
||||
...Range.from(value.location.range),
|
||||
message: value.message,
|
||||
resource: value.location.uri
|
||||
};
|
||||
}
|
||||
|
||||
export function toDiagnosticRelatedInformation(value: IRelatedInformation): types.DiagnosticRelatedInformation {
|
||||
return new types.DiagnosticRelatedInformation(new types.Location(value.resource, toRange(value)), value.message);
|
||||
return new types.DiagnosticRelatedInformation(new types.Location(value.resource, Range.to(value)), value.message);
|
||||
}
|
||||
|
||||
export function fromDiagnosticSeverity(value: number): MarkerSeverity {
|
||||
@@ -223,7 +225,7 @@ export function fromRangeOrRangeWithMessage(ranges: vscode.Range[] | vscode.Deco
|
||||
if (isDecorationOptionsArr(ranges)) {
|
||||
return ranges.map(r => {
|
||||
return {
|
||||
range: fromRange(r.range),
|
||||
range: Range.from(r.range),
|
||||
hoverMessage: Array.isArray(r.hoverMessage) ? MarkdownString.fromMany(r.hoverMessage) : r.hoverMessage && MarkdownString.from(r.hoverMessage),
|
||||
renderOptions: <any> /* URI vs Uri */r.renderOptions
|
||||
};
|
||||
@@ -231,7 +233,7 @@ export function fromRangeOrRangeWithMessage(ranges: vscode.Range[] | vscode.Deco
|
||||
} else {
|
||||
return ranges.map((r): IDecorationOptions => {
|
||||
return {
|
||||
range: fromRange(r)
|
||||
range: Range.from(r)
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -243,11 +245,11 @@ export const TextEdit = {
|
||||
return <modes.TextEdit>{
|
||||
text: edit.newText,
|
||||
eol: EndOfLine.from(edit.newEol),
|
||||
range: fromRange(edit.range)
|
||||
range: Range.from(edit.range)
|
||||
};
|
||||
},
|
||||
to(edit: modes.TextEdit): types.TextEdit {
|
||||
let result = new types.TextEdit(toRange(edit.range), edit.text);
|
||||
let result = new types.TextEdit(Range.to(edit.range), edit.text);
|
||||
result.newEol = EndOfLine.to(edit.eol);
|
||||
return result;
|
||||
}
|
||||
@@ -360,7 +362,7 @@ export namespace HierarchicalSymbolInformation {
|
||||
name: info.name,
|
||||
detail: info.detail,
|
||||
location: location.from(info.location),
|
||||
definingRange: fromRange(info.range),
|
||||
definingRange: Range.from(info.range),
|
||||
kind: SymbolKind.from(info.kind)
|
||||
};
|
||||
if (info.children) {
|
||||
@@ -374,7 +376,7 @@ export namespace HierarchicalSymbolInformation {
|
||||
SymbolKind.to(info.kind),
|
||||
info.detail,
|
||||
location.to(info.location),
|
||||
toRange(info.definingRange)
|
||||
Range.to(info.definingRange)
|
||||
);
|
||||
if (info.children) {
|
||||
result.children = info.children.map(to);
|
||||
@@ -386,28 +388,28 @@ export namespace HierarchicalSymbolInformation {
|
||||
export const location = {
|
||||
from(value: vscode.Location): modes.Location {
|
||||
return {
|
||||
range: value.range && fromRange(value.range),
|
||||
range: value.range && Range.from(value.range),
|
||||
uri: value.uri
|
||||
};
|
||||
},
|
||||
to(value: modes.Location): types.Location {
|
||||
return new types.Location(value.uri, toRange(value.range));
|
||||
return new types.Location(value.uri, Range.to(value.range));
|
||||
}
|
||||
};
|
||||
|
||||
export function fromHover(hover: vscode.Hover): modes.Hover {
|
||||
return <modes.Hover>{
|
||||
range: fromRange(hover.range),
|
||||
range: Range.from(hover.range),
|
||||
contents: MarkdownString.fromMany(hover.contents)
|
||||
};
|
||||
}
|
||||
|
||||
export function toHover(info: modes.Hover): types.Hover {
|
||||
return new types.Hover(info.contents.map(MarkdownString.to), toRange(info.range));
|
||||
return new types.Hover(info.contents.map(MarkdownString.to), Range.to(info.range));
|
||||
}
|
||||
|
||||
export function toDocumentHighlight(occurrence: modes.DocumentHighlight): types.DocumentHighlight {
|
||||
return new types.DocumentHighlight(toRange(occurrence.range), occurrence.kind);
|
||||
return new types.DocumentHighlight(Range.to(occurrence.range), occurrence.kind);
|
||||
}
|
||||
|
||||
export namespace CompletionTriggerKind {
|
||||
@@ -566,13 +568,13 @@ export namespace DocumentLink {
|
||||
|
||||
export function from(link: vscode.DocumentLink): modes.ILink {
|
||||
return {
|
||||
range: fromRange(link.range),
|
||||
range: Range.from(link.range),
|
||||
url: link.target && link.target.toString()
|
||||
};
|
||||
}
|
||||
|
||||
export function to(link: modes.ILink): vscode.DocumentLink {
|
||||
return new types.DocumentLink(toRange(link.range), link.url && URI.parse(link.url));
|
||||
return new types.DocumentLink(Range.to(link.range), link.url && URI.parse(link.url));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -685,7 +687,7 @@ export function toTextEditorOptions(options?: vscode.TextDocumentShowOptions): I
|
||||
return {
|
||||
pinned: typeof options.preview === 'boolean' ? !options.preview : undefined,
|
||||
preserveFocus: options.preserveFocus,
|
||||
selection: typeof options.selection === 'object' ? fromRange(options.selection) : undefined
|
||||
selection: typeof options.selection === 'object' ? Range.from(options.selection) : undefined
|
||||
} as ITextEditorOptions;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user