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

Incompatible language mode error for c files not accounted for in CMakeLists.txt. #12124

Open
tmsrise opened this issue Mar 20, 2024 · 2 comments
Labels
bug Feature: Configuration Provider Related to the configurationProvider property, e.g. ms-vscode.cmake-tools, ms-vscode.makefile-tools. Language Service
Milestone

Comments

@tmsrise
Copy link

tmsrise commented Mar 20, 2024

Environment

  • OS and Version: Windows 11 (WSL2 Ubuntu)
  • VS Code Version: 1.87.0
  • C/C++ Extension Version: 1.19.8
  • If using SSH remote, specify OS of remote machine:

Bug Summary and Steps to Reproduce

Bug Summary:

When "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools" is applied and a .c file is not accounted for in CMakeLists.txt, VsCode supplies the following error at the start of the c file:

command-line error: language modes specified are incompatible

Removing the configuration provider setting solves the issue, but then VsCode does not recognize include directories set by my CMakeLists.

A workaround to this is to create a dummy target in CMakeLists.txt that isn't actually used:

add_custom_target(DummyTarget SOURCES 
testing/test_sources/test1.c 
testing/test_sources/test2.c
examples/an_example/example.c
...
)

Another potential untested workaround is to remove the configuration provider setting and recreate the configuration in vscode settings.json.

Both workarounds cause confusion and multiple touch points whenever relevant changes are introduced.

Steps to reproduce:

  1. New Empty Folder / Workspace
  2. CMake Quick Start -> Unspecified -> "test_name" -> cpp project -> library
  3. create dummy_file.c
  4. Change Configure Provider -> CMake Tools
  5. Error

Reproduction Notes:

  • When reproducing I noticed that only c files are affected, regardless if c or cpp project is chosen. Thus renaming our c files to cpp is another workaround. For my purposes unfortunately, the c files in question need to be .c not .cpp.

Expected behavior:

  • File exists without issue, even if it's never used or built in CMake.

Configuration and Logs

settings.json
{
    "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
}

C/C++ Log Diagnostics
{
  "os": "linux",
  "vscodeVersion": "1.87.2",
  "cmtVersion": "1.17.17",
  "configurations": [
    {
      "folder": "/home/marcus/projects/test",
      "cmakeVersion": "3.22.1",
      "configured": true,
      "generator": "Ninja",
      "usesPresets": false,
      "compilers": {
        "C": "/usr/bin/cc"
      }
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "Debug",
    "buildTypesSeen": [
      "Debug"
    ],
    "requests": [
      "file:https:///home/marcus/projects/test/dummy.c",
      "file:https:///home/marcus/projects/test/dummy.cpp"
    ],
    "responses": [],
    "partialMatches": [],
    "targetCount": 29,
    "executablesCount": 0,
    "librariesCount": 1,
    "targets": []
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": true
    }
  ]
}

Other Extensions

No response

Additional context

No response

@Colengms
Copy link
Collaborator

Hi @tmsrise . Thanks for reporting this. This is a known issue, with a potential (eventual) solution being tracked by: microsoft/vscode-cpptools-api#42 . The issue is that the C/C++ Extension is currently falling back to a singular 'browse configuration' provided to by the configuration provider, to configure IntelliSense for any files the provider does not explicitly provide a configuration for. That likely results in the right behavior for most users who are working with files that aren't explicitly specified in their CMakeLists.txt. But that API lacks a separate standard field for C vs C++, hence the issue you're seeing. We can keep this issue open to track this.

@Colengms Colengms added bug Language Service Feature: Configuration Provider Related to the configurationProvider property, e.g. ms-vscode.cmake-tools, ms-vscode.makefile-tools. labels Mar 21, 2024
@Colengms Colengms added this to the On Deck milestone Mar 21, 2024
@sean-mcmanus
Copy link
Collaborator

The fix for #12144 should also enable this to be fixed since it'll fall back to using the c_cpp_properties.json configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Feature: Configuration Provider Related to the configurationProvider property, e.g. ms-vscode.cmake-tools, ms-vscode.makefile-tools. Language Service
Projects
Status: No status
Development

No branches or pull requests

3 participants