Skip to content
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

[rename on type] feedback incorrect after Rename #93872

Open
egamma opened this issue Mar 31, 2020 · 2 comments
Open

[rename on type] feedback incorrect after Rename #93872

egamma opened this issue Mar 31, 2020 · 2 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug editor-synced-region Issues related to synced region functionality in editor
Milestone

Comments

@egamma
Copy link
Member

egamma commented Mar 31, 2020

Testing #93808

  • place the cursor inside the bo|dy tag of an html document
  • F2 rename to body to 'foobar'
    -> The feedback is no longer selecting the entire tag:

image

@octref octref added bug Issue identified by VS Code Team member as probable bug editor-synced-region Issues related to synced region functionality in editor labels Apr 1, 2020
@octref octref added this to the March 2020 milestone Apr 1, 2020
@octref
Copy link
Contributor

octref commented Apr 2, 2020

I think this is a decorator issue. Here's a simple repro:

  • Run below code as an extension
  • Open a plaintext file with only text body
  • Put cursor at bod|y
  • Rename to foobar
  • 🐛 Decorator no longer covers whole region. As rename provider I provided a replace edit of body -> foobar, so I would expect that edit to keep the decorator on the new text foobar
const vscode = require('vscode');

function activate(context) {

	const smallNumberDecorationType = vscode.window.createTextEditorDecorationType({
		backgroundColor: 'red'
	});

	vscode.commands.registerCommand('extension.helloWorld', () => {
		vscode.window.activeTextEditor.setDecorations(smallNumberDecorationType, [new vscode.Range(0, 0, 0, 4)]);
	});
	
	vscode.languages.registerRenameProvider('plaintext', {
		provideRenameEdits(doc, pos, name) {
			const edit = new vscode.WorkspaceEdit();
			edit.set(vscode.window.activeTextEditor.document.uri, [
				new vscode.TextEdit(new vscode.Range(0, 0, 0, 4), name)
			]);
			return edit;
		}
	})
}

// this method is called when your extension is deactivated
function deactivate() {}

module.exports = {
	activate,
	deactivate
}

@alexdima
Copy link
Member

alexdima commented Apr 2, 2020

@octref decorations should always be validated and reset after an edit by the owner of the decoration. You cannot trust that the editor understands the semantics of an edit it receives and behaves in a certain way. The editor does not discriminate between characters, so spaces, syntax characters or alphanumerical characters are treated the same. The editor maintains decorations as best as it can, but in this case the edits are being sent through a minifier of edits and the rename edits are further broken up into 4 edits, to replace b with fo and dy with bar.

On your side, you can also tweak the stickiness property to try to influence the way in which decorations grow or not when edits occur at their edges.

@alexdima alexdima removed their assignment Apr 27, 2020
@aeschli aeschli modified the milestones: April 2020, May 2020 May 4, 2020
@aeschli aeschli changed the title RenameOnType feedback incorrect after Rename [rename on type] feedback incorrect after Rename May 4, 2020
@aeschli aeschli assigned aeschli and unassigned octref May 4, 2020
@aeschli aeschli modified the milestones: May 2020, June 2020 Jun 4, 2020
@aeschli aeschli modified the milestones: June 2020, On Deck Jun 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug editor-synced-region Issues related to synced region functionality in editor
Projects
None yet
Development

No branches or pull requests

5 participants