nkt / atom-autocomplete-modules

Autocomplete for require/import statements
https://atom.io/packages/autocomplete-modules
MIT License
114 stars 35 forks source link

Fix webpack aliased suggestions being filtered out #130

Open jgconway opened 5 years ago

jgconway commented 5 years ago

Hi,

So I noticed that no suggestions show up when I try and import from a webpack alias. For example, given the following Webpack config:

resolve: {
  alias: {
    "~": path.resolve(__dirname, "src")
  }
}

If I type import App from "~/" then I would expect to see the children of src/, but in fact I see nothing. It looks like the problem is that the suggestions are being filtered based on prefix, but prefix doesn't match any results since they've been transformed by the alias.

So my solution is to copy the massagePrefix behaviour from LocalLookup into WebpackLookup, i.e. suggestions will only be matched on the last part of the path. I can't see any reason why this would be a problem, but hopefully someone more familiar with the codebase can confirm that.

jonyeezs commented 5 years ago

Hi! Does the alias lookup resolve the right path from path.resolve? I thought it was a string match and won't execute that method. I could be wrong. Have you manage to test run your implementation?

jgconway commented 5 years ago

From what I can tell, the webpack config is require'd (see here) so the path.resolve is actually executed before the string comparison happens. It looks like this is covered in the tests too and, since they're still passing, I guess it's okay.

I did verify that this fix actually solves the problem, i.e. the expected suggestions do show up now. I also can't find any other differences in behaviour before vs after these changes, although obviously there's no guarantee that I've checked every case.