Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recompile on Edit [RIP67] #73

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ lazy val riddlIdeaPlugin: Project = Root(
With.build_info,
With.coverage(90),
With.aliases,
With.riddl("0.54.1")
With.riddl("0.56.0")
)
.enablePlugins(KotlinPlugin, JavaAppPackaging)
.settings(
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object Dep {
"com.eclipsesource.minimal-json" % "minimal-json" % "0.9.5" withSources ()
}
val kotlin = "org.jetbrains.kotlin" % "kotlin-stdlib" % "2.0.20"
val riddlCommands = "com.ossuminc" % "riddl-commands_3" % "0.54.1"
val riddlCommands = "com.ossuminc" % "riddl-commands_3" % "0.56.0"

val basic: Seq[ModuleID] = Seq(minimalJson, scalactic, scalatest, scalacheck)

Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
addSbtPlugin("com.ossuminc" % "sbt-ossuminc" % "0.16.2")
addSbtPlugin("com.ossuminc" % "sbt-ossuminc" % "0.17.1")
addSbtPlugin("org.jetbrains" % "sbt-idea-plugin" % "3.26.2")
addSbtPlugin("org.jetbrains.scala" % "sbt-kotlin-plugin" % "3.0.3")

Expand Down
4 changes: 3 additions & 1 deletion resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
</actions>

<projectListeners>
<listener class="com.ossuminc.riddl.plugins.idea.files.RiddlFileListenerHighlighter"
<listener class="com.ossuminc.riddl.plugins.idea.files.RiddlFileEditorListener"
topic="com.intellij.openapi.fileEditor.FileEditorManagerListener"/>
<listener class="com.ossuminc.riddl.plugins.idea.files.RiddlDocumentListener"
topic="com.intellij.openapi.editor.event.DocumentListener"/>
</projectListeners>

</idea-plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,48 @@ package com.ossuminc.riddl.plugins.idea.files

import com.intellij.openapi.editor.event.{DocumentEvent, DocumentListener}
import com.intellij.openapi.editor.EditorFactory
import com.intellij.openapi.util.TextRange
import com.ossuminc.riddl.plugins.idea.files.utils.{
getWholeWordsSubstrings,
highlightKeywordsOnChange
}
import com.ossuminc.riddl.plugins.idea.files.RiddlTokenizer.*
import com.ossuminc.riddl.plugins.idea.files.utils.highlightKeywords
import com.ossuminc.riddl.plugins.idea.utils.highlightForErrorMessage
import com.ossuminc.riddl.plugins.idea.utils.ManagerBasedGetterUtils.*
import com.ossuminc.riddl.plugins.idea.utils.ParsingUtils.runCommandForEditor

import java.nio.file.Path

class RiddlDocumentListener extends DocumentListener {
override def documentChanged(event: DocumentEvent): Unit = {
val doc = event.getDocument

val editors = EditorFactory.getInstance().getEditors(doc)
if editors.nonEmpty then
val newText = doc.getText(
new TextRange(event.getOffset, event.getOffset + event.getNewLength)
)
val wholeWords = getWholeWordsSubstrings(
doc.getText,
newText,
event.getOffset
)
highlightKeywordsOnChange(
wholeWords
.zip(
RiddlTokenizer
.tokenize(wholeWords.map(_._1).mkString(" "))
.filter(!_._1.isBlank)
)
.map((wwTup, tokTup) => (wwTup._1, wwTup._2, tokTup._3)),
editors.head
)
editors.find(_.getDocument == doc) match
case Some(editor) if doc.getText.nonEmpty =>
if editor.getVirtualFile != null then
val editorFilePath = editor.getVirtualFile.getPath

highlightKeywords(editor.getDocument.getText, editor)

getRiddlIdeaStates.allStates.values.toSeq
.filter { state =>
state.getTopLevelPath.exists(path =>
editorFilePath.startsWith(
Path.of(path).getParent.toString
)
)
}
.foreach { state =>
runCommandForEditor(state.getWindowNum)
Thread.sleep(350)
state.getMessagesForEditor
.filter(msg => editorFilePath.endsWith(msg.loc.source.origin))
.foreach { msg =>
highlightForErrorMessage(
state,
Seq(),
Right(msg)
)
}
}

case _ => ()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.ossuminc.riddl.plugins.idea.files

import com.intellij.openapi.fileEditor.{
FileEditorManager,
FileEditorManagerEvent,
FileEditorManagerListener,
}
import com.intellij.openapi.vfs.VirtualFile
import com.ossuminc.riddl.plugins.idea.utils.ManagerBasedGetterUtils.getProject
import com.ossuminc.riddl.plugins.idea.files.utils.highlightKeywordsAndErrorsForFile

class RiddlFileEditorListener extends FileEditorManagerListener {
override def fileOpened(
source: FileEditorManager,
file: VirtualFile
): Unit = highlightKeywordsAndErrorsForFile(source, file)

override def selectionChanged(event: FileEditorManagerEvent): Unit =
if event.getNewFile != null then
highlightKeywordsAndErrorsForFile(
FileEditorManager
.getInstance(getProject),
event.getNewFile
)
}

This file was deleted.

Loading
Loading