Skip to content

Renaming files triggers uri_does_not_exist #5269

Closed

Description

@FMorschel

Describe the bug
When renaming files I got uri_does_not_exist in the line modified by the refactoring.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new empty project
  2. Add file a.dart
  3. Add import to main.dart
  4. Rename a.dart to c.dart
  5. Immediately click on main.dart (I believe)
  6. See that on main.dart you get the uri_does_not_exist lint on the line that now is c.dart

Here is the zip with all logs: temp.zip (main.dart in this case is temp.dart).

Expected behavior
No errors.

Please complete the following information:

Workspace Environment
Dart Code extension: 3.97.20240902
Flutter extension: 3.97.20240902 (activated)

App: Visual Studio Code
App Host: desktop
Version: win 1.93.1

Workspace type: Dart (LSP)
Workspace name: temp

Dart (3.5.3): C:\Users\felip_0vh5fa6\.puro\shared\caches\36335019a8eab588c3c2ea783c618d90505be233\dart-sdk
Flutter (3.24.3): C:\Users\felip_0vh5fa6\.puro\envs\stable\flutter (No device)

Output from 'dart info'

C:\Users\felip_0vh5fa6\.puro\shared\caches\36335019a8eab588c3c2ea783c618d90505be233\dart-sdk\bin\dart.exe info

If providing this information as part of reporting a bug, please review the information
below to ensure it only contains things you're comfortable posting publicly.

General info

  • Dart 3.5.3 (stable) (Wed Sep 11 16:22:47 2024 +0000) on "windows_x64"
  • on windows / "Windows 10 Pro" 10.0 (Build 22631)
  • locale is pt-BR

Project info

  • sdk constraint: '^3.6.0-175.0.dev'
  • dependencies: args
  • dev_dependencies: lints, test

Process info

Memory CPU Elapsed time Command line
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe

Activity

  1. DanTup commented on Sep 16, 2024

    @DanTup
    Member

    Thanks, I've been through the log and filtered it to just the important events and something does look wrong here.

    repro_instrum_filtered.txt

    The operation is done, undone, and redone in the log. The second time everything looks good, but the first time there is a stale uri_does_not_exist that should've become an unused_import.

    The only obvious difference is that in the broken case, the file was opened by VS Code prior to the watch event being processed. I don't know if this is the trigger, but it is something to try and reproduce in a test.

    # VS Code opens c.dart
    13:09:24.286,Req,{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///C%3A/Users/felip_0vh5fa6/Documents/Projects/dart/temp/bin/c.dart","languageId":"dart","version":1,"text":""}},"clientRequestTime":1726488564278}
    
    # The rename happens on disk
    13:09:24.293,Watch,<unknown>,C:\Users\felip_0vh5fa6\Documents\Projects\dart\temp\bin\c.dart,add
    13:09:24.293,Watch,<unknown>,C:\Users\felip_0vh5fa6\Documents\Projects\dart\temp\bin\a.dart,remove
    
    ####### We resend uri_does_not_exist even though the file does exist.. It's possible we haven't processed it yet, but it appears that we never correct the issue.
    13:09:24.426,Res,{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[{"code":"uri_does_not_exist","codeDescription":{"href":"https://dart.dev/diagnostics/uri_does_not_exist"},"message":"Target of URI doesn't exist: 'c.dart'.\nTry creating the file referenced by the URI, or try using a URI for a file that does exist.","range":{"end":{"character":15,"line":2},"start":{"character":7,"line":2}},"severity":1,"source":"dart"},{"code":"unused_import","codeDescription":{"href":"https://dart.dev/diagnostics/unused_import"},"message":"Unused import: 'b.dart'.\nTry removing the import directive.","range":{"end":{"character":15,"line":3},"start":{"character":7,"line":3}},"severity":2,"source":"dart"}],"uri":"file:///C:/Users/felip_0vh5fa6/Documents/Projects/dart/temp/bin/temp.dart"}}
    
  2. added this to the v3.98.0 milestone on Sep 16, 2024
  3. added
    in lsp/analysis serverSomething to be fixed in the Dart analysis server
    in editorRelates to code editing or language features
    on Sep 16, 2024
  4. modified the milestones: v3.98.0, v3.100.0 on Sep 26, 2024
  5. DanTup commented on Oct 28, 2024

    @DanTup
    Member

    I managed to repro this today by undoing and redoing using exactly the steps above. Not sure if important, but I didn't save main.dart after adding the initial import.

    Edit: And at one point, I repro'd without the undo/redo.

    instrum copy.txt

  6. FMorschel commented on Oct 28, 2024

    @FMorschel
    ContributorAuthor

    Not sure if important, but I didn't save main.dart after adding the initial import.

    I do have auto-save set to 1 second so I don't think that would make a difference, but good to track.

  7. DanTup commented on Oct 28, 2024

    @DanTup
    Member

    Yeah, I don't think it matters. I think I've repro'd in a test, and I think it might be the same issue as dart-lang/sdk#55318 and so an easier way to reproduce is:

    • add "import 'foo.dart';" to a file
    • now create "foo.dart"

    The uri_does_not_exist error doesn't go away. I think it may be because creating the file foo.dart does not invalidate any files that had an unresolved import for foo.dart.

  8. DanTup commented on Oct 28, 2024

    @DanTup
    Member

    Fixed by dart-lang/sdk@12d9554. The change is in the analysis server so ships with a future Dart/Flutter SDK.

  9. added
    relies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available
    on Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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