VSCode code autocomplete behavior - visual-studio-code

I noticed that VSCode uses only the files that are opened in editors (tabs) for looking up names for code auto complete. It is strange for me. To my mind the more usual behavior is to look up all files in opened folder, but not use only the opened files. Is this behavior by design ?

Try creating a jsconfig.json file at the root of your workspace:
{
"exclude": [
"node_modules"
]
}
This tells VSCode to treat all JS files in your workspace as part of a single project, even if the files have not been opened yet. You can find more information about jsconfig.json files in our documentation

Actually, to consider the opened folder as JS project, the "jsconfig.json" is required. Read more here

Related

Why doesn't emmet.extensionsPath default to the .vscode/ folder?

I have just started customizing my VS Code project with some project specific emmet snippets (by adding a snipptest.json into the project).
It is possible to just configure "emmet.extensionsPath": [".vscode/"], which will make the snippets file be found for every project.
No I ask myself: Why do I need to manually add the .vscode folder to the emmet search path?
Is there a potential problem with that configuration I don't see? OR other reasons I shouldn't do this?
And if this is totally valid, why isn't this the default behaviour?

Notepad++ Save Session equivalent in Visual Studio Code?

In Notepad++ there is an option called 'Save session' that saves a list of all opened files (in the current window), bookmarks, code foldings, cursor position, etc., so I can reopen that state later even if I close the files.
In Visual Studio Code, I have not found an option like that. It seems the Workspace only saves the folder path and some settings defined to that workspace.
Is there a way to create something like a Notepadd++ session in Visual Studio Code?
I think the most similar thing to what you are asking for are Workspaces. From testing, they do in fact keep the files you had open, so long as you close the workspace in the menu first.
A Visual Studio Code "workspace" is the collection of one or more folders that are opened in a VS Code window (instance). In most cases, you will have a single folder opened as the workspace but, depending on your development workflow, you can include more than one folder, using an advanced configuration called Multi-root workspaces.
The concept of a workspace enables VS Code to:
Configure settings that only apply to a specific folder or folders but not others.
Persist task and debugger launch configurations that are only valid in the context of that workspace.
Store and restore UI state associated with that workspace (for example, the files that are opened).
Selectively enable or disable extensions only for that workspace.
If you look under File, you'll see the Workspace options:
The way it works is it saves a file that is a .code-workspace extension, but really the underlying structure is JSON. For example, the file might look like:
{
"folders": [
{
"path": "..\\..\\..\\..\\dev\\Project Files\\Project\\MyProject"
}
],
"settings": {}
}

How do I prevent vscode from creating workspace files such as ".vscode/settings.json"?

Whenever I open a new folder to edit some code (code .), opening the settings dialog (⌘+,) immediately creates a directory .vscode with a mostly empty file settings.json.
Since there are no workspace-specific settings, the file looks like:
{
}
For the time being, I do not want to have .vscode directories spread across my filesystem. I am happy with global settings.
Is there a way to disable this behavior and prevent Visual Studio Code from creating these files automatically?
Currently this isn't an option, but it is an open issue (see here). This post also contains some work-arounds for git projects.

Tasks are only available on a workspace folder?

Can't find an simple, basic solution anywhere for this problem so I figured it was worth posting it here.
When I go to run my code as a task, I get the following message: "Tasks are only available on a workspace folder" - I can't find a solution anywhere and I'm a beginner at Visual Studio Code so I might need the answer / solution explaining in more simpler terms.
VSC Version = 1.17.0
Visual Studio Code treats the folder containing your program file as a workspace folder.
Your tasks created will be contained in a file tasks.json within a hidden folder .vscode inside your project or workspace folder.
So instead of opening the file directly to create a task, you need to open the folder as a project.
The "Workspace launch configuration" section of VSCode mentions:
With multi-root workspaces, VS Code searches across all folders for launch.json debug configuration files and displays them with the folder name as a suffix.
Additionally VS Code will also display launch configurations defined in the workspace configuration file.
Example of settings: vscode-tslint/vscode-tslint.code-workspace
As an alternative, you can have User level tasks to share them across projects since VSCode 1.42 (Jan. 2020).
But regarding workspace tasks, since VSCode 1.57 (May 2021), said tasks will have to be "trusted" by anyone opening the same workspace, assuming you have versioned and pushed the .vscode folder.
Safe code browsing
It's great that there is so much source code available on public repositories and file shares. No matter the coding task or problem, there is probably already a good solution available somewhere.
However, using open-source code and tools does have risks and you can leave yourself open to malicious code execution and exploits.
Workspace Trust provides an extra layer of security when working with unfamiliar code by preventing automatic code execution when a workspace is open in Restricted Mode.

Disable Auto Generation of .vscode Folder

I often like to use VSCode to quick view some projects to pull snippets from them. However, this leads to a ton of additional .vscode folders being placed on my drive in any folder I use the right-click -> Open with VSCode option.
Is there a way to disable this folder from being created every time vscode loads somewhere new?
This issue was due to the 'C/C++ for Visual Studio Code' extension being outdated.
Upgrading to the latest version of this extension has fixed the problem.
That is not the standard behaviour of VSCode, normally the .vscode only gets generated once there is something like a launch.json put into it. Mind checking what's actually in there?