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

Can we avoid creating extra text documents during batch refactors? #237441

Open
mjbvz opened this issue Jan 7, 2025 · 4 comments
Open

Can we avoid creating extra text documents during batch refactors? #237441

mjbvz opened this issue Jan 7, 2025 · 4 comments
Assignees
Labels
under-discussion Issue is under discussion for relevance, priority, approach

Comments

@mjbvz
Copy link
Collaborator

mjbvz commented Jan 7, 2025

Related to #64485

repo

  1. In a large workspace with no editors open
  2. Do a workspace find replace for a common term

Bug
Observe that for each edited file, VS Code emits a onDidOpenTextDocument and then onDidChangeTextDocument. A bit later onDidCloseTextDocument is emitted when the documents are cleaned up. None of the files are even opened in text editors


When doing bulk edits/refactors on unopened files, can we avoid creating text documents that are exposed to extensions? I think extensions should be using file watching for these cases instead

If changing the behavior is too risky, maybe we could have a flag on these events so extensions can easily ignore them?

cc @andrewbranch

@RedCMD
Copy link
Contributor

RedCMD commented Jan 7, 2025

I agree
having background documents spam extensions is rather annoying
I would prefer flagging the reason why a document was open

I assume you mean ctrl+shift+f SEARCH?
not ctrl+f find

title says fine btw

@mjbvz mjbvz changed the title Can we avoid creating extra text documents during fine/ Can we avoid creating extra text documents during find Jan 8, 2025
@jrieken jrieken added the under-discussion Issue is under discussion for relevance, priority, approach label Jan 8, 2025
@jrieken
Copy link
Member

jrieken commented Jan 8, 2025

I'd say that is by-design and I wouldn't tamper with how or when these open/close events are fired. Some documents might already be open, some might stay open but be ignored.

@mjbvz @andrewbranch So far the issue just describes behaviour but what is the actual problem here?

@andrewbranch
Copy link
Member

andrewbranch commented Jan 8, 2025

It’s a lot of unnecessary work for TS Server. In the case I noticed, I was changing hundreds of closed files, none of which were part of any tsconfig project I had open. For each open/close, TS Server (in addition to parsing/binding/project creation/module resolution) installs (and then almost immediately uninstalls) file watchers for all the resolutions that occur in the open files. But TS Server only does this work because the editor says the file is being opened (meaning a user might interact with it), which is false.

@jrieken
Copy link
Member

jrieken commented Jan 8, 2025

But TS Server only does this work because the editor says the file is being opened (meaning a user might interact with it), which is false.

Thanks for clarifying. The onDidOpenTextDocument might not be what you want, it fires whenever a document is opened as in "read from disk", not necessarily opened in an editor. A better API to approximate "user interacted" is the tabs-API (vscode.window.tabs) which allows you to know if there is actually an active or "passive" editor for a resource.

@mjbvz mjbvz changed the title Can we avoid creating extra text documents during find Can we avoid creating extra text documents during batch refactors? Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
under-discussion Issue is under discussion for relevance, priority, approach
Projects
None yet
Development

No branches or pull requests

4 participants