VS code not debugging correctly - visual-studio-code

So essentially I'm on Ubunto and when I try to debug a file on VS code somehow it debugs the last file saved and not the current one,
Sending my lauch.json since the problem may come from there
lauch.json
Example:
printf("hello world");
and then I change it to:
printf("hello");
Hit ctrl + s to save and hit f5
terminal:
hello world
Although, if I hit the run button manually and then f5 it prints
hello

Related

Auto hotkey to copy selected code and run in cygwin

My company uses Windows, but our AWS resource is in Linux. During code fiddling, it often creates a situation where I open cygwin, ssh to the AWS head node, load R/Python in the cygwin console, copy and paste a block of selected code from my local Rstudio code editor, and paste it to cygwin console and run.
In Rstudio, one can press "Ctrl + Enter" to run a selected block of R/Python code in the code editor. How can I achieve the effect of: by pressing "Ctrl + Shift", the selected block of code will be auto-copied into the cygwin window and run?
I am looking at this post: https://www.autohotkey.com/board/topic/92654-copy-and-paste-between-applications-noobs-first-attempt/ but couldn't figure out how to adjust it to my need.
Thanks!

How to get Clean Terminal in VSC

I want to have a clean Terminal in VSC, but every time I run my code there is some useless stuff I would like to remove, for example my Microsoft Version and the path to my files.
Is there any way to remove them from my Terminal?
On all my other PC's I don't have this Problem, only on this PC. I already tried to change the console argument in my Launch.json but if I change it to InternalConsole it dosen't run the code anymore. Also it would show my results in the debugger and I would like to use the Terminal.
You can clear your Terminal after each run, by typing clear in Terminal. To have it done automatically, check 'Clear Before Reusing', or 'Clear Previous Output' (if you're using Code Runner) in Settings. To get there, press Ctrl + , on Win or Command + , on Mac and type 'clear' in the search box.
Sending the output to the Debug console looks cleaner, but it doesn't allow user input. Other than that, I don't think there's a way to not have the path of your file displayed as the file executes.

How to see the results in IPython Console- Spyder

I'm new to spyder and I'm trying to run the code written in the editor but the IPython console isn't showing the results like it's supposed to. All it says is run file and then the file path. I have tried resetting the spyder default settings, restarting the kernel but it doesn't work. so I wrote some code in IPython console and it does work. I don't know where to see the output of my code and I don't know what's wrong.Image
I'm following a tutorial and it's supposed to be like this.Tutorial-Image
(Spyder maintainer here) The problem you're experiencing is caused because Spyder has several evaluation modes. The person in Tutorial-Image is selecting the code in the Editor with the mouse and then running it by pressing the F9 key. That's why you see in that image that the code written in the editor is pasted directly into the console.
In your case case, you're running the code by pressing the Run button (i.e. green play button) or the F5 key. And when do that, you need to add print statements to see its results in the console.
you didn't output anything in your file of code. use the following code to output what you want print
print("hello,world!")
# or
print(a+b) # the a + b was defined in your file of code
EDIT
I installed the spyder and run the code your mentioned.
The following output is

What settings do I have to change to make Visual Studio Code automatically run files in the right directory?

Coming from IDLE, I am used to be able to just left-click python files anywhere, it'll launch IDLE, and then pressing F5 just runs the script. In VSCode however, I have to open the terminal, cd into the right directory, and only then can I finally run my python script. Is there a way to change this behavior?
I was recommended to use the Code Runner extention and bound the Run Code (code-runner.run) command to my F5 key.
Then I noticed input() not being ran so I had to make sure code-runner.runInTerminal was on, but that re-started my problem from the beginning because the terminal was at the wrong working directory and then I finally found the code-runner.fileDirectoryAsCwd setting to run it from there.
I think this solution is similar to this one for the python extention, but I'm not sure if that would cause the whole wrong working directory issue again.
choose from menu file then click on auto save

Whats the shortcut to Debug in PyDev using Eclipse

The shortcut key is F11 to start debugging. But issue is that I have to be on that file and then hit F11 to start debugging.
Eg.
my file to launch the application is "launch.py" and "example.py".
example.py is open in the editor whereas launch.py is not.
Now, if I hit F11 it will try to launch the application using "example.py" and terminates due to error (as expected).
So then I have to open the "launch.py" in the editor and then hit F11 to start debugging the application.
Is there any neater way to configure the debugging, so that it starts the application in single hit/key?
Edit: example.py is some other file (some module). It does not launch the application.
As this PyDev Eclipse Tutorial suggests:
After the first run, if you type Ctrl+F11, the last file ran is re-run. Or, if you type just F11, a debug session is started with your last run. Let's test this...
Note: This behavior changed in Eclipse 3.3 -- but it's generally recommended to restore it in the preferences at: window > preferences > Run/Debug > Launching and set the Launch Operation to Always launch the previously launched application.
This tutorial will always consider this as the default option.
So, did you have this option selected?
If you have launch at least once launch.py, then you can re-launch it easily.
Although this isn't strictly an answer to what was asked initially, it might help someone looking here that had the same problem as me...
I'm a Java developer mainly, so have the Java view open almost all the time. However, sometimes I want to run some python file to test something (or just create a quick python script, and run it)...
In the Java editor, if the current class has a main(String[] args) method, I run it with (and popup the dialog to ask me what exactly I'd like to run in the middle)
alt+shift+x, j
Unfortunately, that doesn't work in the Python view, and I've not found a similar solution - it just asks me if I'd like to run it as a Java app... however, as the VonC says, you can run the last run thing (provided you've set the preferences accordingly) with
ctrl+f11
and this seems work well with python run configurations too.
But... What if the last thing I ran was a Java program, but I now want to run the active .py file? Previously, to run the .py file, I'd have to go digging through the buttons on the toolbar with the mouse, and I tend to prefer keyboard shortcuts...
Solution! So, finally I come to the actual useful bit of this answer - I just discovered by accident (typing Ivan's suggested shortcut, but missing!), it appears that
f9
will run the currently active python file.
Hope that helps someone get just that little bit faster...
I use CTRL+SHIFT+F9 to relaunch the previous debug configuration in Pydev.