Skip to content

Commit

Permalink
Add check for correct TextRange
Browse files Browse the repository at this point in the history
  • Loading branch information
jlagerweij committed Apr 14, 2018
1 parent 529bd1e commit 8852e0a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ repositories {
}

group 'org.elm.tools.external'
version '1.2.0'
version '1.3.0'
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public AnnotatorFile collectInformation(@NotNull PsiFile file, @NotNull Editor e

/** Called first; in our case, just return file and do nothing */
@Override
@Nullable
@NotNull
public AnnotatorFile collectInformation(@NotNull PsiFile file) {
return new AnnotatorFile(file);
}
Expand Down Expand Up @@ -116,7 +116,11 @@ public void apply(@NotNull PsiFile file,
}

private void annotateForIssue(@NotNull AnnotationHolder holder, Document document, Problems issue, PsiFile file) {
TextRange selector = findAnnotationLocation(document, issue);
Optional<TextRange> optionalSelector = findAnnotationLocation(document, issue);
if (!optionalSelector.isPresent()) {
return;
}
final TextRange selector = optionalSelector.get();

Annotation annotation;
if (issue.type.equals("warning")) {
Expand All @@ -140,16 +144,20 @@ private void annotateForIssue(@NotNull AnnotationHolder holder, Document documen
}

@NotNull
private TextRange findAnnotationLocation(Document document, Problems issue) {
private Optional<TextRange> findAnnotationLocation(Document document, Problems issue) {
Region region = issue.subregion != null ? issue.subregion : issue.region;

int offsetStart = StringUtil.lineColToOffset(document.getText(), region.start.line - 1, region.start.column - 1);
int offsetEnd = StringUtil.lineColToOffset(document.getText(), region.end.line - 1, region.end.column - 1);

if (offsetStart == -1 && offsetEnd == -1) {
return Optional.empty();
}

if (isMultiLineRegion(region)) {
offsetEnd = document.getLineEndOffset(region.start.line - 1);
}
return new TextRange(offsetStart, offsetEnd);
return Optional.of(new TextRange(offsetStart, offsetEnd));
}

private boolean isMultiLineRegion(Region region) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin>
<id>org.elm.tools.external</id>
<name>Elm External Tools</name>
<version>1.2.0</version>
<version>1.3.0</version>
<vendor url="http://www.github.com/jlagerweij">
Jos Lagerweij
</vendor>
Expand All @@ -19,6 +19,7 @@

<change-notes><![CDATA[
<ul>
<li><b>1.3.0</b> <em>(2018-04-14)</em> - Add check for correct TextRange</li>
<li><b>1.2.0</b> <em>(2018-04-10)</em> - Fix issue with saving preferences.</li>
<li><b>1.1.0</b> <em>(2018-02-20)</em> - Add node path configuration. Visible only if the elm-make is a script.</li>
<li><b>1.0.1</b> <em>(2018-02-10)</em> - Minor name change</li>
Expand Down

0 comments on commit 8852e0a

Please sign in to comment.