Skip to content

Fix webpack aliased suggestions being filtered out#130

Open
jgconway wants to merge 1 commit intonkt:masterfrom
jgconway:fix-webpack-alias
Open

Fix webpack aliased suggestions being filtered out#130
jgconway wants to merge 1 commit intonkt:masterfrom
jgconway:fix-webpack-alias

Conversation

@jgconway
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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