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

Header-only IntelliSense should use language ID delivered with didOpen instead of defaulting to C++ #9138

Open
JAicewizard opened this issue Apr 4, 2022 · 6 comments

Comments

@JAicewizard
Copy link

Bug type: Language Service

Describe the bug

  • OS and Version: linux 5.17.1
  • VS Code Version: 1.65.2
  • C/C++ Extension Version: 1.9.7
  • Other extensions you installed (and if the issue persists after disabling them): dart, go, flutter, python, rust (literal names of the extensions)
  • If using SSH remote, specify OS of remote machine:
  • A clear and concise description of what the bug is, including information about the workspace (i.e. is the workspace a single project or multiple projects, size of the project, etc). Workspace is a project with a lot of go code and one file in c, a header file with just one line. This file is located at x/y.h. and contains void z(char *restrict q); which is valid C code. Language is set to C.

Steps to reproduce

  1. Open x/y.h
  2. See error

Expected behavior
No squiggly lines

Code sample and logs

  • Code sample
void z(char *restrict q);
  • Configurations in c_cpp_properties.json

  • Logs from running C/C++: Log Diagnostics from the VS Code command palette

-------- Diagnostics - 04/04/2022, 19:07:04
Version: 1.9.7
Current Configuration:
{
    "name": "Linux",
    "includePath": [
        "${workspaceFolder}/**"
    ],
    "defines": [],
    "compilerPath": "/sbin/clang",
    "cStandard": "c17",
    "cppStandard": "c++14",
    "intelliSenseMode": "linux-clang-x64",
    "compilerArgs": [],
    "intelliSenseModeIsExplicit": false,
    "cStandardIsExplicit": false,
    "cppStandardIsExplicit": false,
    "mergeConfigurations": false,
    "compilerPathIsExplicit": false,
    "browse": {
        "path": [
            "${workspaceFolder}/**"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
Translation Unit Mappings:
[ /.../x/y.h ]:
    /.../x/y.h
Translation Unit Configurations:
[ /.../x/y.h ]:
    Process ID: 17136
    Memory Usage: 12 MB
    Compiler Path: /sbin/clang
    Includes:
        /usr/include/c++/11.2.0
        /usr/include/c++/11.2.0/x86_64-pc-linux-gnu
        /usr/include/c++/11.2.0/backward
        /usr/lib/clang/13.0.1/include
        /usr/local/include
        /usr/include
    Standard Version: c++14
    IntelliSense Mode: linux-clang-x64
    Other Flags:
        --clang
        --clang_version=130001
        --header_only_fallback
Total Memory Usage: 12 MB

------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 26971
Number of files parsed: 3712

- Logs from [the language server logging](https://code.visualstudio.com/docs/cpp/enable-logging-cpp#_enable-logging-for-the-language-server)
loggingLevel: Debug
loggingLevel has changed to: Debug
cpptools/didChangeCppProperties
$/setTraceNotification
cpptools/getCodeActions: /.../x/y.h (id: 149)
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/activeDocumentChange: /.../x/y.h
cpptools/getFoldingRanges: /.../x/y.h (id: 150)
cpptools/getCodeActions: /.../x/y.h (id: 151)
textDocument/didClose: /.../x/y.h
Database safe to open
cpptools/getCodeActions: /.../x/y.h (id: 152)
textDocument/didOpen: /.../x/y.h
Checking for syntax errors: /.../x/y.h
Queueing IntelliSense update for files in translation unit of: /.../x/y.h
cpptools/textEditorSelectionChange
cpptools/getDocumentSymbols: /.../x/y.h (id: 153)
cpptools/textEditorSelectionChange
cpptools/getSemanticTokens: /.../x/y.h (id: 154)
cpptools/getDocumentSymbols
cpptools/activeDocumentChange: /.../x/y.h
cpptools/getFoldingRanges: /.../x/y.h (id: 155)
cpptools/getCodeActions: /.../x/y.h (id: 156)
cpptools/finishUpdateSquiggles
Error squiggle count: 1
terminating child process: 18585
Update IntelliSense time (sec): 0.367
cpptools/getCodeActions: /.../x/y.h(id: 157)
cpptools/getFoldingRanges: /.../x/y.h (id: 158)
cpptools/textEditorSelectionChange
cpptools/activeDocumentChange: /.../x/y.h
@Colengms Colengms self-assigned this Apr 4, 2022
@Colengms
Copy link
Contributor

Colengms commented Apr 4, 2022

Hi @JAicewizard . By default, when a .h file is opened and there is no source file (.cpp, .c, etc.) to associate it with, the C/C++ extension treats the file as containing C++ code. I don't believe the restrict keyword is supported in C++. Note this comment in the C++ specification.

I believe you could work around the issue if you add a .c file that includes that header. That .c file should be found when opening the header, and the header would be interpreted as containing C code instead of C++ code.

Does that resolve your issue?

@Colengms Colengms added Language Service more info needed The issue report is not actionable in its current state labels Apr 4, 2022
@JAicewizard
Copy link
Author

That does "fix" the issue, but I have explicitly set the language to C, not C++.
screenshot-2022-04-04-205227

So it is probably the case that the the language server misinterprets the file even though I told VScode explicitly that this is a C file.

@Colengms
Copy link
Contributor

Colengms commented Apr 4, 2022

Hi @JAicewizard . Thanks. We'll use this issue to track addressing that. In the meanwhile, it would also be possible to work around the issue by setting a file association in settings, like so:

{
    "files.associations": {
        "test.h": "c"
    }
}

@Colengms Colengms changed the title Incorrect error when using restrict keyword. Header-only IntelliSense should use language ID delivered with didOpen instead of defaulting to C++ Apr 4, 2022
@Colengms Colengms added bug and removed more info needed The issue report is not actionable in its current state labels Apr 4, 2022
@Colengms Colengms added this to the On Deck milestone Apr 4, 2022
@Colengms Colengms removed their assignment Apr 4, 2022
@JAicewizard
Copy link
Author

Yup this seems to work, even though vscode is now telling me it is in C++ mode, the c/c++ extension seems to be in C mode now.
Maybe there is something not working with the language mode in vscode? Or maybe it doesnt do what I expect it to do.

@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented Apr 4, 2022

Yeah, it seems like we may not be responding correctly to C versus C++ language mode changes from the status bar. I filed an issue at #9141 .

@Colengms
Copy link
Contributor

I believe this issue is currently blocked due to needing support from VS Code to correctly determine whether the user has altered the language ID of the file or if the default should be used. microsoft/vscode#227643

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

3 participants