multiple cursor in internal api of smart select, #41838

This commit is contained in:
Johannes Rieken
2019-02-11 11:33:32 +01:00
parent 8bbe6acdc8
commit d50b568d87
13 changed files with 141 additions and 131 deletions

View File

@@ -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