When writing a javascript app, it's possible to create an .env
file in the root directory containing just e.g:
NODE_PATH=src/
Which sets up allowing for absolute paths e.g: in import statements in code.
e.g: I can be working on the file /src/actions/index.js
and enter:
import { SAVE_COMMENT } from "actions/types";
..and the import works, but there is no auto-complete and I wonder: Is it possible to auto-complete after I type just:
import { SAVE_COMMENT } from "actions/
?
Relative-path lookup continues to work great. In fact, the relative path lookup is one of my favorite features of vs-code and one of the reasons I use it, so it would be very nice for it to work when absolute paths are configured, too.
Visual Studio Code IntelliSense is provided for JavaScript, TypeScript, JSON, HTML, CSS, SCSS, and Less out of the box. VS Code supports word based completions for any programming language but can also be configured to have richer IntelliSense by installing a language extension.
The suggestion list of Automatic completion appears as soon as you start typing a new identifier. The suggestion list of Basic completion appears when you press the default Visual Studio IntelliSense shortcut Ctrl+Space . If necessary, you can always return to the Visual Studio's native's IntelliSense.
Go to Tools | Options | Text Editor | C/C++. This dialog displays a window that allows you to toggle Automatic brace completion. Automatic brace completion is the feature where, when you type { , a corresponding } is automatically typed for you.
VS Code does not support using NODE_PATH
for intellisense. To achieve what you want, create a jsconfig.json
file at the root of your project with the contents:
{
"compilerOptions": {
"target": "ES6",
"baseUrl": "./src"
},
"exclude": [
"node_modules",
"**/node_modules/*"
]
}
The important setting is baseUrl
. It tells VS Code to resolve non-relative paths relative to the ./src
folder
After configuring jsconfig
and baseUrl
, you can also set "javascript.preferences.importModuleSpecifier": "non-relative"
in VS Code to specify that VS Code should always try to use paths to use the baseUrl
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With