microsoft / vscode-makefile-tools

MAKE integration in Visual Studio Code
Other
194 stars 58 forks source link

Issue with Makefile: incompatible language modes #443

Closed arayq2 closed 1 year ago

arayq2 commented 1 year ago

I open my C++ project and the Makefile in it is annotated with an orange '1'. Opening the file shows an orange cursor at the beginning of the file. The Problems tab says: command-line error: language modes specified are incompatible C/C++ (1027) [Ln 1, Col 1]

What does this message mean? Which component is generating it? What "language modes' (in plural) is it referring to? What is the incompatibility?

From all indications, the Makefile was successfully parsed for configuration, Then, I was able to invoke a build of 'all' (which is also the first target in the file) and it ran to completion successfully. In other words, everything works as expected. Yet there is this inscrutable, utterly uninformative "errror" message. How can I get rid of it?

The Makefile has settings such as:

CXX = g++ CXXFLAGS = -g -pthread -m64 -std=c++14 -Wall

and .vscode/c_cpp_properties.json has:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/g++",
            "cppStandard": "c++14",
            "intelliSenseMode": "linux-gcc-x64",
            "configurationProvider": "ms-vscode.makefile-tools",
            "compileCommands": "${workspaceFolder}/compile_commands.json"
        }
    ],
    "version": 4
}

What extra magical incantations do I need to make a bog standard project acceptable to the Makefile Tools add-in?

gcampbell-msft commented 1 year ago

@arayq2 Thanks for the report! A couple of clarifying questions:

  1. Is this happening in some of your code files? Or is this happening inside of the Makefile itself.
  2. Could you provide a screenshot so that I can more distinctly see and know what you're referencing?

Thanks!

arayq2 commented 1 year ago

@gcampbell-msft

  1. Just the Makefile, although the complaint remains in the Problems tab regardless of the file in the editor window. I've been building the project from the command line without issue for a while now, and only very recently started using VSCode. Thus, I'm quite surprised that the Makefile Tools extension would find problems in a plain vanilla error-and-warning free build, and that too with an "error: unknown error" style message that a company that shall remain nameless is famous for.
  2. Two screen captures, one showing the Problems tab, and the other the Output tab after an apparently issue-free build of target "all".

Make-01 Make-02

arayq2 commented 1 year ago

Other info: Makefile Tools version: 0.6.0 G++ version: 11.3 Gnu make version: 4.3 Environment (Linux): Ubuntu 22.04

andreeis commented 1 year ago

@arayq2 , we've never seen this error applied to a Makefile file. That's very unusual. Some thoughts to get extra info:

Can you define "makefile.extensionOutputFolder": "./MyOutputFolder", "makefile.extensionLog": "extension.log", "makefile.loggingLevel": "Debug" and share with us the files "dryrun.log" and "extension.log" from the "MyOutpuFolder" after you reopen your project and let the extension configure process finish.

How is IntelliSense working for your C/C++ source files? Includes, defines... identified properly?

Do you have other Makefile extensions installed, not from Microsoft Market Place?

Do you see the squiggle also with the extension Makefile Tools uninstalled or disabled?

andreeis commented 1 year ago

Is your project open source or easy to package for us to repro on our side? In case things cannot be shared with the world, we've been using successfully so far the microsoft email makefiletools@microsoft.com with other users.

gcampbell-msft commented 1 year ago

@arayq2 Additionally, if you feel comfortable, could you send us a list of your installed extensions? I'm curious if you have other extensions installed that may try to provide Intellisense for the Makefile itself. Thanks!

arayq2 commented 1 year ago

@andreeis Sorry, no, the code is not open source. At present, a good portion of it is proprietary, and some of that will probably have to remain so. Other parts are either public domain or open source (MIT license). That's why I'm hesitant to pass along the dryrun.log and extension.log files: although from inspecting them, nothing unusual or unexpected seems to be present. The dryrun.log looks exactly like the output of running make on the command line with the '-n' option. A large part of the extension.log file is just the details of compiling individual files. If I edit those lines out, leaving only the "meta" information, will that be enough?

arayq2 commented 1 year ago

@gcampbell-msft
I'm using the Remote-SSH extension to run a VSCode session on a Linux box from a Windows 10 box (both machines on a local home network.) I have these extensions installed in this instance: C/C++; C/C++ Extension Pack; CMake; CMake Tools; GitLens; MakeFile Tools; along with C/C++ Themes installed "globally" in the underlying VSCode instance. Could the CMake extensions be running interference here (there is no CMakeLists.txt file anywhere)? Where would they be logging their activity?

andreeis commented 1 year ago

@arayq2, no interference with CMake Tools (especially if no CMakeLists.txt is present). In the extension.log, do you see any "Sending configuration" and on the same line, instead of c/c++ source file we would pass along the makefile file ? Any "not found" message in the same "extension.log" associated with the makefile file?

@sean-mcmanus, @Colengms judging from the "C/C++" hint in the problems tab, the CppTools extension emits this problem, correct? Any ideas here?

sean-mcmanus commented 1 year ago

We need to see the C/C++: Log Diagnostics. The "incompatible language modes" is usually when there's a C versus C++ mismatch, i.e. a -std for C++ is sent for a file we believe is C or vice versa. Another similar issue we've seen is at https://github.com/microsoft/vscode-cpptools/issues/9684, but we weren't able to get enough information yet.

arayq2 commented 1 year ago

UPDATE: As mysteriously as the issue appeared, so has it disappeared! And I can't reproduce it. :-( All I did was to disable a couple of extensions (specificially, CMake and CMake Tools), reload the project, and when that didn't so anything, re-enable those extensions, and instead of reloading the project, I quit VSCode altogether and started over. And lo, it was gone.

I had this issue with another project - again, just the Makefile - which I "solved" by fiddling with the values in the c_cpp_properties.json file of "cStandard" and "cppStandard". That "solution" didn't work here (which is why I didn't mention it).

But for future reference something along the lines of disabling/re-enabling extensions along with re-starting VSCode may be a viable workaround. It seems to be a common type of resort for inscrutable errors with any Microsoft product ("if all else fails, re-start/re-boot/re-install") ...

arayq2 commented 1 year ago

@andreeis For completeness: The "Sending configuration" lines in the extension.log were of two kinds: first, 70 lines of "Sending configuration (from cache)" for every distinct source file in my ./src subdirectory, followed by 88 lines of "Sending configuration for file" for the same files with some repeats. And no lines at all with "not found". This is what the file looks like:

Configurations cached at [[PROJECT_DIRECTORY]]/.vscode/configurationCache.log
No folder path to the makefile is defined in the settings file.
Always pre-configure: false
Dry-run switches: --always-make,--keep-going,--print-directory
Additional compiler names: 
Exclude compiler names: 
No current configuration is defined in the workspace state. Assuming 'Default'.
Reading current build target "all" from the workspace state.
No current launch configuration is set in the workspace state.
Default launch configuration: MIMode = undefined,
                    miDebuggerPath = undefined,
                    stopAtEntry = undefined,
                    symbolSearchPath = undefined
Configure on open: true
Configure on edit: true
Configure after command: true
Only .PHONY targets: false
Save before build or configure: true
Build before launch: true
Clear output before build: true
Ignore directory commands: true
compile_commands.json path: null
Deduced command 'make -f [[PROJECT_DIRECTORY]]/Makefile' for configuration "Default"
Saving opened files before build.
Configuring from cache: [[PROJECT_DIRECTORY]]/.vscode/configurationCache.log
Load configuration from cache elapsed time: 0.201
Sending Workspace Browse Configuration: -----------------------------------
    Browse Path: [[PROJECT_DIRECTORY]]/include;[[PROJECT_DIRECTORY]]/include/amq;[[PROJECT_DIRECTORY]]/include/apr-1;[[PROJECT_DIRECTORY]]/include/sg;[[PROJECT_DIRECTORY]]/include/utility;[[PROJECT_DIRECTORY]]/src
    Standard: c++14
    Compiler Path: /usr/bin/g++
    Compiler Arguments: -g;-pthread;-m64;-Wall;-c;src/OutBound2.cpp;-o;src/OutBound2.o [[sic]]
[[ **70** entries of the form:
---------------------------------------------------------------------------------------------------
Sending configuration (from cache) for file [[PROJECT_DIRECTORY]]/src/Table_main.cpp -----------------------------------
    Defines: 
    Includes: [[PROJECT_DIRECTORY]]/include;[[PROJECT_DIRECTORY]]/include/sg;[[PROJECT_DIRECTORY]]/include/amq;[[PROJECT_DIRECTORY]]/include/apr-1;[[PROJECT_DIRECTORY]]/include/utility
    Force Includes: 
    Standard: c++14
    IntelliSense Mode: gcc-x64
    Compiler Path: /usr/bin/g++
    Compiler Arguments: -g;-pthread;-m64;-Wall;-c;src/Table_main.cpp;-o;src/Table_main.o
]]
---------------------------------------------------------------------------------------------------
Generating in the background a new configuration cache with command: 'make all -f [[PROJECT_DIRECTORY]]/Makefile --dry-run --always-make --keep-going --print-directory'
Writing the dry-run output: [[PROJECT_DIRECTORY]]/.vscode/dryrun.log
Spawning child process with:
 process name: make
 process args: all,-f,[[PROJECT_DIRECTORY]]/Makefile,--dry-run,--always-make,--keep-going,--print-directory
 working directory: [[PROJECT_DIRECTORY]]
 shell type: default
Generating dry-run elapsed time: 0.031
Preprocessing: "[[PROJECT_DIRECTORY]]/.vscode/dryrun.log"
Preprocess elapsed time: 0
Parsing for IntelliSense.
Updating the CppTools IntelliSense Configuration Provider.
Parsing dry-run output for CppTools Custom Configuration Provider.
Analyzing line: make: Entering directory '[[PROJECT_DIRECTORY]]'
MAKE -C: entering directory [[PROJECT_DIRECTORY]]
[[ **88** entries of the form:
---------------------------------------------------------------------------------------------------
Found compiler command: g++ -g -pthread -m64 -std=c++14 -Wall -I include -I include/sg -I include/amq -I include/apr-1 -I include/utility -c src/Table_main.cpp -o src/Table_main.o
Sending configuration for file [[PROJECT_DIRECTORY]]/src/Table_main.cpp -----------------------------------
    Defines: 
    Includes: [[PROJECT_DIRECTORY]]/include;[[PROJECT_DIRECTORY]]/include/sg;[[PROJECT_DIRECTORY]]/include/amq;[[PROJECT_DIRECTORY]]/include/apr-1;[[PROJECT_DIRECTORY]]/include/utility
    Force Includes: 
    Standard: c++14
    IntelliSense Mode: gcc-x64
    Compiler Path: /usr/bin/g++
    Compiler Arguments: -g;-pthread;-m64;-Wall;-c;src/Table_main.cpp;-o;src/Table_main.o
]]
Parsing for IntelliSense elapsed time: 2.54
Parsing for launch targets.
Analyzing line: make: Entering directory '[[PROJECT_DIRECTORY]]'
MAKE -C: entering directory [[PROJECT_DIRECTORY]]
[[ **32** entries of the form:
Found linker command: g++ -g -pthread -m64 -std=c++14 -Wall -o  [[Objects]] [[Libraries]]
Producing target binary: [[Executable]]
Adding launch configuration:
[[PROJECT_DIRECTORY]]/bin>[[Executable]]()
]]
POPD command or end of MAKE -C: leaving directory [[PROJECT_DIRECTORY]] and entering directory [[PROJECT_DIRECTORY]]
Found the following 32 launch targets defined in the makefile: [[Long list]]
Complete list of launch targets: [[Same list]]
Parsing for launch targets elapsed time: 0.084
Generating parse content for build targets.
Generating targets information with command: 'make all -f [[PROJECT_DIRECTORY]]/Makefile --print-data-base --no-builtin-variables --no-builtin-rules --question'
Writing the dry-run output: [[PROJECT_DIRECTORY]]/.vscode/targets.log
Spawning child process with:
 process name: make
 process args: all,-f,[[PROJECT_DIRECTORY]]/Makefile,--print-data-base,--no-builtin-variables,--no-builtin-rules,--question
 working directory: [[PROJECT_DIRECTORY]]
 shell type: default
Generating dry-run elapsed time: 0.02
Parsing for build targets from: "[[PROJECT_DIRECTORY]]/.vscode/targets.log"
Found the following 13 build targets defined in the makefile: all;bin;bin/Director;bin/Launch;bin/LaunchMasterpoint;bin/LaunchRobot;bin/LaunchTable;bin/MakeTable;bin/Recorder;bin/Section;bin/Table;clean;others
Complete list of build targets: all;bin;bin/Director;bin/Launch;bin/LaunchMasterpoint;bin/LaunchRobot;bin/LaunchTable;bin/MakeTable;bin/Recorder;bin/Section;bin/Table;clean;others
Parsing build targets elapsed time: 0.002
Configure finished. The status for all the subphases that ran:
loadFromCache: return code = 0, elapsed time = 0.201
generateParseContent: return code = 0, elapsed time = 0.031
preprocessParseContent: return code = 0, elapsed time = 0
parseIntelliSense: return code = 0, elapsed time = 2.54
parseLaunch: return code = 0, elapsed time = 0.084
dryrunTargets: return code = 1, elapsed time = 0.02
parseTargets: return code = 0, elapsed time = 0.002
Configure succeeded.
Sending telemetry: eventName = configure
properties: firstTime = "false",makeDryRun = "true",readCache = "true",isClean = "true",processTargetsSeparately = "false",resetBuildTarget = "false",triggeredBy = "configure dirty (on open), settings (configureOnOpen)",buildTarget = "all"
measures: numberBuildTargets = "13",numberLaunchTargets = "32",numberIndexedSourceFiles = "70",numberMakefileConfigurations = "0",totalElapsedTime = "3.06",exitCode = "0",loadFromCache.exitCode = "0",loadFromCache.elapsed = "0.201",generateParseContent.exitCode = "0",generateParseContent.elapsed = "0.031",preprocessParseContent.exitCode = "0",preprocessParseContent.elapsed = "0",parseIntelliSense.exitCode = "0",parseIntelliSense.elapsed = "2.54",parseLaunch.exitCode = "0",parseLaunch.elapsed = "0.084",dryrunTargets.exitCode = "1",dryrunTargets.elapsed = "0.02",parseTargets.exitCode = "0",parseTargets.elapsed = "0.002"
Configure elapsed time: 3.06
Sending telemetry: eventName = settings
properties: makefile.loggingLevel = "Debug",makefile.makeDirectory = "undefined",makefile.makefilePath = "...",makefile.extensionOutputFolder = "...",makefile.extensionLog = "..."

`

andreeis commented 1 year ago

Interesting :). Not closing this though, we can still gather more clues.

@arayq2. Please provide the C/C++ Diagnostics log for @sean-mcmanus and @Colengms to look at. If you already did and I didn't see, I apologize. Run the diagnostics command after you see the red squiggle, after you open the makefile file (when you happen to reproduce again, hopefully soon for the sake of getting to the root cause).

@arayq2, thank you for the Makefile Tools logs. Those look good. From what I see, I don't see the Makefile extension trying to convince CppTools that we provide IntelliSense for makefile. @gcampbell-msft, you need to investigate the same on CMake Tools side. Is CMake Tools trying to create an IntelliSense configuration entry associated with the makefile file instead of only c/c++ files? (not sure if CMake Tools has some equivalent logging for 'Sending configuration for...'). Also, is CppTools asking for IntelliSense configuration and requesting the makefile path instead of a c/c++ source file path? The equivalent for "not found" in the logging. We can follow up offline and find where that logging is how it is phrased so that @arayq2 searches for it in the CMake Tools output channel. Then we either find CMT as the culprit or we rule it out.

@sean-mcmanus , regarding the CppTools issue 9684 which you referenced above... I see they moved on to CMake, so I'm not replying there but to summarize my experience with all the occurrences of this CppTools squiggle message (on C/C++ source files, never on makefiles until this one :) ). It always happened, no exception, for c/c++ source files that we (Makefile Tools) were not providing CppTools configurations for: either because we had parser bugs which we fixed or because the users were opening files from outside the scope of their builds, meaning our "make --dry-run --always-make" was not producing an output that contained a compiler/linker command with the opened file... or users had some by design issues with --always-make, had to remove it and their files were up to date, our "make --dry-run" was not seeing them in the output (outside of our control).

arayq2 commented 1 year ago

@andreeis For clarity, there was no red squiggle, only a caret cursor at llne 1 column 1 of the Makefile. That first line was (and still is) completely empty. I even tried adding a shebang line ('#!/usr/bin/make -f'), just in case the parser was looking for that (!), to no effect.

The C/C++ Diagnostics output looks like this:

-------- Diagnostics - 3/25/2023, 9:03:24 PM
Version: 1.14.5
Current Configuration:
{
    "name": "Linux",
    "includePath": [
        "[[PROJECT_DIRECTORY]]/include/**"
    ],
    "defines": [],
    "compilerPath": "/usr/bin/g++",
    "cStandard": "c11",
    "cppStandard": "c++14",
    "intelliSenseMode": "linux-gcc-x64",
    "configurationProvider": "ms-vscode.makefile-tools",
    "browse": {
        "limitSymbolsToIncludedHeaders": true,
        "path": [
            "${workspaceFolder}/include/**",
            "${workspaceFolder}"
        ]
    },
    "compilerPathIsExplicit": true,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": true,
    "intelliSenseModeIsExplicit": true,
    "mergeConfigurations": false
}
Custom browse configuration: 
{
    "browsePath": []
}
No active translation units.
sean-mcmanus commented 1 year ago

@arayq2 The C/C++: Log Diagnostics needs to be run after opening a file (after it's been reproing the error message about incompatible language modes), assuming you can still repro that.

andreeis commented 1 year ago

@arayq2 I am closing this ticket but please reactivate if you still reproduce this issue and as Sean says, run the Log Diagnostics command after you open the file with the problem.