-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
[scss] link doesn't work with ~Tilde to search in node module or webpack alias #78894
Comments
Some extra information: I see there happened to be a pull request here on exactly this and it seems to be merged, but for some reason doesn't work?: Documentation webpack about imports with a tilde: |
I had this working but was unaware that the distributed version of vscode has parts of the code webpacked, including where I had written the resolve function, so webpack complained and the code was reverted. This was rewritten by @aeschli but the rewritten version doesn't work in most use cases as far as I'm aware. We need to either find a way to get this to work after being processed by webpack, or have the code sit in a non-webpacked part of vscode (if that's exists/is possible) and have the code called from there. Unfortunately my knowledge of why and how vscode is using webpack for the distributable is beyond me and I have no idea where to search for help on this. |
Perhaps someone from the vscode team can answer:
For some context to the last point, see vscode/extensions/css-language-features/server/src/utils/documentContext.ts Lines 22 to 30 in 36ae347
I want |
webpack is probably the best packager out there. For browsers and also for commonjs. It's a pity that its so restrictive with
In the webpack.config.js you set a list of node modules that should not be bundled but just required. Alternative is to reimplement the require lookup. I think that's the typescript language server does: |
I just remembered this Which I think is what's calling require.resolve when you do jump to definition on a .js file. I assume there's a way we can use require.resolve in the same way? Will look in to it a bit more |
I'm not questioning the choice of webpack specifically, just why there's a need to package at all and not just run from modular, transpiled code |
https://github.com/browserify/resolve may be an option |
@aeschli I think you mentioned this before but I couldn't find it. Do you mean in this file? https://github.com/microsoft/vscode/blob/master/extensions/shared.webpack.config.js Or this one? Or another? |
It would go into extension.webpack.config.js.
|
I've drafted something here #79651 but not had a chance to test yet, will hopefully pick up later or tomorrow |
I propose that we don't add one-liner dependencies to just bypass webpack. Does doing it this way work for your cases?
For example, if you have
|
I think you mean |
@octref for now, I think your suggestion should satisfy most use cases, however I am pretty sure it will stop working once npm tink is finalised: https://blog.npmjs.org/post/178027064160/next-generation-package-management I think using node module resolution directly would allow easier solutions to things like this, although admittedly it could be hard to ensure vscode's node runtime would always resolve in the same way as the node runtime for the open project. I also previously mentioned yarn pnp and the yarn portal protocol which could cause issues but I'm not sure how these could be easily solved! |
I just realised @zkat has left npm and development on tink seems to have stopped, though it is on the roadmap for npm 8 |
as per comments from @octref on #78894 microsoft/vscode#78894 (comment)
@roblourens Not sure who you target your message at and what you do or don't know about sass etc., but maybe this helps you?: The path starting with Open door, but just in case: Is the bootstrap package installed there and does the file Also as I understand it you see this in a If the import path in the scss-file is not 'linkified' it sounds like something is not working as expected, as normally Does this help? |
I'm asking @aeschli what I need to set up to verify that it was fixed. And CSS imports do exist. But when I have a workspace with a sass file and an import like and |
Just checking this on my commit here 06634e1
@import '~bootstrap/scss/bootstrap-grid'; /* unable to open */
@import '~bootstrap/scss/bootstrap-grid.scss'; /* works */
@import '../node_modules/bootstrap/scss/bootstrap-grid'; /* unable to open */
@import '~bootstrap/scss/bootstrap-grid'; /* unable to open */
@import '../node_modules/bootstrap/scss/utilities/sizing'; /* unable to open */
@import '~bootstrap/scss/bootstrap-grid'; // works
@import '~bootstrap/scss/bootstrap-grid.scss'; // works
@import '../node_modules/bootstrap/scss/bootstrap-grid'; // works
@import '~bootstrap/scss/bootstrap-grid'; // works
@import '../node_modules/bootstrap/scss/utilities/sizing'; // works All of the above, I think, is intended behaviour as I wouldn't expect a css file to import an scss file using scss filename resolution (but if for some reason it directly linked to the file then it links through fine). (edit - if anything is incorrect here it's that the css file shouldn't underline the invalid links?) @JacksonKearl @roblourens what versions/commits are you testing against? |
here's a test project (make sure to run |
@roblourens and the files definitely exist on disk? i.e. you’ve done a yarn or npm install bootstrap? I’ll try check the insiders build shortly but may be Monday |
Yeah |
|
I pushed a change to my demo repo as I had the wrong relative path in the root scss files sorry (there are also a second set in a sub directory called styles). Confirmed for me on Insiders (commit b1ef2bf ) that in the scss file, only the relative links work. However, on the commit where I raised the PR this was working. Will see if I can figure out what changes. |
@aeschli looks like you removed the code here? 2e5b082#diff-90971796685fd5e48e8f97b9daf95404L58-L79 |
ok I'm confused now, I wrote a test that should be failing but it's passing. @aeschli could you take a look? I'm happy to work on this but could do with some pointers e.g.
|
@penx Yes, I moved the code into the service: https://github.com/microsoft/vscode-css-languageservice/blob/master/src/services/cssNavigation.ts#L273 I broke the node module resolving for scss as scss has some additional resolving resolving on. If you have any additional any tests, you can add them
|
Yes I know. But it doesn't make sense to import sass from css. |
Using a **~**Tilde to go directly to a node_module path without having to add aliases to webpack this path doesn't get resolved by VS Code.
So with a node_module 'bootstrap' installed, we can import bootstrap sass-files using this construction:
While this is working fine with Webpack and the sass-loader/node_sass, VS Code doesn't recognise this tilde-construction and searches on a follow-link in our
source-folder\bootstrap\
instead of innode_modules\bootstrap\
When we use aliases in Javascript we solved his resolve problem by adding aliases to the jsconfig.json. But AFAIK there's not such a config file for Sass in VS Code.
I've been searching everywhere, including settings on sass, but couldn't find anything where we could make VS Code respect the node_modules path (and Webpack aliases) with a tilde~.
So unfortunately we seem to not being able to click to follow link on these sass imports.
versions
Steps to Reproduce:
@import '~bootstrap/scss/bootstrap-grid';
Result: it shows an error-message popup saying 'Unable to open' with the wrong path
extensions
Does this issue occur when all extensions are disabled?: Yes
The text was updated successfully, but these errors were encountered: