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

SCSS follow link resolves wrong path (prefixes base with underscore) #58204

Closed
Spown opened this issue Sep 7, 2018 · 49 comments
Closed

SCSS follow link resolves wrong path (prefixes base with underscore) #58204

Spown opened this issue Sep 7, 2018 · 49 comments
Assignees
Labels
css-less-scss Issues and items concerning CSS,Less,SCSS styling feature-request Request for new features or functionality on-testplan
Milestone

Comments

@Spown
Copy link

Spown commented Sep 7, 2018

  • VSCode Version: 1.27.1
  • OS Version: Win10x64

Steps to Reproduce:


Does this issue occur when all extensions are disabled?: Yes
Insiders?: Yes

@vscodebot
Copy link

vscodebot bot commented Sep 7, 2018

(Experimental duplicate detection)
Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

@vscodebot vscodebot bot added the new release label Sep 7, 2018
@Spown Spown changed the title SCSS follow link resolves wrong path (prexixes base with underscore) SCSS follow link resolves wrong path (prefixes base with underscore) Sep 7, 2018
@octref
Copy link
Contributor

octref commented Sep 7, 2018

I'm guessing the file you are working on is located at /static/css, is that correct? Can you run a tree command at the folder and selectively paste useful information here?

@octref octref added info-needed Issue requires more information from poster and removed new release labels Sep 7, 2018
@Spown
Copy link
Author

Spown commented Sep 8, 2018

correct

[project_root]/static/css
│   admin.css 
│   admin.scss //<-main import entry point, compiles
│   style.css
│   style.scss
│
├───maps
│       admin.css.map
│       style.css.map
│
├───mixins //<-imports, not compiled on itself
│   │   common.scss
│   │   filemanager.scss
│   │   flash_messages.scss
│   │   fonts.scss
│   │   lang_switcher.scss
│   │   list_table.scss
│   │   native.scss
│   │   reset.scss
│   │   scrollbar.scss
│   │   slick-theme.scss
│   │   slick.scss
│   │   unique.scss
│   │   variables.scss
│   │
│   └───scrollbar
│           mixins.scss
│           themes.scss
│           variables.scss
│
└───views
        admin__work_add_edit.scss

@octref
Copy link
Contributor

octref commented Sep 8, 2018

I see, in SCSS you don't have to put an underscore before the filename for it to not compile...

@Spown
Copy link
Author

Spown commented Sep 8, 2018

I can't say for every scss compiler tool. maybe some has this convention and act upon it by default. I use gulp-sass which I explicitly tell to compile "./static/css/*.scss" so it doesn't go in the subfolders

@GrimLink
Copy link

GrimLink commented Sep 9, 2018

This error also happens when you leave out the file type.
The name must be exact to its file name.
This makes sense for most cases.
But not for scss files, since the import statement does not required the file type and the underscore.

Example:
file: _card.scss

@import "card"; // Fails
@import "_card"; // Fails
@import "card.scss"; // Fails
@import "_card.scss"; // Works

@octref & @Spown the underscore is purely for scss files that are imported via an scss file.
It is a best practice to use it when the scss file is not outputted to a css file.
Most compilers will convert the scss file without one to a css file.

@octref octref added bug Issue identified by VS Code Team member as probable bug and removed info-needed Issue requires more information from poster labels Sep 9, 2018
@octref octref added this to the September 2018 milestone Sep 9, 2018
@octref
Copy link
Contributor

octref commented Sep 9, 2018

I see. And during my testing, unless you specifically specify card.css, SCSS resolves card to card.scss when there are both card.css and card.scss.

@octref octref added the css-less-scss Issues and items concerning CSS,Less,SCSS styling label Sep 12, 2018
@octref
Copy link
Contributor

octref commented Sep 18, 2018

@aeschli Do you have any suggestions as to how to do this in service?

  • @import "card.scss" might be importing either card.scss or _card.scss
  • I need to use fs to check which one the import resolves to, but fs is not available in service

@Spown
Copy link
Author

Spown commented Sep 18, 2018

I personally don't understand why the service even needs to guess anything. Follow link is being supplied an definite path from the file source.

@octref
Copy link
Contributor

octref commented Sep 18, 2018

@Spown The service is used in Monaco too, which can be used in browser that doesn't have file system access: https://microsoft.github.io/monaco-editor/playground.html.

@aeschli
Copy link
Contributor

aeschli commented Sep 19, 2018

@octref we could add something like a file system provider that we initialise the service with.
With that service we could also move path completion to the service.

@octref
Copy link
Contributor

octref commented Sep 20, 2018

Moving to October since introducing a FS Provider to the Language Service is more work.

@octref octref modified the milestones: September 2018, October 2018 Sep 20, 2018
@octref octref modified the milestones: October 2018, November 2018 Oct 29, 2018
@Mushr0000m
Copy link

Same problem for me, I have a master.scss that only does multiples@import "...", the autocompletion works but the go to click doesn't. The most weird part is that it works in some case and not in others :

  • @import "components/header.scss" => Works
  • @import "pages/home.scss" => Works
  • @import "base/icons.scss" => Doesn't work, it tries to find base/_icons.scss. For everything inside my base folder when I try to use the go to on click it search for the file with the underscore name....

Is there any way to make it just go to what is written, just follow the path in any case ?

@andremacola
Copy link

Another simple problem in VSCode that is not fixed by the team.
VSCode need a task force for several small big problems in the editor.

@ericmorand
Copy link

It also doesn't resolve imports like this:

@import '~font-awesome/scss/font-awesome';

Which is normal since it is by no mean part of SASS specifications.

@ericmorand
Copy link

Is there an alternative extension available? This makes Visual Code useless for frontend developers.

@proteus-aholt
Copy link

Is there an alternative extension available? This makes Visual Code useless for frontend developers.

that seems like a stretch. VSCode is by no means useless for frontend developers with this bug.

Lets try to keep the hyperbole down to a believable level. Is the bug annoying? yes. Can it be worked around? also yes. Ctrl + P then type in the file name.

I would be awesome if this were fixed, though, as it is a major annoyance at the very least.

@octref octref modified the milestones: May 2019, June 2019 May 24, 2019
@vedmant
Copy link

vedmant commented Jun 7, 2019

Also important one is to fix "~" as a node_modules shortcut, it doesn't resolve paths like @import '~font-awesome/scss/font-awesome';

@aeschli
Copy link
Contributor

aeschli commented Jun 7, 2019

@vedmant There's now (some) support for paths starting with ~: #70693

@BPScott
Copy link

BPScott commented Jul 1, 2019

In case anybody is looking to implement, here's the spec for resolving @imports in sass: https://github.com/sass/sass/blob/master/spec/at-rules/import.md

@BPScott
Copy link

BPScott commented Jul 1, 2019

microsoft/vscode-css-languageservice#159 should fix the inconsistency where @import './foobar' resolves to to _foobar.scss while @import './foo-bar resolves to foo-bar. Once that is merged then filenames containing non-alphanumeric charachers (like hypens) shall also be prefixed with an underscore and get their extension too.

It doesn't solve the underlying problem of VScode assuming the convention of "Sass files that are only meant to be imported, not compiled on their own, begin with _ (as in _code.scss)" rather than following the import spec but at least it makes that behaviour more consistent.

@octref
Copy link
Contributor

octref commented Jul 3, 2019

I'll fix this with a dynamic resolver. Previously there's no fs access from css language service, as it needs to be usable in Monaco.

Here's my plan:

  • The - causing inconsistent behavior is a bug. I'll fix that with @BPScott's PR.
  • a could resolve to either a.scss, _a.scss or a/index.scss or a/_index.scss (dynamic link)
  • _a could only resolve to _a.scss (static link)
  • When using imports with suffix, such as a.scss or a.css, resolve without guessing the alternative such as _a.scss (static link)

@ericmorand
Copy link

Is "a could resolve to either a.scss, _a.scss or a/index.scss or a/_index.scss (dynamic link)" part of SASS specifications?

octref added a commit to microsoft/vscode-css-languageservice that referenced this issue Jul 14, 2019
@octref octref added feature-request Request for new features or functionality on-testplan and removed bug Issue identified by VS Code Team member as probable bug labels Jul 17, 2019
@kasvtv
Copy link

kasvtv commented Aug 13, 2019

I still can't get SCSS referencing to work after the update. It's true that it no longer requires an underscore in front of the filename, but absolute imports only work if prepended by a slash, however that tends not to compile with webpack's sass-loader.

@octref
Copy link
Contributor

octref commented Aug 13, 2019

@kasvtv Please post new issues with full reproducible steps.

@ericmorand
Copy link

ericmorand commented Aug 14, 2019

@kasvtv then it's an issue with sass-loader, isn't it? Absolute import in SASS requires the forward slash, it's in the CSS specs that SASS conforms to.

@import "foo"; is relative and same as @import "./foo";
@import "/foo"; is absolute

@vscodebot vscodebot bot locked and limited conversation to collaborators Aug 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
css-less-scss Issues and items concerning CSS,Less,SCSS styling feature-request Request for new features or functionality on-testplan
Projects
None yet
Development

No branches or pull requests