Skip to content

[css] Custom aliases in CSS file resolution #163967

Open

Description

@mechite

Please read from tsconfig/jsconfig to resolve SCSS modules. My suggestion to make this reliable is to simply only allow the import aliases to work inside of an aliased directory, and in every subfolder starting from the tsconfig/jsconfig as the root, so that we can theoretically open huge projects with weird build settings and have a sane default for it. The tsconfig/jsconfig essentially define majority of these weird quirks such as these path aliases for the entire IDE, and we should just stick to allowing this to continue even if it "makes no sense" to read from these files for what is "just SCSS".

If this won't be supported, we could at least make it possible to define these aliases in the .vscode settings.json and then use those paths across the IDE as the standard. No matter what though, we need these path aliases as for large projects not being able to jump to the definition of an imported module is very annoying.

Activity

  1. mechite commented on Oct 18, 2022

    @mechite
    Author
  2. aeschli commented on Oct 19, 2022

    @aeschli
    Contributor

    See my comment in #131954 (comment)

    I'm not opposed to put aliases in the settings. If you want to work on a PR for this, I'm happy to point to to where the changes need to be made.

  3. added
    css-less-scss
    feature-request
    on Oct 19, 2022
  4. vscodenpa commented on Oct 20, 2022

    @vscodenpa

    This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

    Happy Coding!

  5. mechite commented on Oct 21, 2022

    @mechite
    Author

    See my comment in #131954 (comment)

    I'm not opposed to put aliases in the settings. If you want to work on a PR for this, I'm happy to point to to where the changes need to be made.

    I am happy to work on a PR for it however I'm not very familiar with VSCode as I've never submitted a change before. If I figure things out in my free time, I'll submit a patch and link it here for review, otherwise expect indefinite silence from me if I don't.

    This could and should apply to CSS in general, with native @import and other preprocessors like less or stylus, maybe it just works in every language and this can simply just be a long mapping of aliases for paths, relative to a directory starting from the open folder containing .vscode.

  6. vscodenpa commented on Dec 10, 2022

    @vscodenpa

    This feature request has not yet received the 20 community upvotes it takes to make to our backlog. 10 days to go. To learn more about how we handle feature requests, please see our documentation.

    Happy Coding!

  7. changed the title [-][scss] Custom aliases in module resolution[/-] [+]Custom aliases in module resolution[/+] on Dec 10, 2022
  8. changed the title [-]Custom aliases in module resolution[/-] [+]Custom aliases in CSS file resolution[/+] on Dec 10, 2022
  9. vscodenpa commented on Dec 11, 2022

    @vscodenpa

    🙂 This feature request received a sufficient number of community upvotes and we moved it to our backlog. To learn more about how we handle feature requests, please see our documentation.

    Happy Coding!

  10. changed the title [-]Custom aliases in CSS file resolution[/-] [+][scss] Custom aliases in CSS file resolution[/+] on Dec 19, 2022
  11. 4 remaining items

  12. mechite commented on Mar 10, 2023

    @mechite
    Author

    This is still an issue. What's the status of it?

    Unresolved, though in the backlog. I don't have bandwidth to contribute so based on what I know it'll probably take a few years for them to land on the issue and make the changes

  13. SStranks commented on Oct 23, 2023

    @SStranks

    I was looking for a solution and stumbled across this extension: https://github.com/dgeibi/alias-tool

    Haven't tried it as I wasn't sure if it was safe or not, but adding it here in case it perhaps contains relevant code.

  14. SStranks commented on Oct 24, 2023

    @SStranks

    See my comment in #131954 (comment)

    I'm not opposed to put aliases in the settings. If you want to work on a PR for this, I'm happy to point to to where the changes need to be made.

    Could you provide this? I would like to take look.

  15. aeschli commented on Oct 24, 2023

    @aeschli
    Contributor

    https://github.com/microsoft/vscode-css-languageservice/blob/0f2dfc45a53fd0d6ec9b3d1cd54a86b2eccb5ddf/src/services/cssNavigation.ts#L379
    is where import paths are resolved to an actual path.
    This is where settings could be read as well that could allow users to provide additional folders to look into.

  16. SStranks commented on Oct 25, 2023

    @SStranks

    https://github.com/microsoft/vscode-css-languageservice/blob/0f2dfc45a53fd0d6ec9b3d1cd54a86b2eccb5ddf/src/services/cssNavigation.ts#L379 is where import paths are resolved to an actual path. This is where settings could be read as well that could allow users to provide additional folders to look into.

    Looking at the codebase I can't see how I might access the settings.json within this function - is it available on the FileSystemProvider somehow?

  17. aeschli commented on Oct 25, 2023

    @aeschli
    Contributor

    You have to add a field in the LanguageSettings: https://github.com/microsoft/vscode-css-languageservice/blob/0f2dfc45a53fd0d6ec9b3d1cd54a86b2eccb5ddf/src/cssLanguageTypes.ts#L45

    It will be set by the CSS language server here:

    for (const languageId in languageServices) {

    The CSS language server gets it from the language client which will read it from the settings

  18. SStranks commented on Oct 30, 2023

    @SStranks

    I'm not opposed to put aliases in the settings. If you want to work on a PR for this, I'm happy to point to to where the changes need to be made.

    I've made two pull requests for this issue:
    PR #197033: This one adds settings (and tool tip descriptions) in package.json/package.nls.json, within vscode/extensions/css-language-features.
    PR #368: This one adds the functionality in cssNavigation, within vscode-css-languageservice.

    Notes:
    The code makes use of documentContext (line 414; cssNavigation) to get the root folder; consequently if the project folder isn't a root folder of the workspace the reference path will fail. There was discussion about tsconfig in this thread, so one possibility could be to make a simple function to recursively go up from the css file until a package.json, or tsconfig, is found and treat that level as the root.

    It will be set by the CSS language server here:

    for (const languageId in languageServices) {

    The CSS language server gets it from the language client which will read it from the settings

    Due to the code above, of settings getting bound to the respective language service, there is duplication of the alias settings with one for css and one for scss.

    It's my first pull request/contribution - any feedback welcome!

  19. NoelAbrahams commented on Oct 10, 2025

    @NoelAbrahams
    Contributor

    For crying out loud, why has this not been fixed? Why even mark this as a feature request when it's clearly a bug?

  20. SStranks commented on Oct 14, 2025

    @SStranks

    Links to pending PRs for the issue:
    #460
    #197033

  21. SubSploink commented on Jul 9, 2026

    @SubSploink

    It appears this feature was already realized years ago in this repo: https://github.com/microsoft/vscode-css-languageservice

    Users would be able to add import aliases to the workspace settings under alias or importAliases.

    "importAliases": {
    	"paths": {
    		"@SingleStylesheet": "/src/assets/styles.css",
    		"@AssetsDir/*": "/src/assets/*",
    	}
    }

    I am unsure how that repository relates to the built in extensions located in this repo.
    Nevertheless the feature seems to be missing.

    Pull Request:
    microsoft/vscode-css-languageservice#368

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

css-less-scssfeature-request

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions