-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Node module resolution for CSS import #70693
Node module resolution for CSS import #70693
Conversation
extensions/css-language-features/server/src/utils/documentContext.ts
Outdated
Show resolved
Hide resolved
// and [sass-loader's](https://github.com/webpack-contrib/sass-loader#imports) | ||
// convention, if an import path starts with ~ then use node module resolution | ||
// *unless* it starts with "~/" as this refers to the user's home directory. | ||
if (ref[0] === '~' && ref[1] !== '/') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how this can be unit tested, I guess I'd need to mock require.resolve, I don't see an equivalent test for
https://github.com/Microsoft/vscode-languageserver-node/blob/master/server/src/resolve.ts
@@ -8,6 +8,14 @@ import { endsWith, startsWith } from '../utils/strings'; | |||
import * as url from 'url'; | |||
import { WorkspaceFolder } from 'vscode-languageserver'; | |||
|
|||
function getModuleNameFromPath(path: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could add unit tests for this fairly easily, but that would lead me to put it in its own module, which in turn makes me wonder if there's an existing util in vscode that already does this that I could use instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the unit tests for this part of the code (completion.test.ts) only seem to be testing the public API rather than internal functions so I'm not going to add unit tests for now. Happy to take direction on this if you want unit tests adding!
386069f
to
a2c0729
Compare
Add support for `@import "~bootstrap/dist/css/bootstrap";` as per https://github.com/webpack-contrib/sass-loader#imports Fixes microsoft/vscode-css-languageservice#136
extract resolvePathToModule and ensure we resolve to package root
if require.resolve fails, defer to default behaviour -url.resolve(base, ref)
a2c0729
to
2e9bd07
Compare
@octref previous build issues were not related to this PR. All solved now after rebase off master. Please let me know if you'd like any changes |
You are also in this thread: sass/sass#2350. I'm not sure if VS Code should add such url resolving mechanism. It's not part of css or sass language, and only comes from some webpack plugins that you have configured. Ping @aeschli |
sass-loader and css-loader are the standard webpack loaders for styling and the behaviour this PR supports is for their default behaviour without any additional configuration. https://webpack.js.org/loaders#styling These loaders are used by many config-less uses of webpack, e.g. when using create-react-app I agree that this isn't in the underlying spec for Sass, however I suspect that a very large number of people using VSCode to write Sass are using sass-loader under the hood. Even more so, I think it's safe to assume that near to 100% of vscode users that encounter If you're still against this being the default behaviour of "Go to definition" in VSCode then perhaps it can be behind a config option instead? I personally would find this very useful, and I use what I believe are fairly standard build setups for writing CSS/Sass. |
Can't you provide autocompletion also?? |
Waiting for @aeschli to confirm this feature can be merged first! |
@penx This feature is needed too much. if you can do that please post another PR. |
@penx Thanks, sorry for the delay! |
Tests would be very appreciated. I created a first link tests: ae6be63 To run, |
@penx This PR has finally been merged. Please start another PR that provides variables completion across files. |
@aeschli sorry for the delay in responding, yes unfortunately what you have written assumes that See:
Is it possible that we do something like |
I you find a way to trick webpack, I'm happy to take a PR. |
@aeschli ok I should be able to look in to this, is there a way I can replicate the issue? Is there a particular build task I need to run to get the webpacked version that was causing the issue? |
From what I understand, the development build I was using is not webpacked, but when you do a production/distribution build it is. If I run
Which I guess is the issue you encountered when you merged my PR. |
You can manually invoke webpack by calling |
I'm still thinking about this but have had limited time. From some initial tests I think the current implementation only works if you're editing an scss file that's in the same directory as the node_modules folder you want to jump in to, which is rarely the case. |
Add 'Go to definition' support for
as per
Fixes microsoft/vscode-css-languageservice#136
Also see https://stackoverflow.com/questions/48499853/how-to-jump-to-definition-for-a-file-in-node-modules-from-vs-code