-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve initial rename value #37691
Resolve initial rename value #37691
Changes from all commits
ec5253c
beedeba
b21090f
b0e71f6
1f6aedf
403d5d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2664,6 +2664,11 @@ declare module 'vscode' { | |
appendVariable(name: string, defaultValue: string | ((snippet: SnippetString) => any)): SnippetString; | ||
} | ||
|
||
export interface RenameInitialValue { | ||
range: Range | ||
text?: string | ||
} | ||
|
||
/** | ||
* The rename provider interface defines the contract between extensions and | ||
* the [rename](https://code.visualstudio.com/docs/editor/editingevolved#_rename-symbol)-feature. | ||
|
@@ -2682,6 +2687,8 @@ declare module 'vscode' { | |
* signaled by returning `undefined` or `null`. | ||
*/ | ||
provideRenameEdits(document: TextDocument, position: Position, newName: string, token: CancellationToken): ProviderResult<WorkspaceEdit>; | ||
|
||
resolveInitialRenameValue?(document: TextDocument, position: Position, token: CancellationToken): ProviderResult<RenameInitialValue>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe resolveRenameInformation?(document: TextDocument, position: Position, token: CancellationToken): ProviderResult<RenameInformation>;
provideRenameInformation?(document: TextDocument, position: Position, token: CancellationToken): ProviderResult<RenameInformation>; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or something more clever sounding, like |
||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -470,6 +470,10 @@ class NavigateTypeAdapter { | |
|
||
class RenameAdapter { | ||
|
||
static supportsResolving(provider: vscode.RenameProvider): boolean { | ||
return typeof provider.resolveInitialRenameValue === 'function'; | ||
} | ||
|
||
private _documents: ExtHostDocuments; | ||
private _provider: vscode.RenameProvider; | ||
|
||
|
@@ -505,6 +509,22 @@ class RenameAdapter { | |
} | ||
}); | ||
} | ||
|
||
resolveInitialRenameValue(resource: URI, position: IPosition) : TPromise<modes.RenameInitialValue> { | ||
if (typeof this._provider.resolveInitialRenameValue !== 'function') { | ||
return TPromise.as(undefined); | ||
} | ||
|
||
let doc = this._documents.getDocumentData(resource).document; | ||
let pos = TypeConverters.toPosition(position); | ||
|
||
return asWinJsPromise(token => this._provider.resolveInitialRenameValue(doc, pos, token)).then((value) => { | ||
return <modes.RenameInitialValue> { | ||
range: TypeConverters.fromRange(value.range), | ||
text: value.text | ||
}; | ||
}); | ||
} | ||
} | ||
|
||
|
||
|
@@ -1010,14 +1030,18 @@ export class ExtHostLanguageFeatures implements ExtHostLanguageFeaturesShape { | |
|
||
registerRenameProvider(selector: vscode.DocumentSelector, provider: vscode.RenameProvider): vscode.Disposable { | ||
const handle = this._addNewAdapter(new RenameAdapter(this._documents, provider)); | ||
this._proxy.$registerRenameSupport(handle, selector); | ||
this._proxy.$registerRenameSupport(handle, selector, RenameAdapter.supportsResolving(provider)); | ||
return this._createDisposable(handle); | ||
} | ||
|
||
$provideRenameEdits(handle: number, resource: UriComponents, position: IPosition, newName: string): TPromise<modes.WorkspaceEdit> { | ||
return this._withAdapter(handle, RenameAdapter, adapter => adapter.provideRenameEdits(URI.revive(resource), position, newName)); | ||
} | ||
|
||
$resolveInitialRenameValue(handle: number, resource: URI, position: IPosition): TPromise<modes.RenameInitialValue> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
return this._withAdapter(handle, RenameAdapter, adapter => adapter.resolveInitialRenameValue(resource, position)); | ||
} | ||
|
||
// --- suggestion | ||
|
||
registerCompletionItemProvider(selector: vscode.DocumentSelector, provider: vscode.CompletionItemProvider, triggerCharacters: string[]): vscode.Disposable { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs maybe some better naming here but idea is good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am actually wondering when we would return both, so range and text (which then would be different from the text in range?). Do you have a use-case in mind?