Skip to content

Commit

Permalink
refact: address Sonar findings
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed Aug 24, 2024
1 parent fa1aef4 commit 0b8893e
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public boolean isUserEnabled() {
}

public boolean isExtensionEnabled(@Nullable URI uri) {
return enablement != null ? enablement.evaluate(uri) : true;
return enablement != null && enablement.evaluate(uri);
}

public @Nullable EnablementTester getEnablementCondition() {
Expand Down
16 changes: 7 additions & 9 deletions org.eclipse.lsp4e/src/org/eclipse/lsp4e/LSPEclipseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1055,15 +1055,13 @@ private static boolean applyWorkspaceEditIfSingleOpenFile(WorkspaceEdit wsEdit)
.filter(Objects::nonNull)
.findFirst();

doc.ifPresent(document -> {
UI.getDisplay().syncExec(() -> {
try {
LSPEclipseUtils.applyEdits(document, firstDocumentEdits);
} catch (BadLocationException ex) {
LanguageServerPlugin.logError(ex);
}
});
});
doc.ifPresent(document -> UI.getDisplay().syncExec(() -> {
try {
LSPEclipseUtils.applyEdits(document, firstDocumentEdits);
} catch (BadLocationException ex) {
LanguageServerPlugin.logError(ex);
}
}));
return doc.isPresent();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.UnaryOperator;

import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.contentassist.CompletionProposal;
Expand Down Expand Up @@ -46,7 +47,7 @@ class CompletionSnippetParser {
* @param insertionOffset the document offset this completion will be applied to
* @param getVariableValue a function that resolves variable values
*/
public CompletionSnippetParser(IDocument document, String snippetText, int insertionOffset, Function<String, String> getVariableValue) {
public CompletionSnippetParser(IDocument document, String snippetText, int insertionOffset, UnaryOperator<String> getVariableValue) {
this.document = document;
this.snippetText = snippetText;
this.insertionOffset = insertionOffset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ public LSContentAssistProcessor(boolean errorAsCompletionItem, boolean incomplet
.collectAll((w, ls) -> cancellationSupport.execute(ls.getTextDocumentService().completion(param)) //
.thenAccept(completion -> {
boolean isIncomplete = completion != null && completion.isRight()
? completion.getRight().isIncomplete()
: false;
&& completion.getRight().isIncomplete();
proposals.addAll(toProposals(document, offset, completion, w, cancellationSupport,
isIncomplete));
if (isIncomplete) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ protected void execute(ExecutionEvent event, ITextEditor textEditor) {
return;

try {
formatter.requestFormatting(doc, textSelection)
.thenAcceptAsync(result -> {
result.ifPresent(edits -> {
formatter.requestFormatting(doc, textSelection) //
.thenAcceptAsync(result -> result.ifPresent(edits -> {
try {
edits.apply();
} catch (final ConcurrentModificationException ex) {
Expand All @@ -58,8 +57,7 @@ protected void execute(ExecutionEvent event, ITextEditor textEditor) {
} catch (BadLocationException e) {
LanguageServerPlugin.logError(e);
}
});
}, UI.getDisplay());
}), UI.getDisplay());
} catch (BadLocationException e) {
LanguageServerPlugin.logError(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void setLabel(final @Nullable String label) {

protected static @Nullable String getInlayHintString(InlayHint inlayHint) {
Either<String, @Nullable List<InlayHintLabelPart>> label = inlayHint.getLabel();
return label.map(Function.identity(), (parts) -> {
return label.map(Function.identity(), parts -> {
if (parts == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ private void updateLinkedEditing(int offset) {
linkedModel.exit(ILinkedModeListener.EXIT_ALL);
this.linkedModel = null;
}
collectLinkedEditingRanges(document, offset).thenAcceptAsync(optional -> {
optional.ifPresent(this::applyLinkedEdit);
}).exceptionally(e -> {
if (!CancellationUtil.isRequestCancelledException(e)) { // do not report error if the server has cancelled the request
LanguageServerPlugin.logError(e);
}
return null;
});
collectLinkedEditingRanges(document, offset)
.thenAcceptAsync(optional -> optional.ifPresent(this::applyLinkedEdit)) //
.exceptionally(e -> {
if (!CancellationUtil.isRequestCancelledException(e)) { // do not report error if the server has cancelled the request
LanguageServerPlugin.logError(e);
}
return null;
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public StyledString getStyledText(@Nullable Object element) {
if (element instanceof SymbolInformation symbolInformation) {
name = symbolInformation.getName();
kind = symbolInformation.getKind();
deprecated = isDeprecated(symbolInformation.getTags()) || symbolInformation.getDeprecated() == null ? false: symbolInformation.getDeprecated();
deprecated = isDeprecated(symbolInformation.getTags()) || Boolean.TRUE.equals(symbolInformation.getDeprecated());
try {
location = URI.create(symbolInformation.getLocation().getUri());
} catch (IllegalArgumentException e) {
Expand All @@ -299,13 +299,13 @@ public StyledString getStyledText(@Nullable Object element) {
name = documentSymbol.getName();
kind = documentSymbol.getKind();
detail = documentSymbol.getDetail();
deprecated = isDeprecated(documentSymbol.getTags()) || documentSymbol.getDeprecated() == null ? false: documentSymbol.getDeprecated();
deprecated = isDeprecated(documentSymbol.getTags()) || Boolean.TRUE.equals(documentSymbol.getDeprecated());
} else if (element instanceof DocumentSymbolWithURI symbolWithURI) {
name = symbolWithURI.symbol.getName();
kind = symbolWithURI.symbol.getKind();
detail = symbolWithURI.symbol.getDetail();
location = symbolWithURI.uri;
deprecated = isDeprecated(symbolWithURI.symbol.getTags()) || symbolWithURI.symbol.getDeprecated() == null ? false: symbolWithURI.symbol.getDeprecated();
deprecated = isDeprecated(symbolWithURI.symbol.getTags()) || Boolean.TRUE.equals(symbolWithURI.symbol.getDeprecated());
}
if (name != null) {
if (deprecated) {
Expand Down

0 comments on commit 0b8893e

Please sign in to comment.