Can you attach a terminal to IJulia Notebook in VSCode? - visual-studio-code

Usually, when working in VSCode, I can attach a file to REPL (Ctrl + Shift + P > Attach to session) and then any code I write can be executed by running the file by going Ctrl + Shift + P > Julia: Execute ...
This way, I can view the variables just by typing them out in the REPL among other things.
However when I try code in a Juptyter notebook, this doesnt seem to work. Is there any way of starting a terminal that shares the variables inside the notebook?

No, notebook kernels use different logic than the REPL process. You can access the workspace, but code execution is only possible in the notebook itself. There are no plans to change this behaviour currently.

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!

Does VS code have variable explorer object like we have it in spyder?

I will post the picture of what exactly I am asking variable explorer in spyder
So do we have this feature in VS code?
I tried a lot to find it on google but was unhappy to not find it.
Open your .py script in vscode
Right click anywhere on the script > Run current File in interactive Window
In the toolbar of the interactive window click on the variable icon
You can now consult the values of variables created by your script
spyder is probably running a REPL (Jupyter is doing that also). From that python process they show the local and global variables, just like a debugger would do on a breakpoint.
If you use Python Interactive you have similar functionality with the Variables Explorer and Data Viewer or use Jupyter notebooks
You can now find all variables in a Jupyter Notebook in VS Code in the Output panel under Jupyter: Variables

VS Code: Is there some way to associate my debug session to a specific terminal?

I'm always working with multiple nodejs projects, and every time I debug a new terminal is opened so I'm constantly getting lost on which terminal corresponds to each debug session.
Is there some way to do something like double clicking the debug session in the call stack and open the terminal it corresponds? Any insight would be greatly appreciated.
Thanks.
Based on my personal experience, looking at all the logs in one terminal makes it more confusing.
I have a better alternative for you, so let say you are debugging A and B projects.
Open A project in one window of VS code and use an integrated terminal
Open B project in another window of VS and use integrated terminal
and so on...
(To open the integrated terminal, Mac: Cmd + j and for Windows: Ctrl+` )
Windows:
Ctrl + Shift + P
Mac:
Cmd + Shift + p
And running those hotkeys type: Terminal: Rename, now you can change the terminal title
You could also add a keyboard shortcut for this command: workbench.action.terminal.rename
in addition to the answers, my approach is isolate the VS by opening different windows for different sessions, and keep the 2 windows on 2 different monitors, for that you need an extra monitor.
when i had 1 monitor, identifying which window corresponded to which was a time waste task and more of distraction. now attaching extra monitor to laptop has saved me a ton of time, organizing windows and switching between became seamless and of course most importantly, productivity and speed increased around 33%.

Running a script in julia VSCode

this might sound like a very stupid question, but what is the difference between F5 command in julia vscode and Ctrl + Enter? I know, that F5 means start debbuging, but I just don't understand, why a script written by someone else openend in julia vscode can be executed only by the Ctrl + Enter command. Is it something like debbuging is only for some kind of projects and this is only a script?
Thanks for your help.
As with all things in vs code you can run them from the command palette by pressing ctrl/cmd+shift+p and typing in “Julia” will pop out the various run commands.
As for keybinds, you can check if there is one set or set your own to run this command by managing your keyboard shortcuts. cmd/ctrl+k cmd/ctrl+s will bring up the keyboard shortcut palette.

How to allow VS Code to take input from users?

I have installed Visual Studio Code 1.23.1 and added extensions - Python, Code Runner.
With Code Runner, now I can see the Run Code symbol (triangle) and on highlighting it, I see the shortcut Ctrl + Alt + N. But when I try to use it to run the code that asks for user input, I can't find a way to provide the input. When I try to enter user input, I get error message "Cannot edit in read-only editor". I think this is because I am missing some configuration part for Code Runner like setting up PATH or some other Workspace settings.
Question: Please assist me in identifying what all configuration will I need to do and how?
I did select "Add Python 3.6 to PATH" while installing Python. I have attached screenshots for reference:
Note: Even now when I right click and select "Run Python File in Terminal" for the same program, I can enter user input fine and get the expected output.
Here's another alternative answer, I think more accurate.
Add following settings to your vscode user settings file:
"code-runner.executorMap": {
"python": "$pythonPath -u $fullFileName",
},
Check out this reference for some useful variables:
Variables Reference
You can provide input by telling code runner to use the terminal. To do this, there is a setting called code-runner.runInTerminal, set to false by default, that you can set to true.
There is one more thing that you should watch out for if you are using a windows command line for the terminal like CMD or PowerShell. If your project directory has spaces in it (e.g. C:\Example Test) you will get an error. To fix this, you need to add escaped quotation marks (\") around the directory path variables (normally $dir or $workspaceRoot) found under the setting code-runner.executorMap and code-runner.executorMapByFileExtension in the user settings.
The main problem here is that the output window that the code runner extension uses by default is read only. If you use the terminal instead, your program will be able to accept input as normal.
You can configure Code Runner to use the integrated terminal instead of the output window by setting the code-runner.runInTerminal setting to true (the default is false). In the settings.json file it should look like: "code-runner.runInTerminal": true
If you want to use the GUI instead the setting should look like this once set to true.
If you are using a virtual environment instead of the system python install, you will also need to configure a second setting for it to work properly with installed modules.
The code-runner.executorMap setting will configure what code runner actually does once you press run or use the Ctrl + Alt + N shortcut. By default it seems to simply invoke the python interpreter added to the PATH.
If you change the setting in the settings.json file to:
"code-runner.executorMap": {
"python": "$pythonPath -u $fullFileName"
}
then Code Runner will use whatever value is in the pythonPath variable instead. You can set this using the Python: Select Interpreter command from the command palette (Ctrl + Shift + P). This way you can select the interpreter in your virtual environment and use that instead of the one attached to the PATH by default.
The two settings above should allow you to A) Enter input inside of the integrated terminal and B) Select which python interpreter code-runner should execute easily using existing commands.