mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 02:28:34 +01:00
allow to return range or range and placeholder, #7340
This commit is contained in:
@@ -22,6 +22,7 @@ import { regExpLeadsToEndlessLoop } from 'vs/base/common/strings';
|
||||
import { IPosition } from 'vs/editor/common/core/position';
|
||||
import { IRange } from 'vs/editor/common/core/range';
|
||||
import { isFalsyOrEmpty } from 'vs/base/common/arrays';
|
||||
import { isObject } from 'vs/base/common/types';
|
||||
|
||||
// --- adapter
|
||||
|
||||
@@ -506,7 +507,7 @@ class RenameAdapter {
|
||||
});
|
||||
}
|
||||
|
||||
resolveRenameLocation(resource: URI, position: IPosition): TPromise<IRange> {
|
||||
resolveRenameLocation(resource: URI, position: IPosition): TPromise<modes.RenameLocation> {
|
||||
if (typeof this._provider.resolveRenameLocation !== 'function') {
|
||||
return TPromise.as(undefined);
|
||||
}
|
||||
@@ -514,15 +515,28 @@ class RenameAdapter {
|
||||
let doc = this._documents.getDocumentData(resource).document;
|
||||
let pos = TypeConverters.toPosition(position);
|
||||
|
||||
return asWinJsPromise(token => this._provider.resolveRenameLocation(doc, pos, token)).then(range => {
|
||||
return asWinJsPromise(token => this._provider.resolveRenameLocation(doc, pos, token)).then(rangeOrLocation => {
|
||||
|
||||
let range: vscode.Range;
|
||||
let text: string;
|
||||
if (Range.isRange(rangeOrLocation)) {
|
||||
range = rangeOrLocation;
|
||||
text = doc.getText(rangeOrLocation);
|
||||
|
||||
} else if (isObject(rangeOrLocation)) {
|
||||
range = rangeOrLocation.range;
|
||||
text = rangeOrLocation.placeholder;
|
||||
}
|
||||
|
||||
if (!range) {
|
||||
return undefined;
|
||||
}
|
||||
if (range && (!range.isSingleLine || range.start.line !== pos.line)) {
|
||||
console.warn('INVALID rename context, range must be single line and on the same line');
|
||||
|
||||
if (!range.contains(pos)) {
|
||||
console.warn('INVALID rename location: range must contain position');
|
||||
return undefined;
|
||||
}
|
||||
return TypeConverters.fromRange(range);
|
||||
return { range: TypeConverters.fromRange(range), text };
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1088,7 +1102,7 @@ export class ExtHostLanguageFeatures implements ExtHostLanguageFeaturesShape {
|
||||
return this._withAdapter(handle, RenameAdapter, adapter => adapter.provideRenameEdits(URI.revive(resource), position, newName));
|
||||
}
|
||||
|
||||
$resolveRenameLocation(handle: number, resource: URI, position: IPosition): TPromise<IRange> {
|
||||
$resolveRenameLocation(handle: number, resource: URI, position: IPosition): TPromise<modes.RenameLocation> {
|
||||
return this._withAdapter(handle, RenameAdapter, adapter => adapter.resolveRenameLocation(resource, position));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user