Recipies to develop CMSSW using VSCode
Contents:
- Indexing files: C++ source navigation and setup using
clangd
- ROOT files: View ROOT files directly in VSCode
- Fix VSCode SSH Connection Errors with AFS: Avoid having to manually delete
.vscode-server
every time your connection drops
This AFS-related SSH bug tends to come back periodically — especially when your internet connection is unstable or slow — so it's definitely worth applying the fix described at the end.
Indexing files allows VSCode to easily resolve references to imported files. This provides:
More details and features in the VSCode and clangd documentations.
Indexing C++ files is based on the clangd extension alongside a compile-commands.json file.
- Install clangd.
- In VSCode in the side bar go to Extensions.
- In the search bar type clangd.
- Click Install.
- Click Install in SSH: lxplus.cern.ch.
- Disable IntelliSense if you have to installed (comes with the C/C++ Microsoft extension).
- In VSCode press Ctrl + Shift + P, type Preferences: Open Settings (UI) and click Enter.
- Switch to Remote [SSH: lxplus.cern.ch].
- In the search bar type C_Cpp.intelliSenseEngine.
- Switch to disabled.
- Initialize your CMSSW release environment: execute
cmsenv
in the src subdirectory of your CMSSW repo. This will add two additional environment variables:CMSSW_RELEASE_BASE
: path to the CMSSW repo on the CVMFS shared network file system.CMSSW_BASE
: path to your locally cloned CMSSW repo.
- Point clangd to the compile_commands.json file. VSCode will look for it on the
CMSSW_BASE
path, regardless which subdirectory you open. A couple of options exist:- Add the directory with the file to the clangd settings:
- In your terminal with the environment set up get the value of
CMSSW_RELEASE_BASE
:[tostafin@lxplus960 src]$ echo $CMSSW_RELEASE_BASE /cvmfs/cms.cern.ch/el9_amd64_gcc12/cms/cmssw/CMSSW_14_0_6
- In VSCode press Ctrl + Shift + P, type Preferences: Open Settings (UI) and click Enter.
- Switch to Remote [SSH: lxplus.cern.ch].
- In the search bar type clangd.arguments.
- Add a new argument:
--compile-commands-dir=<value-of-CMSSW_RELEASE_BASE>
. For instance using the value above:--compile-commands-dir=/cvmfs/cms.cern.ch/el9_amd64_gcc12/cms/cmssw/CMSSW_14_0_6
.
- In your terminal with the environment set up get the value of
- Create a symbolic link to the file: in your terminal with the environment set up execute
ln -s $CMSSW_RELEASE_BASE/compile_commands.json $CMSSW_BASE
. - Copy the file: in your terminal with the environment set up execute
cp $CMSSW_RELEASE_BASE/compile_commands.json $CMSSW_BASE
.
- Add the directory with the file to the clangd settings:
- Restart the clangd server. Press Ctrl + Shift + P, type clangd: Restart language server and click Enter.
Note: you don't have to wait for all files to be indexed to use clangd features.
ROOT is a data analysis framework used for visualizing large amounts of data using histograms, scatter plots etc.
These graphics can be viewed in VSCode using the ROOT File Viewer extension.
- Install ROOT File Viewer
- In VSCode in the side bar go to Extensions.
- In the search bar type ROOT File Viewer.
- Click Install.
- Open a ROOT file by left-clicking on it in the Explorer tab.
- Select a graphic to display.
If you connect to a remote machine using AFS (Andrew File System), you might encounter a recurring bug that forces you to delete the .vscode-server
folder from the remote every time you want to reconnect.
-
Create a dedicated folder for VSCode server files in your EOS home directory.
Suppose your username is
jkowal
, run the following command on the remote machine:mkdir -p /eos/user/j/jkowal/vscode-server
-
Remove the existing
.vscode-server
from your AFS home directory.rm -r ~/.vscode-server
-
Create a symbolic link pointing from your AFS home directory to the new folder.
ln -s /eos/user/j/jkowal/vscode-server ~/.vscode-server