Skip to content

Commit 000054f

Browse files
committed
progress towards #14 showing a file-level annotation when the contents of the editor have changed
1 parent 3a5d71c commit 000054f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/main/java/com/github/rogerhowell/javaparser_ast_inspector/plugin/ui/extensions/JavaParserExternalAnnotator.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public PsiFile collectInformation(@NotNull PsiFile file) {
6464

6565

6666
/**
67-
* Called 2nd; run antlr on file
67+
* Called 2nd; run on file
6868
*/
6969
@Nullable
7070
@Override
@@ -84,6 +84,8 @@ public void apply(@NotNull PsiFile file, List<Object> infos, @NotNull Annotation
8484
final String canonicalPath = file.getVirtualFile().getCanonicalPath();
8585
final Path psiPath = Paths.get(canonicalPath).normalize();
8686

87+
String x = "File contents appear to have changed since parsing with JavaParser - highlighted areas may not line up correctly until it is re-parsed.";
88+
8789
this.hls.getSelectedNode().ifPresent(selectedNode -> {
8890
selectedNode.findCompilationUnit()
8991
.flatMap(CompilationUnit::getStorage)
@@ -93,6 +95,15 @@ public void apply(@NotNull PsiFile file, List<Object> infos, @NotNull Annotation
9395

9496
final Path nodePath = Paths.get(selectedNodeCanonicalPath).normalize();
9597
if (nodePath.equals(psiPath)) {
98+
99+
// check if the file contents have changed - if so, add a file annotation
100+
boolean isDirty = true; // TODO (#14): Determine this dynamically.
101+
if(isDirty) {
102+
holder.newAnnotation(HighlightSeverity.WARNING, x)
103+
.fileLevel()
104+
.create();
105+
}
106+
96107
// We have confirmed that the file in the editor is the same as the file we have parsed
97108
selectedNode.getRange().ifPresent(range -> {
98109
final TextRange textRange = this.hls.javaparserRangeToIntellijOffsetRange(file, range);
@@ -102,6 +113,10 @@ public void apply(@NotNull PsiFile file, List<Object> infos, @NotNull Annotation
102113
.needsUpdateOnTyping(true)
103114
.create();
104115
});
116+
117+
118+
119+
105120
} else {
106121
System.out.println("paths do not match: " +
107122
"\n IJ: " + nodePath.toString() +

0 commit comments

Comments
 (0)