VS Code - some process and useful tips #2139
Replies: 12 comments 20 replies
-
@samsrabin I'd love to see what your process/extensions are! |
Beta Was this translation helpful? Give feedback.
-
Cool, thanks so much for putting this together @adrifoster - this is really useful to have this documentation of how to set up the remote ssh, build & debugging for CTSM in VSCode!! |
Beta Was this translation helpful? Give feedback.
-
Thanks so much for this writeup, @adrifoster! So far I've only experimented with the Remote SSH feature. Some notes on my experience with that:
|
Beta Was this translation helpful? Give feedback.
-
I think a useful thing we should consider for the future is to add the .vscode directory and a few tasks for it that we would all find useful. We probably need more time to figure out how useful that would be. But, that would add the directory for everyone, and might be a good way for individuals to get started in adding their own tasks for their use. It demonstrates how to do it. Actually, this sort of thing could be useful to have available for everyone's use. So for example, possibly VIM and EMACS things could be shared in a similar space for developers that use those different editors... |
Beta Was this translation helpful? Give feedback.
-
Here's a quick video tutorial I found that is the official VS Code channel. So there likely are others that are useful there. I'll post if I find others that look useful. https://www.youtube.com/watch?v=B-s71n0dHUk It's nice because it's short, but it also goes over the major functionality and shows usage. So it somewhat overlaps with what @adrifoster shows above, but also has different things as well. |
Beta Was this translation helpful? Give feedback.
-
I am setting up VSCode with Remote SSH and coming across issues maintaining the session when my laptop goes to sleep. I found microsoft/vscode-jupyter#1378 but it currently does not have a good solution. Have you created workarounds that retains the terminals/windows you have open during a session? |
Beta Was this translation helpful? Give feedback.
-
I left my VS code session active overnight and my inbox is full of messages:
|
Beta Was this translation helpful? Give feedback.
-
I put in a request to the github NCAR organization a couple of days ago for approval to use git-copilot. I haven't heard anything - what experience have others had with this? Do you know who to contact? |
Beta Was this translation helpful? Give feedback.
-
Login node limit is ~~4 GB~~ 5 GB (See #2139 (reply in thread)), and I have heard that linters unfortunately can
eat up a lot of memory. I haven't been able to get fortls working on my
system despite a lot of troubleshooting
…On Thu, Mar 7, 2024, 10:58 Jim Edwards ***@***.***> wrote:
Good question - I'm going to query user services.
—
Reply to this email directly, view it on GitHub
<#2139 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AK2GOYZG6XHIG3NSCMKVCKLYXCFBRAVCNFSM6AAAAAA4PPRBWGVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DOMBZGQ3DC>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
The new (or at least new by default?) "sticky scroll" feature (where the function header is kept in the top line(s) of your window) is neat, but I just stumbled upon something that can arguably make it more useful (if you have enough screen real estate, at least): If you change "Editor: Sticky Scroll: Default Model" from outlineModel to foldingProviderModel, you see all of the levels of nesting above the current point (loops, conditionals, etc.). The video in microsoft/vscode#159198 illustrates this. You can also click on any level to jump to the top of that level of nesting. I'd recommend then also increasing "Editor: Sticky Scroll: Max Line Count". I have tried this in Python and Fortran files. I haven't used it enough to know for sure if I like it, but I see potential. |
Beta Was this translation helpful? Give feedback.
-
Would this be a good place to post the links to Adrianna's and Sam's (and others'?) recent talks about VS Code? Was there info in there regarding linking somehow with JupyterHub? |
Beta Was this translation helpful? Give feedback.
-
Some tips from @negin513 on managing memory use on remote systems, if you're getting nastygrams about your login taking up too many resources:
|
Beta Was this translation helpful? Give feedback.
-
@samsrabin and I are users of VS Code (perhaps others are as well?) and we've been getting requests for showcasing how we use VS Code.
In particular, I just figured out how to use the remote configuration of VS Code - so I'm using it on my own personal computer, but I'm viewing and editing files on cheyenne.
So, here are (hopefully complete) instructions for getting VS Code to work for editing and debugging code on cheyenne or some other remote machine.
Basics
Download and install VS Code on your personal machine. Download it here. I installed this a while ago and I believe it was easy? Note that I have a Mac (Ventura 13.5.1) with an Intel chip. I know this works great on Linux machines. Not sure about Windows, but since Microsoft makes it I really feel like it should work??
Open VS Code! First do this from your Applications folder.
Set VS Code up so that you can open it form the terminal with
code
orcode $filename
.- Type Ctrl (or Command) + Shift + P to open the Command Palette
- Type "shell command" to find Shell Command: Install 'code' command in PATH command and hit enter
- Restart the terminal for this to work.
Open up a test workspace - use this to start
src.zip
- Inside VS Code, use Cmd + O to open the
src
folder- This should open up a workspace and you should see the folder and files on the left hand Explorer panel
- Click on
fibonacci.f90
- If you just downloaded VS Code it probably doesn't have any syntax highlighting (Boo) but we'll fix that later
Open a terminal inside VS Code.
Try to compile and run this program - it should work - inside that terminal window. I used
gfortran -o fibonacci fibonacci.f90 get_integer.f90
After compilation you can try to run it as well:./a.out
In general I move around files, do git stuff, etc. inside terminal windows in VS Code, but you of course don't need to.
Add some extensions!
Click on the Extensions tab on the left panel (looks kind of like a Tetris game?)
You can search (e.g., "Fortran") for ones you want
Ones I'd recommend:
Modern Fortran
,C/C++
,Remote - SSH
I use some Python ones, but I think those come standard?
You may have to install fortran-language-server for this to work. In the terminal, you can do this using
pip
, e.g.,pip3 install fortran-language-server
which fortls
command in your terminal. Then go to the Modern Fortran extension's settings and add that path in theFortran > Linter: Compiler Path
andFortran > Fortls: Path
settings. Please note that I also unsynced these (by clicking the gear icon) so that these wouldn't (?) sync between my local and remote settings, since they will be different. I'm not sure this is necessary but it seems to be working.Now you should be able to see syntax highlighting, as well as some Intellisense features for Fortran. For example, if you hover your mouse over a variable or function, you should see some information pop up about it. You can also "Command + Click" on a function/module/subroutine to take you to its definition. VS Code will open the relevant file and go to the function/variable/subroutine definition.
Remote Usage
Okay so the cool thing I just figured out how to do was using this remotely on Cheyenne.
Remote - SSH
extension installed[email protected]
and then hit entercheyenne.ucar.edu
will then pop up as a configured host you can just click onModern Fortran
andC/C++
, and anything else you'd like.module load python
and thenpip install fortran-language-server
Then you will need to update the remote settings for this Extension to tell Modern Fortran where your fortls is. Go back to the extension page, click the gear icon to go to settings, and then you should see a tab for "User" and then some kind of "ssh" tab. Click on the "ssh" tab to make sure you only update that version of the setting.Tasks and Debugging
VS Code lets you create tasks that you can have it kick off. For my purposes I created a folder (
.vscode
inside myCTSM
repo. My CTSM repo is the top level of my VS Code workspace. I don't think this will work otherwise? Tasks can then be executed by Cmd + Shift + P and then typing Tasks. Once you have set up tasks, they should populate here.Inside this folder I created a file
tasks.json
:The "create" task submits a script I wrote
create_test_case
, you can see this on my cheyenne work directory in /glade/work/afoster/test_cases.The "build" task builds this specific case I made. By putting it in the "build" group I can actually do Cmd + Shift + B to build this case
After building we can actually try debugging (with gdb)! I created another file inside the
.vscode
dir calledlaunch.json
:To use either of these files you'll need to update some of the file paths, etc.
So first open a file in the CTSM repo (say
clm_initaliazeMod.F90
and click to the left on the line numbers somewhere - lets say line 246) to create a breakpoint. You should see a little red circle pop up.Click on the little debug icon on the left (triangle with a bug). Then you should see "Run GDB" (or whatever you named it in
launch.json
). Click the green triangle.After a bit (model is running...), if this is all working, you should see the Debug Console populate, and then on the file you placed a breakpoint you should see a green/yellow line across where the breakpoint is. Woohoo! We've reached a breakpoint.
To the left you should see some variables you can investigate, and then up top there should be some arrows you can use to "step over" - step forward one task, "step into" - actually go into a method you are on, "step out of" - step out of a method, and even "stop" the run... You'll notice that VS Code will actually bring up new files as you are moving around in the code.
Okay...this was a lot...
Please let me know if this is useful to you, and if you encounter any problems. I am a bit concerned about the Remote SSH because they just did an update to VS Code and I think it might have caused an issue. But I am still able to connect after some finagling - let me know if you run into an issue with this step.
Beta Was this translation helpful? Give feedback.
All reactions