microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.53k stars 1.56k forks source link

C_Cpp.codeAnalysis.exclude does work with ${workspaceFolder} or ${workspaceFolder]/** #12392

Closed Timmmm closed 4 months ago

Timmmm commented 4 months ago

Environment

Bug Summary and Steps to Reproduce

Bug Summary:

C_Cpp.codeAnalysis.exclude claims to exclude files from intellisense. I need this because I have a few 100k line generated C files in my project and every time I open them cpptools gets stuck at 100% forever and I have to kill it.

However, this setting doesn't seem to do anything.

Steps to reproduce:

  1. Create .vscode/settings.json containing
{
    "C_Cpp.codeAnalysis.exclude": {
        "${projectRoot}/foo.c": true
    }
}
  1. Create foo.c containing:
int foo() {
    return sdfsdf;
}

int main() {
    foo();
}
  1. Reload the window to be sure.
  2. Hover sdfsdf, ctrl-click foo();. It all still works. Clearly it is analysing the file.

Expected behavior:

I guess syntax highlighting should still work but no errors should be highlighted and go-to-definition shouldn't work.

Configuration and Logs

No `c_cpp_properties.json`. 

-------- Diagnostics - 19/06/2024, 12:34:58
Version: 1.20.5
Current Configuration:
{
    "name": "Linux",
    "includePath": [
        "/home/me/d11/**",
        "/home/me/local/vcpkg/installed/x64-linux/include"
    ],
    "defines": [],
    "cStandard": "c17",
    "cppStandard": "c++14",
    "intelliSenseMode": "linux-clang-x64",
    "intelliSenseModeIsExplicit": false,
    "cStandardIsExplicit": false,
    "cppStandardIsExplicit": false,
    "mergeConfigurations": false,
    "compilerPath": "/usr/bin/g++",
    "compilerPathIsExplicit": true,
    "browse": {
        "path": [
            "/home/me/d11/**",
            "/home/me/local/vcpkg/installed/x64-linux/include",
            "${workspaceFolder}"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
cpptools version (native): 1.20.5.0
Translation Unit Mappings:
[ /home/me/d11/foo.c - source TU]:
Translation Unit Configurations:
[ /home/me/d11/foo.c ]:
    Process ID: 3048040
    Memory Usage: 15 MB
    Compiler Path: /usr/bin/g++
    Includes:
        /home/me/local/vcpkg/installed/x64-linux/include
        /usr/lib/gcc/x86_64-redhat-linux/8/include
        /usr/local/include
        /usr/include
    Standard Version: c17
    IntelliSense Mode: linux-gcc-x64
    Other Flags:
        --gcc
        --gnu_version=80500
Total Memory Usage: 15 MB

------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 4929


### Other Extensions

_No response_

### Additional context

_No response_
sean-mcmanus commented 4 months ago

@Timmmm C_Cpp.codeAnalysis.exclude only applies to the "code analysis" (i.e. clang-tidy) feature and not "IntelliSense" or our tag parser. You should use C_Cpp.files.exclude with an exclusion pattern that matches of folder. If you really need a per-file exclusion, then set C_Cpp.exclusionPolicy to to "checkFilesAndFolders". Does that work for you?

Timmmm commented 4 months ago

Unfortunately not. With this settings.json:

{
    "C_Cpp.codeAnalysis.exclude": {
        "${workspaceFolder}": true
    },
    "C_Cpp.files.exclude": {
        "${workspaceFolder}": true
    }
}

If I open foo.c it still analyses it.

sean-mcmanus commented 4 months ago

@Timmmm It looks like it doesn't work for that case. It works if you use the expanded path (not the variable) followed by /** or if you use ${workspaceFolder}/someSubDir.

Timmmm commented 4 months ago

That doesn't seem to work either unfortunately:

image

Timmmm commented 4 months ago

Also tried these just to be sure:

image

sean-mcmanus commented 4 months ago

@Timmmm The squiggles you're getting are not from the code analysis feature -- they're from IntelliSense. You can tell because IntelliSense errors have a number error code instead of a clang error code. You can turn off IntelliSense errors with the C_Cpp.errorSquiggles setting, but we don't have a per-file way to turn off the squiggles. Or you can turn off IntelliSense completely with C_Cpp.intelliSenseEngine set to "Tag Parser" or "disabled".

Timmmm commented 4 months ago

Ah I see - I turned this into a feature request: #12421

Or you can turn off IntelliSense completely with C_Cpp.intelliSenseEngine set to "Tag Parser" or "disabled".

Yeah I'd rather not lose intellisense for the rest of my project where it works fine.

Timmmm commented 4 months ago

Btw if anyone else is in this situation, I also tried switching to the Clangd extension and that seems to have no issues with the huge C files I'm working with. Worth a shot anyway.