bluefireteam / vscode-dart-import

A simple plugin for VSCode to change all Dart/Flutter imports to relative format.
64 stars 14 forks source link

failed to initialize #2

Closed ghost closed 5 years ago

ghost commented 5 years ago

keep getting this error when trying to run the extension:

Failed to initialize extension. Is this a valid Dart/Flutter project?

my flutter doctor result:

[√] Flutter (Channel dev, v1.2.0, on Microsoft Windows [Version 10.0.17763.292], locale en-US) [√] Android toolchain - develop for Android devices (Android SDK version 28.0.3) [!] Android Studio (version 3.3) X Flutter plugin not installed; this adds Flutter specific functionality. X Dart plugin not installed; this adds Dart specific functionality. [√] VS Code (version 1.31.0) [!] Connected device ! No devices available

luanpotter commented 5 years ago

Hi, @runedrune ! This plugin works by finding the pubspec.yaml file in the root of the project you opened. It does that to find out your project name. Make sure you have actually opened your root folder on VSCode.

ghost commented 5 years ago

This seems to be the actual error: Expected line 'name:' on pubspec.yaml to match regex, but it didn't (line: name: jaiza ).

Not sure what's wrong. It was working before.

luanpotter commented 5 years ago

The Regex it's trying to match is this: /^\s*name:\s*(.*)$/

Maybe there is something unexpected inside your pubspec file...

I suspect it's a trailling space, please check your pubspec file, according to the error message there is an extra space after your project name.

However upon quick check of the regex it doesn't look like it should matter much; so, in case the error persist, could you please send the file so we can understand what's the issue?

ghost commented 5 years ago

Strange. I've checked everything. Maybe I'm missing something right in front of me. Here's the complete file:

name: jaiza
description: A flutter app to access the Jamaat e Islami Jaiza website.

version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^0.1.2
  intl: ^0.15.7
  http: ^0.12.0
  firebase_messaging: ^3.0.0

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true
  assets:
    - assets/logo.png
luanpotter commented 5 years ago

Hi, I had a theory it had to do with dangling /r characters from your operating system. I released a new version, 0.1.1, please take a look and see if it's a fix :)

ghost commented 5 years ago

Well the error changed after updating to 0.1.1.

Current file is not on project root or not on lib folder? File must be on $root/lib.

But it is in the lib folder.

luanpotter commented 5 years ago

So that worked out (the first problem). Probably it was a dangling character like a /r or non-printable-character at the end of that line in your pubspec file. Some OS's like to add those stuff, I'd suggest you to take a look at the ascii characters in your file to be sure if you want to dig into that.

But that's solve, now there is another problem. This error I supposed shouldn't happen, because it's saying that your file is not in the same folder as your pubspec file (or children), because it's matching the path with startsWith.

So I released a 0.1.2 version with a better error message. It won't fix it, but maybe we will learn will by printing in the error both paths.

Could you please update and send me the new error message?

ghost commented 5 years ago

Current file is not on project root or not on lib folder? File must be on $root/lib. Your current file path is: 'c:\Users\Fawad Khan\Documents\Flutter Projects\jamaat_e_islami_app\lib\tables\selectparticipants.dart' and the lib folder according to the pubspec.yaml file is 'c:\Users\Fawad Khan\Documents\Flutter Projects\jamaat_e_islami_app\pubspec.yaml/lib'.

luanpotter commented 5 years ago

Oh, I see the problem. It seems you are using Windows, and therefore the extension will not be able to process file paths correctly, because windows for some reason uses inverted separators for file paths... That also explains it adding weird \r characters to the end of the lines, which caused the problem with the regex earlier.

I believe there is a way in node to use the path module to construct the file paths in a way that's independent of the PATH_SEPARATOR. I'm not sure if it's available within vscode extension environment, but it believe it might.

It will, however, require changes in all the code that handles path to consider the case to have a weird path separator.

Would you like to contribute with a PR? I'd be glad to merge this feature to make it work on Windows systems!

luanpotter commented 5 years ago

Closing in favor of #6