diff --git a/jsoncdb/org.eclipse.cdt.jsoncdb.core/src/org/eclipse/cdt/jsoncdb/core/CommandEntry.java b/jsoncdb/org.eclipse.cdt.jsoncdb.core/src/org/eclipse/cdt/jsoncdb/core/CommandEntry.java index 78da5aa0a3b..f24b76e732a 100644 --- a/jsoncdb/org.eclipse.cdt.jsoncdb.core/src/org/eclipse/cdt/jsoncdb/core/CommandEntry.java +++ b/jsoncdb/org.eclipse.cdt.jsoncdb.core/src/org/eclipse/cdt/jsoncdb/core/CommandEntry.java @@ -12,16 +12,20 @@ package org.eclipse.cdt.jsoncdb.core; /** - * Represents a parsed command entry of a compile_commands.json file. - * @author weber + * Represents a parsed command entry of a compile_commands.json file.
+ * See the JSON Compilation Database Format Specification. + * + * @author Martin Weber */ class CommandEntry { private String directory; private String command; + private String[] arguments; private String file; /** - * Gets the build directory as a String. + * Gets the working directory of the compilation the build directory as a String.
+ * The specification states: All paths specified in the command or file fields must be either absolute or relative to this directory. */ public String getDirectory() { return directory; @@ -34,6 +38,14 @@ class CommandEntry { return command; } + /** + * Gets the command-line to compile the source file split up into arguments.
+ * Either {@link #getCommand()} or {@link #getArguments()} will return a non-null value. + */ + public String[] getArguments() { + return arguments; + } + /** * Gets the source file path as a String. */ diff --git a/jsoncdb/org.eclipse.cdt.jsoncdb.core/src/org/eclipse/cdt/jsoncdb/core/CompileCommandsJsonParser.java b/jsoncdb/org.eclipse.cdt.jsoncdb.core/src/org/eclipse/cdt/jsoncdb/core/CompileCommandsJsonParser.java index 95a36778eef..9be7d1f79d4 100644 --- a/jsoncdb/org.eclipse.cdt.jsoncdb.core/src/org/eclipse/cdt/jsoncdb/core/CompileCommandsJsonParser.java +++ b/jsoncdb/org.eclipse.cdt.jsoncdb.core/src/org/eclipse/cdt/jsoncdb/core/CompileCommandsJsonParser.java @@ -211,7 +211,10 @@ public class CompileCommandsJsonParser { // NOTE that this is the absolute file system path of the source file in // CMake-notation (directory separator are forward slashes, even on windows) final String file = sourceFileInfo.getFile(); - final String cmdLine = sourceFileInfo.getCommand(); + String cmdLine = sourceFileInfo.getCommand(); + if (cmdLine == null) { + cmdLine = String.join(" ", sourceFileInfo.getArguments()); //$NON-NLS-1$ + } if (file != null && !file.isEmpty() && cmdLine != null && !cmdLine.isEmpty()) { ParserDetection.ParserDetectionResult pdr = fastDetermineDetector(cmdLine); if (pdr != null) {