Skip to content

Commit

Permalink
working
Browse files Browse the repository at this point in the history
  • Loading branch information
onriv committed Nov 30, 2024
1 parent 9040e93 commit ca500e4
Show file tree
Hide file tree
Showing 17 changed files with 1,189 additions and 94 deletions.
19 changes: 19 additions & 0 deletions .run/GoalTest.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="GoalTest" type="JUnit" factoryName="JUnit" nameIsGenerated="true">
<module name="lean4ij.test" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="lean4ij.infoview.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="lean4ij.infoview" />
<option name="MAIN_CLASS_NAME" value="lean4ij.infoview.GoalTest" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="class" />
<option name="VM_PARAMETERS" value="--add-exports=java.base/jdk.internal.vm=ALL-UNNAMED --add-exports=java.base/sun.util.calendar=ALL-UNNAMED --add-exports=java.desktop/sun.awt=ALL-UNNAMED --add-exports=jdk.scripting.nashorn/jdk.nashorn.internal.ir=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.module=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.math=ALL-UNNAMED --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.base/java.time=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/jdk.internal.jimage=ALL-UNNAMED --add-opens=java.base/jdk.internal.jimage.decompressor=ALL-UNNAMED --add-opens=java.base/jdk.internal.jrtfs=ALL-UNNAMED --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED --add-opens=java.base/jdk.internal.math=ALL-UNNAMED --add-opens=java.base/jdk.internal.module=ALL-UNNAMED --add-opens=java.base/jdk.internal.perf=ALL-UNNAMED --add-opens=java.base/jdk.internal.platform.cgroupv1=ALL-UNNAMED --add-opens=java.base/jdk.internal.ref=ALL-UNNAMED --add-opens=java.base/jdk.internal.reflect=ALL-UNNAMED --add-opens=java.base/jdk.internal.util.jar=ALL-UNNAMED --add-opens=java.base/jdk.internal.vm=ALL-UNNAMED --add-opens=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.desktop/com.apple.eawt=ALL-UNNAMED --add-opens=java.desktop/com.apple.eawt.event=ALL-UNNAMED --add-opens=java.desktop/com.apple.laf=ALL-UNNAMED --add-opens=java.desktop/java.awt=ALL-UNNAMED --add-opens=java.desktop/java.awt.dnd.peer=ALL-UNNAMED --add-opens=java.desktop/java.awt.event=ALL-UNNAMED --add-opens=java.desktop/java.awt.image=ALL-UNNAMED --add-opens=java.desktop/java.awt.peer=ALL-UNNAMED --add-opens=java.desktop/javax.swing=ALL-UNNAMED --add-opens=java.desktop/javax.swing.plaf.basic=ALL-UNNAMED --add-opens=java.desktop/javax.swing.text.html=ALL-UNNAMED --add-opens=java.desktop/sun.awt=ALL-UNNAMED --add-opens=java.desktop/sun.awt.image=ALL-UNNAMED --add-opens=java.desktop/sun.awt.windows=ALL-UNNAMED --add-opens=java.desktop/sun.font=ALL-UNNAMED --add-opens=java.desktop/sun.java2d=ALL-UNNAMED --add-opens=java.desktop/sun.lwawt=ALL-UNNAMED --add-opens=java.desktop/sun.lwawt.macosx=ALL-UNNAMED --add-opens=java.desktop/sun.swing=ALL-UNNAMED --add-opens=java.logging/sun.util.logging.internal=ALL-UNNAMED --add-opens=java.xml/javax.xml.catalog=ALL-UNNAMED --add-opens=java.xml/jdk.xml.internal=ALL-UNNAMED --add-opens=jdk.attach/sun.tools.attach=ALL-UNNAMED --add-opens=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED --add-opens=jdk.jdi/com.sun.tools.jdi=ALL-UNNAMED --add-opens=jdk.management/com.sun.management.internal=ALL-UNNAMED --add-opens=jdk.management.jfr/jdk.management.jfr=ALL-UNNAMED --add-opens=jdk.zipfs/jdk.nio.zipfs=ALL-UNNAMED -Didea.force.use.core.classloader=true -Djava.system.class.loader=com.intellij.util.lang.PathClassLoader -ea" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
14 changes: 6 additions & 8 deletions src/main/kotlin/lean4ij/infoview/LeanInfoViewWindowFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.EDT
import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.LogicalPosition
import com.intellij.openapi.editor.colors.EditorColorsManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.OnePixelDivider
Expand Down Expand Up @@ -77,7 +75,7 @@ class LeanInfoViewWindowFactory : ToolWindowFactory {
val start = infoviewRender.length
val header = "${file.name}:${position.line+1}:${position.character}"
infoviewRender.append("${header}")

Check notice on line 77 in src/main/kotlin/lean4ij/infoview/LeanInfoViewWindowFactory.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Redundant curly braces in string template

Redundant curly braces in string template

Check warning on line 77 in src/main/kotlin/lean4ij/infoview/LeanInfoViewWindowFactory.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Redundant string template

Redundant string template
infoviewRender.highlight(start, infoviewRender.length, EditorColorsManager.getInstance().globalScheme.getAttributes(TextAttributesKeys.SwingInfoviewCurrentPosition.key))
infoviewRender.highlight(start, infoviewRender.length, EditorColorsManager.getInstance().globalScheme.getAttributes(Lean4TextAttributesKeys.SwingInfoviewCurrentPosition.key))
infoviewRender.append('\n')
// TODO here maybe null?
// TODO refactor this
Expand Down Expand Up @@ -124,11 +122,11 @@ class LeanInfoViewWindowFactory : ToolWindowFactory {
// the toInfoViewString method
val content = i.message.toInfoViewString(infoviewRender, null)
if (i.message.f0 is MsgUnsupported) {
infoviewRender.highlight(start, end1, TextAttributesKeys.SwingInfoviewAllMessageUnsupportedPos)
infoviewRender.highlight(start, end1, Lean4TextAttributesKeys.SwingInfoviewAllMessageUnsupportedPos)
} else if (content.contains("declaration uses 'sorry'")) {
infoviewRender.highlight(start, end1, TextAttributesKeys.SwingInfoviewAllMessageSorryPos)
infoviewRender.highlight(start, end1, Lean4TextAttributesKeys.SwingInfoviewAllMessageSorryPos)
} else {
infoviewRender.highlight(start, end1, TextAttributesKeys.SwingInfoviewAllMessagePos)
infoviewRender.highlight(start, end1, Lean4TextAttributesKeys.SwingInfoviewAllMessagePos)
}
} else {
// TODO for TaggedTextAppend there is also case for not supported trace
Expand All @@ -141,9 +139,9 @@ class LeanInfoViewWindowFactory : ToolWindowFactory {
// | DiagnosticSeverity.hint => 4⟩
// check src/Lean/Data/Lsp/Diagnostics.lean
var key = if (i.severity == 1) {

Check warning on line 141 in src/main/kotlin/lean4ij/infoview/LeanInfoViewWindowFactory.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Local 'var' is never modified and can be declared as 'val'

Variable is never modified, so it can be declared using 'val'
TextAttributesKeys.SwingInfoviewAllMessageErrorPos
Lean4TextAttributesKeys.SwingInfoviewAllMessageErrorPos
} else {
TextAttributesKeys.SwingInfoviewAllMessagePos
Lean4TextAttributesKeys.SwingInfoviewAllMessagePos
}
infoviewRender.highlight(start, end1, key)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ fun createTextAttributesKey(color: Color?, fallbackKey: TextAttributesKey?) {
}
}

enum class TextAttributesKeys(val style: String, private val fallbackKey: TextAttributesKey,
val attrSelect: AttrSelect,
val key: TextAttributesKey = TextAttributesKey.createTextAttributesKey(style, fallbackKey)) {
enum class Lean4TextAttributesKeys(val style: String, private val fallbackKey: TextAttributesKey,
val attrSelect: AttrSelect,

Check warning on line 30 in src/main/kotlin/lean4ij/infoview/LeanInfoviewColorSettingPage.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Property "attrSelect" is never used
val key: TextAttributesKey = TextAttributesKey.createTextAttributesKey(style, fallbackKey)) {
Header("header", DefaultLanguageHighlighterColors.CLASS_NAME, AttrSelect.FOREGROUND),
GoalHyp("goal-hyp", DefaultLanguageHighlighterColors.INSTANCE_FIELD, AttrSelect.FOREGROUND),
GoalInaccessible("goal-inaccessible", DefaultLanguageHighlighterColors.LINE_COMMENT, AttrSelect.FOREGROUND),
Expand All @@ -54,7 +54,7 @@ class LeanInfoviewColorSettingPage : ColorSettingsPage {

companion object {
@OptIn(ExperimentalStdlibApi::class)

Check notice on line 56 in src/main/kotlin/lean4ij/infoview/LeanInfoviewColorSettingPage.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unnecessary '@OptIn' annotation

The opt-in annotation is redundant: no matching experimental API is used
val keys = TextAttributesKeys.entries
val keys = Lean4TextAttributesKeys.entries
.associateBy({ it.style }, { it.key })
.toMutableMap()
}
Expand Down
129 changes: 129 additions & 0 deletions src/main/kotlin/lean4ij/infoview/dsl/dsl.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package lean4ij.infoview.dsl

import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.FoldRegion
import com.intellij.openapi.editor.colors.EditorColorsManager
import com.intellij.openapi.editor.colors.TextAttributesKey
import com.intellij.openapi.editor.markup.HighlighterLayer
import com.intellij.openapi.editor.markup.HighlighterTargetArea
import lean4ij.infoview.Lean4TextAttributesKeys

fun info(init: InfoObjectBuilder.()->Unit) : InfoObjectModel {
val infoObjectBuilder = InfoObjectBuilder().apply {
init()
}
return infoObjectBuilder.build()
}

// fun fold(init: InfoObjectBuilder.()->Unit) {
// val infoObjectBuilder = InfoObjectBuilder().apply {
// init()
// }
// return infoObjectBuilder.build().apply {
// fold = Pair("", true)
// }
// }

class InfoObjectBuilder {

private val data: MutableList<InfoObjectModel> = mutableListOf()

fun build(): InfoObjectModel {
return InfoObjectModel(children = data)
}

fun info(model: InfoObjectModel) {
data.add(model)
}

fun fold(init: InfoObjectBuilder.() -> Unit) {
val model = InfoObjectBuilder().run {
init()
build()
}
model.fold = Pair("", true)
data.add(model)
}

fun h1(text: String) {
// TODO add attr for h1?
data.add(InfoObjectModel(text))
}

fun h2(text: String) {
data.add(InfoObjectModel(text, attr = Lean4TextAttributesKeys.SwingInfoviewCasePos.key))
}

fun p(text: String, attr: MutableList<TextAttributesKey> = mutableListOf()) {
data.add(InfoObjectModel(text, attr=attr))
}

operator fun String.unaryPlus() {
data.add(InfoObjectModel(this))
}

}


class InfoObjectModel(
val text: String = "",
val attr: MutableList<TextAttributesKey> = mutableListOf(),
val children: MutableList<InfoObjectModel>? = mutableListOf(),
// TODO make a class for this
var fold: Pair<String, Boolean>? = null
) {
constructor(text: String, attr: TextAttributesKey) : this(text, attr = mutableListOf(attr))
fun insert(infoviewObject: InfoObjectModel) {

Check warning on line 76 in src/main/kotlin/lean4ij/infoview/dsl/dsl.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "insert" is never used
children?.add(infoviewObject)
}

fun output(renderBuffer: InfoviewRenderBuffer) {

Check notice on line 80 in src/main/kotlin/lean4ij/infoview/dsl/dsl.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Function 'output' could be private

Check warning on line 80 in src/main/kotlin/lean4ij/infoview/dsl/dsl.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "output" is never used
// TODO here using some dsl the start/end could be moved to InfoviewRenderBuffer, but
// currently we do it this way
val start = renderBuffer.length()
renderBuffer.output(text)
if (children != null) {
for (elem in children) {
elem.output(renderBuffer)
}
}
val end = renderBuffer.length()
for (key in attr) {
renderBuffer.attr(start, end, key)
}
if (fold != null) {
renderBuffer.fold(start, end, fold!!.first, fold!!.second)
}
}
}


class InfoviewRenderBuffer(private val sb: StringBuilder, private val editor: Editor) {

fun length() = sb.length

fun output(text: String) {
sb.append(text)
}

fun attr(start: Int, end: Int, attr: TextAttributesKey) {
EditorColorsManager.getInstance().globalScheme.getAttributes(attr)?.let {
editor.markupModel.addRangeHighlighter(start, end, HighlighterLayer.SYNTAX, it, HighlighterTargetArea.EXACT_RANGE)
}
}

fun fold(start: Int, end: Int, placeholderText: String, expanded: Boolean) {
val foldRegion = editor.foldingModel.addFoldRegion(start, end, placeholderText)
foldRegion?.isExpanded = expanded
}

/**
* This is mainly for some logic in handling all messages. Once it's expanded, it will keep expanded even
* default to collapse.
*/
fun fold(start: Int, end: Int, placeholderText: String, expanded: Boolean, consumer: (FoldRegion)->Unit) {

Check warning on line 124 in src/main/kotlin/lean4ij/infoview/dsl/dsl.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "fold" is never used
val foldRegion = editor.foldingModel.addFoldRegion(start, end, placeholderText)
foldRegion?.isExpanded = expanded
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class JcefInfoviewService(private val project: Project) {

// handle link clicks, which should be opened in real browser but not jcef

// browser.cefBrowser.find
browser.jbCefClient
.addRequestHandler(object : CefRequestHandler {
override fun onBeforeBrowse(
Expand Down
6 changes: 2 additions & 4 deletions src/main/kotlin/lean4ij/infoview/external/Route.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.google.gson.Gson
import com.google.gson.JsonElement
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors
import com.intellij.openapi.editor.colors.ColorKey
import com.intellij.openapi.editor.colors.EditorColors
import com.intellij.openapi.editor.colors.EditorColorsListener
Expand All @@ -24,8 +23,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch
import lean4ij.setting.Lean4SettingsView
import lean4ij.infoview.TextAttributesKeys
import lean4ij.infoview.Lean4TextAttributesKeys
import lean4ij.infoview.external.data.ApplyEditParam
import lean4ij.infoview.external.data.InfoviewEvent
import lean4ij.lsp.LeanLanguageServer
Expand Down Expand Up @@ -284,7 +282,7 @@ fun createThemeCss(scheme: EditorColorsScheme) : String {
// check https://plugins.jetbrains.com/docs/intellij/jcef.html?from=jetbrains.org#disposing-resources
val scrollbarStyle = JBCefScrollbarsHelper.buildScrollbarsStyle()
return """:root {
${themeSb} --header-foreground-color: ${scheme.getAttributes(TextAttributesKeys.Header.key).foregroundColor.toHexRgba()};
${themeSb} --header-foreground-color: ${scheme.getAttributes(Lean4TextAttributesKeys.Header.key).foregroundColor.toHexRgba()};

Check notice on line 285 in src/main/kotlin/lean4ij/infoview/external/Route.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Redundant curly braces in string template

Redundant curly braces in string template
--vscode-editor-background: $background;
--vscode-editor-foreground: $foreground;
/* fonts */
Expand Down
Loading

0 comments on commit ca500e4

Please sign in to comment.