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

vscode.workspace.onDidChangeTextDocument is called with no changes #50344

Closed
fabiospampinato opened this issue May 23, 2018 · 7 comments
Closed
Assignees
Labels
extensions Issues concerning extensions under-discussion Issue is under discussion for relevance, priority, approach

Comments

@fabiospampinato
Copy link
Contributor

fabiospampinato commented May 23, 2018

I've noticed the function passed to vscode.workspace.onDidChangeTextDocument gets called twice if I just insert a new line into the document, the first time it gets called contentChanges is empty.

An extension might perform a lot of work when the document changes, triggering this event without any actual change seems pretty wasteful.

@vscodebot
Copy link

vscodebot bot commented May 23, 2018

(Experimental duplicate detection)
Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

@vscodebot vscodebot bot added the extensions Issues concerning extensions label May 23, 2018
@fabiospampinato fabiospampinato changed the title onDidChangeTextDocument vscode.workspace.onDidChangeTextDocument is called with no changes May 23, 2018
@fabiospampinato
Copy link
Contributor Author

contentChanges seems to be empty only after the very first change to the document.

@alexdima
Copy link
Member

I believe there was an unfortunate idea to call this event when the file gets saved ... or something along those lines. IMHO we should remove that.

@alexdima alexdima assigned jrieken and unassigned alexdima May 28, 2018
@jrieken
Copy link
Member

jrieken commented May 29, 2018

That's the current design and when the dirty-state changes the event is being send. Not sure we can change this without breaking others

@jrieken jrieken added the under-discussion Issue is under discussion for relevance, priority, approach label May 29, 2018
@fabiospampinato
Copy link
Contributor Author

@jrieken from what I can see the function passed to onDidChangeTextDocument is called twice in succession after the very first edit, if somebody for some reason is relying on this behavior they are probably writing bad code.

@jrieken
Copy link
Member

jrieken commented May 29, 2018

I am not here to judge code quality but my role is to not break existing extensions ;-) I think checking the contentChanges-array for being empty isn't a high burden. It's also documented like that

This usually happens when the contents changes but also when other things like the dirty-state changes.

@jrieken
Copy link
Member

jrieken commented Sep 10, 2018

Closing because no code change is planned

@jrieken jrieken closed this as completed Sep 10, 2018
@vscodebot vscodebot bot locked and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
extensions Issues concerning extensions under-discussion Issue is under discussion for relevance, priority, approach
Projects
None yet
Development

No branches or pull requests

3 participants