Skip to content

Commit

Permalink
Fix crash on opening kotlin files and update dependencies
Browse files Browse the repository at this point in the history
Tested-by: Pranav Purwar <purwarpranav80@gmail.com>
Signed-off-by: PranavPurwar <purwarpranav80@gmail.com>
  • Loading branch information
PranavPurwar committed Mar 24, 2024
1 parent 1ab0b9c commit c9b5491
Show file tree
Hide file tree
Showing 27 changed files with 353 additions and 297 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 36 additions & 25 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,34 @@ android {
resolutionStrategy.force("com.squareup.okhttp3:okhttp:4.12.0")
}

packagingOptions.resources.excludes.addAll(
listOf(
"META-INF/INDEX.LIST",
"META-INF/eclipse.inf",
"META-INF/CHANGES",
"META-INF/README.md",
"META-INF/DEPENDENCIES",
"about_files/LICENSE-2.0.txt",
"META-INF/AL2.0",
"META-INF/LGPL2.1",
"plugin.xml",
"plugin.properties",
"about.mappings",
"about.properties",
"about.ini",
"src/*"
)
)
packaging {
resources {
excludes.addAll(
listOf(
"META-INF/INDEX.LIST",
"META-INF/eclipse.inf",
"META-INF/CHANGES",
"META-INF/README.md",
"META-INF/DEPENDENCIES",
"about_files/LICENSE-2.0.txt",
"META-INF/AL2.0",
"META-INF/LGPL2.1",
"plugin.xml",
"plugin.properties",
"about.mappings",
"about.properties",
"about.ini",
"src/*",
)
)

pickFirsts.addAll(
listOf(
"OSGI-INF/l10n/plugin.properties"
)
)
}
}
buildFeatures {
buildConfig = true
}
Expand Down Expand Up @@ -182,14 +192,14 @@ dependencies {
implementation("androidx.core:core-splashscreen:1.1.0-alpha02")
implementation("androidx.documentfile:documentfile:1.1.0-alpha01")
implementation("androidx.fragment:fragment-ktx:1.7.0-beta01")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.0-alpha03")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.0-alpha03")
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01")
implementation("androidx.viewpager2:viewpager2:1.1.0-beta02")
implementation("androidx.activity:activity-ktx:1.9.0-beta01")
implementation("androidx.startup:startup-runtime:1.2.0-alpha02")

val editorVersion = "0.22.2-3e1c25a-SNAPSHOT"
val editorVersion = "0.23.4"
//noinspection GradleDependency
implementation("io.github.Rosemoe.sora-editor:editor:$editorVersion")
//noinspection GradleDependency
Expand All @@ -198,8 +208,10 @@ dependencies {
implementation("io.github.Rosemoe.sora-editor:language-treesitter:$editorVersion") {
isTransitive = false
}
implementation("com.itsaky.androidide.treesitter:android-tree-sitter:4.0.0")
implementation("com.itsaky.androidide.treesitter:tree-sitter-java:4.0.0")
implementation("com.itsaky.androidide.treesitter:android-tree-sitter:4.3.1")
implementation("com.itsaky.androidide.treesitter:tree-sitter-java:4.3.1")
implementation("com.itsaky.androidide.treesitter:tree-sitter-kotlin:4.3.1")

implementation("io.github.itsaky:nb-javac-android:17.0.0.3")

implementation("org.eclipse.jgit:org.eclipse.jgit:5.13.2.202306221912-r")
Expand All @@ -215,13 +227,12 @@ dependencies {
implementation("de.maxr1998:modernandroidpreferences:2.4.0-beta1")

implementation("com.github.Cosmic-Ide.kotlinc-android:kotlinc:2a0a6a7291")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.0-RC2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1-Beta")
implementation("org.lsposed.hiddenapibypass:hiddenapibypass:4.3")
implementation("org.slf4j:slf4j-simple:2.1.0-alpha1")

implementation("com.google.ai.client.generativeai:generativeai:0.2.2")


val shizukuVersion = "13.1.5"
implementation("dev.rikka.shizuku:api:$shizukuVersion")

Expand Down
84 changes: 42 additions & 42 deletions app/src/main/assets/tree-sitter-queries/java/indents.scm
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
; Query for computing indents in tree-sitter language
; Capture names can be 'indent' or 'outdent'. Any other capture name will be ignored
; indent - increments indentation
; outdent - decrements indentation

(class_body
"{" @indent
"}" @outdent)

(enum_body
"{" @indent
"}" @outdent)

(interface_body
"{" @indent
"}" @outdent)

(constructor_body
"{" @indent
"}" @outdent)

(block
"{" @indent
"}" @outdent)

(switch_block
"{" @indent
"}" @outdent)

(array_initializer
"{" @indent
"}" @outdent)

(formal_parameters
"(" @indent
")" @outdent)

(argument_list
"(" @indent
")" @outdent)

; (expression_statement (method_invocation) @indent)
; https://github.com/nvim-treesitter/nvim-treesitter/blob/57a8acf0c4ed5e7f6dda83c3f9b073f8a99a70f9/queries/java/indents.scm

; format-ignore
[
; ... refers to the portion that this indent query will have effects on
(class_body) ; { ... } of `class X`
(enum_body) ; { ... } of `enum X`
(interface_body) ; { ... } of `interface X`
(constructor_body) ; { `modifier` X() {...} } inside `class X`
(annotation_type_body) ; { ... } of `@interface X`
(block) ; { ... } that's not mentioned in this scope
(switch_block) ; { ... } in `switch X`
(array_initializer) ; [1, 2]
(argument_list) ; foo(...)
(formal_parameters) ; method foo(...)
(annotation_argument_list) ; @Annotation(...)
(element_value_array_initializer) ; { a, b } inside @Annotation()
] @indent.begin

(expression_statement
(method_invocation) @indent.begin)

[
"("
")"
"{"
"}"
"["
"]"
] @indent.branch

(annotation_argument_list
")" @indent.end) ; This should be a special cased as `()` here doesn't have ending `;`

"}" @indent.end

(line_comment) @indent.ignore

[
(ERROR)
(block_comment)
] @indent.auto
77 changes: 42 additions & 35 deletions app/src/main/kotlin/org/cosmicide/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -228,43 +228,50 @@ class App : Application() {
private fun setupHooks() {
// Some libraries may call System.exit() to exit the app, which crashes the app.
// Currently, only JGit does this.
HookManager.registerHook(object : Hook(
method = "exit",
argTypes = arrayOf(Int::class.java),
type = System::class.java
) {
override fun before(param: XC_MethodHook.MethodHookParam) {
System.err.println("System.exit() called!")
// Setting result to null bypasses the original method call.
param.result = null
}
})

// Fix crash in ViewPager2
HookManager.registerHook(object : Hook(
method = "onLayoutChildren",
argTypes = arrayOf(RecyclerView.Recycler::class.java, RecyclerView.State::class.java),
type = LinearLayoutManager::class.java
) {
override fun before(param: XC_MethodHook.MethodHookParam) {
try {
// Call the original method.
HookManager.invokeOriginal(
param.method,
param.thisObject,
param.args[0],
param.args[1]
)
} catch (e: Exception) {
e.printStackTrace()
try {
HookManager.registerHook(object : Hook(
method = "exit",
argTypes = arrayOf(Int::class.java),
type = System::class.java
) {
override fun before(param: XC_MethodHook.MethodHookParam) {
System.err.println("System.exit() called!")
// Setting result to null bypasses the original method call.
param.result = null
}
// Bypass method call as we have already called the original method.
param.result = null
}
})
})

// Fix crash in ViewPager2
HookManager.registerHook(object : Hook(
method = "onLayoutChildren",
argTypes = arrayOf(
RecyclerView.Recycler::class.java,
RecyclerView.State::class.java
),
type = LinearLayoutManager::class.java
) {
override fun before(param: XC_MethodHook.MethodHookParam) {
try {
// Call the original method.
HookManager.invokeOriginal(
param.method,
param.thisObject,
param.args[0],
param.args[1]
)
} catch (e: Exception) {
e.printStackTrace()
}
// Bypass method call as we have already called the original method.
param.result = null
}
})

injectPrint("fine")
injectPrint("info")
injectPrint("fine")
injectPrint("info")
} catch (e: UnsatisfiedLinkError) {
Log.e("App", "Failed to setup hooks", e)
}
}

private fun injectPrint(method: String) {
Expand Down
1 change: 0 additions & 1 deletion app/src/main/kotlin/org/cosmicide/adapter/EditorAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.DiffUtil
import androidx.viewpager2.adapter.FragmentStateAdapter
import io.github.rosemoe.sora.event.ContentChangeEvent
import io.github.rosemoe.sora.event.SelectionChangeEvent
import io.github.rosemoe.sora.event.SubscriptionReceipt
import io.github.rosemoe.sora.lang.EmptyLanguage
import io.github.rosemoe.sora.langs.textmate.TextMateColorScheme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class KotlinLanguage(
it.value.kotlinFile
}, ktFile)


editor.post {
editor.diagnostics = container
}
Expand Down Expand Up @@ -119,6 +118,7 @@ class KotlinLanguage(
Log.e(TAG, "Failed to fetch code completions", e)
}
}
kotlinEnvironment.analysis = null
}

companion object {
Expand Down
4 changes: 2 additions & 2 deletions build-tools/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ dependencies {
implementation("com.github.Cosmic-Ide.kotlinc-android:kotlinc:2a0a6a7291")
implementation("io.github.Rosemoe.sora-editor:editor:0.23.4-3895689-SNAPSHOT")
implementation("io.github.itsaky:nb-javac-android:17.0.0.3")
implementation("com.google.guava:guava:33.0.0-jre")
implementation("com.android.tools:r8:8.2.33")
implementation("com.google.guava:guava:33.1.0-android")
implementation("com.android.tools:r8:8.3.37")
}
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
id("com.android.library") version "8.4.0-alpha03" apply false
id("org.jetbrains.kotlin.android") version "2.0.0-Beta5" apply false
id("org.jetbrains.kotlin.jvm") version "2.0.0-Beta5" apply false
id("dev.rikka.tools.materialthemebuilder") version "1.3.3" apply false
id("dev.rikka.tools.materialthemebuilder") version "1.4.1" apply false
}

buildscript {
Expand Down
13 changes: 8 additions & 5 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,20 @@ android {


dependencies {
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("androidx.databinding:viewbinding:8.2.0")
implementation("androidx.appcompat:appcompat:1.7.0-alpha03")
implementation("androidx.databinding:viewbinding:8.5.0-alpha02")

"prodImplementation"(projects.feature.appwrite)
"devImplementation"("com.google.firebase:firebase-analytics-ktx:21.5.0")
"devImplementation"("com.google.firebase:firebase-analytics-ktx:21.6.1")

implementation("com.itsaky.androidide.treesitter:android-tree-sitter:4.3.1")

api("androidx.preference:preference-ktx:1.2.1")

implementation("com.google.android.material:material:1.11.0")
implementation("com.google.android.material:material:1.12.0-beta01")

implementation(platform("io.github.Rosemoe.sora-editor:bom:0.22.1"))
implementation(platform("io.github.Rosemoe.sora-editor:bom:0.23.4"))
api("io.github.Rosemoe.sora-editor:editor")
api("io.github.Rosemoe.sora-editor:language-textmate")
api("io.github.Rosemoe.sora-editor:language-treesitter")
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import io.github.rosemoe.sora.lang.format.Formatter
import io.github.rosemoe.sora.langs.textmate.registry.GrammarRegistry
import io.github.rosemoe.sora.langs.textmate.registry.ThemeRegistry
import io.github.rosemoe.sora.text.Content
import io.github.rosemoe.sora.widget.SymbolPairMatch
import org.cosmicide.common.Prefs
import org.cosmicide.editor.language.IdeFormatter
import org.eclipse.tm4e.core.grammar.IGrammar
import org.eclipse.tm4e.languageconfiguration.model.LanguageConfiguration
import org.eclipse.tm4e.languageconfiguration.internal.model.LanguageConfiguration

/**
* A language implementation for the IDE.
Expand All @@ -40,21 +39,6 @@ open class IdeLanguage(
createIdentifiers
) {

private val _symbolPairs: SymbolPairMatch by lazy {
val symbolPair = SymbolPairMatch()
langConfiguration?.autoClosingPairs?.forEach { autoClosingPair ->
symbolPair.putPair(
autoClosingPair.open,
SymbolPairMatch.SymbolPair(
autoClosingPair.open,
autoClosingPair.close,
TextMateSymbolPairMatch.SymbolPairEx(autoClosingPair)
)
)
}
symbolPair
}

private val _formatter: IdeFormatter by lazy {
IdeFormatter(this)
}
Expand All @@ -71,13 +55,6 @@ open class IdeLanguage(
return Prefs.useSpaces.not()
}

override fun getSymbolPairs(): SymbolPairMatch {
if (Prefs.bracketPairAutocomplete) {
return _symbolPairs
}
return SymbolPairMatch()
}

fun formatCode(text: Content): String {
return text.toString()
}
Expand Down
Loading

0 comments on commit c9b5491

Please sign in to comment.