Dart-Code: LSP: Request textDocument/codeAction failed. Invalid file path

Describe the bug This just came up, have never seen it before. Whenever I type something in a specific dart file VSCode’s Output panel opens up with an error message along with a notification about it. The message is as follows:

[Error - 20:39:21] Request textDocument/codeAction failed.
  Message: Invalid file path
  Code: -32003 
c:\Users\myuser\dev\project\lib\core\widgets\sidebar.dart

As I said, it only happens within this one specific file. No other files. It actually happens when clicking around in the file too. I’ve tried reloading the window, restarting VSCode, disabling and reenabling the Dart extension, disabling the Vim extension. Removing the file and recreating it pasting the stuff I previously had present in the file. Nothing works at this point. As I also said, this just started happening, and I have never seen it before. Nor do I have any idea on my own what I could have done to cause anything.

To Reproduce I really don’t know how to reproduce, to be honest…

Hmm… So while writing I started fiddling around a little bit. Started by removing everything in the file I had problems with and retyped it from a copy in Notepad. ~As soon as I came to adding the square brackets to this line~ I had actually typed out all the other stuff, since I used the tools present in VSCode to generate most of it:

static final List<String> _items = [];

It started freaking out. The type doesn’t seem to matter. I think it’s the combination of static, final, and the list square brackets OR curly braces, instead of square brackets. Also, the underscore does not matter, just so you know.

Also, to add for clarification: This works without errors:

static final String _string = "dwadnwaj";

// this too, although it doesn't compile of course
static final List<String> _grndjkgr = "adsnfshjfs";

The snippets above should be surrounded by the other content of the file in the steps below. Otherwise I cannot reproduce.

I’m gonna give my computer a restart a try. I’ll report back if anything changes.

  1. Create a file from root flutter project, lib/core/widgets/sidebar.dart, with the following contents:
  2. Add the following contents to the file:
    import 'package:flutter/widgets.dart';
    
    /// This widget is a reimplementatino of the [Drawer] widget with the added
    ///  ability to act as a collapsable sidebar on desktop sized screens.
    class Sidebar extends StatelessWidget {
      static final List<Widget> _items = [
        _SidebarItem(),
      ];
    
      final bool expanded;
    
      const Sidebar({
        Key key,
        this.expanded = false,
      }) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return LayoutBuilder(
          builder: (context, constraints) => ListView.builder(
            scrollDirection: Axis.vertical,
            itemCount: _items.length,
            itemBuilder: (context, index) => _items[index],
          ),
        );
      }
    }
    
    // class _SidebarItem {}
    

Sad truth is that I can’t reproduce the narrowed problem in any other file. Just the sidebar.dart one.

I have a really hard time believing anyone else will be able to reproduce, it feels like it has to do something with my exact setup. But I guess we’ll find out.

English is not my native language.

I’ll be here for questions if anyone has them.

Thanks for everyone’s time!

Expected behavior No errors should be thrown.

Versions (please complete the following information):

  • VS Code version: 1.52.1 (user setup)
  • Dart extension version: v3.18.1 (LSP enabled)
  • Dart/Flutter SDK version: Dart 2.12.0 (build 2.12.0-133.2.beta) / Flutter 1.25.0-8.2.pre • channel beta
  • OS: Windows 10 2004 (since it might have to do with file paths?)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 10
  • Comments: 51 (22 by maintainers)

Most upvoted comments

Probably someone has workarounds? Have the same error

You don’t need to restart the entire system. just restart VS code

@thesame for anyone having this issue when you add BeamerDelegate with a BeamerLocationBuilder, the solution is to make sure the widget doesn’t have a const constructor:

//Before: const HomeScreen({ Key? key }) : super(key: key);

//After: HomeScreen({ Key? key }) : super(key: key);

@Vikingslord glad you sorted it. I’m not sure what may have happened - it should generally be safe to update from the command line, but please do file an issue (here or in dart-lang/sdk) with the exception from the log detailed above if you see it again.

Hi I faced with the same error. I just upgraded flutter and errors disappeared.

Rather than re-using this issue (since the original comment here clearly has a drive letter), I’ve opened https://github.com/Dart-Code/Dart-Code/issues/3794 to track looking into this (although I suspect it’ll be moved to VS Code once I’ve done more testing). Thanks!

I guess under the hood VS Code is trying to locate the file which is throwing the exception to help coder pinpoint the issue

Ah, interesting - that makes the issue much worse. I will try to reproduce this on Windows today and if so file a new issue with VS Code, as this seems like much more of a problem than if it was only triggered by clicking the links. Thanks!

@thanh-mel thanks! I looked through your log and found this request to open a file:

1642593505250:Req:{"jsonrpc"::"2.0","method"::"textDocument/didOpen","params"::{"textDocument"::{"uri"::"file::///src/apps/qrpark/lib/src/screens/checkin/checkin_main_widget.dart"

The path of the file is /src/apps/qrpark/lib/src/screens/checkin/checkin_main_widget.dart. It’s missing the drive letter. I suspect that you clicked on a link in the terminal that VS Code did not detect correctly. Although the path is somewhat valid on Windows, it relies on the “current drive” for the process, so although VS Code can open the file, it’s not really valid for it to pass to a server. It also results in multiple copies of the same open file in VS Code, reported here:

https://github.com/microsoft/vscode/issues/108660

I don’t think there’s a lot we can do to handle this here, I think it needs to be fixed in VS Code.

ease don’t sen Ok, let me send the logs via the email as per your suggestion.

Restarting my computer did not seem to fix the issue.

I’ll keep investigating