mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
feat: add preference to disable Java diagnostics (experimental)
This commit is contained in:
@@ -17,12 +17,13 @@
|
||||
|
||||
package com.itsaky.androidide.preferences
|
||||
|
||||
import android.content.Context
|
||||
import androidx.preference.Preference
|
||||
import com.itsaky.androidide.R
|
||||
import com.itsaky.androidide.preferences.internal.GOOGLE_CODE_STYLE
|
||||
import com.itsaky.androidide.preferences.internal.JAVA_DIAGNOSTICS_ENABLED
|
||||
import com.itsaky.androidide.preferences.internal.googleCodeStyle
|
||||
import com.itsaky.androidide.preferences.internal.isJavaDiagnosticsEnabled
|
||||
import com.itsaky.androidide.resources.R.drawable
|
||||
import com.itsaky.androidide.resources.R.string
|
||||
import com.itsaky.androidide.preferences.internal.GOOGLE_CODE_STYLE
|
||||
import com.itsaky.androidide.preferences.internal.googleCodeStyle
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
@@ -33,28 +34,27 @@ internal class JavaCodeConfigurations(
|
||||
) : IPreferenceGroup() {
|
||||
init {
|
||||
addPreference(GoogleCodeStyle())
|
||||
addPreference(JavaDiagnosticsEnabled())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Akash Yadav
|
||||
*/
|
||||
/** @author Akash Yadav */
|
||||
@Parcelize
|
||||
private class GoogleCodeStyle(
|
||||
override val key: String = GOOGLE_CODE_STYLE,
|
||||
override val title: Int = string.idepref_java_useGoogleStyle_title,
|
||||
override val summary: Int? = string.idepref_java_useGoogleStyle_summary,
|
||||
override val icon: Int? = drawable.ic_format_code,
|
||||
) : SwitchPreference() {
|
||||
|
||||
override fun onCreatePreference(context: Context): Preference {
|
||||
val preference = super.onCreatePreference(context) as androidx.preference.SwitchPreference
|
||||
preference.isChecked = googleCodeStyle
|
||||
return preference
|
||||
}
|
||||
|
||||
override fun onPreferenceChanged(preferece: Preference, newValue: Any?): Boolean {
|
||||
googleCodeStyle = newValue as Boolean? ?: googleCodeStyle
|
||||
return true
|
||||
}
|
||||
}
|
||||
) : SwitchPreference(getValue = ::googleCodeStyle::get, setValue = ::googleCodeStyle::set)
|
||||
|
||||
@Parcelize
|
||||
private class JavaDiagnosticsEnabled(
|
||||
override val key: String = JAVA_DIAGNOSTICS_ENABLED,
|
||||
override val title: Int = R.string.idepref_java_diagnosticEnabled_title,
|
||||
override val summary: Int? = R.string.idepref_java_diagnosticsEnabled_summary,
|
||||
override val icon: Int? = drawable.ic_compilation_error
|
||||
) :
|
||||
SwitchPreference(
|
||||
getValue = ::isJavaDiagnosticsEnabled::get,
|
||||
setValue = ::isJavaDiagnosticsEnabled::set
|
||||
)
|
||||
|
||||
@@ -38,6 +38,14 @@ public interface IServerSettings {
|
||||
* @return {@code true} if enabled, {@code false} otherwise.
|
||||
*/
|
||||
boolean completionsEnabled();
|
||||
|
||||
/**
|
||||
* Called by the language server to check if the source code analysis is enabled or not.
|
||||
* @return {@code true} if enabled, {@code false} otherwise.
|
||||
*/
|
||||
default boolean diagnosticsEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the language server to check if the code actions are enabled.
|
||||
|
||||
@@ -180,6 +180,10 @@ public class JavaLanguageServer implements ILanguageServer {
|
||||
|| !this.completionProvider.canComplete(params.getFile())) {
|
||||
return CompletionResult.EMPTY;
|
||||
}
|
||||
|
||||
if (diagnosticProvider.isAnalyzing()) {
|
||||
diagnosticProvider.cancel();
|
||||
}
|
||||
|
||||
this.completionProvider.reset(
|
||||
compiler, this.settings, this.cachedCompletion, this::updateCachedCompletion);
|
||||
@@ -233,7 +237,7 @@ public class JavaLanguageServer implements ILanguageServer {
|
||||
@NonNull
|
||||
@Override
|
||||
public DiagnosticResult analyze(@NonNull Path file) {
|
||||
if (!DocumentUtils.isJavaFile(file)) {
|
||||
if (!settings.diagnosticsEnabled() || !DocumentUtils.isJavaFile(file)) {
|
||||
return DiagnosticResult.NO_UPDATE;
|
||||
}
|
||||
|
||||
|
||||
+8
-2
@@ -16,7 +16,8 @@
|
||||
*/
|
||||
package com.itsaky.androidide.lsp.java.models;
|
||||
|
||||
import static com.itsaky.androidide.preferences.internal.EditorPreferencesKt.GOOGLE_CODE_STYLE;
|
||||
import static com.itsaky.androidide.preferences.internal.JavaPreferencesKt.GOOGLE_CODE_STYLE;
|
||||
import static com.itsaky.androidide.preferences.internal.JavaPreferencesKt.isJavaDiagnosticsEnabled;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
@@ -44,7 +45,12 @@ public class JavaServerSettings extends PrefBasedServerSettings {
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean diagnosticsEnabled() {
|
||||
return isJavaDiagnosticsEnabled();
|
||||
}
|
||||
|
||||
public JavaFormatterOptions getFormatterOptions() {
|
||||
return JavaFormatterOptions.builder().formatJavadoc(true).style(getStyle()).build();
|
||||
}
|
||||
|
||||
+12
@@ -78,6 +78,14 @@ class JavaDiagnosticProvider {
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
fun isAnalyzing(): Boolean {
|
||||
return this.analyzing.get()
|
||||
}
|
||||
|
||||
fun cancel() {
|
||||
this.analyzingThread?.cancel()
|
||||
}
|
||||
|
||||
fun clearTimestamp(file: Path) {
|
||||
analyzeTimestamps.remove(file)
|
||||
@@ -104,6 +112,10 @@ class JavaDiagnosticProvider {
|
||||
inner class AnalyzingThread(val compiler: JavaCompilerService, val file: Path) :
|
||||
Thread("JavaAnalyzerThread") {
|
||||
lateinit var result: DiagnosticResult
|
||||
|
||||
fun cancel() {
|
||||
ProgressManager.instance.cancel(this)
|
||||
}
|
||||
|
||||
override fun run() {
|
||||
result =
|
||||
|
||||
-1
@@ -18,7 +18,6 @@
|
||||
package com.itsaky.androidide.preferences.internal
|
||||
|
||||
const val COMPLETIONS_MATCH_LOWER = "idepref_editor_completions_matchLower"
|
||||
const val GOOGLE_CODE_STYLE = "idepref_editor_java_googleCodeStyle"
|
||||
|
||||
const val FLAG_WS_LEADING = "idepref_editor_wsLeading"
|
||||
const val FLAG_WS_TRAILING = "idepref_editor_wsTrailing"
|
||||
|
||||
+11
-1
@@ -17,8 +17,18 @@
|
||||
|
||||
package com.itsaky.androidide.preferences.internal
|
||||
|
||||
const val GOOGLE_CODE_STYLE = "idepref_editor_java_googleCodeStyle"
|
||||
const val JAVA_DIAGNOSTICS_ENABLED = "idepref_editor_java_diagnosticsEnabled"
|
||||
|
||||
var googleCodeStyle: Boolean
|
||||
get() = prefManager.getBoolean(GOOGLE_CODE_STYLE, false)
|
||||
set(value) {
|
||||
prefManager.putBoolean(GOOGLE_CODE_STYLE, value)
|
||||
}
|
||||
}
|
||||
|
||||
/** Whether diagnostics are enabled for the Java source files. */
|
||||
var isJavaDiagnosticsEnabled: Boolean
|
||||
get() = prefManager.getBoolean(JAVA_DIAGNOSTICS_ENABLED, true)
|
||||
set(value) {
|
||||
prefManager.putBoolean(JAVA_DIAGNOSTICS_ENABLED, value)
|
||||
}
|
||||
|
||||
@@ -538,4 +538,6 @@
|
||||
<string name="idepref_general_materialYou_summary">Enjoy an experience closer to your device (requires restart).</string>
|
||||
<string name="idepref_general_projectConfig">Project configuration</string>
|
||||
<string name="msg_app_launch_failed">Failed to launch application. See IDE logs for more info.</string>
|
||||
<string name="idepref_java_diagnosticEnabled_title">Diagnostics enabled</string>
|
||||
<string name="idepref_java_diagnosticsEnabled_summary">(EXPERIMENTAL) Whether the Java source files should be analyzed for errors or not.</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user