This repository has been archived by the owner on Nov 30, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
417b6a8
commit 7545bc3
Showing
6 changed files
with
189 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
src/main/scala/intellij/haskell/editor/HaskellProblemsView.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package intellij.haskell.editor | ||
|
||
import java.util | ||
import java.util.UUID | ||
|
||
import com.intellij.compiler.ProblemsView | ||
import com.intellij.compiler.impl.ProblemsViewPanel | ||
import com.intellij.compiler.progress.CompilerTask | ||
import com.intellij.icons.AllIcons | ||
import com.intellij.ide.errorTreeView.{ErrorTreeElement, ErrorTreeElementKind, GroupingElement} | ||
import com.intellij.openapi.compiler.{CompileScope, CompilerMessage} | ||
import com.intellij.openapi.fileEditor.OpenFileDescriptor | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.util.{Disposer, IconLoader} | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import com.intellij.openapi.wm.{ToolWindowAnchor, ToolWindowManager} | ||
import com.intellij.pom.Navigatable | ||
import com.intellij.ui.content.ContentFactory | ||
import com.intellij.util.concurrency.SequentialTaskExecutor | ||
import com.intellij.util.ui.UIUtil | ||
|
||
class HaskellProblemsView(project: Project, toolWindowManager: ToolWindowManager) extends ProblemsView(project) { | ||
|
||
private final val ProblemsToolWindowId = "Haskell Problems" | ||
private final val ActiveIcon = AllIcons.Toolwindows.Problems | ||
private final val PassiveIcon = IconLoader.getDisabledIcon(ActiveIcon) | ||
|
||
private val viewUpdater = SequentialTaskExecutor.createSequentialApplicationPoolExecutor("ProblemsView Pool") | ||
|
||
private val problemsPanel = new ProblemsViewPanel(project) | ||
|
||
Disposer.register(project, () => { | ||
Disposer.dispose(problemsPanel) | ||
}) | ||
|
||
UIUtil.invokeLaterIfNeeded(() => { | ||
if (!project.isDisposed) { | ||
val toolWindow = toolWindowManager.registerToolWindow(ProblemsToolWindowId, false, ToolWindowAnchor.LEFT, project, true) | ||
val content = ContentFactory.SERVICE.getInstance.createContent(problemsPanel, "", false) | ||
content.setHelpId("reference.problems.tool.window") | ||
toolWindow.getContentManager.addContent(content) | ||
Disposer.register(project, () => { | ||
toolWindow.getContentManager.removeAllContents(true) | ||
}) | ||
updateIcon() | ||
} | ||
}) | ||
|
||
def clearOldMessages(currentFile: VirtualFile): Unit = { | ||
viewUpdater.execute(() => { | ||
cleanupChildrenRecursively(problemsPanel.getErrorViewStructure.getRootElement.asInstanceOf[ErrorTreeElement], currentFile) | ||
updateIcon() | ||
problemsPanel.reload() | ||
}) | ||
} | ||
|
||
// See previous clearOldMessages | ||
def clearOldMessages(scope: CompileScope, currentSessionId: UUID): Unit = { | ||
throw new RuntimeException("Not implemented because no session id is available and need current file to clear only old messages of that file.") | ||
} | ||
|
||
override def addMessage(messageCategoryIndex: Int, text: Array[String], groupName: String, navigatable: Navigatable, exportTextPrefix: String, rendererTextPrefix: String, sessionId: UUID): Unit = { | ||
viewUpdater.execute(() => { | ||
if (navigatable != null) { | ||
problemsPanel.addMessage(messageCategoryIndex, text, groupName, navigatable, exportTextPrefix, rendererTextPrefix, sessionId) | ||
} | ||
else { | ||
problemsPanel.addMessage(messageCategoryIndex, text, null, -1, -1, sessionId) | ||
} | ||
updateIcon() | ||
}) | ||
} | ||
|
||
def addMessage(message: CompilerMessage): Unit = { | ||
val file = message.getVirtualFile | ||
val navigatable = if (message.getNavigatable == null && file != null && !file.getFileType.isBinary) { | ||
new OpenFileDescriptor(myProject, file, -1, -1) | ||
} else { | ||
message.getNavigatable | ||
} | ||
val category = message.getCategory | ||
val categoryIndex = CompilerTask.translateCategory(category) | ||
val messageText = splitMessage(message) | ||
val groupName = if (file != null) file.getPresentableUrl else category.getPresentableText | ||
addMessage(categoryIndex, messageText, groupName, navigatable, message.getExportTextPrefix, message.getRenderTextPrefix, null) | ||
} | ||
|
||
override def setProgress(text: String, fraction: Float): Unit = { | ||
problemsPanel.setProgress(text, fraction) | ||
} | ||
|
||
override def setProgress(text: String): Unit = { | ||
problemsPanel.setProgressText(text) | ||
} | ||
|
||
override def clearProgress(): Unit = { | ||
problemsPanel.clearProgressData() | ||
} | ||
|
||
private def splitMessage(message: CompilerMessage): Array[String] = { | ||
val messageText = message.getMessage | ||
if (messageText.contains("\n")) { | ||
messageText.split("\n") | ||
} else { | ||
Array[String](messageText) | ||
} | ||
} | ||
|
||
private def cleanupChildrenRecursively(errorTreeElement: ErrorTreeElement, currentFile: VirtualFile): Unit = { | ||
val errorViewStructure = problemsPanel.getErrorViewStructure | ||
for (element <- errorViewStructure.getChildElements(errorTreeElement)) { | ||
element match { | ||
case groupElement: GroupingElement => | ||
if (groupElement.getFile == currentFile) { | ||
cleanupChildrenRecursively(element, currentFile) | ||
} | ||
case _ => errorViewStructure.removeElement(element) | ||
} | ||
} | ||
} | ||
|
||
private def updateIcon() = { | ||
UIUtil.invokeLaterIfNeeded(() => { | ||
if (!myProject.isDisposed) { | ||
val toolWindow = ToolWindowManager.getInstance(myProject).getToolWindow(ProblemsToolWindowId) | ||
if (toolWindow != null) { | ||
val active = problemsPanel.getErrorViewStructure.hasMessages(util.EnumSet.of(ErrorTreeElementKind.ERROR, ErrorTreeElementKind.WARNING, ErrorTreeElementKind.NOTE)) | ||
toolWindow.setIcon(if (active) ActiveIcon else PassiveIcon) | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters