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

Missing onDidOpenTextDocument/onDidCloseTextDocument events for documents opened with openTextDocument #138924

Closed
mkhl opened this issue Dec 11, 2021 · 3 comments
Assignees
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code)

Comments

@mkhl
Copy link
Contributor

mkhl commented Dec 11, 2021

Issue Type: Bug

During extension development I noticed that
opening files with openTextDocument
didn't always fire the didOpenTextDocument events I was expecting.

This test suite is there to explore and reproduce the problem.

Reproduction

In the reproduction repo:

  • npm ci
  • npm test

Expected results

All tests in the suite succeed.

Actual results

The test for events fired by openTextDocument
followed by showTextDocument
for an existing file fails.

It seems like closing the editor with the text document
doesn't actually close the document
(and doesn't fire onDidCloseTextDocument),
so subsequent attempts to open the document
don't fire onDidOpenTextDocument.

The same sequence of events works for nonexistent files
(with the untitled uri scheme),
as does opening the file with the vscode.open command.

Other commands for closing editors (like workbench.action.closeAllEditors)
don't improve the situation,
and the API doesn't seem to provide any other method to close documents.

For more details, see the test suite in src/test/suite/extension.test.ts.

VS Code version: Code 1.63.0 (7db1a2b, 2021-12-07T05:16:45.441Z)
OS version: Linux x64 5.15.6-200.fc35.x86_64
Restricted Mode: No

System Info
Item Value
CPUs Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz (8 x 2997)
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
opengl: enabled_on
rasterization: disabled_software
skia_renderer: enabled_on
video_decode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) 1, 1, 1
Memory (System) 23.24GB (0.83GB free)
Process Argv --unity-launch
Screen Reader no
VM 0%
DESKTOP_SESSION gnome
XDG_CURRENT_DESKTOP GNOME
XDG_SESSION_DESKTOP gnome
XDG_SESSION_TYPE wayland
Extensions (38)
Extension Author (truncated) Version
vscode-unfancy-file-icons ale 3.15.0
icons-carbon ant 0.2.4
chalice-icon-theme art 1.2.16
awk-ide-vscode bea 0.6.2
vscode-fish bma 1.0.24
init-script bod 0.1.3
make-task-provider car 2.1.1
npm-intellisense chr 1.4.0
path-intellisense chr 2.6.0
vscode-eslint dba 2.2.2
EditorConfig Edi 0.16.4
gtk-dark-titlebar fkr 1.2.3
vscode-pull-request-github Git 0.34.0
go gol 0.29.0
terraform has 2.17.0
nix-ide jno 0.1.18
language-julia jul 1.5.6
rust-analyzer mat 0.2.842
git-graph mhu 1.30.0
fluent-icons mig 0.0.15
direnv mkh 0.3.0
vscode-docker ms- 1.18.0
python ms- 2021.12.1559732655
vscode-pylance ms- 2021.12.1
jupyter ms- 2021.11.1001550889
jupyter-keymap ms- 1.0.0
jupyter-renderers ms- 1.0.4
remote-containers ms- 0.209.5
remote-ssh ms- 0.68.0
remote-ssh-edit ms- 0.68.0
vsliveshare ms- 1.0.5196
vscode-commons red 0.0.6
vscode-yaml red 1.2.2
edit-with-shell ryu 1.3.0
lua sum 2.5.3
even-better-toml tam 0.14.2
shellcheck tim 0.18.2
redo zom 0.1.0

(6 theme extensions excluded)

@ArturoDent
Copy link

ArturoDent commented Dec 12, 2021

#114005 and similar might help for background information.

And #15178 - API access to open editors.

@mkhl
Copy link
Contributor Author

mkhl commented Dec 12, 2021

Ah, so openTextDocument is behaving as intended and vscode.open is an outlier I shouldn't rely upon?

mkhl added a commit to direnv/direnv-vscode that referenced this issue Dec 12, 2021
the lifecycle of a text document, which may map to a file,
is unrelated to whether that document is opened in an editor,
and closing an editor does not reliably close the document

(it _currently_ does for documents opened with the `vscode.open` command,
but apparently that's an implementation detail we cannot rely on)

there is currently no event in vscode for when a file is opened in an editor

this change ensures that our own commands notice
when we're opening a blocked .envrc file,
and documents the limitation

related upstream issues:
- microsoft/vscode#138924
- microsoft/vscode#114005
- microsoft/vscode#15178
- microsoft/vscode#133532
@jrieken jrieken added the *question Issue represents a question, should be posted to StackOverflow (VS Code) label Dec 13, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jan 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code)
Projects
None yet
Development

No branches or pull requests

4 participants
@mkhl @jrieken @ArturoDent and others