1414import com .intellij .openapi .progress .ProgressIndicator ;
1515import com .intellij .openapi .progress .ProgressManager ;
1616import com .intellij .openapi .util .TextRange ;
17+ import com .intellij .openapi .vfs .VirtualFile ;
1718import com .intellij .psi .PsiFile ;
1819import com .intellij .util .DocumentUtil ;
1920import com .intellij .util .execution .ParametersListUtil ;
@@ -55,7 +56,7 @@ private static ProblemHighlightType severityToHighlightType(@NotNull final Strin
5556 }
5657
5758 // TODO: make configurable
58- private static final boolean VERBOSE_LOG = false ;
59+ private static final int VERBOSE_LOG = 0 ;
5960 private static final String INCONCLUSIVE_TEXT = ":inconclusive" ;
6061
6162 @ NotNull
@@ -65,10 +66,11 @@ public static List<ProblemDescriptor> parseOutput(@NotNull final PsiFile psiFile
6566 @ NotNull final String cppcheckOutput ,
6667 @ NotNull final String sourceFileName ) throws IOException , SAXException , ParserConfigurationException {
6768
68- if (VERBOSE_LOG ) {
69+ final VirtualFile vFile = psiFile .getVirtualFile ();
70+ if (VERBOSE_LOG >= 1 ) {
6971 // TODO: provide XML output via a "Show Cppcheck output" action - event log messages are truncated
70- CppcheckNotification .send ("execution output for " + psiFile . getVirtualFile () .getCanonicalPath (),
71- cppcheckOutput ,
72+ CppcheckNotification .send ("finished analysis for " + vFile .getCanonicalPath (),
73+ "" ,
7274 NotificationType .INFORMATION );
7375 }
7476
@@ -127,7 +129,7 @@ public static List<ProblemDescriptor> parseOutput(@NotNull final PsiFile psiFile
127129 }
128130
129131 // suppress this warning for headers until Cppcheck handles them in a better way
130- if (SupportedExtensions .isHeaderFile (psiFile . getVirtualFile () ) && id .equals ("unusedStructMember" )) {
132+ if (SupportedExtensions .isHeaderFile (vFile ) && id .equals ("unusedStructMember" )) {
131133 continue ;
132134 }
133135
@@ -150,7 +152,7 @@ public static List<ProblemDescriptor> parseOutput(@NotNull final PsiFile psiFile
150152
151153 // ignore entries without location e.g. missingIncludeSystem
152154 if (location == null ) {
153- CppcheckNotification .send ("no location for " + psiFile . getVirtualFile () .getCanonicalPath (),
155+ CppcheckNotification .send ("no location for " + vFile .getCanonicalPath (),
154156 id + " " + severity + " " + inconclusive + " " + errorMessage ,
155157 NotificationType .ERROR );
156158 continue ;
@@ -167,6 +169,12 @@ public static List<ProblemDescriptor> parseOutput(@NotNull final PsiFile psiFile
167169 column = Integer .parseInt (columnAttr .getNodeValue ());
168170 }
169171
172+ if (VERBOSE_LOG >= 4 ) {
173+ CppcheckNotification .send (id + " for " + vFile .getCanonicalPath (),
174+ id + " " + severity + " " + inconclusive + " " + errorMessage + " " + fileName + " " + lineNumber + " " + column ,
175+ NotificationType .INFORMATION );
176+ }
177+
170178 // If a file #include's header files, Cppcheck will also run on the header files and print
171179 // any errors. These errors don't apply to the current file and should not be drawn. They can
172180 // be distinguished by checking the file name.
@@ -176,7 +184,7 @@ public static List<ProblemDescriptor> parseOutput(@NotNull final PsiFile psiFile
176184
177185 // Cppcheck error
178186 if (lineNumber <= 0 || lineNumber > document .getLineCount ()) {
179- CppcheckNotification .send ("line number out-of-bounds for " + psiFile . getVirtualFile () .getCanonicalPath (),
187+ CppcheckNotification .send ("line number out-of-bounds for " + vFile .getCanonicalPath (),
180188 id + " " + severity + " " + inconclusive + " " + errorMessage + " " + fileName + " " + lineNumber + " " + column ,
181189 NotificationType .ERROR );
182190 continue ;
@@ -201,20 +209,27 @@ public static List<ProblemDescriptor> parseOutput(@NotNull final PsiFile psiFile
201209
202210 private static final int TIMEOUT_MS = 60 * 1000 ;
203211
204- public static String executeCommandOnFile (@ NotNull final String command ,
212+ public static String executeCommandOnFile (@ NotNull final VirtualFile vFile ,
213+ @ NotNull final String command ,
205214 @ NotNull final String options ,
206- @ NotNull final String filePath ,
215+ @ NotNull final File filePath ,
207216 final String cppcheckMisraPath ) throws CppcheckError , ExecutionException {
208217 final GeneralCommandLine cmd = new GeneralCommandLine ()
209218 .withExePath (command )
210219 .withParameters (ParametersListUtil .parse (options ))
211- .withParameters (ParametersListUtil .parse ("\" " + filePath + "\" " ));
220+ .withParameters (ParametersListUtil .parse ("\" " + filePath . getAbsolutePath () + "\" " ));
212221
213222 // Need to be able to get python from the system env
214223 if (cppcheckMisraPath != null && !cppcheckMisraPath .isEmpty ()) {
215224 cmd .withParentEnvironmentType (GeneralCommandLine .ParentEnvironmentType .SYSTEM );
216225 }
217226
227+ if (VERBOSE_LOG >= 2 ) {
228+ CppcheckNotification .send ("options for " + vFile .getCanonicalPath (),
229+ cmd .getCommandLineString (),
230+ NotificationType .INFORMATION );
231+ }
232+
218233 final CapturingProcessHandler processHandler = new CapturingProcessHandler (cmd );
219234 final ProgressIndicator indicator = ProgressManager .getInstance ().getProgressIndicator ();
220235 final ProcessOutput output = processHandler .runProcessWithProgressIndicator (
0 commit comments