Skip to content

Commit c279c8f

Browse files
Merge remote-tracking branch 'upstream/main'
2 parents d9003a3 + 0ba6b02 commit c279c8f

File tree

50 files changed

+1262
-365
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1262
-365
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "oniguruma-native/src/main/cpp/oniguruma"]
22
path = oniguruma-native/src/main/cpp/oniguruma
3-
url = git@github.com:kkos/oniguruma.git
3+
url = git@github.com:project-sora/oniguruma.git

app/src/main/java/io/github/rosemoe/sora/app/MainActivity.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class MainActivity : AppCompatActivity() {
215215

216216
// Configure editor
217217
binding.editor.apply {
218-
registerInlayHintRenderer(TextInlayHintRenderer)
218+
registerInlayHintRenderer(TextInlayHintRenderer.DefaultInstance)
219219
typefaceText = typeface
220220
props.stickyScroll = true
221221
setLineSpacing(2f, 1.1f)
@@ -541,10 +541,12 @@ class MainActivity : AppCompatActivity() {
541541
updatePositionText()
542542
updateBtnState()
543543

544-
binding.editor.inlayHints = InlayHintsContainer().also {
545-
it.add(TextInlayHint(28, 0, "unit:"))
546-
it.add(TextInlayHint(28, 7, "open"))
547-
it.add(TextInlayHint(28, 22, "^class"))
544+
if ("big_sample" !in name) {
545+
binding.editor.inlayHints = InlayHintsContainer().also {
546+
it.add(TextInlayHint(28, 0, "unit:"))
547+
it.add(TextInlayHint(28, 7, "open"))
548+
it.add(TextInlayHint(28, 22, "^class"))
549+
}
548550
}
549551
}
550552
}

app/src/main/java/io/github/rosemoe/sora/app/lsp/LspTestActivity.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ import io.github.rosemoe.sora.lsp.client.languageserver.serverdefinition.CustomL
4848
import io.github.rosemoe.sora.lsp.client.languageserver.wrapper.EventHandler
4949
import io.github.rosemoe.sora.lsp.editor.LspEditor
5050
import io.github.rosemoe.sora.lsp.editor.LspProject
51+
import io.github.rosemoe.sora.lsp.editor.text.MarkdownCodeHighlighterRegistry
52+
import io.github.rosemoe.sora.lsp.editor.text.withEditorHighlighter
5153
import io.github.rosemoe.sora.lsp.events.EventType
5254
import io.github.rosemoe.sora.lsp.events.code.codeAction
5355
import io.github.rosemoe.sora.lsp.utils.asLspRange
@@ -148,7 +150,8 @@ class LspTestActivity : BaseEditorActivity() {
148150
)
149151

150152
val luaServerDefinition =
151-
object : CustomLanguageServerDefinition("lua",
153+
object : CustomLanguageServerDefinition(
154+
"lua",
152155
ServerConnectProvider {
153156
LocalSocketStreamConnectionProvider("lua-lsp")
154157
}
@@ -170,6 +173,8 @@ class LspTestActivity : BaseEditorActivity() {
170173

171174
lspProject.addServerDefinition(luaServerDefinition)
172175

176+
177+
173178
withContext(Dispatchers.Main) {
174179
lspEditor = lspProject.createEditor("$projectPath/sample.lua")
175180
val wrapperLanguage = createTextMateLanguage()
@@ -237,6 +242,16 @@ class LspTestActivity : BaseEditorActivity() {
237242
}
238243
)
239244

245+
MarkdownCodeHighlighterRegistry.global.withEditorHighlighter { languageName ->
246+
if (languageName == "lua") {
247+
Pair(
248+
TextMateLanguage.create("source.lua", false),
249+
TextMateColorScheme.create(ThemeRegistry.getInstance()).apply {
250+
}
251+
)
252+
} else null
253+
}
254+
240255
return TextMateLanguage.create(
241256
"source.lua", false
242257
)

app/src/main/java/io/github/rosemoe/sora/lang/langJava.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ class TsJavaSpanFactory(
111111
return super.createSpans(capture, column, spanStyle)
112112
}
113113

114-
val text = content.subContent(start.line, start.column, end.line, end.column)
114+
val text =
115+
content.subContent(start.line, start.column, end.line, end.column, false).toString()
115116
val results = HEX_REGEX.findAll(text)
116117

117118
val spans = mutableListOf<Span>()

editor-lsp/src/main/java/io/github/rosemoe/sora/lsp/editor/LspEditor.kt

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,9 @@ import org.eclipse.lsp4j.Range
7474
import org.eclipse.lsp4j.SignatureHelp
7575
import org.eclipse.lsp4j.TextDocumentSyncKind
7676
import org.eclipse.lsp4j.jsonrpc.messages.Either
77-
import java.lang.RuntimeException
7877
import java.lang.ref.WeakReference
7978
import java.util.concurrent.TimeoutException
8079
import java.util.concurrent.atomic.AtomicReference
81-
import kotlin.reflect.KClass
8280

8381
class LspEditor(
8482
val project: LspProject,
@@ -134,13 +132,14 @@ class LspEditor(
134132
currentEditor.setEditorLanguage(currentLanguage)
135133

136134
if (isEnableSignatureHelp) {
137-
signatureHelpWindowWeakReference = WeakReference(SignatureHelpWindow(currentEditor))
135+
signatureHelpWindowWeakReference =
136+
WeakReference(SignatureHelpWindow(currentEditor, coroutineScope))
138137
}
139138
if (isEnableHover) {
140-
hoverWindowWeakReference = WeakReference(HoverWindow(currentEditor))
139+
hoverWindowWeakReference = WeakReference(HoverWindow(currentEditor, coroutineScope))
141140
}
142141
if (isEnableInlayHint) {
143-
currentEditor.registerInlayHintRenderer(TextInlayHintRenderer)
142+
currentEditor.registerInlayHintRenderer(TextInlayHintRenderer.DefaultInstance)
144143
}
145144

146145
codeActionWindowWeakReference = WeakReference(CodeActionWindow(this, currentEditor))
@@ -219,29 +218,33 @@ class LspEditor(
219218
val isShowHover
220219
get() = hoverWindowWeakReference.get()?.isShowing ?: false
221220

222-
223221
val isShowCodeActions
224222
get() = codeActionWindowWeakReference.get()?.isShowing ?: false
225223

226224
var isEnableHover = true
227-
get() = hoverWindow?.isEnabled() ?: false
228225
set(value) {
229226
field = value
230227
if (value) {
231-
editor?.let { hoverWindowWeakReference = WeakReference(HoverWindow(it)) }
228+
editor?.let {
229+
hoverWindowWeakReference = WeakReference(HoverWindow(it, coroutineScope))
230+
}
232231
} else {
233232
hoverWindow?.setEnabled(false)
234233
hoverWindowWeakReference.clear()
235234
}
236235
}
237236

238237
var isEnableSignatureHelp = true
239-
get() = signatureHelpWindow?.isEnabled() ?: false
240238
set(value) {
241239
field = value
242240
if (value) {
243241
editor?.let {
244-
signatureHelpWindowWeakReference = WeakReference(SignatureHelpWindow(it))
242+
signatureHelpWindowWeakReference = WeakReference(
243+
SignatureHelpWindow(
244+
it,
245+
coroutineScope
246+
)
247+
)
245248
}
246249
} else {
247250
signatureHelpWindow?.setEnabled(false)
@@ -255,7 +258,7 @@ class LspEditor(
255258
field = value
256259
val editor = editor ?: return
257260
if (value) {
258-
editor.registerInlayHintRenderer(TextInlayHintRenderer)
261+
editor.registerInlayHintRenderer(TextInlayHintRenderer.DefaultInstance)
259262
coroutineScope.launch {
260263
this@LspEditor.requestInlayHint(CharPosition(0, 0))
261264
}

editor-lsp/src/main/java/io/github/rosemoe/sora/lsp/editor/hover/DefaultHoverLayout.kt

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import io.github.rosemoe.sora.lsp.R
1212
import io.github.rosemoe.sora.lsp.editor.curvedTextScale
1313
import io.github.rosemoe.sora.lsp.editor.text.SimpleMarkdownRenderer
1414
import io.github.rosemoe.sora.widget.schemes.EditorColorScheme
15+
import kotlinx.coroutines.Dispatchers
16+
import kotlinx.coroutines.launch
1517
import org.eclipse.lsp4j.Hover
1618

1719
class DefaultHoverLayout : HoverLayout {
@@ -25,7 +27,6 @@ class DefaultHoverLayout : HoverLayout {
2527
private var baselineEditorTextSize: Float? = null
2628
private var baselineHoverTextSize: Float? = null
2729
private var latestEditorTextSize: Float? = null
28-
private val markdownRenderer = SimpleMarkdownRenderer()
2930

3031
override fun attach(window: HoverWindow) {
3132
this.window = window
@@ -58,8 +59,24 @@ class DefaultHoverLayout : HoverLayout {
5859
}
5960

6061
override fun renderHover(hover: Hover) {
61-
hoverTextView.text = buildHoverText(hover)
62+
val hoverText = buildHoverText(hover)
63+
hoverTextView.text = SimpleMarkdownRenderer.render(
64+
markdown = hoverText,
65+
boldColor = highlightColor,
66+
inlineCodeColor = highlightColor,
67+
codeTypeface = codeTypeface,
68+
linkColor = highlightColor
69+
)
6270
container.post { container.smoothScrollTo(0, 0) }
71+
window.coroutineScope.launch(Dispatchers.Main) {
72+
hoverTextView.text = SimpleMarkdownRenderer.renderAsync(
73+
markdown = hoverText,
74+
boldColor = highlightColor,
75+
inlineCodeColor = highlightColor,
76+
codeTypeface = codeTypeface,
77+
linkColor = highlightColor
78+
)
79+
}
6380
}
6481

6582
override fun onTextSizeChanged(oldSize: Float, newSize: Float) {
@@ -91,24 +108,16 @@ class DefaultHoverLayout : HoverLayout {
91108
hoverTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textBaseline * curvedScale)
92109
}
93110

94-
private fun buildHoverText(hover: Hover): CharSequence {
111+
112+
private fun buildHoverText(hover: Hover): String {
95113
val hoverContents = hover.contents ?: return ""
96-
val rawText = if (hoverContents.isLeft) {
114+
return if (hoverContents.isLeft) {
97115
val items = hoverContents.left.orEmpty()
98-
items.joinToString("\n\n") { either -> formatMarkedStringEither(either) ?: ""}
116+
items.joinToString("\n\n") { either -> formatMarkedStringEither(either) ?: "" }
99117
} else {
100118
val markup = hoverContents.right
101119
formatMarkupContent(markup) ?: ""
102120
}
103-
104-
return markdownRenderer.render(
105-
markdown = rawText,
106-
boldColor = highlightColor,
107-
inlineCodeColor = highlightColor,
108-
blockCodeColor = textColor,
109-
codeTypeface = codeTypeface,
110-
linkColor = highlightColor
111-
)
112121
}
113122

114123
}

editor-lsp/src/main/java/io/github/rosemoe/sora/lsp/editor/hover/HoverWindow.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ import io.github.rosemoe.sora.widget.component.EditorAutoCompletion
1616
import io.github.rosemoe.sora.widget.component.EditorDiagnosticTooltipWindow
1717
import io.github.rosemoe.sora.widget.component.EditorTextActionWindow
1818
import io.github.rosemoe.sora.widget.getComponent
19+
import kotlinx.coroutines.CoroutineScope
1920
import org.eclipse.lsp4j.Hover
2021
import org.eclipse.lsp4j.MarkupContent
2122
import org.eclipse.lsp4j.jsonrpc.messages.Either
2223

2324
open class HoverWindow(
2425
editor: CodeEditor,
26+
internal val coroutineScope: CoroutineScope
2527
) : EditorPopupWindow(
2628
editor,
2729
FEATURE_HIDE_WHEN_FAST_SCROLL or FEATURE_SCROLL_AS_CONTENT

editor-lsp/src/main/java/io/github/rosemoe/sora/lsp/editor/signature/DefaultSignatureHelpLayout.kt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import io.github.rosemoe.sora.lsp.R
1919
import io.github.rosemoe.sora.lsp.editor.curvedTextScale
2020
import io.github.rosemoe.sora.lsp.editor.text.SimpleMarkdownRenderer
2121
import io.github.rosemoe.sora.widget.schemes.EditorColorScheme
22+
import kotlinx.coroutines.Dispatchers
23+
import kotlinx.coroutines.launch
2224
import org.eclipse.lsp4j.SignatureInformation
2325
import org.eclipse.lsp4j.SignatureHelp
2426

@@ -40,7 +42,6 @@ class DefaultSignatureHelpLayout : SignatureHelpLayout {
4042
private var baselineDocumentationTextSize: Float? = null
4143
private var baselineCounterTextSize: Float? = null
4244
private var latestEditorTextSize: Float? = null
43-
private val markdownRenderer = SimpleMarkdownRenderer()
4445

4546
private var signatureHelp: SignatureHelp? = null
4647
private var currentIndex = 0
@@ -154,22 +155,29 @@ class DefaultSignatureHelpLayout : SignatureHelpLayout {
154155
else -> documentation.right?.value ?: ""
155156
}
156157

157-
val renderedDocumentation = if (documentationText.isNotEmpty()) {
158-
markdownRenderer.render(
158+
if (documentationText.isNotEmpty()) {
159+
documentationTextView.text = SimpleMarkdownRenderer.render(
159160
markdown = documentationText,
160161
boldColor = highlightColor,
161162
inlineCodeColor = highlightColor,
162-
blockCodeColor = textColor,
163163
codeTypeface = codeTypeface,
164164
linkColor = highlightColor
165165
)
166+
documentationTextView.visibility = View.VISIBLE
167+
window.coroutineScope.launch(Dispatchers.Main) {
168+
documentationTextView.text = SimpleMarkdownRenderer.renderAsync(
169+
markdown = documentationText,
170+
boldColor = highlightColor,
171+
inlineCodeColor = highlightColor,
172+
codeTypeface = codeTypeface,
173+
linkColor = highlightColor
174+
)
175+
}
166176
} else {
167-
""
177+
documentationTextView.text = ""
178+
documentationTextView.visibility = View.GONE
168179
}
169180

170-
documentationTextView.text = renderedDocumentation
171-
documentationTextView.visibility = if (documentationText.isEmpty()) View.GONE else View.VISIBLE
172-
173181
counterView.text = "${currentIndex + 1}/${signatures.size}"
174182
container.post { container.smoothScrollTo(0, 0) }
175183
}

editor-lsp/src/main/java/io/github/rosemoe/sora/lsp/editor/signature/SignatureHelpWindow.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ import io.github.rosemoe.sora.widget.CodeEditor
3737
import io.github.rosemoe.sora.widget.base.EditorPopupWindow
3838
import io.github.rosemoe.sora.widget.component.EditorDiagnosticTooltipWindow
3939
import io.github.rosemoe.sora.widget.getComponent
40+
import kotlinx.coroutines.CoroutineScope
4041
import org.eclipse.lsp4j.SignatureHelp
4142

4243
open class SignatureHelpWindow(
4344
editor: CodeEditor,
45+
val coroutineScope: CoroutineScope,
4446
) : EditorPopupWindow(
4547
editor,
4648
FEATURE_HIDE_WHEN_FAST_SCROLL or FEATURE_SCROLL_AS_CONTENT

0 commit comments

Comments
 (0)