Using Atom as a C/C++ Ide (linux)

I dont like heavyweight IDEs such as eclipse or even VSCode/Codium.

I much prefer light ones, such as netbeans. 

I want them to be just a thin wrapper on top of my CMake projects, and that they start in a second or so.

For quick edit, (N)Vim +  coc.vim is incredibly powerful, but for big projects i  prefer something more comfortable.

So i gave Atom a try, and it's pretty good. Really good actually.

The thing is you have to install a bunch of plugins to configure it to be a C/C++ IDE.

 And as a bonus, the code completion setup is similar to the setup for coc.vim, so i can setup it once, and it works for both.

Coc.vim is superior imho for c++, but the Atom is more confortable for large projects.



Atom configuration

So here we go (ubunto 20, it 's a bit more complicated for windows but similar ( use chocolatey for example) :

1- Install  Atom . Nothing special here.

2- Install the following plugins. Edit->Preferences->Install

linter
linter-gcc
atom-ide-base
atom-ide-ui
atom-ide-definitions
ide-c-cpp
ide-ccls
build
build-cmake

3- install ccls through apt/.... Be careful if you install ccls from source it might not work (different version ?)
4- install compdb using pip : pip3 install compdb
5- make sure ccls and compdb are your path : which ccls && which compdb
6- Preferences -> Core -> untick Exclude VCS ignored Paths. This is needed for global search to work.
7- Preference->Package->Autocomplete plus ->Settings -> Keymap for confirming a suggestion -> tab
8- Restart atom

Per project configuration

1- Go to your project folder (cmake based!)
2- Create the code database with  the following commands (put them in a .sh file)
mkdir -p buildAtom
cd buildAtom
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=True ..
cd ..
compdb -p  buildAtom/ list > compile_commands.json

We are creating a fake cmake build where we ask cmake for dependencies and feed that to ccls. That will enable code completion etc..

3- Create a default CMakeSettings.json (if you dont it will NOT Work properly, even if it's basically defaults)

{
 "configurations": [
   {
     "name": "Debug",
     "generator": "Unix Makefiles",
     "configurationType" : "Debug",
      "buildRoot":  "${projectDir}/build",
     "cmakeCommandArgs":  "",
     "buildCommandArgs": "",
     "ctestCommandArgs":  "",
     "variables": [{
       "name": "TEST_VAR",
       "value": "ON"
       }]
   }
 ]
}


4- File -> addFolder : your favorite project

The basic C/C++ setup is done. You can tweak things  (compilation flags...) etc.. but that setup works "as-is" as a start. 

You can toggle between generate cmake project and build cmake project with the pulldown menu on the bottom left (default is Debug:generate you probably want  Debug:build all)

That includes :

  • Syntax highlighting
  • On the fly code suggestion
  • On the fly linter (with some false warnings if you didnt set it up completely, but good enough imho)

Now you use the following default keybindings :

  • Ctrl+Click on a symbol : Go to definition
  • Ctrl+Alt+B : Generate cmake or build (change it through the small menu on the bottom left)
  • Ctrl+Alt+H : Go to next build error
Of course you can now add other plugins to your liking (themes, cmake syntax, code formating,....)

NB:  Atom works VERY well for rust too.

The only thing i'm not too happy with is to get the list of places where a symbol is used.
With coc.vim 'gr' will do it instantly
With atom, the only thing I've found to work is global search, which is slow and clunky.







Comments

Popular posts from this blog

Component tester with STM32 : Part 1 ADC, Resistor

Fixing the INA3221

INA3221, weird wiring