mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 10:38:59 +01:00
add SelectionRange and SelectionRangeKind, #63935
This commit is contained in:
@@ -784,6 +784,8 @@ export function createApiFactory(
|
||||
Range: extHostTypes.Range,
|
||||
RelativePattern: extHostTypes.RelativePattern,
|
||||
Selection: extHostTypes.Selection,
|
||||
SelectionRange: extHostTypes.SelectionRange,
|
||||
SelectionRangeKind: extHostTypes.SelectionRangeKind,
|
||||
ShellExecution: extHostTypes.ShellExecution,
|
||||
ShellQuoting: extHostTypes.ShellQuoting,
|
||||
SignatureHelpTriggerKind: extHostTypes.SignatureHelpTriggerKind,
|
||||
|
||||
@@ -886,7 +886,7 @@ export interface ExtHostLanguageFeaturesShape {
|
||||
$provideDocumentColors(handle: number, resource: UriComponents, token: CancellationToken): Promise<IRawColorInfo[]>;
|
||||
$provideColorPresentations(handle: number, resource: UriComponents, colorInfo: IRawColorInfo, token: CancellationToken): Promise<modes.IColorPresentation[]>;
|
||||
$provideFoldingRanges(handle: number, resource: UriComponents, context: modes.FoldingContext, token: CancellationToken): Promise<modes.FoldingRange[]>;
|
||||
$provideSelectionRanges(handle: number, resource: UriComponents, position: IPosition, token: CancellationToken): Promise<IRange[]>;
|
||||
$provideSelectionRanges(handle: number, resource: UriComponents, position: IPosition, token: CancellationToken): Promise<modes.SelectionRange[]>;
|
||||
}
|
||||
|
||||
export interface ExtHostQuickOpenShape {
|
||||
|
||||
@@ -18,7 +18,6 @@ import { CustomCodeAction } from 'vs/workbench/api/node/extHostLanguageFeatures'
|
||||
import { ICommandsExecutor, PreviewHTMLAPICommand, OpenFolderAPICommand, DiffAPICommand, OpenAPICommand, RemoveFromRecentlyOpenedAPICommand, SetEditorLayoutAPICommand } from './apiCommands';
|
||||
import { EditorGroupLayout } from 'vs/workbench/services/group/common/editorGroupsService';
|
||||
import { isFalsyOrEmpty, isNonEmptyArray } from 'vs/base/common/arrays';
|
||||
import { IRange } from 'vs/editor/common/core/range';
|
||||
|
||||
export class ExtHostApiCommands {
|
||||
|
||||
@@ -421,14 +420,14 @@ export class ExtHostApiCommands {
|
||||
});
|
||||
}
|
||||
|
||||
private _executeSelectionRangeProvider(resource: URI, position: types.Position): Promise<types.Range[]> {
|
||||
private _executeSelectionRangeProvider(resource: URI, position: types.Position): Promise<vscode.SelectionRange[]> {
|
||||
const args = {
|
||||
resource,
|
||||
position: position && typeConverters.Position.from(position)
|
||||
};
|
||||
return this._commands.executeCommand<IRange[]>('_executeSelectionRangeProvider', args).then(result => {
|
||||
return this._commands.executeCommand<modes.SelectionRange[]>('_executeSelectionRangeProvider', args).then(result => {
|
||||
if (isNonEmptyArray(result)) {
|
||||
return result.map(typeConverters.Range.to);
|
||||
return result.map(typeConverters.SelectionRange.to);
|
||||
}
|
||||
return [];
|
||||
});
|
||||
|
||||
@@ -853,21 +853,21 @@ class SelectionRangeAdapter {
|
||||
private readonly _provider: vscode.SelectionRangeProvider
|
||||
) { }
|
||||
|
||||
provideSelectionRanges(resource: URI, position: IPosition, token: CancellationToken): Promise<IRange[]> {
|
||||
provideSelectionRanges(resource: URI, position: IPosition, token: CancellationToken): Promise<modes.SelectionRange[]> {
|
||||
const { document } = this._documents.getDocumentData(resource);
|
||||
const pos = typeConvert.Position.to(position);
|
||||
return asPromise(() => this._provider.provideSelectionRanges(document, pos, token)).then(ranges => {
|
||||
if (isFalsyOrEmpty(ranges)) {
|
||||
return asPromise(() => this._provider.provideSelectionRanges(document, pos, token)).then(selectionRanges => {
|
||||
if (isFalsyOrEmpty(selectionRanges)) {
|
||||
return undefined;
|
||||
}
|
||||
let result: IRange[] = [];
|
||||
let result: modes.SelectionRange[] = [];
|
||||
let last: vscode.Position | vscode.Range = pos;
|
||||
for (const range of ranges) {
|
||||
if (!range.contains(last)) {
|
||||
for (const sel of selectionRanges) {
|
||||
if (!sel.range.contains(last)) {
|
||||
throw new Error('INVALID selection range, must contain the previous range');
|
||||
}
|
||||
result.push(typeConvert.Range.from(range));
|
||||
last = range;
|
||||
result.push(typeConvert.SelectionRange.from(sel));
|
||||
last = sel.range;
|
||||
}
|
||||
return result;
|
||||
});
|
||||
@@ -1280,7 +1280,7 @@ export class ExtHostLanguageFeatures implements ExtHostLanguageFeaturesShape {
|
||||
return this._createDisposable(handle);
|
||||
}
|
||||
|
||||
$provideSelectionRanges(handle: number, resource: UriComponents, position: IPosition, token: CancellationToken): Promise<IRange[]> {
|
||||
$provideSelectionRanges(handle: number, resource: UriComponents, position: IPosition, token: CancellationToken): Promise<modes.SelectionRange[]> {
|
||||
return this._withAdapter(handle, SelectionRangeAdapter, adapter => adapter.provideSelectionRanges(URI.revive(resource), position, token));
|
||||
}
|
||||
|
||||
|
||||
@@ -835,6 +835,30 @@ export namespace Color {
|
||||
}
|
||||
}
|
||||
|
||||
export namespace SelectionRangeKind {
|
||||
|
||||
export function from(kind: vscode.SelectionRangeKind): string {
|
||||
return kind.value;
|
||||
}
|
||||
|
||||
export function to(value: string): vscode.SelectionRangeKind {
|
||||
return new types.SelectionRangeKind(value);
|
||||
}
|
||||
}
|
||||
|
||||
export namespace SelectionRange {
|
||||
export function from(obj: vscode.SelectionRange): modes.SelectionRange {
|
||||
return {
|
||||
kind: SelectionRangeKind.from(obj.kind),
|
||||
range: Range.from(obj.range)
|
||||
};
|
||||
}
|
||||
|
||||
export function to(obj: modes.SelectionRange): vscode.SelectionRange {
|
||||
return new types.SelectionRange(SelectionRangeKind.to(obj.kind), Range.to(obj.range));
|
||||
}
|
||||
}
|
||||
|
||||
export namespace TextDocumentSaveReason {
|
||||
|
||||
export function to(reason: SaveReason): vscode.TextDocumentSaveReason {
|
||||
|
||||
@@ -1036,6 +1036,37 @@ export class CodeActionKind {
|
||||
}
|
||||
}
|
||||
|
||||
export class SelectionRangeKind {
|
||||
|
||||
private static readonly _sep = '.';
|
||||
|
||||
static readonly Empty = new SelectionRangeKind('');
|
||||
static readonly Statement = SelectionRangeKind.Empty.append('statement');
|
||||
static readonly Expression = SelectionRangeKind.Empty.append('expression');
|
||||
static readonly Block = SelectionRangeKind.Empty.append('block');
|
||||
|
||||
readonly value: string;
|
||||
|
||||
constructor(value: string) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
append(value: string): SelectionRangeKind {
|
||||
return new SelectionRangeKind(this.value ? this.value + SelectionRangeKind._sep + value : value);
|
||||
}
|
||||
}
|
||||
|
||||
export class SelectionRange {
|
||||
|
||||
kind: SelectionRangeKind;
|
||||
range: Range;
|
||||
|
||||
constructor(kind: SelectionRangeKind, range: Range) {
|
||||
this.kind = kind;
|
||||
this.range = range;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class CodeLens {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user