question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feat request: absolute path for auto import

See original GitHub issue
  • 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!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:16
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
praveenpugliacommented, Sep 17, 2019
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 <kbd>Ctrl</kbd> + <kbd>Space</kbd> 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.

1reaction
IWANABETHATGUYcommented, Oct 26, 2019
Read more comments on GitHub >

github_iconTop Results From Across the Web

Auto import in Visual Studio Code only offering absolute path ...
In Visual Studio Code, menu File → Preferences → Settings → User Settings, "typescript.preferences.importModuleSpecifier": "relative".
Read more >
Configuring the Style of Imports in JavaScript and TypeScript
To control that for auto imports, open the Imports tab and check the option “Use paths relative to the project, resource or sources...
Read more >
API — Flask Documentation (2.2.x)
from flask import Flask app = Flask(__name__) ... Relative to the application root_path or an absolute path. Defaults to 'static' .
Read more >
Configuration Options | Navidrome
Option in config file Env var Description Def... ND_CONFIGFILE Load configurations from an external config file "./n... DataFolder ND_DATAFOLDER Folder to store application data (DB,...
Read more >
Get Started with the Google Fonts API
Copy and paste the following HTML into a file: <html> ... Add a stylesheet link to request the desired web font(s):. <link rel="stylesheet"...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found