Skip to content

[linked editing] finalize LinkedEditingRangeProvider #109923

Closed

Description

The OnTypeRenameProvider allows the editor to apply a rename to a symbol automatically to other ranges as well.

The feature can be seen in action in HTML, where modifications to an open tag is automatically applied to the close tag (and vice versa). (Requires settings: "editor.renameOnType": true)

	/**
	 * The 'on type' rename provider interface defines the contract between extensions and
	 * the 'on type' rename feature.
	 */
	export interface OnTypeRenameProvider {
		/**
		 * For a given position in a document, returns the range of the symbol at the position and all ranges
		 * that have the same content and can be renamed together. Optionally a result specific word pattern can be returned as well
		 * that describes valid contents. A rename to one of the ranges can be applied to all other ranges if the new content
		 * matches the word pattern.
		 * If no result-specific word pattern is provided, the word pattern defined when registering the provider is used.
		 *
		 * @param document The document in which the provider was invoked.
		 * @param position The position at which the provider was invoked.
		 * @param token A cancellation token.
		 * @return A list of ranges that can be renamed together. The ranges must have
		 * identical length and contain identical text content. The ranges cannot overlap. Optionally a word pattern
		 * that overrides the word pattern defined when registering the provider can be provided.
		 */
		provideOnTypeRenameRanges(document: TextDocument, position: Position, token: CancellationToken): ProviderResult<{ ranges: Range[]; wordPattern?: RegExp; }>;
	}

	namespace languages {
		/**
		 * Register a 'on type' rename provider.
		 *
		 * Multiple providers can be registered for a language. In that case providers are sorted
		 * by their [score](#languages.match) and the best-matching provider that has a result is used. Failure
		 * of the selected provider will cause a failure of the whole operation.
		 *
		 * @param selector A selector that defines the documents this provider is applicable to.
		 * @param provider An 'on type' rename provider.
		 * @param wordPattern A word pattern to describes valid contents of renamed ranges.
		 * @return A [disposable](#Disposable) that unregisters this provider when being disposed.
		 */
		export function registerOnTypeRenameProvider(selector: DocumentSelector, provider: OnTypeRenameProvider, wordPattern?: RegExp): Disposable;
	}

Activity

  1. added
    editor-synced-region
    feature-request
    on Nov 3, 2020
  2. changed the title [-]Finalize OnTypeRenameProvider[/-] [+][rename on type] finalize OnTypeRenameProvider[/+] on Nov 6, 2020
  3. jrieken commented on Nov 10, 2020

    @jrieken
    Contributor
    • pattern per result only
    • result as object with ctor
    • what about multi cursor?
  4. aeschli commented on Nov 11, 2020

    @aeschli
    ContributorAuthor

    Adopted feedback: New state:

    	/**
    	 * The 'on type' rename provider interface defines the contract between extensions and
    	 * the 'on type' rename feature.
    	 */
    	export interface OnTypeRenameProvider {
    		/**
    		 * For a given position in a document, returns the range of the symbol at the position and all ranges
    		 * that have the same content and can be renamed together. Optionally a word pattern can be returned
    		 * to describe valid contents. A rename to one of the ranges can be applied to all other ranges if the new content
    		 * is valid.
    		 * If no result-specific word pattern is provided, the word pattern from the language configuration is used.
    		 *
    		 * @param document The document in which the provider was invoked.
    		 * @param position The position at which the provider was invoked.
    		 * @param token A cancellation token.
    		 * @return A list of ranges that can be renamed together
    		 */
    		provideOnTypeRenameRanges(document: TextDocument, position: Position, token: CancellationToken): ProviderResult<OnTypeRenameRanges>;
    	}
    
    	namespace languages {
    		/**
    		 * Register a 'on type' rename provider.
    		 *
    		 * Multiple providers can be registered for a language. In that case providers are sorted
    		 * by their [score](#languages.match) and the best-matching provider that has a result is used. Failure
    		 * of the selected provider will cause a failure of the whole operation.
    		 *
    		 * @param selector A selector that defines the documents this provider is applicable to.
    		 * @param provider An 'on type' rename provider.
    		 * @return A [disposable](#Disposable) that unregisters this provider when being disposed.
    		 */
    		export function registerOnTypeRenameProvider(selector: DocumentSelector, provider: OnTypeRenameProvider): Disposable;
    	}
    
    	/**
    	 * Represents a list of ranges that can be renamed together along with a word pattern to describe valid range contents.
    	 */
    	export class OnTypeRenameRanges {
    		constructor(ranges: Range[], wordPattern?: RegExp);
    
    		/**
    		 * A list of ranges that can be renamed together. The ranges must have
    		 * identical length and contain identical text content. The ranges cannot overlap.
    		 */
    		readonly ranges: Range[];
    
    		/**
    		 * An optional word pattern that describes valid contents for the given ranges.
    		 * If no pattern is provided, the language configuration's word pattern will be used.
    		 */
    		readonly wordPattern?: RegExp;
    	}
    
  5. jrieken commented on Nov 16, 2020

    @jrieken
    Contributor

    /Naming nit/ - In the past we haven't been super consistent but when the function is called provideOnTypeRenameRanges (which I like) than the provider should be called OnTypeRenameRangeProvider = today is misses Range tho it is rename ranges that it provides

  6. gjsjohnmurray commented on Nov 16, 2020

    @gjsjohnmurray
    Contributor

    Johannes Rieken (@jrieken) why Range and not Ranges?

  7. jrieken commented on Nov 16, 2020

    @jrieken
    Contributor

    Actually unsure but that's the majority of cases. I'd say the logic is that a provider can provide a thing and then there is call to provide many - and in some case a call to resolve one.

  8. aeschli commented on Nov 16, 2020

    @aeschli
    ContributorAuthor

    Makes sense. I made the rename to OnTypeRenameRangeProvider

  9. 11 remaining items

  10. added
    unreleased
    on Dec 1, 2020
  11. aeschli commented on Dec 1, 2020

    @aeschli
    ContributorAuthor

    Moved to public vscode.d.ts.

    To verify, please create a small extension, install it like a regular extension and verify it works (no more proposedAPI checks)

  12. added
    verification-needed
    on Dec 1, 2020
  13. added
    insiders-released
    and removed
    unreleased
    on Dec 2, 2020
  14. johnsoncodehk commented on Dec 9, 2020

    @johnsoncodehk
    Contributor

    I found this registerOnTypeRenameProvider is work to html-language-features in VSCode v0.15.1, but it not working when I try to following html-language-features to added client.registerProposedFeatures() and "enableProposedApi": true.

    It should be work? or use proposed API in non Insiders VSCode is built-in package's privilege?

    supplement: It working for VSCode Insiders

  15. aeschli commented on Dec 9, 2020

    @aeschli
    ContributorAuthor

    Yes, built-in extensions are allowed to use proposed API also in stable.

    But the new API is now public in 1.52: languages.registerLinkedEditingRangeProvider

  16. johnsoncodehk commented on Dec 10, 2020

    @johnsoncodehk
    Contributor

    Martin Aeschlimann (@aeschli) can't wait for it! :) can turn editor.linkedEditing default on? otherwise 99% of users will miss it.

  17. added a commit that references this issue on Dec 16, 2020
    9022eff
  18. added a commit that references this issue on Dec 22, 2020
    535463c
  19. added a commit that references this issue on Jan 5, 2021
    93c7727
  20. Ares9323 commented on Jan 7, 2021

    @Ares9323

    registerLinkedEditingRangeProvider

    Can you please explain how to use this setting?
    I have version 1.52.1 and settings.json says "Unknown Configuration Settings"
    I have read the documentation for both "editor.renameOnType" and "editor.linkedEditing" but it looks like there's nothing there.

    I'd like to have an example of the syntax of this setting too, I tried several but none of them matched.

    An extension I use to beautify files only supports html, js and css and I managed to make it work with "blade" and "php" files as they were .html with this setting:
    "beautify.language": {"html": ["htm","html","php","blade",]},
    Do I have to do something similar or do I just need to type the extension in a particular way?

    Thanks in advance, have a nice day

  21. locked and limited conversation to collaborators on Jan 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

api-finalizationeditor-synced-regionfeature-requestinsiders-releasedverification-neededverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions