Skip to content

Commit d2a695b

Browse files
committed
Added Show Cppcheck XML Output action to show the latest XML output - refs johnthagen#53
1 parent a5bebb2 commit d2a695b

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ Deployment.
6262

6363
### 1.6.3 - 20XX-XX-XX
6464

65+
- Added `Show Cppcheck XML Output` action to show the latest XML output.
66+
6567
### 1.6.2 - 2022-01-25
6668

6769
- Fixed `NullPointerException` with Cppcheck < 1.89 caused by missing `column` attribute in XML result.

resources/META-INF/plugin.xml

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
]]></description>
6161

6262
<change-notes><![CDATA[
63+
- Added `Show Cppcheck XML Output` action to show the latest XML output.
6364
]]>
6465
</change-notes>
6566

@@ -84,6 +85,8 @@
8485

8586
<actions>
8687
<!-- Add your actions here -->
88+
<action id="com.github.johnthagen.cppcheck.ShowOutputAction" class="com.github.johnthagen.cppcheck.ShowOutputAction"
89+
text="Show Cppcheck XML Output" description="Show the raw Cppcheck --xml output for the current file"/>
8790
</actions>
8891

8992
</idea-plugin>

src/com/github/johnthagen/cppcheck/CppcheckInspection.java

+7
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919
import javax.xml.parsers.ParserConfigurationException;
2020
import java.io.File;
2121
import java.io.IOException;
22+
import java.nio.file.Path;
23+
import java.nio.file.Paths;
2224
import java.util.List;
2325

2426
class CppcheckInspection extends LocalInspectionTool {
27+
final static Path LATEST_RESULT_FILE = Paths.get(FileUtil.getTempDirectory(), "clion-cppcheck-latest.xml");
28+
2529
@Nullable
2630
@Override
2731
public ProblemDescriptor[] checkFile(@NotNull final PsiFile file,
@@ -60,6 +64,9 @@ public ProblemDescriptor[] checkFile(@NotNull final PsiFile file,
6064
CppCheckInspectionImpl.executeCommandOnFile(vFile, cppcheckPath, prependIncludeDir(cppcheckOptions, vFile),
6165
tempFile, cppcheckMisraPath);
6266

67+
// store the output of the latest analysis
68+
FileUtil.writeToFile(LATEST_RESULT_FILE.toFile(), cppcheckOutput);
69+
6370
final List<ProblemDescriptor> descriptors = CppCheckInspectionImpl.parseOutput(file, manager, document, cppcheckOutput,
6471
tempFile.getName());
6572
return descriptors.toArray(new ProblemDescriptor[0]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.github.johnthagen.cppcheck;
2+
3+
import com.intellij.openapi.actionSystem.AnAction;
4+
import com.intellij.openapi.actionSystem.AnActionEvent;
5+
import com.intellij.openapi.fileEditor.FileEditorManager;
6+
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
7+
import com.intellij.openapi.project.Project;
8+
import com.intellij.openapi.vfs.LocalFileSystem;
9+
import com.intellij.openapi.vfs.VirtualFile;
10+
import org.jetbrains.annotations.NotNull;
11+
12+
import static com.github.johnthagen.cppcheck.CppcheckInspection.LATEST_RESULT_FILE;
13+
14+
public class ShowOutputAction extends AnAction {
15+
@Override
16+
public void actionPerformed(@NotNull final AnActionEvent anActionEvent) {
17+
final VirtualFile vFile = LocalFileSystem.getInstance().findFileByIoFile(LATEST_RESULT_FILE.toFile());
18+
if (vFile == null) {
19+
return;
20+
}
21+
22+
final Project project = anActionEvent.getProject();
23+
if (project == null) {
24+
return;
25+
}
26+
27+
// TODO: make it possible to view the output for the currently open file
28+
// TODO: find a way to display this without writing to the file system
29+
FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, vFile), true);
30+
}
31+
}

0 commit comments

Comments
 (0)