Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to using vscode JavaScript's 'go to definition' cross files?

Is there anyway to use 'go to definition' find one function definition in other file? Two files are in the same folder/own the same parent folder.

I know the html holds all .js files, but I can't find any way in Google.

like image 568
Kamil Avatar asked Mar 09 '18 00:03

Kamil


People also ask

How do you jump to define in VS Code?

Go to Definition# Tip: You can jump to the definition with Ctrl+Click or open the definition to the side with Ctrl+Alt+Click.

How do you link a feature file with step definition in Visual Studio Code?

Place your cursor on the step in your feature file. Right-click and select Go To Step Definition from the menu (F12). The file containing the binding is opened at the appropriate step definition method.

How do you link a file with a VS Code?

As one option, we can right-click on the source file and choose "Copy" and then right-click on the destination project and choose "Paste". The keyboard shortcuts Ctrl+C and Ctrl+V also work as long as you have the correct items selected in the Solution Explorer.


4 Answers

You must enable "TypeScript and JavaScript Language Features" extension in VS Code. It could be disabled by ESLint extension.

enter image description here

like image 175
galishmann Avatar answered Sep 28 '22 11:09

galishmann


You need to create a jsconfig.json file at the root of your project.

{
    "compilerOptions": {
        "target": "ES6"
    },
    "exclude": [
        "node_modules",
        "**/node_modules/*"
    ]
}

This file tells VS Code to treat all *.js files in the workspace as part of the same project. However it will not enable intellisense between javascript in <script> blocks and regular js files.

If this is still not working, try enabling checkJS in your js files to track down what is going wrong: https://code.visualstudio.com/Docs/languages/javascript#_type-checking-and-quick-fixes-for-javascript-files

like image 40
Matt Bierner Avatar answered Sep 28 '22 12:09

Matt Bierner


May be i am late in the show but even after trying all of the above answers i was facing the same issue but soon while editing the settings.json (Same as Settings which comes when we do "Ctrl + ," on VSCode) I realized that there was a setting "editor.multiCursorModifier" set as "ctrlCmd" as shown in the snapshot which when i commented resolved my problem. So this may be considered as a solution for the issue posted.

User Settings

like image 37
dev_khan Avatar answered Sep 28 '22 11:09

dev_khan


This may be overkill, but it seemed to work for me (on a Mac):

rm -rfv "$HOME/.vscode"
rm -rfv "$HOME/Library/Application Support/Code"
rm -rfv "$HOME/Library/Caches/com.microsoft.VSCode"
rm -rfv "$HOME/Library/Saved Application State/com.microsoft.VSCode.savedState"

Restart VSC - code . (Should start from scratch)

Also remove .vscode/ rm -rf .vscode/

like image 29
Vaibhav Jain Avatar answered Sep 28 '22 12:09

Vaibhav Jain