Skip to content

"Unable to edit document because the file was not previously opened" when using "dart.onlyAnalyzeProjectsWithOpenFiles":true (and plugins) #4862

Closed
@DanTup

Description

@DanTup

Splitting this from #4740 since it's not the same as the original issue and I'm not yet certain that it's plugin-related at all.

To reproduce:

  • Create a simple empty project that references an analyzer plugin (like custom_lint)
    I'm not sure the plugin is relevant yet, but it seems to repro pretty reliably with and I couldn't repro without
  • Ensure "dart.onlyAnalyzeProjectsWithOpenFiles":true is set for the workspace and that no files are open
  • Run the Developer: Reload Window command to get a clean analyzer with no open files
  • Open analysis_options.yaml and press Save
  • Close analysis_options.yaml
    Modifying analysis_options may or may not be relevant
  • Open a .dart file
  • Make some changes to the file

This open results in an error like:

image

Opening the file triggers rebuilding of analysis roots, but it also seems to remove the overlay:

1701185971585:Req:{"jsonrpc"::"2.0","method"::"textDocument/didOpen","params"::{"textDocument"::{"uri"::"file::///C%3A/Dev/Test%20Projects/dartcode_4740_repro/lib/dartcode_4740_repro.dart","languageId"::"dart","version"::1,"text"::"int calculate() {\n  return 6 * 7;\n}\n"}},"clientRequestTime"::1701185971583}
1701185971585:Info:Setting overlay for C::\Dev\Test Projects\dartcode_4740_repro\lib\dartcode_4740_repro.dart
1701185971587:Info:Setting roots
1701185971588:Info:Done setting roots
1701185971588:Info:Done setting roots
1701185971588:Info:Removing overlay for C::\Dev\Test Projects\dartcode_4740_repro\lib\dartcode_4740_repro.dart
1701185972690:Req:{"jsonrpc"::"2.0","method"::"textDocument/didChange","params"::{"textDocument"::{"uri"::"file::///C%3A/Dev/Test%20Projects/dartcode_4740_repro/lib/dartcode_4740_repro.dart","version"::2},"contentChanges"::[{"range"::{"start"::{"line"::3,"character"::0},"end"::{"line"::3,"character"::0}},"rangeLength"::0,"text"::"d"}]},"clientRequestTime"::1701185972204}
1701185972690:Res:{"jsonrpc"::"2.0","method"::"window/showMessage","params"::{"message"::"Unable to edit document because the file was not previously opened:: C::\\Dev\\Test Projects\\dartcode_4740_repro\\lib\\dartcode_4740_repro.dart","type"::1}}
1701185972690:Res:{"jsonrpc"::"2.0","method"::"window/logMessage","params"::{"message"::"An unrecoverable error occurred.\n\nUnable to edit document because the file was not previously opened:: C::\\Dev\\Test Projects\\dartcode_4740_repro\\lib\\dartcode_4740_repro.dart\n\n-32099\n\nnull","type"::1}}

We always verify we have an overlay before processing a textDocument/didChange event so this results in us throwing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    in editorRelates to code editing or language featuresin lsp/analysis serverSomething to be fixed in the Dart analysis serveris bugrelies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions