mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 11:38:51 +01:00
multiple cursor in internal api of smart select, #41838
This commit is contained in:
@@ -921,7 +921,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<modes.SelectionRange[]>;
|
||||
$provideSelectionRanges(handle: number, resource: UriComponents, positions: IPosition[], token: CancellationToken): Promise<modes.SelectionRange[][]>;
|
||||
}
|
||||
|
||||
export interface ExtHostQuickOpenShape {
|
||||
|
||||
@@ -17,7 +17,7 @@ import { ExtHostCommands } from 'vs/workbench/api/node/extHostCommands';
|
||||
import { CustomCodeAction } from 'vs/workbench/api/node/extHostLanguageFeatures';
|
||||
import { ICommandsExecutor, PreviewHTMLAPICommand, OpenFolderAPICommand, DiffAPICommand, OpenAPICommand, RemoveFromRecentlyOpenedAPICommand, SetEditorLayoutAPICommand } from './apiCommands';
|
||||
import { EditorGroupLayout } from 'vs/workbench/services/editor/common/editorGroupsService';
|
||||
import { isFalsyOrEmpty, isNonEmptyArray } from 'vs/base/common/arrays';
|
||||
import { isFalsyOrEmpty } from 'vs/base/common/arrays';
|
||||
|
||||
export class ExtHostApiCommands {
|
||||
|
||||
@@ -199,7 +199,7 @@ export class ExtHostApiCommands {
|
||||
description: 'Execute selection range provider.',
|
||||
args: [
|
||||
{ name: 'uri', description: 'Uri of a text document', constraint: URI },
|
||||
{ name: 'position', description: 'Position in a text document', constraint: types.Position }
|
||||
{ name: 'positions', description: 'Positions in a text document', constraint: a => Array.isArray(a) }
|
||||
],
|
||||
returns: 'A promise that resolves to an array of ranges.'
|
||||
});
|
||||
@@ -420,16 +420,15 @@ export class ExtHostApiCommands {
|
||||
});
|
||||
}
|
||||
|
||||
private _executeSelectionRangeProvider(resource: URI, position: types.Position): Promise<vscode.SelectionRange[]> {
|
||||
private _executeSelectionRangeProvider(resource: URI, positions: types.Position[]): Promise<vscode.SelectionRange[][]> {
|
||||
let pos = positions.map(typeConverters.Position.from);
|
||||
const args = {
|
||||
resource,
|
||||
position: position && typeConverters.Position.from(position)
|
||||
position: pos[0],
|
||||
positions: pos
|
||||
};
|
||||
return this._commands.executeCommand<modes.SelectionRange[]>('_executeSelectionRangeProvider', args).then(result => {
|
||||
if (isNonEmptyArray(result)) {
|
||||
return result.map(typeConverters.SelectionRange.to);
|
||||
}
|
||||
return [];
|
||||
return this._commands.executeCommand<modes.SelectionRange[][]>('_executeSelectionRangeProvider', args).then(result => {
|
||||
return result.map(oneResult => oneResult.map(typeConverters.SelectionRange.to));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -876,24 +876,26 @@ class SelectionRangeAdapter {
|
||||
private readonly _provider: vscode.SelectionRangeProvider
|
||||
) { }
|
||||
|
||||
provideSelectionRanges(resource: URI, position: IPosition, token: CancellationToken): Promise<modes.SelectionRange[]> {
|
||||
provideSelectionRanges(resource: URI, positions: 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(selectionRanges => {
|
||||
if (isFalsyOrEmpty(selectionRanges)) {
|
||||
return undefined;
|
||||
}
|
||||
let result: modes.SelectionRange[] = [];
|
||||
let last: vscode.Position | vscode.Range = pos;
|
||||
for (const sel of selectionRanges) {
|
||||
if (!sel.range.contains(last)) {
|
||||
throw new Error('INVALID selection range, must contain the previous range');
|
||||
return Promise.all(positions.map(position => {
|
||||
const pos = typeConvert.Position.to(position);
|
||||
return asPromise(() => this._provider.provideSelectionRanges(document, pos, token)).then(selectionRanges => {
|
||||
if (isFalsyOrEmpty(selectionRanges)) {
|
||||
return undefined;
|
||||
}
|
||||
result.push(typeConvert.SelectionRange.from(sel));
|
||||
last = sel.range;
|
||||
}
|
||||
return result;
|
||||
});
|
||||
let oneResult: modes.SelectionRange[] = [];
|
||||
let last: vscode.Position | vscode.Range = pos;
|
||||
for (const sel of selectionRanges) {
|
||||
if (!sel.range.contains(last)) {
|
||||
throw new Error('INVALID selection range, must contain the previous range');
|
||||
}
|
||||
oneResult.push(typeConvert.SelectionRange.from(sel));
|
||||
last = sel.range;
|
||||
}
|
||||
return oneResult;
|
||||
});
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1307,8 +1309,8 @@ export class ExtHostLanguageFeatures implements ExtHostLanguageFeaturesShape {
|
||||
return this._createDisposable(handle);
|
||||
}
|
||||
|
||||
$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));
|
||||
$provideSelectionRanges(handle: number, resource: UriComponents, positions: IPosition[], token: CancellationToken): Promise<modes.SelectionRange[][]> {
|
||||
return this._withAdapter(handle, SelectionRangeAdapter, adapter => adapter.provideSelectionRanges(URI.revive(resource), positions, token));
|
||||
}
|
||||
|
||||
// --- configuration
|
||||
|
||||
Reference in New Issue
Block a user