pucelle / vscode-css-navigation

Allowing Go to definition from HTML to CSS, or Find References from CSS to HTML.
https://marketplace.visualstudio.com/items?itemName=pucelle.vscode-css-navigation
MIT License
64 stars 8 forks source link

"Error: ENOENT: no such file or directory" at WSL2 environment #47

Closed kanlukasz closed 3 years ago

kanlukasz commented 3 years ago

Hello,

While i working at WSL2 environment at Windows 10 i notice one error:

[Error - 2:29:37 PM] Error: ENOENT: no such file or directory, open '/file:///var/www/project/public_html/wp-content/themes/my2020/assets/css/style.min.css'
2 files loaded in 10 ms

That's not true because this file exist.

Maybe the problem is the beginning of the path '/file://?

Another interesting thing is that directory wp-content/themes/my2020/assets/css is ignored in .gitignore, so it should not be scanned

What can we do with this? Let me know if you need more details

pucelle commented 3 years ago

Yes, /file:/// is not correct, correct path should be started with file:///. But I still can't point out what's exactly happened, can you check this option as below image shows and reproduce it again, then paste output channel messages to here? image

Otherwise, this is indeed a mechanism to force load files when your code explicitly import codes like <style src="..."> or @import ..., you may disable this by uncheck this option: image

kanlukasz commented 3 years ago

Huh.... it wasn't easy to reproduce, but I finally caught it. Hard to explain but i try 😱

We have two issues here - one causes the other:

  1. There is some problem with respecting exclusions from .gitignore. Note: your ignoreFilesBy option has a default setting

    (I assume my git exclusions are correct too as the git repository cannot see these files):

    # ignore specific current theme directory
    wp-content/themes/xxxxxxxxx/assets/css

    As you can see css directory is ignored and there is a file style.min.css But when i open that file, your plugin starts tracking it:

    [14:48:34] file:///var/www/xxxxxxxxxx/public_html/wp-content/themes/xxxxxxxxxxxx/assets/css/style.min.css tracked
  2. Now we can jump to the main issue. The file gets the wrong path because it's read accidentally while my package.json scripts are executing. Let's compare it:

    • When i open file in normal way:

      [14:48:34] file:///var/www/xxxxxxxxxx/public_html/wp-content/themes/xxxxxxxxxxxx/assets/css/style.min.css tracked

    • When i run my scripts from package.json:

      [15:04:35] file:///file%3A///var/www/xxxxxxxx/public_html/wp-content/themes/xxxxxxxx/assets/css/style.min.css tracked

    After this action, erroneous messages start

My package.json file:

{
    "private": true,
    "devDependencies": {
        "autoprefixer": "latest",
        "bootstrap": "latest",
        "node-sass": "latest",
        "nodemon": "latest",
        "postcss": "latest",
        "postcss-cli": "latest",
        "stylelint": "latest",
        "stylelint-config-recommended": "latest",
        "stylelint-config-sass-guidelines": "latest",
        "stylelint-config-standard": "latest",
        "svgo": "latest"
    },
    "scripts": {
        "css-compile": "npx node-sass --include-path node_modules --output-style compressed --source-map true --source-map-contents true --precision 6 wp-content/themes/xxxxxxxxxxxxxx/assets/scss/style.scss wp-content/themes/xxxxxxxxxxxxxx/assets/css/style.min.css",
        "css-prefix": "npx postcss --replace wp-content/themes/xxxxxxxxxxxxxx/assets/css/style.min.css --use autoprefixer --map",
        "css": "npm run css-compile && npm run css-prefix",
        "watch": "nodemon -e scss --watch wp-content/themes/xxxxxxxxxxxxxx/assets/scss --exec \"npm run css\""
    }
}

Half solution (at first glance):

Excluding this directory using CSSNavigation.excludeGlobPatterns

    "CSSNavigation.excludeGlobPatterns": [
        "**/node_modules/**",
        "**/bower_components/**",
        "**/vendor/**",
        "**/coverage/**",
        "**/wp-content/themes/xxxxxxxxxxxx/assets/css/**"
    ]

Everything works fine with this setting added

Conclusion:

Honestly, I don't know what now.

  1. Should I close this ticket and open another one about incorrectly ignoring by .gitignore?
  2. Do you see anything else what should be fixed?
  3. Any another comment?

PS:

During testing, I also accidentally noticed another problem. It is not related to what I described above but it may be useful for you. From what I can see, this only happens once after I reload VSCode and start using my project files

[Error - 1:55:03 PM] Request textDocument/definition failed.
  Message: Request textDocument/definition failed with message: Cannot read property 'length' of null
  Code: -32603 

If it is important, of course I can create a separate ticket. Let me know

pucelle commented 3 years ago

I think I already catch the main issue... fixing it.

pucelle commented 3 years ago

Hi, I already publish a new version v1.10.3, can you help to check this? I think my system can't reproduce it.

Otherwise, I changed the description of option alwaysIncludeImportedFiles to explain when true it will always include the imported files although they should be excluded aspect to .gitignore.

kanlukasz commented 3 years ago

Hello,

I did a quick test and now it looks like the path is generating correctly: [19:43:48] file:///var/www/xxxxxx/public_html/wp-content/themes/xxxxxxx/assets/css/style.min.css tracked

Still not sure about alwaysIncludeImportedFiles behavior as whatever it is on true or false still tracked files excluded in gitignore. But I think I need to re-verify it, maybe I missed something. If I find any irregularities, I will let you know in a separate issue.

Anyway I think we can say that the main issue is solved 👍 and we can close this ticket ✔

Thanks for the quick issue fix, I appreciate it very much By the way, happy new year 🎉

pucelle commented 3 years ago

Now I'm sure there's something wrong in the ignore-walk library I'm using, I will check it, thanks.

Otherwise, happy new year to you!☺

pucelle commented 3 years ago

Sorry I did some test but can't reproduce.

Otherwise there is an exception you may meet: if you already opened the CSS file you expected to be ignored in your vscode, definitions will can be found inside it.

I know this is a little mess...