Skip to content
This repository was archived by the owner on Jun 14, 2025. It is now read-only.

Commit c9b5491

Browse files
committed
Fix crash on opening kotlin files and update dependencies
Tested-by: Pranav Purwar <[email protected]> Signed-off-by: PranavPurwar <[email protected]>
1 parent 1ab0b9c commit c9b5491

File tree

27 files changed

+353
-297
lines changed

27 files changed

+353
-297
lines changed

.idea/compiler.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle.kts

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,34 @@ android {
8181
resolutionStrategy.force("com.squareup.okhttp3:okhttp:4.12.0")
8282
}
8383

84-
packagingOptions.resources.excludes.addAll(
85-
listOf(
86-
"META-INF/INDEX.LIST",
87-
"META-INF/eclipse.inf",
88-
"META-INF/CHANGES",
89-
"META-INF/README.md",
90-
"META-INF/DEPENDENCIES",
91-
"about_files/LICENSE-2.0.txt",
92-
"META-INF/AL2.0",
93-
"META-INF/LGPL2.1",
94-
"plugin.xml",
95-
"plugin.properties",
96-
"about.mappings",
97-
"about.properties",
98-
"about.ini",
99-
"src/*"
100-
)
101-
)
84+
packaging {
85+
resources {
86+
excludes.addAll(
87+
listOf(
88+
"META-INF/INDEX.LIST",
89+
"META-INF/eclipse.inf",
90+
"META-INF/CHANGES",
91+
"META-INF/README.md",
92+
"META-INF/DEPENDENCIES",
93+
"about_files/LICENSE-2.0.txt",
94+
"META-INF/AL2.0",
95+
"META-INF/LGPL2.1",
96+
"plugin.xml",
97+
"plugin.properties",
98+
"about.mappings",
99+
"about.properties",
100+
"about.ini",
101+
"src/*",
102+
)
103+
)
104+
105+
pickFirsts.addAll(
106+
listOf(
107+
"OSGI-INF/l10n/plugin.properties"
108+
)
109+
)
110+
}
111+
}
102112
buildFeatures {
103113
buildConfig = true
104114
}
@@ -182,14 +192,14 @@ dependencies {
182192
implementation("androidx.core:core-splashscreen:1.1.0-alpha02")
183193
implementation("androidx.documentfile:documentfile:1.1.0-alpha01")
184194
implementation("androidx.fragment:fragment-ktx:1.7.0-beta01")
185-
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
186-
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0")
195+
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.0-alpha03")
196+
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.0-alpha03")
187197
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01")
188198
implementation("androidx.viewpager2:viewpager2:1.1.0-beta02")
189199
implementation("androidx.activity:activity-ktx:1.9.0-beta01")
190200
implementation("androidx.startup:startup-runtime:1.2.0-alpha02")
191201

192-
val editorVersion = "0.22.2-3e1c25a-SNAPSHOT"
202+
val editorVersion = "0.23.4"
193203
//noinspection GradleDependency
194204
implementation("io.github.Rosemoe.sora-editor:editor:$editorVersion")
195205
//noinspection GradleDependency
@@ -198,8 +208,10 @@ dependencies {
198208
implementation("io.github.Rosemoe.sora-editor:language-treesitter:$editorVersion") {
199209
isTransitive = false
200210
}
201-
implementation("com.itsaky.androidide.treesitter:android-tree-sitter:4.0.0")
202-
implementation("com.itsaky.androidide.treesitter:tree-sitter-java:4.0.0")
211+
implementation("com.itsaky.androidide.treesitter:android-tree-sitter:4.3.1")
212+
implementation("com.itsaky.androidide.treesitter:tree-sitter-java:4.3.1")
213+
implementation("com.itsaky.androidide.treesitter:tree-sitter-kotlin:4.3.1")
214+
203215
implementation("io.github.itsaky:nb-javac-android:17.0.0.3")
204216

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

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

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

224-
225236
val shizukuVersion = "13.1.5"
226237
implementation("dev.rikka.shizuku:api:$shizukuVersion")
227238

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
; Query for computing indents in tree-sitter language
2-
; Capture names can be 'indent' or 'outdent'. Any other capture name will be ignored
3-
; indent - increments indentation
4-
; outdent - decrements indentation
5-
6-
(class_body
7-
"{" @indent
8-
"}" @outdent)
9-
10-
(enum_body
11-
"{" @indent
12-
"}" @outdent)
13-
14-
(interface_body
15-
"{" @indent
16-
"}" @outdent)
17-
18-
(constructor_body
19-
"{" @indent
20-
"}" @outdent)
21-
22-
(block
23-
"{" @indent
24-
"}" @outdent)
25-
26-
(switch_block
27-
"{" @indent
28-
"}" @outdent)
29-
30-
(array_initializer
31-
"{" @indent
32-
"}" @outdent)
33-
34-
(formal_parameters
35-
"(" @indent
36-
")" @outdent)
37-
38-
(argument_list
39-
"(" @indent
40-
")" @outdent)
41-
42-
; (expression_statement (method_invocation) @indent)
1+
; https://github.com/nvim-treesitter/nvim-treesitter/blob/57a8acf0c4ed5e7f6dda83c3f9b073f8a99a70f9/queries/java/indents.scm
2+
3+
; format-ignore
4+
[
5+
; ... refers to the portion that this indent query will have effects on
6+
(class_body) ; { ... } of `class X`
7+
(enum_body) ; { ... } of `enum X`
8+
(interface_body) ; { ... } of `interface X`
9+
(constructor_body) ; { `modifier` X() {...} } inside `class X`
10+
(annotation_type_body) ; { ... } of `@interface X`
11+
(block) ; { ... } that's not mentioned in this scope
12+
(switch_block) ; { ... } in `switch X`
13+
(array_initializer) ; [1, 2]
14+
(argument_list) ; foo(...)
15+
(formal_parameters) ; method foo(...)
16+
(annotation_argument_list) ; @Annotation(...)
17+
(element_value_array_initializer) ; { a, b } inside @Annotation()
18+
] @indent.begin
19+
20+
(expression_statement
21+
(method_invocation) @indent.begin)
22+
23+
[
24+
"("
25+
")"
26+
"{"
27+
"}"
28+
"["
29+
"]"
30+
] @indent.branch
31+
32+
(annotation_argument_list
33+
")" @indent.end) ; This should be a special cased as `()` here doesn't have ending `;`
34+
35+
"}" @indent.end
36+
37+
(line_comment) @indent.ignore
38+
39+
[
40+
(ERROR)
41+
(block_comment)
42+
] @indent.auto

app/src/main/kotlin/org/cosmicide/App.kt

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -228,43 +228,50 @@ class App : Application() {
228228
private fun setupHooks() {
229229
// Some libraries may call System.exit() to exit the app, which crashes the app.
230230
// Currently, only JGit does this.
231-
HookManager.registerHook(object : Hook(
232-
method = "exit",
233-
argTypes = arrayOf(Int::class.java),
234-
type = System::class.java
235-
) {
236-
override fun before(param: XC_MethodHook.MethodHookParam) {
237-
System.err.println("System.exit() called!")
238-
// Setting result to null bypasses the original method call.
239-
param.result = null
240-
}
241-
})
242-
243-
// Fix crash in ViewPager2
244-
HookManager.registerHook(object : Hook(
245-
method = "onLayoutChildren",
246-
argTypes = arrayOf(RecyclerView.Recycler::class.java, RecyclerView.State::class.java),
247-
type = LinearLayoutManager::class.java
248-
) {
249-
override fun before(param: XC_MethodHook.MethodHookParam) {
250-
try {
251-
// Call the original method.
252-
HookManager.invokeOriginal(
253-
param.method,
254-
param.thisObject,
255-
param.args[0],
256-
param.args[1]
257-
)
258-
} catch (e: Exception) {
259-
e.printStackTrace()
231+
try {
232+
HookManager.registerHook(object : Hook(
233+
method = "exit",
234+
argTypes = arrayOf(Int::class.java),
235+
type = System::class.java
236+
) {
237+
override fun before(param: XC_MethodHook.MethodHookParam) {
238+
System.err.println("System.exit() called!")
239+
// Setting result to null bypasses the original method call.
240+
param.result = null
260241
}
261-
// Bypass method call as we have already called the original method.
262-
param.result = null
263-
}
264-
})
242+
})
243+
244+
// Fix crash in ViewPager2
245+
HookManager.registerHook(object : Hook(
246+
method = "onLayoutChildren",
247+
argTypes = arrayOf(
248+
RecyclerView.Recycler::class.java,
249+
RecyclerView.State::class.java
250+
),
251+
type = LinearLayoutManager::class.java
252+
) {
253+
override fun before(param: XC_MethodHook.MethodHookParam) {
254+
try {
255+
// Call the original method.
256+
HookManager.invokeOriginal(
257+
param.method,
258+
param.thisObject,
259+
param.args[0],
260+
param.args[1]
261+
)
262+
} catch (e: Exception) {
263+
e.printStackTrace()
264+
}
265+
// Bypass method call as we have already called the original method.
266+
param.result = null
267+
}
268+
})
265269

266-
injectPrint("fine")
267-
injectPrint("info")
270+
injectPrint("fine")
271+
injectPrint("info")
272+
} catch (e: UnsatisfiedLinkError) {
273+
Log.e("App", "Failed to setup hooks", e)
274+
}
268275
}
269276

270277
private fun injectPrint(method: String) {

app/src/main/kotlin/org/cosmicide/adapter/EditorAdapter.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import androidx.fragment.app.Fragment
1717
import androidx.recyclerview.widget.DiffUtil
1818
import androidx.viewpager2.adapter.FragmentStateAdapter
1919
import io.github.rosemoe.sora.event.ContentChangeEvent
20-
import io.github.rosemoe.sora.event.SelectionChangeEvent
2120
import io.github.rosemoe.sora.event.SubscriptionReceipt
2221
import io.github.rosemoe.sora.lang.EmptyLanguage
2322
import io.github.rosemoe.sora.langs.textmate.TextMateColorScheme

app/src/main/kotlin/org/cosmicide/editor/language/KotlinLanguage.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ class KotlinLanguage(
7979
it.value.kotlinFile
8080
}, ktFile)
8181

82-
8382
editor.post {
8483
editor.diagnostics = container
8584
}
@@ -119,6 +118,7 @@ class KotlinLanguage(
119118
Log.e(TAG, "Failed to fetch code completions", e)
120119
}
121120
}
121+
kotlinEnvironment.analysis = null
122122
}
123123

124124
companion object {

build-tools/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ dependencies {
6262
implementation("com.github.Cosmic-Ide.kotlinc-android:kotlinc:2a0a6a7291")
6363
implementation("io.github.Rosemoe.sora-editor:editor:0.23.4-3895689-SNAPSHOT")
6464
implementation("io.github.itsaky:nb-javac-android:17.0.0.3")
65-
implementation("com.google.guava:guava:33.0.0-jre")
66-
implementation("com.android.tools:r8:8.2.33")
65+
implementation("com.google.guava:guava:33.1.0-android")
66+
implementation("com.android.tools:r8:8.3.37")
6767
}

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ plugins {
1111
id("com.android.library") version "8.4.0-alpha03" apply false
1212
id("org.jetbrains.kotlin.android") version "2.0.0-Beta5" apply false
1313
id("org.jetbrains.kotlin.jvm") version "2.0.0-Beta5" apply false
14-
id("dev.rikka.tools.materialthemebuilder") version "1.3.3" apply false
14+
id("dev.rikka.tools.materialthemebuilder") version "1.4.1" apply false
1515
}
1616

1717
buildscript {

common/build.gradle.kts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,20 @@ android {
4949

5050

5151
dependencies {
52-
implementation("androidx.appcompat:appcompat:1.6.1")
53-
implementation("androidx.databinding:viewbinding:8.2.0")
52+
implementation("androidx.appcompat:appcompat:1.7.0-alpha03")
53+
implementation("androidx.databinding:viewbinding:8.5.0-alpha02")
5454

5555
"prodImplementation"(projects.feature.appwrite)
56-
"devImplementation"("com.google.firebase:firebase-analytics-ktx:21.5.0")
56+
"devImplementation"("com.google.firebase:firebase-analytics-ktx:21.6.1")
57+
58+
implementation("com.itsaky.androidide.treesitter:android-tree-sitter:4.3.1")
5759

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

60-
implementation("com.google.android.material:material:1.11.0")
62+
implementation("com.google.android.material:material:1.12.0-beta01")
6163

62-
implementation(platform("io.github.Rosemoe.sora-editor:bom:0.22.1"))
64+
implementation(platform("io.github.Rosemoe.sora-editor:bom:0.23.4"))
6365
api("io.github.Rosemoe.sora-editor:editor")
6466
api("io.github.Rosemoe.sora-editor:language-textmate")
67+
api("io.github.Rosemoe.sora-editor:language-treesitter")
6568
}

common/src/main/java/org/cosmicide/editor/language/IdeLanguage.kt

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ import io.github.rosemoe.sora.lang.format.Formatter
1111
import io.github.rosemoe.sora.langs.textmate.registry.GrammarRegistry
1212
import io.github.rosemoe.sora.langs.textmate.registry.ThemeRegistry
1313
import io.github.rosemoe.sora.text.Content
14-
import io.github.rosemoe.sora.widget.SymbolPairMatch
1514
import org.cosmicide.common.Prefs
1615
import org.cosmicide.editor.language.IdeFormatter
1716
import org.eclipse.tm4e.core.grammar.IGrammar
18-
import org.eclipse.tm4e.languageconfiguration.model.LanguageConfiguration
17+
import org.eclipse.tm4e.languageconfiguration.internal.model.LanguageConfiguration
1918

2019
/**
2120
* A language implementation for the IDE.
@@ -40,21 +39,6 @@ open class IdeLanguage(
4039
createIdentifiers
4140
) {
4241

43-
private val _symbolPairs: SymbolPairMatch by lazy {
44-
val symbolPair = SymbolPairMatch()
45-
langConfiguration?.autoClosingPairs?.forEach { autoClosingPair ->
46-
symbolPair.putPair(
47-
autoClosingPair.open,
48-
SymbolPairMatch.SymbolPair(
49-
autoClosingPair.open,
50-
autoClosingPair.close,
51-
TextMateSymbolPairMatch.SymbolPairEx(autoClosingPair)
52-
)
53-
)
54-
}
55-
symbolPair
56-
}
57-
5842
private val _formatter: IdeFormatter by lazy {
5943
IdeFormatter(this)
6044
}
@@ -71,13 +55,6 @@ open class IdeLanguage(
7155
return Prefs.useSpaces.not()
7256
}
7357

74-
override fun getSymbolPairs(): SymbolPairMatch {
75-
if (Prefs.bracketPairAutocomplete) {
76-
return _symbolPairs
77-
}
78-
return SymbolPairMatch()
79-
}
80-
8158
fun formatCode(text: Content): String {
8259
return text.toString()
8360
}

0 commit comments

Comments
 (0)