Skip to content

Commit

Permalink
Update lsp4j dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
henryju authored and jblievremont committed Jun 8, 2020
1 parent e1f32ba commit 11eb31d
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<dependency>
<groupId>org.eclipse.lsp4j</groupId>
<artifactId>org.eclipse.lsp4j</artifactId>
<version>0.7.2</version>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>org.sonarsource.sonarlint.core</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public List<Either<Command, CodeAction>> computeCodeActions(CodeActionParams par
for (Diagnostic d : params.getContext().getDiagnostics()) {
cancelToken.checkCanceled();
if (SONARLINT_SOURCE.equals(d.getSource())) {
String ruleKey = d.getCode();
String ruleKey = d.getCode().getLeft();
cancelToken.checkCanceled();
String titleShowRuleDesc = String.format("Open description of SonarLint rule '%s'", ruleKey);
CodeAction actionShowRuleDesc = new CodeAction(titleShowRuleDesc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
import org.assertj.core.api.iterable.ThrowingExtractor;
Expand Down Expand Up @@ -405,4 +406,24 @@ protected List<Diagnostic> didSaveAndWaitForDiagnostics(String uri, String conte
protected ThrowingExtractor<? super MessageParams, String, RuntimeException> withoutTimestamp() {
return p -> p.getMessage().replaceAll("\\[(\\w*)\\s*-(.*)\\]", "[$1]");
}

protected Function<? super Diagnostic, ?> code() {
return d -> d.getCode().getLeft();
}

protected Function<? super Diagnostic, ?> endCharacter() {
return d -> d.getRange().getEnd().getCharacter();
}

protected Function<? super Diagnostic, ?> endLine() {
return d -> d.getRange().getEnd().getLine();
}

protected Function<? super Diagnostic, ?> startCharacter() {
return d -> d.getRange().getStart().getCharacter();
}

protected Function<? super Diagnostic, ?> startLine() {
return d -> d.getRange().getStart().getLine();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void analyzeSimpleJavaFileReuseCachedClasspath() throws Exception {
List<Diagnostic> diagnostics = didOpenAndWaitForDiagnostics(uri, "java", "public class Foo {\n public static void main() {\n // System.out.println(\"foo\");\n}\n}");

assertThat(diagnostics)
.extracting("range.start.line", "range.start.character", "range.end.line", "range.end.character", "code", "source", "message", "severity")
.extracting(startLine(), startCharacter(), endLine(), endCharacter(), code(), Diagnostic::getSource, Diagnostic::getMessage, Diagnostic::getSeverity)
.containsExactlyInAnyOrder(
tuple(0, 13, 0, 16, "java:S1118", "sonarlint", "Add a private constructor to hide the implicit public one.", DiagnosticSeverity.Warning),
tuple(2, 0, 2, 31, "java:S125", "sonarlint", "This block of commented-out lines of code should be removed.", DiagnosticSeverity.Warning));
Expand All @@ -98,7 +98,7 @@ public void analyzeSimpleJavaFileReuseCachedClasspath() throws Exception {
diagnostics = didChangeAndWaitForDiagnostics(uri, "public class Foo {\n public static void main() {\n System.out.println(\"foo\");\n}\n}");

assertThat(diagnostics)
.extracting("range.start.line", "range.start.character", "range.end.line", "range.end.character", "code", "source", "message", "severity")
.extracting(startLine(), startCharacter(), endLine(), endCharacter(), code(), Diagnostic::getSource, Diagnostic::getMessage, Diagnostic::getSeverity)
.containsExactlyInAnyOrder(
tuple(0, 13, 0, 16, "java:S1118", "sonarlint", "Add a private constructor to hide the implicit public one.", DiagnosticSeverity.Warning),
tuple(2, 2, 2, 12, "java:S106", "sonarlint", "Replace this use of System.out or System.err by a logger.", DiagnosticSeverity.Warning));
Expand All @@ -120,7 +120,7 @@ public void analyzeSimpleJavaTestFileOnOpen() throws Exception {
"import org.junit.Test;\npublic class FooTest {\n @Test\n public void test() {\n String s = \"foo\";\n}\n}");

assertThat(diagnostics)
.extracting("range.start.line", "range.start.character", "range.end.line", "range.end.character", "code", "source", "message", "severity")
.extracting(startLine(), startCharacter(), endLine(), endCharacter(), code(), Diagnostic::getSource, Diagnostic::getMessage, Diagnostic::getSeverity)
.containsExactlyInAnyOrder(
tuple(3, 14, 3, 18, "java:S2699", "sonarlint", "Add at least one assertion to this test case.", DiagnosticSeverity.Error));
}
Expand Down Expand Up @@ -154,7 +154,7 @@ public void testClassPathUpdateTriggersNewAnalysis() throws Exception {
}

assertThat(diagnostics)
.extracting("range.start.line", "range.start.character", "range.end.line", "range.end.character", "code", "source", "message", "severity")
.extracting(startLine(), startCharacter(), endLine(), endCharacter(), code(), Diagnostic::getSource, Diagnostic::getMessage, Diagnostic::getSeverity)
.containsExactlyInAnyOrder(
tuple(3, 14, 3, 18, "java:S2699", "sonarlint", "Add at least one assertion to this test case.", DiagnosticSeverity.Error));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void analyzeSimpleJsFileOnOpen() throws Exception {
List<Diagnostic> diagnostics = didOpenAndWaitForDiagnostics(uri, "javascript", "function foo() {\n alert('toto');\n var plouf = 0;\n}");

assertThat(diagnostics)
.extracting("range.start.line", "range.start.character", "range.end.line", "range.end.character", "code", "source", "message", "severity")
.extracting(startLine(), startCharacter(), endLine(), endCharacter(), code(), Diagnostic::getSource, Diagnostic::getMessage, Diagnostic::getSeverity)
.containsExactlyInAnyOrder(
tuple(1, 2, 1, 15, "javascript:S1442", "sonarlint", "Unexpected alert.", DiagnosticSeverity.Information),
tuple(2, 6, 2, 11, "javascript:UnusedVariable", "sonarlint", "Remove the declaration of the unused 'plouf' variable.",
Expand All @@ -109,7 +109,7 @@ public void analyzeSimpleJsFileWithCustomRuleConfig() throws Exception {

List<Diagnostic> diagnostics = didOpenAndWaitForDiagnostics(uri, "javascript", jsSource);
assertThat(diagnostics)
.extracting("range.start.line", "range.start.character", "range.end.line", "range.end.character", "code", "source", "message", "severity")
.extracting(startLine(), startCharacter(), endLine(), endCharacter(), code(), Diagnostic::getSource, Diagnostic::getMessage, Diagnostic::getSeverity)
.containsExactlyInAnyOrder(
tuple(2, 2, 2, 15, "javascript:S1442", "sonarlint", "Unexpected alert.", DiagnosticSeverity.Information),
tuple(3, 6, 3, 11, "javascript:UnusedVariable", "sonarlint", "Remove the declaration of the unused 'plouf' variable.", DiagnosticSeverity.Information));
Expand All @@ -129,7 +129,7 @@ public void analyzeSimpleJsFileWithCustomRuleConfig() throws Exception {
assertTrue(client.diagnosticsLatch.await(1, TimeUnit.MINUTES));

assertThat(client.getDiagnostics(uri))
.extracting("range.start.line", "range.start.character", "range.end.line", "range.end.character", "code", "source", "message", "severity")
.extracting(startLine(), startCharacter(), endLine(), endCharacter(), code(), Diagnostic::getSource, Diagnostic::getMessage, Diagnostic::getSeverity)
.containsExactlyInAnyOrder(
tuple(2, 2, 2, 15, "javascript:S1442", "sonarlint", "Unexpected alert.", DiagnosticSeverity.Information),
tuple(1, 1, 1, 2, "javascript:S1105", "sonarlint", "Move this open curly brace to the end of the previous line.", DiagnosticSeverity.Information)
Expand All @@ -146,7 +146,7 @@ public void analyzeSimpleTsFileOnOpen() throws Exception {
List<Diagnostic> diagnostics = didOpenAndWaitForDiagnostics(uri, "typescript", "function foo() {\n if(bar() && bar()) { return 42; }\n}");

assertThat(diagnostics)
.extracting("range.start.line", "range.start.character", "range.end.line", "range.end.character", "code", "source", "message", "severity")
.extracting(startLine(), startCharacter(), endLine(), endCharacter(), code(), Diagnostic::getSource, Diagnostic::getMessage, Diagnostic::getSeverity)
.containsExactly(tuple(1, 4, 1, 18, "typescript:S1764", "sonarlint", "Correct one of the identical sub-expressions on both sides of operator \"&&\"",
DiagnosticSeverity.Warning));
}
Expand All @@ -158,7 +158,7 @@ public void analyzeSimplePythonFileOnOpen() throws Exception {
List<Diagnostic> diagnostics = didOpenAndWaitForDiagnostics(uri, "python", "def foo():\n print 'toto'\n");

assertThat(diagnostics)
.extracting("range.start.line", "range.start.character", "range.end.line", "range.end.character", "code", "source", "message", "severity")
.extracting(startLine(), startCharacter(), endLine(), endCharacter(), code(), Diagnostic::getSource, Diagnostic::getMessage, Diagnostic::getSeverity)
.containsExactly(
tuple(1, 2, 1, 7, "python:PrintStatementUsage", "sonarlint", "Replace print statement by built-in function.", DiagnosticSeverity.Warning));
}
Expand All @@ -170,7 +170,7 @@ public void analyzeSimplePhpFileOnOpen() throws Exception {
List<Diagnostic> diagnostics = didOpenAndWaitForDiagnostics(uri, "php", "<?php\nfunction foo() {\n echo(\"Hello\");\n}\n?>");

assertThat(diagnostics)
.extracting("range.start.line", "range.start.character", "range.end.line", "range.end.character", "code", "source", "message", "severity")
.extracting(startLine(), startCharacter(), endLine(), endCharacter(), code(), Diagnostic::getSource, Diagnostic::getMessage, Diagnostic::getSeverity)
.containsExactly(tuple(2, 2, 2, 6, "php:S2041", "sonarlint", "Remove the parentheses from this \"echo\" call.", DiagnosticSeverity.Error));
}

Expand All @@ -181,7 +181,7 @@ public void analyzeSimpleHtmlFileOnOpen() throws Exception {
List<Diagnostic> diagnostics = didOpenAndWaitForDiagnostics(uri, "html", "<html><body></body></html>");

assertThat(diagnostics)
.extracting("range.start.line", "range.start.character", "range.end.line", "range.end.character", "code", "source", "message", "severity")
.extracting(startLine(), startCharacter(), endLine(), endCharacter(), code(), Diagnostic::getSource, Diagnostic::getMessage, Diagnostic::getSeverity)
.containsExactlyInAnyOrder(
tuple(0, 0, 0, 6, "Web:DoctypePresenceCheck", "sonarlint", "Insert a <!DOCTYPE> declaration to before this <html> tag.",
DiagnosticSeverity.Warning),
Expand All @@ -197,7 +197,7 @@ public void analyzeSimpleJspFileOnOpen() throws Exception {
List<Diagnostic> diagnostics = didOpenAndWaitForDiagnostics(uri, "jsp", "<html><body></body></html>");

assertThat(diagnostics)
.extracting("range.start.line", "range.start.character", "range.end.line", "range.end.character", "code", "source", "message", "severity")
.extracting(startLine(), startCharacter(), endLine(), endCharacter(), code(), Diagnostic::getSource, Diagnostic::getMessage, Diagnostic::getSeverity)
.containsExactlyInAnyOrder(
tuple(0, 0, 0, 6, "Web:DoctypePresenceCheck", "sonarlint", "Insert a <!DOCTYPE> declaration to before this <html> tag.",
DiagnosticSeverity.Warning),
Expand Down Expand Up @@ -239,7 +239,7 @@ public void analyzeSimpleJsFileOnChange() throws Exception {
List<Diagnostic> diagnostics = didChangeAndWaitForDiagnostics(uri, "function foo() {\n alert('toto');\n}");

assertThat(diagnostics)
.extracting("range.start.line", "range.start.character", "range.end.line", "range.end.character", "code", "source", "message", "severity")
.extracting(startLine(), startCharacter(), endLine(), endCharacter(), code(), Diagnostic::getSource, Diagnostic::getMessage, Diagnostic::getSeverity)
.containsExactly(tuple(1, 2, 1, 15, "javascript:S1442", "sonarlint", "Unexpected alert.", DiagnosticSeverity.Information));
}

Expand All @@ -257,7 +257,7 @@ public void delayAnalysisOnChange() throws Exception {
if (client.diagnosticsLatch.await(1, TimeUnit.MINUTES)) {
List<Diagnostic> diagnostics = client.getDiagnostics(uri);
assertThat(diagnostics)
.extracting("range.start.line", "range.start.character", "range.end.line", "range.end.character", "code", "source", "message", "severity")
.extracting(startLine(), startCharacter(), endLine(), endCharacter(), code(), Diagnostic::getSource, Diagnostic::getMessage, Diagnostic::getSeverity)
.containsExactly(tuple(1, 2, 1, 15, "javascript:S1442", "sonarlint", "Unexpected alert.", DiagnosticSeverity.Information),
tuple(2, 2, 2, 15, "javascript:S1442", "sonarlint", "Unexpected alert.", DiagnosticSeverity.Information));
} else {
Expand All @@ -272,7 +272,7 @@ public void analyzeSimpleJsFileOnSave() throws Exception {
List<Diagnostic> diagnostics = didSaveAndWaitForDiagnostics(uri, "function foo() {\n alert('toto');\n}");

assertThat(diagnostics)
.extracting("range.start.line", "range.start.character", "range.end.line", "range.end.character", "code", "source", "message", "severity")
.extracting(startLine(), startCharacter(), endLine(), endCharacter(), code(), Diagnostic::getSource, Diagnostic::getMessage, Diagnostic::getSeverity)
.containsExactly(tuple(1, 2, 1, 15, "javascript:S1442", "sonarlint", "Unexpected alert.", DiagnosticSeverity.Information));
}

Expand All @@ -285,7 +285,7 @@ public void diagnosticRelatedInfos() throws Exception {
"foo(\"a\", \"b\", \"c\");\n");

assertThat(diagnostics)
.extracting("range.start.line", "range.start.character", "range.end.line", "range.end.character", "code", "source", "message", "severity")
.extracting(startLine(), startCharacter(), endLine(), endCharacter(), code(), Diagnostic::getSource, Diagnostic::getMessage, Diagnostic::getSeverity)
.containsExactly(
tuple(2, 0, 2, 18, "javascript:S930", "sonarlint", "This function expects 2 arguments, but 3 were provided.", DiagnosticSeverity.Error));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void analyzeSimpleJsFileOnOpenWithoutTypescriptCompilerPath() throws Exce
List<Diagnostic> diagnostics = didOpenAndWaitForDiagnostics(uri, "javascript", "function foo() {\n alert('toto');\n var plouf = 0;\n}");

assertThat(diagnostics)
.extracting("range.start.line", "range.start.character", "range.end.line", "range.end.character", "code", "source", "message", "severity")
.extracting(startLine(), startCharacter(), endLine(), endCharacter(), code(), Diagnostic::getSource, Diagnostic::getMessage, Diagnostic::getSeverity)
.containsExactlyInAnyOrder(
tuple(1, 2, 1, 15, "javascript:S1442", "sonarlint", "Unexpected alert.", DiagnosticSeverity.Information),
tuple(2, 6, 2, 11, "javascript:UnusedVariable", "sonarlint", "Remove the declaration of the unused 'plouf' variable.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void analyzeSimpleJsFileOnOpen() throws Exception {
List<Diagnostic> diagnostics = didOpenAndWaitForDiagnostics(uri, "javascript", "function foo() {\n alert('toto');\n var plouf = 0;\n}");

assertThat(diagnostics)
.extracting("range.start.line", "range.start.character", "range.end.line", "range.end.character", "code", "source", "message", "severity")
.extracting(startLine(), startCharacter(), endLine(), endCharacter(), code(), Diagnostic::getSource, Diagnostic::getMessage, Diagnostic::getSeverity)
.containsExactlyInAnyOrder(
tuple(1, 2, 1, 15, "javascript:S1442", "sonarlint", "Unexpected alert.", DiagnosticSeverity.Information),
tuple(2, 6, 2, 11, "javascript:UnusedVariable", "sonarlint", "Remove the declaration of the unused 'plouf' variable.",
Expand Down

0 comments on commit 11eb31d

Please sign in to comment.