Compile current C++ file when saving? - visual-studio-code

I'm trying to make more daily use of Visual Studio Code, but there's one feature I really miss from my existing GVim setup: I use syntastic to compile C++ source when I save the current file, and then I can jump directly to error lines in the editor.
Is there any way to set up VS Code to do something similar?
I know that I can create a tasks.json and have Ctrl+Shift+B compile the whole project, but the turnaround for that is excessive. I just want to compile the current file when saving it, and have the error list be navigable (presumably in the Problems tab).
Success criteria:
When I save a C++ file, it runs a configured g++ command, rather than build the entire project.
It should somehow parse the output from that, and make the warnings and errors easily navigable so that I can step through them with a simple keystroke. Navigation should place my cursor on the relevant line. In Visual Studio, this used to be bound to the F8 key.

VS Code is not an IDE, it is a text editor with extension support, and it cannot be treated as such. Natively, it does not have any features allowing it to parse error output from a build task and visualize it in the editor.
The linter has the ability to markup the editor when syntax errors are present, but that is all the stock linter is capable of doing. It is the only part of VS Code that has the ability to use the Problems panel and annotate the editor with syntax errors.
That said, you are able to accomplish the 1st point you require. You can set up a keybind that executes more than one command. In your case, a keybind that would save the file and then build it. Something like:
{
"key": "ctrl+shift+b",
"command": "workbench.action.files.save",
"command": "workbench.action.tasks.build"
}
in keybindings.json would save the file and then execute the default build task when you press Ctrl+Shift+B.

Related

Where does the "Run Python" button at the top-right of the editor come from?

When opening a Python file in vscode, I see an overlay in the upper right corner of the window that allows me to directly run the program:
Where does this overlay comes from?
from an extension specific to Python?
from something that leverage tasks and allows for such display?
something else?
I am asking because it would be great to have such a shortcut in other programming languages (Go in my case) to quickly launch (something, usually to run a program)
This functionality comes from the ms-python.python extension.
You can verify for yourself: Disable the extension, then do the required IDE reload, then observe that that button is gone. Then enable the extension and observe that it is back.
There's even a corresponding command that you can use in the command palette: Straight from the extension docs:
Python: Run Python File in Terminal
Runs the active Python file in the VS Code terminal. You can also run a Python file by right-clicking on the file and selecting Run Python File in Terminal.
Note: Since you mentioned:
I am asking because it would be great to have such a shortcut in other programming languages (Go in my case) to quickly launch (something, usually to run a program)
Since this is functionality provided by an extension, you're "at the mercy" of whatever the extension devlopers actually want to implement, and whether such a feature actually makes sense for a given language.
Such a "run file" button would very natural for languages that lend themselves toward scripting, but less so for languages geared toward larger projects where it's not statistically normal for a file to "have a main function".

Is there a way to define different keybinds depending on file extension in VSCode?

I am trying to get something similar to VSCode Python Jupyter Notebook functionality but with C++, and I have succeeded for the most part by using Code Runner extension along with a custom python script to add a preamble to the cpp file before running it. However, I do not know of a way to make the same keybind that launches Jupyter Notebooks (Shift+Enter) working in cpp files but instead use the Code Runner, and so I was wondering if there is a built-in way or an extension that allows adding keybinds which are prioritized under a particular file extension.
It might also be that there is a better way to do what I'm trying to do that I do not know about. Regardless, it'd be helpful to find out about the options I have.
According to this answer:
Go into your keyboard shortcuts JSON file (ctrl+shift+p and search keyboard shortcuts)
Create a new entry with the keybind you want and the command you want (if the command is through an extension you should check their Github repo for info on the specific commands enacted inside vscode)
For the "when" section you should use the "editorLangId == ..." clause and place the language you want to use where the ... is.
In the end it should look something like this
{
"key": "[keybind you want]",
"command": "[command you want]",
"when": "editorLangId == [lang]"
}

VSCode run JavaScript file line by line like REPL

Is it possible to run JavaScript/TypeScript file opened in VSCode line by line?
Like you press something like CMD+XXX+Enter and it runs the current line or code block?
So you can play with code interactively.
P.S.
I don't want to open JS console - I want to run the code (or code snippet) from the file currently opened in Editor.
It should be stateful, you run the first line, then second etc. "Code Runner" plugin not working that way, it forgets the previous run. So you ran the first line, then try to execute the second line - and it complains about undefined variables that were defined in the first one.
VS Code doesn't has this feature built-in, but there are a lot of extensions for it. The most used is Code Runner, but there are many others. For example, Quokka.js executes code as you type and it's the ideal to know the output of some little piece of code.
The new open source VS Code extension Javascript REPL is promising.

Netbeans Formatting from Terminal

SITUATION: In Netbeans you can format the whole project or its folders recursively by selecting a tree node in Project window and pressing Ctrl+Shift+F.
PROBLEM: To get unified format for our team project we need to format it with fixed formatting settings before merges. Some don't use Netbeans. Opening it for this sort of operation is uncomfortable. Also imported formatting settings can be manually modified by irresponsible programmers later. Automation is required. A possibility to call this function as a part of special script is required.
QUESTION: Is there a way to call this Netbeans function from terminal (command line)?

Run eclipse editor action on entire project

Question:
Is there a way to run an eclipse action that is available from the context menu in the editor on every file of an project.
Actual Case:
I have to work with the leon3 and my dull mind has trouble enough understanding the code, that I do not want to scan lines to see if there is a semicolon hidden in there to see if there are multiple instructions or if the end if happens to be behind another instruction rather than on a line of its own (I missed an end if, which caused me to think that statements were conditional,...), therefore I would like to format the source nicely. I have access to Sigasi PRO which offers the option to "beautify" code as an operation in the editor. I would like to run this operation on all files in the leon project automatically.
Sigasi indeed only offers formatting in the editor at this time. In the Sigasi editor, you can format a selection or the entire editor's content. But, you can not trigger the formatting action without an editor.
I have not tried this, but I think you can achieve this with the Eclipse EASE project. EASE is a scripting environment for Eclipse.