Visual Studio Code: problemMatcher output remains there after the issue is fixed - unit-testing

I have a npm task in which I watch my TypeScript application for changes, compile it and then run tests automatically. I'm trying to have Visual Studio Code warn me in the Problems tab whenever a test fails.
While I've managed to achieve that, whenever I fix the code so that the tests pass again, the warning remains in the Problems tab. This is quite bothering, since I would be getting lots of false positives and I might overlook actual test failures. I wonder if there is a way to flush the contents of the Problems tab every time my tests are executed?
Here's my tasks.json file:
{
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"showOutput": "silent",
"suppressTaskName": true,
"tasks": [
{
"taskName": "start",
"args": ["start"],
"isBackground": true,
"problemMatcher": {
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": [
// Omitted for brevity
],
"watching": {
"activeOnStart": true,
"beginsPattern": "\\[1\\] Starting 'test'\\.\\.\\.",
"endsPattern": ".*Finished 'test' after.*"
}
}
}
]
}
Thanks!

While this doesn't directly answer my question, I'm sharing this in case someone stumbles upon the same issue.
Right now I'm using node-tdd, which was a bit difficult to set up since its Windows support is limited, but it seems to fit the bill just fine.

Related

How do I set global Prettier override settings?

I want to override some settings for specific files.
For example, instead of creating a .prettierrc file at the root of my project, I want to be able to define some global overrides to all files ending with .sol in my settings.json of VS Code.
{
"overrides": [
{
"files": "*.sol",
"options": {
"printWidth": 80,
"tabWidth": 2,
"useTabs": true,
"singleQuote": false,
"bracketSpacing": false,
"explicitTypes": "never"
}
}
]
}
I would like to add the above to my global settings in VS Code.
Prettier doesn't support global overrides intentionally
I was trying to do the same thing as you, and realized after researching the issue that it's intentionally unsupported.
From the docs:
Prettier intentionally doesn’t support any kind of global configuration. This is to make sure that when a project is copied to another computer, Prettier’s behavior stays the same. Otherwise, Prettier wouldn’t be able to guarantee that everybody in a team gets the same consistent results.
Also see this response in a closed issue on Github:
Prettier doesn't support global configuration. It's supposed to be configured per project.

How to make VSCode indent an if statement without brackets?

I'd like for VSCode to indent automatically indent when I create a newline in the following case:
if(statement)
func();
The default functionality does the following when hitting newline:
if(statement)
func();
This is a longstanding issue in VSCode: https://github.com/microsoft/vscode/issues/43244
I'd appreciate any kind of hack/extension that can accomplish this behavior. There are other instances of indentation getting mangled in the github issue link, but I only really care about this simple case.
Figured out how to do this without installing an extension. There may be a better way that can be done in settings.json but I couldn't find it. You can modify a languages configuration directly from the source, which for me was C:\Program Files\Microsoft VS Code\resources\app\extensions\cpp\language-configuration.json. There is a guide for these files settings. I added the following to my c++ language configuration:
"onEnterRules": [
{
"beforeText": "^\\s*(?:if|while)\\(.*\\)\\s*$",
"action": {
"indent": "indent"
}
},
{
"beforeText": "(?=)",
"previousLineText": "^\\s*(?:if|while)\\(.*\\)\\s*$",
"action": {
"indent": "outdent"
}
}
]
This works, but unfortunately the official c++ vscode extension C/C++ for Visual Studio Code breaks it for some reason.
Below was my initial method of doing this, which breaks too many things to be useful.
"indentationRules": {
"increaseIndentPattern": "^\\s*if\\(.*\\)\\s*$",
"decreaseIndentPattern": "(?!)"
}
The field decreaseIndentPattern must be set (here the regex will never capture anything), otherwise it ignores the indentationRules field (I guess they never tested whether just one would be set?) Note that these edits need to be done with administrative privleges, and I found VSCode pretty convenient for making them. Also these changes do not take effect until VSCode is closed.
So as it turns out I've run into the same issues mentioned in this PR: https://github.com/microsoft/vscode/pull/115454. This fix breaks too much other vscode indentation behavior, such as deindenting after the first properly indented line in if statements.

The Prettier Extension is not correcting inconsistent formatting of code

I have downloaded some exercise files to learn how to use Javascript. I am using Visual Studio Code as the editor and can open the exercise javascript files in the editor. I have installed the extensions Prettier - Code Formatter and ESlint and Live Server and npm-install and advised in the course video. The ESlint extension seems to work ok i.e. when I remove some of the code, errors in the code are underscored and when I move the mouse over the error a pop-up indicates what is missing. However, in the code below I removed the opening and closing brackets around the word 'update' and indented the line which begins with the word 'main.' and remove the semi colon which should follow the first bracket. However, the Prettier extension does not correct these amends, as the video advised it should and I received the error ["ERROR" - 14:55:15] Prettier could not be loaded. See previous logs for more information.
const updateBackpack = (update) => {
let main = document.querySelector("main"); // main is an element
main.innerHTML = markup(backpack);
console.info(update);
};
Do you know why Prettier is not working and how I can get it to work. Please bear in mind I am new to coding and Javascript.
Thanks,
Clive
I think you have the exact same problem as me, while following the exact same course as me :D!
First install prettier, using :
npm i prettier -g
Then configure the VS code to pick that downloaded package.
Here is what I did : Search for 'Prettier Path' in settings > select 'Edit in settings.json' and add the following config :
{
"editor.minimap.enabled": false,
"editor.fontSize": 12,
"editor.formatOnSave": true,
"editor.tabSize": 2,
"liveServer.settings.donotShowInfoMsg": true,
"editor.wordWrap": "on",
"emmet.triggerExpansionOnTab": true,
"emmet.showSuggestionsAsSnippets": true,
"editor.snippetSuggestions": "top",
"[javascript]": {
// "editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.formatOnPaste": true
},
"workbench.colorTheme": "Monokai",
"window.zoomLevel": 0,
"editor.columnSelection": false,
"explorer.compactFolders": false,
"typescript.updateImportsOnFileMove.enabled": "always",
"javascript.updateImportsOnFileMove.enabled": "always",
"liveServer.settings.donotVerifyTags": true,
"prettier.prettierPath": "/usr/local/lib/node_modules/prettier"
}
Make sure prettier is installed at the given path : "prettier.prettierPath": "/usr/local/lib/node_modules/prettier"
You can make prettier the default also by uncommenting the code : "editor.defaultFormatter": "esbenp.prettier-vscode"
It has my custom settings of visuals, so review those and then set, for beginners try pasting as-is!

vscode: task extending another task / passing parameters

starting position
A tasks.json that defines a working build task (currently the only one, defined as default and working fine, also triggered by [CTRL]+[SHIFT]+[B]).
It triggers an external command (batch/shell script) and passes some parameters. Excerpt:
{
"label": "sample task",
"windows": {
"command": "${workspaceFolder}\\procedures_win\\doStuff.bat"
},
"linux": {
"command": "${workspaceFolder}/procedures/doStuff.sh"
},
"type": "shell",
"args": [
"fixedParm",
"${fileBasename}"
]
}
(the complete one is much longer, mainly because of the amount of entries in the problemMatcher, contains target specific environment settings, 100 lines+ ...)
goal
Create a second task "sample task (check-only)" that is completely identical but passes one extra argument to the script "check-only".
options?
Is it possible to "extend" the given task "overriding" only the args?
If not: Is it possible to have a task actually run (not depend on) another task and setting an environment parameter that may then be used by the original task as "${env:someValue}" (an will either result to the empty string or the requested "check-only")?
As a last resort one possibly could define 5 instead of the two tasks (1 nearly identical to the current one, but taking an input from an external command/file; 2+3 meta tasks depending on 4+5, 4+5 command that creates a file ${workspaceFolder}/.taskmode that contains either nothing or "check-only").
question
How does a working solution without installing extensions look like?

how can i use cuda with nodejs

Cuda is Nivida provided api that lets c/c++ use gpu for some stuff, even though i don't what that some stuff is & would like to know, from what i saw the gains were remarkable. Also cuda only works for nivida gpus...
There does exist a module for nodejs, but it's only for 64bit version of windows, yet there exists cuda for 32bit version as well so only thing missing binding/extension for nodejs to cuda in c++. And There is no sign of documents anywhere on github or internet about that module. Last commits were like 1/2 year+ ago.
If it's all possible than it'd be very great. As nodejs would be able to use gpu for operations, putting it in the whole new level for web stuff, and other applications. Also given parallel nature of nodejs it fits perfectly with gpu's parallel nature.
Suppose there is no module that exists right now. What are my choices.
it's been done already by someone else: http://www.cs.cmu.edu/afs/cs/academic/class/15418-s12/www/competition/r2jitu.com/418/final_report.pdf
here is a binding.gyp file that will build a node extension using two source files
hello.cpp, goodby.cu, and goodby1.cu
{
## for windows, be sure to do node-gyp rebuild -msvs_version=2013,
## and run under a msvs shell
## for all targets
'conditions': [
[ 'OS=="win"', {'variables': {'obj': 'obj'}},
{'variables': {'obj': 'o'}}]],
"targets": [
{
"target_name": "hello",
"sources": [ "hello.cpp", "goodby.cu", "goodby1.cu",],
'rules': [{
'extension': 'cu',
'inputs': ['<(RULE_INPUT_PATH)'],
'outputs':[ '<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).<(obj)'],
'conditions': [
[ 'OS=="win"',
{'rule_name': 'cuda on windows',
'message': "compile cuda file on windows",
'process_outputs_as_sources': 0,
'action': ['nvcc -c <(_inputs) -o <(_outputs)'],
},
{'rule_name': 'cuda on linux',
'message': "compile cuda file on linux",
'process_outputs_as_sources': 1,
'action': ['nvcc','-Xcompiler','-fpic','-c',
'<#(_inputs)','-o','<#(_outputs)'],
}]]}],
'conditions': [
[ 'OS=="mac"', {
'libraries': ['-framework CUDA'],
'include_dirs': ['/usr/local/include'],
'library_dirs': ['/usr/local/lib'],
}],
[ 'OS=="linux"', {
'libraries': ['-lcuda', '-lcudart'],
'include_dirs': ['/usr/local/include'],
'library_dirs': ['/usr/local/lib', '/usr/local/cuda/lib64'],
}],
[ 'OS=="win"', {
'conditions': [
['target_arch=="x64"',
{
'variables': { 'arch': 'x64' }
}, {
'variables': { 'arch': 'Win32' }
}
],
],
'variables': {
'cuda_root%': '$(CUDA_PATH)'
},
'libraries': [
'-l<(cuda_root)/lib/<(arch)/cuda.lib',
'-l<(cuda_root)/lib/<(arch)/cudart.lib',
],
"include_dirs": [
"<(cuda_root)/include",
],
}, {
"include_dirs": [
"/usr/local/cuda/include"
],
}]
]
}
]
}
The proper way to do this is to use the Nvidia CUDA toolkit to write your cuda app in C++ and then invoke it as a separate process from node. This way you can get the most from CUDA and draw on the power of node for controlling that process.
For example, if you have a cuda application and you want to scale it to, say, 32 computers, you would write the application in fast C or C++ and then use node to push it to all the PC's in the cluster and handle communication with each remote process over the network. Node shines in this area. Once each CUDA app instance finishes it's job, you join all the data with node and present it to the user.
The most natural way to hook up CUDA and Node.js would be through an "addon", which allows you to expose c++ code to your javascript programs running on node.
Node itself is a c++ app built on top of the v8 javascript engine, and addons are a way for you to write c++ libraries that can be used by javascript libraries in the same sort of way that node's own libraries do.
From the outside, an addon just looks like a module. The c++ gets compiled into a dynamic library and then exposed to node like any other module.
e.g. my-addon.cc -> (compile) -> my-addon.dylib -> (node-gyp) -> my-addon.node -> var myFoo = require('my-addon').foo()
From inside the addon, you use the v8 and Node APIs to interface with the Javascript environment, and access CUDA with the the normal c++ APIs.
There are a lot of moving parts down at this level. Something as simple as passing a value from one to the other means you need to worry about both c++ memory management and the javascript garbage collector while you wrap/unwrap javascript values to and from appropriate c++ types.
The good news is that most of the issues are fine individually, with great docs and supporting libraries abounding e.g. nan will get a skeleton addon running in no time, and on the CUDA side, you're talking about their normal c++ interface, with truckloads of of docs and tutorials.