Skip to content

Add path alias to the auto import suggestions  #20525

Closed

Description

@mjbvz

From Maus3rVonDutch on December 2, 2017 9:52

Right now the auto import feature provides the file location of any symbol, which is great but could be improved upon. In the ts compiler options you have the option to provide path aliases, so you can combine multiple symbols in one import declaration:

tsconfig.json

{
    "compilerOptions": {
        ...
        "paths": {
            "@my-application/common": [
                "./src/app/common/index"
            ],
            "@my-application/module1": [
                "./src/app/module1/index"
            ],
            "@my-application/module2": [
                "./src/app/module2/index"
            ]          
        }
}

With this configuration you can import multiple classes in one declaration:

import { CommonA, CommonB } from '@my-application/common';
import { ClassA, ClassB, ClassC } from '@my-application/module1';
import { ClassD, ClassE } from '@my-application/module2';

It would be a great feature if the import suggestion provider would be able to pick up those paths from the tsconfig.json file and provide those aliases as well. Maybe the provider could have a configuration that allows you to include both options (the local file path and the alias) or just one or the other. As a note, when choosing the alias, the import feature would have to add the symbol to any existing declaration (and not just always add the alias as a new import line)

Copied from original issue: microsoft/vscode#39459

Activity

  1. added
    VS Code Tracked
    and removed on Dec 7, 2017
  2. mjbvz commented on Dec 7, 2017

    @mjbvz
    ContributorAuthor

    Tested with TS 2.6.2 and 2.7-dev-20171203. Confirmed that auto imports do not seem to ever show suggestions that use the paths

  3. removed their assignment
    on Jan 3, 2018
  4. added
    Domain: LS: Quick Fixes
    Domain: LS: Completion Lists
    and removed
    Domain: LS: Quick Fixes
    on Jan 4, 2018
  5. ghost added
    Fixed
    on Jan 5, 2018
  6. ghost closed this as completedin #21035on Jan 9, 2018
  7. locked and limited conversation to collaborators on Jul 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDomain: LS: Completion ListsFixedVS Code Tracked

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions