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

Feat request: absolute path for auto import #1177

Closed
3 tasks done
nereuseng opened this issue Apr 3, 2019 · 5 comments
Closed
3 tasks done

Feat request: absolute path for auto import #1177

nereuseng opened this issue Apr 3, 2019 · 5 comments

Comments

@nereuseng
Copy link

nereuseng commented Apr 3, 2019

  • I have searched through existing issues
  • I have read through docs
  • I have read FAQ

Info

  • Platform: Window 10 1809
  • Vetur version: 0.18.0
  • VS Code version: 1.32.3

Problem

Currently the auto import is imported in relative path, is that any possible to add support auto import in absolute path or with alias?
Example:

  1. absolute path:
import { getStoreUserData } from './store/getter.types.js'
  1. with alias
import { getStoreUserData } from '@/store/getter.types.js'

Besides, I find that another extension auto import was working in previous version, but It was broken after new version installed. Is that any possible to disable?

Thank you so much for contributing such a great work, I hope It will getting better!

@octref
Copy link
Member

octref commented Apr 3, 2019

@nereuseng
Copy link
Author

nereuseng commented Apr 4, 2019

Nope. Alias work on importing .vue file, but not working on auto import.

image

@praveenpuglia
Copy link

tsconfig.json

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "sourceMap": true,
    "baseUrl": ".",
    "types": ["webpack-env", "jest"],
    "paths": {
      "@/*": ["src/*"]
    },
    "lib": ["esnext", "dom", "dom.iterable", "scripthost"]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
  ],
  "exclude": ["node_modules"]
}

Extension Version

Name: Vetur
Id: octref.vetur
Description: Vue tooling for VS Code
Version: 0.22.3
Publisher: Pine Wu
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=octref.vetur

What's Happening

With the above tsconfig.json here's what I get.

  • Aliases work when the import path is typed manually. So I write @/ and then hit Ctrl + Space and I get the autocompletion as expected.

  • If somewher in the code, say a method, I try to access anything that's exported in some other file and TS knows about it, it allows me to automatically import it. BUT, when it does that, it doesn't use absolute path starting from say @/.

  • In a TS file however, if I try to import anything that's exported in a file that doesn't exist in the same directory, VSCode does full path completion. Here's a screenshot.

image

  • In a TS file itself however, if I import something that exists in file that resides in same directory, VSCode uses relative path like...
import something from './something.js';

What do I expect?

I would love the autocompletion inside the .vue file for a TS/JS project to always use absolute path, with the root alias.

Why?

With relative paths, it becomes a pain to figure out at what level a thing is and then moving those file while refactoring becomes an even bigger pain because VSCode's automatic file path updates don't work for .vue files.

With an absolute path, it's absolutely easy to move around things.

@IWANABETHATGUY
Copy link
Contributor

maybe you should try this vscode-extension https://marketplace.visualstudio.com/items?itemName=IWANABETHATGUY.path-alias

@octref
Copy link
Member

octref commented Aug 3, 2020

Fixed by #1753.

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

No branches or pull requests

4 participants