11

I just downloaded visual studio code for linux ubuntu 14.04. I created a simple test.cpp and wrote it in vscode and the intellisense did not work.

Here is the code inside test.cpp:

struct test{
    int a = 5;
}

int main(){
    test t;
    t.
}

There was no intellisense telling me the members of t when I wrote "t." and there should have been.

I created the test.cpp file in the linux terminal with the command "touch test.cpp" then I opened test.cpp with visual studio code and wrote the code. A screenshot can be seen here: https://i.stack.imgur.com/fLhSA.png

Anyone know how to get intellisense working for vscode in linux?

Ulrich Eckhardt
  • 16,572
  • 3
  • 28
  • 55
skarl
  • 113
  • 1
  • 1
  • 4

6 Answers6

12

As the others suggested you can now add the C/C++ extension.

You might run into the following two issues with the extension:

The extension does not detect custom libraries:

You have to add the include paths of the custom libs. Do the following:

Ctr + Shift + P

C/C++ Extension: Configuration

Incude Paths (add one path per line, e.g.)

${workspaceFolder}/**
/home/me/Documents/my_custom_lib/

The extension suddenly stops to give you any suggestions no more:

This might happen if you do not open the project root, but a child of it. Open the project root folder and reload the window.

User12547645
  • 6,955
  • 3
  • 38
  • 69
  • 1
    The extension also doesn't work when you have a new, unsaved file, even if you mark the language mode as C++. – mic Jun 14 '20 at 14:04
  • 1
    I use the WSL and my intellisense was not working. So I go to the `C/C++ Extension: Configuration` thanks to your keyboard shortcut and I changed my default compiler to use the WSL compiler and add the /usr/include path in avanced parameters and it works ! – Sunchock Jul 02 '20 at 13:18
  • 2
    What defines where my project root is? Can it be configured? – Andreas Vinter-Hviid Oct 07 '20 at 11:04
11

The following applies mainly if using ROS1, using the C/C++ extension for vscode:

In the file .vscode/c_cpp_properties.json (generated by the VSCode ROS extension), try to change from "cppStandard": "gnu++14" to "cppStandard": "c++14".

The file would look something like that:

{
    "configurations": [
        {
            "browse": {
                "databaseFilename": "",
                "limitSymbolsToIncludedHeaders": true
            },
            "includePath": [
                "/home/user/catkin_ws/devel/include/**",
                "/opt/ros/melodic/include/**",
                ...,
                "/usr/include/**"
            ],
            "name": "ROS",
            "intelliSenseMode": "gcc-x64",
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++14"
        }
    ],
    "version": 4
}

ROS is using the c++14 standard, so specifying gnu++14 seems to break things. This was deduced from this question.

An issue exists about this (now closed).

LoW
  • 582
  • 7
  • 15
2

There is no internal intellisense, but there is a C/C++ plugin. Recently it stopped working for me. I uninstalled and installed again, and goto definition works now.

Ariel Gabizon
  • 2,851
  • 2
  • 17
  • 22
0

I have noticed on VSCode (using the C/C++ plugin) as well as other C IDEs with autocomplete/Intellisense like features that rely on static code analysis, that using nested functions really confuses the static code analayzer and causes things like autocomplete to stop working.

I just had a VS Code project that I've been working on for a while show this. Restarting Intellisense or VSCode iteslf didn't fix it, however I noticed that it was really not working only in the main file I was working on. In other files that had helper fuctions, library fuctions, etc.. the autocomplete worked fine.

I removed my nested function and replaced it with a goto cleanup; pattern instead (common but I had always liked onReturn(); as a nested method to avoid usage of the goto pattern). However I can see now that the nested function really disturbs the static code analysis / autocomplete.

I removed the nested function, replaced it with a goto cleanup; and voila, the Intellisense started working well.

So in the odd case where you're like me and you like to use nested functions in C, that often can trip up static code analyzers/Intellisense.

Papyrus
  • 232
  • 3
  • 10
0

clangd plugin

For C++ I've had very good results with the clangd plugin: https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd which integrates clangd into vscode.

This plugin parses code using clang based on a compile_commads.json database which contains the exact compilation commands as produced by the build system, This plugin parses code using clang based on a compile_commads.json database which contains the exact compilation commands as produced by the build system, and as a result tends to produce the most accurate results.

I've covered its setup in more detail at: VSCode "go to definition" not working

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
-9

At the time of writing, the the languages supported said that C++ didn't have IntelliSense.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621