Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix webpack aliased suggestions being filtered out #130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jgconway
Copy link

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
Copy link
Collaborator

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants