Visual Studio Code Intellisense Slow on Node proyect - visual-studio-code

Currently I have this problem in big projects, either in node or python (django) projects.
And I noticed that vscode intellisense works very slow +7 seconds.
What I have tried to solve the problem.
Remove all extensions.
Disable all extensions.
Try the Insiders version.
Configure a basic jsconfig.json for the project.
Have the correct .gitignore.
Make a full clean install.
One thing I noticed, is that when I enter the project(just started the window, intellisense works fine) until it finishes loading the "loading intellisense status" that appears below and the slowness returns.
For which I believe that the problem comes from the fact that they are "big" projects.
My jsconfig.json
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Node",
"target": "ES2020",
"strictNullChecks": true,
"strictFunctionTypes": true
},
"exclude": [
"node_modules",
"**/node_modules/*"
]
}

Related

Auto run tests in visual studio code

How do I run the tests automatically in visual studio code. My project has testing setup, and the settings JSON/UI has settings related to auto running tests, but I don't see an option for the test to actually run automatically. I have found topics around this issue, but those seem to be out of date, or related to a (different) plugin.
settings
In complement to the answer provided by #DanCiborowski, I would use the extension RunItOn instead of the RunOnSave because it is possible to run internal VSCode commands. Like so, the output from pytest is correctly integrated in the VSCode IDE.
Once RunItOn is installed, you can configure it with the settings:
"runItOn": {
"commands": [
{
"match": "\\.py$",
"isAsync": true,
"isShellCommand": false,
"cmd": "testing.runAll"
},
],
},
I've prepared a step-by-step tutorial here:
https://cordmaur.medium.com/how-to-autorun-python-tests-in-vscode-step-by-step-cfb24c6fc4be
Since VSCode is a text editor rather than a fully-fledged IDE, tests are not a native feature. Testing frameworks also vary drastically between different programming languages or environments. I'd suggest looking into command-line tools such jest for JavaScript which you can run via VSCode's integrated terminal.
Another approach is to create a custom task to run your test. Find an example for jest here.
The Python support for VSCode is an extension, which does not fully support "all" the testing features. The "Testing > Auto Run" settings are currently missing. This issue is being tracked here.
https://github.com/microsoft/vscode-python/issues/19046
Until this feature is properly implemented, the best way to achieve this uses extensions such as "Run on Save", the most popular item in the marketplace.
https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave
"emeraldwalk.runonsave": {
"commands": [
{
"match": "**.py",
"isAsync": true,
"cmd": "pytest"
}
]
}
(disclosure, I work for MSFT and was investigating this issue prior to finding the question while doing my own research on alternatives)

Is it possible to create a VS Code extension that runs a specific gulp task?

Since I'm a lazy programmer, I've built a gulp task that does some minor tasks for me but I'd like to turn this into an extension so I can install it on my computer and it just "works". Like I install it, boot up VS code and the tasks execute and start watching my code automatically.
I haven't found much things online but then again I could be googling the wrong things. Anything helps - thanks!
Have a look at run task on folderOpen option: vscode docs.
This works for me:
// in tasks.json
{
"label": "Tasks: copy3",
"type": "shell",
"command": "gulp",
"args": [
"copy3",
"--file",
"${fileBasename}"
],
"problemMatcher": [],
"runOptions": {
"runOn": "folderOpen"
}
},
Now the copy3 task in gulpfile.js will automatically be run when that folder (or workspace) is opened. You may have to select Tasks: Allow Automatic Tasks in Folder first in the command palette. And definitely reload.
No extension - it is built-in behaviour more recently. See run task on folder open.
Looks like Yuki Doi had you to it with "Blade Runner". This extension does exactly what you're looking for, it automatically runs build task when a folder is opened.
Related question

Is there a way on VS Code to import Makefile projects?

As the title said, can I populate automatically c_cpp_properties.json from an existing Makefile?
Edit:
For others trying to import makefiles, I have found a set of scripts that perform exactly what I wanted to achieve, the management of STM32 embedded projects through VS Code. If you dig into the scripts folder you can find the make parser and the VSCode project files populator.
Here the repo, enjoy!
This answer may not entirely give you what you want, but hopefully it helps you setting up your VS Code environment.
In your question title, you mention "Makefile projects", which is an indication that you have the wrong impression that (GNU) Makefiles capture project settings in a way similar to Visual Studio project files do. Makefiles do not work like that and the short answer to your question is No, there does not seem to be a way to "import" Makefiles into VS Code and have it automatically set values in your c_cpp_properties.json file.
Having said that, there are some other mechanisms that may help you getting started with VS Code in your situation, depending on the other elements you have in your toolchain.
VS Code works with the premise that it opens one or more directories in your file system. When you do so, it will automatically scan all its subdirectories, display the tree and do linting (if enabled) to detect problems. Indeed, include directories need to be added manually to your c_cpp_properties.json file but to add all your subdirectories recursively to the list of include directories, you can use the expression
"${workspaceRoot}/**"
as one of the elements in your includePath setting. See the blog post Visual Studio Code C/C++ extension May 2018 Update – IntelliSense configuration just got so much easier! for more details. That often resolves a lot of the missing symbols. If you are using external or 3rd party libraries as well, then you have to add those to your includePath setting manually, there is no way around that.
Additionally, you can create VS Code Tasks to execute your make command to your liking. This is explained here: Integrate with External Tools via Tasks. The Microsoft C/C++ Extension comes with a set of so-called problemMatchers that parse the output of your command and can interpret that for certain known compilers. You will see hyperlinks for errors and warning to navigate directly to the associated location in your code.
An example of such a Task may look like this:
{
"label": "Build All Debug",
"type": "shell",
"command": "make -f path/to/Makefile DEBUG=1",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "new"
},
"problemMatcher": [
"$gcc"
]
}
Visual Studio Code's Intellisense extension for C/C++ supports a compile_commands.json database. Some makefile utilities can generate these databases by themselves, but I don't have any experience using them to do so. With GNU make, you'll need some kind of helper script or tool. I used the python package compiledb:
sudo pip install compiledb
cd projectfolder
make clean
compiledb make
After running that, you should end up with a compile_commands.json file. Then, in VS Code, you need to edit c_cpp_properties.json for the workspace in question. One way to open it is by clicking the configuration name in the lower right corner of the status bar then clicking "Edit Configurations (json)". Or, you can open the command palatte (CTRL + SHIFT + P on my system), and entering C/C++: Edit configurations (JSON)
Then, in configuration you are using, add the property "compileCommands": "${workspaceFolder}/compile_commands.json"
Full example:
{
"configurations": [
{
"name": "geany",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64",
"browse": {
"path": [
"${workspaceFolder}/**"
],
"limitSymbolsToIncludedHeaders": true
},
"compileCommands": "${workspaceFolder}/compile_commands.json"
}
],
"version": 4
}
Now, Visual Studio code's Intellisense analysis should be using the exactly correct include directories, define directives, and other command line compiler flags unique to each individual source file.
For others trying to import makefiles, I have found a set of scripts that perform exactly what I wanted to achieve, the management of STM32 embedded projects through VS Code. If you dig into the scripts folder you can find the make parser and the VSCode project files populator.
Here the repo, enjoy!
GNU Make is commonly used to compile C projects, but it can produce any sort of output files you want.
You can create a script for this purpose, or you can do it from another makefile, eg: VSCode.mk that you include in your top level Makefile.
This solution is using One Shell but if that is not viable a separate script would look nicer.
The # makes your output nicer.
Most likely you can't safely copy paste this code because Make uses literal tabs, not whitespace.
.ONESHELL:
SOURCE_DIRECTORY := src
DEFINED_VALUE := 1
# Recipe:
.vscode/c_cpp_properties.json:
#
cat << EOF > "$#"
{
"configurations": [
{
"name": "Linux",
"includePath": [
"\$${workspaceFolder}/$(SOURCE_DIRECTORY)*"
],
"defines": [
"DEFINED_VALUE=$(DEFINED_VALUE)"
],
"compilerPath": "$(CC)",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64",
"browse" : {
"limitSymbolsToIncludedHeaders" : true
}
}
],
"version": 4
}
EOF

Can VSCode (Visual Studio Code) be used to run elm-make?

I am new to VSCode.
I am new to ELM.
I am perfectly capable of using VIM and command line tools to create an ELM Project, but I want to utilize an IDE. I have chosen VSCode on advice from the internet since it seems to pick up some nice pieces of VIM.
So now I have a few .elm files.
Main.elm
View.elm
Model.elm
I want to run elm-make on Model.elm to make sure it has no errors.
Then I want to run elm-make on Main.elm to create an index.html so I can view my project.
I think this is a pretty simple question for people familiar with how to customize VSCode, but as I stated previously, I am new to VSCode.
Try setting up a task for elm-make:
Create a ./vscode/tasks.json with the contents:
{
"version": "0.1.0",
"tasks": [
{
"taskName": "elm make",
"isBuildCommand": true,
"command": "elm-make",
"args": ["./main.elm"],
"isShellCommand": true
}
]
}
You can then use the build command to run the task, or run the task individually.
You may also want to look into the elm extension: https://marketplace.visualstudio.com/items?itemName=sbrink.elm

VSCode build not working - No build task defined. Mark a task with 'isBuildCommand' in the tasks.json file

I have fresh install of VSCode, and this tiny basic TypeScript app.
First time, when I want to build the app, VScode needs to generate tasks.json.
And it worked long time ago before.
Today I am getting this weird message
No build task defined. Mark a task with 'isBuildCommand' in the tasks.json file.
I don't remember seeing this message before.
But, OK, I click Configure Build Task, select TypeScript task, and tasks.json gets generated.
But, what happens, after I try to build now, Ctrl+Shift+B, and I get the exact same message again
Any ideas? Thanks.
BTW, adding this setting to tasks.json doesnt solve the problem.
This issue was also adressed here:
https://github.com/Microsoft/vscode/issues/24796
It says:
Closing and reopening the window (without starting Code) resolves this issue.
Closing and reopening the window
Which window? Closing and reopening the tasks.json window didn't work for me (in VS Code 1.11.2).
Here's what did though:
Closing and re-opening Visual Studio Code
Ctrl-Shift-B (or your build shortcut)
[As of 18th September 2021] and VS Code version: 1.60.0
For me, it turned out to be that I wasn't having "isBuildCommand": true.
I understand that this post already assumes that isBuildCommand is already included. But VS Code didn't include this by default for me and being new to VS code if I reached this page, it might be helpful to someone else who is new.
I wanted to have two configurations - Debug and Release. This is how my two configs looks -
{
"label": "build Debug",
"command": "dotnet",
"type": "process",
"isBuildCommand": true,
"args": [
"build",
"${workspaceFolder}/ABCD/ABCD.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "build Release",
"command": "dotnet",
"type": "process",
"isBuildCommand": true,
"args": [
"build",
"${workspaceFolder}/ABCD/ABCD.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary",
"-c",
"Release"
],
"problemMatcher": "$msCompile"
}
In my case, my tasks.json had some nonsense in it. Instead of the "command" property, I wrongly named it "executable"...*
So consider if:
Your JSON is valid syntactically (see screenshot below)
Your JSON is valid according to what VS Code expects
Syntactically invalid:
Schematically invalid:
And while I think the other answers are probably correct (I can't reproduce so I can't verify; the issue has been fixed...), I think when the comment said ...
Closing and reopening the window (without starting Code)
... it may have meant the Reload Window command.
*I wrongly named the tasks.json property "executable", vs "command" because...
I thought "command" was causing issues (it wasn't)
I wanted to run a specific executable in a specific directory like "C:/somewhere/python.exe"; ("command" can do that).
I don't know why I thought "executable" was valid! I thought I was referencing some example, but can't find it... :) )
For me, it worked when I put the tasks.json file in a new .vscode folder next to the file I wanted to build.
My folder >
myFile
.vscode >
tasks.json
tasks.json (this file has no effect)
The funny thing is, My folder was already named .vscode in my case. I guess it has to be a sub-layer.
I had errors even after checking task.json. Turned out to be that there was an error in IntelliSense Configurations - Compiler path...
Not sure if this would help, but it solved my problem.