Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intellisense Can't Find Preprocessor Definition from "defines" Field of "c_cpp_properties.json" #5572

Closed
abhra0897 opened this issue May 26, 2020 · 2 comments
Labels
Feature: Configuration An issue related to configuring the extension or IntelliSense Language Service more info needed The issue report is not actionable in its current state

Comments

@abhra0897
Copy link

Type: LanguageService

Describe the bug

  • OS and Version: Ubuntu 20.04 LTS
  • VS Code Version: 1.45.1
  • C/C++ Extension Version: 0.28.1
  • Other extensions you installed (and if the issue persists after disabling them): Cortex-Debug (Yes)
  • Does this issue involve using SSH remote to run the extension on a remote machine?: No
  • Bug Description: Intellisense can't find preprocessor macro definitions that are passed to the defines field in the c_cpp_properties.json file. This bug occurs regardless of the project size or the number of projects opened in the workspace.

Steps to reproduce

  1. Create a folder and open vscode into that folder.
  2. Create a new file and name it main.c.
  3. Write the following C code into that file and save it.
#if defined (FOO)
  #define BAR 10
#endif
int main()
{
    int var_bar = BAR;
    return 0;
}
  1. Create a new file and name it c_cpp_properties.json.
  2. Write the following JSON code into that file and save it.
{
    "configurations": [
      {
        "name": "Linux",
        "intelliSenseMode": "gcc-x64",
        "defines": [
          "FOO"
        ],
        "includePath": []
      }
    ],
    "version": 1
}
  1. See: intellisense can't find that FOO is defined and showing red error line under BAR in the int var_bar = BAR; line.

Expected behavior
The defines field in the c_cpp_properties.json file contains a list of preprocessor definitions for the IntelliSense engine to use while parsing files. So, as FOO is written in defines, IntelliSense should NOT show error in int var_bar = BAR;.

Logs
-------- Diagnostics - 27/5/2020, 4:11:08 am
Version: 0.28.1
Current Configuration:
{
    "name": "Linux",
    "includePath": [
        "${workspaceFolder}/**"
    ],
    "defines": [],
    "compilerPath": "/usr/bin/clang",
    "cStandard": "c11",
    "cppStandard": "c++14",
    "intelliSenseMode": "clang-x64",
    "compilerArgs": [],
    "browse": {
        "path": [
            "${workspaceFolder}/**"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
Translation Unit Mappings:
[ /home/rik/Works/C_CPP/intellisense_bug_repro/main.c ]:
    /home/rik/Works/C_CPP/intellisense_bug_repro/main.c
Translation Unit Configurations:
[ /home/rik/Works/C_CPP/intellisense_bug_repro/main.c ]:
    Process ID: 21119
    Memory Usage: 16 MB
    Compiler Path: /usr/bin/clang
    Includes:
        /usr/local/include
        /usr/lib/llvm-10/lib/clang/10.0.0/include
        /usr/include/x86_64-linux-gnu
        /usr/include
    Standard Version: c11
    IntelliSense Mode: clang-x64
    Other Flags:
        --clang
        --clang_version=100000
Total Memory Usage: 16 MB
File exclude: **/.git
File exclude: **/.svn
File exclude: **/.hg
File exclude: **/CVS
File exclude: **/.DS_Store
File exclude: **/.vscode
Search exclude: **/node_modules
Search exclude: **/bower_components
Search exclude: **/*.code-search
Search exclude: **/.vscode
Populate include completion cache.
Discovering files...
  Processing folder (recursive): /usr/local/include/
  Processing folder (recursive): /usr/lib/llvm-10/lib/clang/10.0.0/include/
  Processing folder (recursive): /usr/include/
Error squiggle count: 1
Update IntelliSense time (sec): 0.253
  Processing folder (recursive): /home/rik/Works/C_CPP/intellisense_bug_repro/
  Discovering files: 20467 file(s) processed
  0 file(s) removed from database
Done discovering files.
Parsing remaining files...
  Parsing: 1 files(s) processed
Done parsing remaining files.

Screenshots

Screenshot from 2020-05-27 03-40-22

@Colengms
Copy link
Collaborator

Hi @abhra0897 . I'm not able to (easily) repro this issue. With (almost) exactly what you've provided, this works for me. Are you sure your c_cpp_properties.json is in the correct location? It should be in the workspace, in a .vscode directory. If you do not yet have a c_cpp_properties.json, you can use the C/C++: Edit Configurations (JSON) command to create it.

One thing that I noticed is that your c_cpp_properties.json contains a version number of "1". Version 1 is no longer recognized. When I try to save a c_cpp_properties.json with a version of 1, I get an error message, and a version of 4 is immediately written in its place.

Could you try repro'ing with a newly created c_cpp_properties.json file, perhaps in a new empty folder, and confirm that it uses version 4 and not 1? If you still repro, could you provide the exactly contents of that repro? (perhaps attach the 2 text files involved to this issue, and note the directory structure).

@Colengms Colengms added Feature: Configuration An issue related to configuring the extension or IntelliSense Language Service more info needed The issue report is not actionable in its current state labels May 26, 2020
@abhra0897
Copy link
Author

abhra0897 commented May 26, 2020

Are you sure your c_cpp_properties.json is in the correct location? It should be in the workspace, in a .vscode directory.

@Colengms Yes, I've just figured it out and was about to explain and close this issue. It's solved now. Thanks for your reply.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Feature: Configuration An issue related to configuring the extension or IntelliSense Language Service more info needed The issue report is not actionable in its current state
Projects
None yet
Development

No branches or pull requests

2 participants