Skip to content

workspace.textDocuments includes closed documents #47140

Closed

Description

@DanTup

In #10304 I was advised that workspace.textDocuments was the correct way to get open files; however I'm trying to write tests that rely on documents being closed and finding that they still exist in there despite being closed (I can see in the extension host there there are no open editors).

Here's a sample test:

it.only("test", async () => {
	// Open two files
	await vs.workspace.openTextDocument(emptyFile);
	await vs.workspace.openTextDocument(everythingFile);
	console.log(`There are ${vs.workspace.textDocuments.length} documents`);

	// Close all files
	while (vs.window.activeTextEditor) {
		await vs.commands.executeCommand("workbench.action.closeActiveEditor");
	}
	console.log(`There are ${vs.workspace.textDocuments.length} documents`);

	// Wait a short period just in case...
	await new Promise((resolve) => setTimeout(resolve, 1000));
	console.log(`There are ${vs.workspace.textDocuments.length} documents`);
});

This outputs:

There are 2 documents
There are 2 documents
There are 2 documents

Activity

  1. DanTup commented on Apr 3, 2018

    @DanTup
    ContributorAuthor

    Also weird, the while loop seems to only execute once.

  2. added
    *as-designed
    on Apr 3, 2018
  3. jrieken commented on Apr 3, 2018

    @jrieken
    Contributor

    however I'm trying to write tests that rely on documents being closed and finding that they still exist in

    You cannot assume the opposite and closing an editor doesn't mean that we close the document too.

  4. added
    *question
    on Apr 3, 2018
  5. vscodebot commented on Apr 3, 2018

    @vscodebot

    Please ask your question on StackOverflow. We have a great community over there. They have already answered thousands of questions and are happy to answer yours as well. See also our issue reporting guidelines.

    Happy Coding!

  6. DanTup commented on Apr 3, 2018

    @DanTup
    ContributorAuthor

    Johannes Rieken (@jrieken) Then the answer to my original question is not satisfied :( How do I get a list of the documents that are open? I want to provide my language server with a list of priority documents, which are first the visible text editors, and then any editors that are open but not visible.

  7. added a commit that references this issue on Apr 16, 2018
  8. locked and limited conversation to collaborators on May 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

*as-designed*question

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions