refactor(editor): reformat IDEEditor

This commit is contained in:
Akash Yadav
2023-07-08 23:51:08 +05:30
parent 8f4fdc3210
commit 907c6b89a3
@@ -117,7 +117,7 @@ public class IDEEditor extends CodeEditor implements IEditor, ILspEditor {
// we do not use getSignatureHelpWindow() to avoid initializing the window unnecessarily
if (languageClient == null || cursor == null || cursor.isSelected() ||
(signatureHelpWindow != null && signatureHelpWindow.isShowing())) {
(signatureHelpWindow != null && signatureHelpWindow.isShowing())) {
return;
}
@@ -231,7 +231,7 @@ public class IDEEditor extends CodeEditor implements IEditor, ILspEditor {
}
final var openEvent = new DocumentOpenEvent(getFile().toPath(), getText().toString(),
fileVersion = 0);
fileVersion = 0);
// Notify FileManager first
FileManager.INSTANCE.onDocumentOpen(openEvent);
@@ -252,12 +252,12 @@ public class IDEEditor extends CodeEditor implements IEditor, ILspEditor {
public void signatureHelp() {
if (languageServer != null && getFile() != null) {
final CompletableFuture<SignatureHelp> future = CompletableFuture.supplyAsync(
() -> languageServer.signatureHelp(
new SignatureHelpParams(getFile().toPath(), getCursorLSPPosition())));
() -> languageServer.signatureHelp(
new SignatureHelpParams(getFile().toPath(), getCursorLSPPosition())));
future.whenComplete((help, error) -> {
if (help == null || languageClient == null || future.isCancelled() ||
future.isCompletedExceptionally()) {
future.isCompletedExceptionally()) {
LOG.error("An error occurred while finding signature help", error);
return;
}
@@ -310,7 +310,7 @@ public class IDEEditor extends CodeEditor implements IEditor, ILspEditor {
public void setSelection(@NonNull Range range) {
if (isValidPosition(range.getStart(), true) && isValidPosition(range.getEnd(), true)) {
setSelectionRegion(range.getStart().getLine(), range.getStart().getColumn(),
range.getEnd().getLine(), range.getEnd().getColumn());
range.getEnd().getLine(), range.getEnd().getColumn());
} else {
LOG.warn("Selection range is invalid", range);
}
@@ -380,7 +380,7 @@ public class IDEEditor extends CodeEditor implements IEditor, ILspEditor {
final var end = range.getEnd();
return isValidPosition(start, allowColumnEqual) && isValidPosition(end, allowColumnEqual) &&
start.compareTo(end) < 0; // make sure start position is before end position
start.compareTo(end) < 0; // make sure start position is before end position
}
/**
@@ -396,7 +396,7 @@ public class IDEEditor extends CodeEditor implements IEditor, ILspEditor {
}
return isValidLine(position.getLine()) &&
isValidColumn(position.getLine(), position.getColumn(), allowColumnEqual);
isValidColumn(position.getLine(), position.getColumn(), allowColumnEqual);
}
/**
@@ -499,20 +499,20 @@ public class IDEEditor extends CodeEditor implements IEditor, ILspEditor {
}
final ProgressDialog pd = ProgressDialog.show(getContext(), null,
getContext().getString(string.msg_finding_definition));
getContext().getString(string.msg_finding_definition));
try {
final CompletableFuture<DefinitionResult> future = CompletableFuture.supplyAsync(() -> {
final var params = new com.itsaky.androidide.lsp.models.DefinitionParams(getFile().toPath(),
new com.itsaky.androidide.models.Position(getCursor().getLeftLine(),
getCursor().getLeftColumn()));
new Position(getCursor().getLeftLine(),
getCursor().getLeftColumn()));
return languageServer.findDefinition(params);
});
future.whenComplete((result, error) -> {
if (result == null || languageClient == null || future.isCancelled() ||
future.isCompletedExceptionally()) {
future.isCompletedExceptionally()) {
LOG.error("An error occurred while finding definition", error);
showDefinitionNotFound(pd);
return;
@@ -534,7 +534,7 @@ public class IDEEditor extends CodeEditor implements IEditor, ILspEditor {
return;
}
languageClient.showDocument(
new ShowDocumentParams(location.getFile(), location.getRange()));
new ShowDocumentParams(location.getFile(), location.getRange()));
} else {
languageClient.showLocations(locations);
}
@@ -586,15 +586,14 @@ public class IDEEditor extends CodeEditor implements IEditor, ILspEditor {
}
@SuppressWarnings("deprecation") final ProgressDialog pd = ProgressDialog.show(getContext(),
null, getContext().getString(string.msg_finding_references));
null, getContext().getString(string.msg_finding_references));
try {
final var future = CompletableFuture.supplyAsync(() -> {
final var referenceParams = new ReferenceParams(getFile().toPath(),
new com.itsaky.androidide.models.Position(getCursor().getLeftLine(),
getCursor().getLeftColumn()), true);
return languageServer.findReferences(referenceParams);
});
final var referenceParams = new ReferenceParams(getFile().toPath(),
getCursorLSPPosition(), true);
final var future = CompletableFuture.supplyAsync(
() -> languageServer.findReferences(referenceParams));
future.whenComplete((result, error) -> onFindReferencesResult(pd, future, result, error));
} catch (Throwable th) {
@@ -605,11 +604,11 @@ public class IDEEditor extends CodeEditor implements IEditor, ILspEditor {
@SuppressWarnings("deprecation")
private void onFindReferencesResult(final ProgressDialog pd,
final CompletableFuture<ReferenceResult> future,
final ReferenceResult result, final Throwable error
final CompletableFuture<ReferenceResult> future,
final ReferenceResult result, final Throwable error
) {
if (result == null || languageClient == null || future.isCancelled() ||
future.isCompletedExceptionally()) {
future.isCompletedExceptionally()) {
LOG.error("An error occurred while finding references", error);
showReferencesNotFound(pd);
return;
@@ -661,10 +660,10 @@ public class IDEEditor extends CodeEditor implements IEditor, ILspEditor {
//noinspection deprecation
final var pd = ProgressDialog.show(getContext(), null,
getContext().getString(string.please_wait), true, false);
getContext().getString(string.please_wait), true, false);
final CompletableFuture<Range> future = CompletableFuture.supplyAsync(
() -> languageServer.expandSelection(
new ExpandSelectionParams(getFile().toPath(), getCursorLSPRange())));
() -> languageServer.expandSelection(
new ExpandSelectionParams(getFile().toPath(), getCursorLSPRange())));
future.whenComplete(((range, throwable) -> {
pd.dismiss();
@@ -681,7 +680,7 @@ public class IDEEditor extends CodeEditor implements IEditor, ILspEditor {
@Override
protected void onFocusChanged(final boolean gainFocus, final int direction,
@Nullable final Rect previouslyFocusedRect
@Nullable final Rect previouslyFocusedRect
) {
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
if (!gainFocus) {
@@ -741,7 +740,7 @@ public class IDEEditor extends CodeEditor implements IEditor, ILspEditor {
}
final var changeLength = event.getChangedText().length();
if (event.getAction() != ContentChangeEvent.ACTION_INSERT || changeLength > 0 &&
changeLength <= 2) { // changeLength will be 2 as '(' and ')' are inserted at the same time
changeLength <= 2) { // changeLength will be 2 as '(' and ')' are inserted at the same time
return;
}
@@ -772,11 +771,11 @@ public class IDEEditor extends CodeEditor implements IEditor, ILspEditor {
final var start = event.getChangeStart();
final var end = event.getChangeEnd();
final var changeRange = new Range(new Position(start.line, start.column, start.index),
new Position(end.line, end.column, end.index));
new Position(end.line, end.column, end.index));
final var changedText = event.getChangedText().toString();
final var changeEvent = new DocumentChangeEvent(file, changedText, getText().toString(),
++fileVersion, type, changeDelta, changeRange);
++fileVersion, type, changeDelta, changeRange);
// Notify FileManager first
FileManager.INSTANCE.onDocumentContentChange(changeEvent);
@@ -785,7 +784,7 @@ public class IDEEditor extends CodeEditor implements IEditor, ILspEditor {
public static int createInputFlags() {
var flags = EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE |
EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
if (getVisiblePasswordFlag()) {
flags |= EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
}
@@ -804,11 +803,11 @@ public class IDEEditor extends CodeEditor implements IEditor, ILspEditor {
public void analyze() {
if (languageServer != null && getFile() != null && getEditorLanguage() instanceof IDELanguage) {
CompletableFuture.supplyAsync(() -> languageServer.analyze(getFile().toPath()))
.whenComplete((diagnostics, throwable) -> {
if (languageClient != null) {
languageClient.publishDiagnostics(diagnostics);
}
});
.whenComplete((diagnostics, throwable) -> {
if (languageClient != null) {
languageClient.publishDiagnostics(diagnostics);
}
});
}
}
@@ -929,7 +928,7 @@ public class IDEEditor extends CodeEditor implements IEditor, ILspEditor {
@Override
public void beginSearchMode() {
throw new UnsupportedOperationException(
"Search ActionMode is not supported. Use CodeEditorView.beginSearch() instead.");
"Search ActionMode is not supported. Use CodeEditorView.beginSearch() instead.");
}
public void dispatchDocumentSaveEvent() {
@@ -970,13 +969,13 @@ public class IDEEditor extends CodeEditor implements IEditor, ILspEditor {
}
public void applyTreeSitterLang(final TreeSitterLanguage language, final String type,
@Nullable SchemeAndroidIDE scheme
@Nullable SchemeAndroidIDE scheme
) {
applyTreeSitterLang(((Language) language), type, scheme);
}
private void applyTreeSitterLang(final Language language, final String type,
@Nullable SchemeAndroidIDE scheme
@Nullable SchemeAndroidIDE scheme
) {
if (scheme == null) {
LOG.error("Failed to read current color scheme");
@@ -984,7 +983,7 @@ public class IDEEditor extends CodeEditor implements IEditor, ILspEditor {
}
if (scheme instanceof IDEColorScheme &&
((IDEColorScheme) scheme).getLanguageScheme(type) == null) {
((IDEColorScheme) scheme).getLanguageScheme(type) == null) {
LOG.warn("Color scheme does not support file type '" + type + "'");
scheme = SchemeAndroidIDE.newInstance(getContext());
}