Skip to content

Commit caf4dbe

Browse files
authored
v0.4.4 (#693)
* fix view history on watch log expression * lower logging * rename * update * link * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * trigger event * convenience method * createMethodGutterMark * default * lazy changelog * move method * impl SWLiveViewService * allow live view commands * move code to processor * impl show/hide quick stats * todo * accept events to indiv subscriber * bump * don't need * Update JVMMarkerUtils.kt * auto-display endpoint quick stats setting * auto-display endpoint quick stats setting * change default * impl auto-resolve for SWLiveService * fix compatibility issues * fix compatibility issues * fix compatibility issues * fixes https://github.com/sourceplusplus/interface-jetbrains/issues/690 * clean * fix command highlighting * fixes #681 * clean * bump * fix dupes caused by quick stats indicator * keep focused if empty * ability to set virtual text font and offset * fixes https://github.com/sourceplusplus/interface-jetbrains/issues/692 * remove unused and fix font refactor to jb colors * fixes https://github.com/sourceplusplus/interface-jetbrains/issues/692 * fixes https://github.com/sourceplusplus/interface-jetbrains/issues/692 * more distinct * updated icons * better coloring * fix off center text * bold values instead of labels * improve coloring * improve coloring * fix auto resolving for spp install * ability to set editor * refactor * refactor * bump * merge revert * refactor * revert
1 parent c0b2023 commit caf4dbe

File tree

89 files changed

+804
-499
lines changed

Some content is hidden

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

89 files changed

+804
-499
lines changed

gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ kotlin.code.style=official
44

55
pluginGroup = spp.jetbrains
66
pluginName = Source++
7-
projectVersion=0.4.3
7+
projectVersion=0.4.4
88
pluginSinceBuild = 202.4357
99
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
1010
# See https://jb.gg/intellij-platform-builds-list for available build versions
11-
pluginVerifierIdeVersions = 2020.3.2, 2021.3.2
11+
pluginVerifierIdeVersions = 2020.3.2, 2021.3.3
1212

1313
platformType = IC
14-
ideVersion = 2021.3.2
14+
ideVersion = 2021.3.3
1515
platformDownloadSources = true
1616
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
1717
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22

marker/src/main/kotlin/spp/jetbrains/marker/SourceMarker.kt

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ object SourceMarker {
5151
private val availableSourceFileMarkers = Maps.newConcurrentMap<Int, SourceFileMarker>()
5252
private val globalSourceMarkEventListeners = Lists.newArrayList<SourceMarkEventListener>()
5353

54-
fun clearAvailableSourceFileMarkers() {
54+
suspend fun clearAvailableSourceFileMarkers() {
5555
check(enabled) { "SourceMarker disabled" }
5656

5757
availableSourceFileMarkers.forEach {
@@ -60,23 +60,7 @@ object SourceMarker {
6060
availableSourceFileMarkers.clear()
6161
}
6262

63-
fun refreshAvailableSourceFileMarkers(recreateFileMarkers: Boolean) {
64-
check(enabled) { "SourceMarker disabled" }
65-
66-
if (recreateFileMarkers) {
67-
val previousFileMarkers = getAvailableSourceFileMarkers()
68-
clearAvailableSourceFileMarkers()
69-
previousFileMarkers.forEach {
70-
getSourceFileMarker(it.psiFile)!!.refresh()
71-
}
72-
} else {
73-
availableSourceFileMarkers.forEach {
74-
it.value.refresh()
75-
}
76-
}
77-
}
78-
79-
fun deactivateSourceFileMarker(sourceFileMarker: SourceFileMarker): Boolean {
63+
suspend fun deactivateSourceFileMarker(sourceFileMarker: SourceFileMarker): Boolean {
8064
check(enabled) { "SourceMarker disabled" }
8165

8266
if (availableSourceFileMarkers.remove(sourceFileMarker.hashCode()) != null) {

marker/src/main/kotlin/spp/jetbrains/marker/plugin/FileActivityListener.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import com.intellij.openapi.project.Project
3131
import com.intellij.openapi.vfs.VirtualFile
3232
import com.intellij.psi.PsiFile
3333
import com.intellij.psi.PsiManager
34+
import kotlinx.coroutines.runBlocking
3435
import org.slf4j.LoggerFactory
3536
import spp.jetbrains.marker.SourceMarker
3637
import spp.jetbrains.marker.source.SourceFileMarker
@@ -61,7 +62,9 @@ class FileActivityListener : FileEditorManagerListener {
6162
val psiFile = PsiManager.getInstance(source.project).findFile(file)
6263
val fileMarker = psiFile?.getUserData(SourceFileMarker.KEY)
6364
if (fileMarker != null) {
64-
SourceMarker.deactivateSourceFileMarker(fileMarker)
65+
runBlocking {
66+
SourceMarker.deactivateSourceFileMarker(fileMarker)
67+
}
6568
}
6669
}
6770
}

marker/src/main/kotlin/spp/jetbrains/marker/plugin/SourceInlayHintProvider.kt

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import com.intellij.openapi.editor.impl.EditorImpl
2929
import com.intellij.openapi.editor.markup.EffectType
3030
import com.intellij.openapi.editor.markup.TextAttributes
3131
import com.intellij.openapi.fileEditor.FileEditorManager
32+
import com.intellij.openapi.util.Disposer
3233
import com.intellij.psi.PsiElement
3334
import com.intellij.psi.PsiFile
3435
import com.intellij.ui.paint.EffectPainter
@@ -37,6 +38,7 @@ import org.slf4j.LoggerFactory
3738
import spp.jetbrains.marker.SourceMarker
3839
import spp.jetbrains.marker.SourceMarker.getSourceFileMarker
3940
import spp.jetbrains.marker.source.mark.api.event.SourceMarkEventCode.MARK_REMOVED
41+
import spp.jetbrains.marker.source.mark.api.event.SourceMarkEventListener
4042
import spp.jetbrains.marker.source.mark.api.key.SourceKey
4143
import spp.jetbrains.marker.source.mark.inlay.InlayMark
4244
import spp.jetbrains.marker.source.mark.inlay.config.InlayMarkVirtualText
@@ -60,37 +62,32 @@ abstract class SourceInlayHintProvider : InlayHintsProvider<NoSettings> {
6062
companion object {
6163
private val log = LoggerFactory.getLogger(SourceInlayHintProvider::class.java)
6264

63-
@Volatile
64-
@JvmField
65-
var latestInlayMarkAddedAt: Long = -1L
66-
67-
init {
68-
SourceMarker.addGlobalSourceMarkEventListener { event ->
69-
when (event.eventCode) {
70-
VIRTUAL_TEXT_UPDATED, INLAY_MARK_VISIBLE, INLAY_MARK_HIDDEN -> {
71-
ApplicationManager.getApplication().invokeLater {
72-
FileEditorManager.getInstance(event.sourceMark.project).selectedTextEditor?.inlayModel
73-
//todo: smaller range
74-
?.getInlineElementsInRange(0, Integer.MAX_VALUE)?.forEach {
75-
it.repaint()
76-
}
77-
FileEditorManager.getInstance(event.sourceMark.project).selectedTextEditor?.inlayModel
78-
//todo: smaller range
79-
?.getAfterLineEndElementsInRange(0, Integer.MAX_VALUE)?.forEach {
80-
it.repaint()
81-
}
82-
FileEditorManager.getInstance(event.sourceMark.project).selectedTextEditor?.inlayModel
83-
//todo: smaller range
84-
?.getBlockElementsInRange(0, Integer.MAX_VALUE)?.forEach {
85-
it.repaint()
86-
}
87-
}
65+
val EVENT_LISTENER = SourceMarkEventListener { event ->
66+
when (event.eventCode) {
67+
VIRTUAL_TEXT_UPDATED, INLAY_MARK_VISIBLE, INLAY_MARK_HIDDEN -> {
68+
ApplicationManager.getApplication().invokeLater {
69+
FileEditorManager.getInstance(event.sourceMark.project).selectedTextEditor?.inlayModel
70+
//todo: smaller range
71+
?.getInlineElementsInRange(0, Integer.MAX_VALUE)?.forEach {
72+
it.repaint()
73+
}
74+
FileEditorManager.getInstance(event.sourceMark.project).selectedTextEditor?.inlayModel
75+
//todo: smaller range
76+
?.getAfterLineEndElementsInRange(0, Integer.MAX_VALUE)?.forEach {
77+
it.repaint()
78+
}
79+
FileEditorManager.getInstance(event.sourceMark.project).selectedTextEditor?.inlayModel
80+
//todo: smaller range
81+
?.getBlockElementsInRange(0, Integer.MAX_VALUE)?.forEach {
82+
it.repaint()
83+
}
8884
}
89-
MARK_REMOVED -> {
90-
ApplicationManager.getApplication().invokeLater {
91-
FileEditorManager.getInstance(event.sourceMark.project).selectedTextEditor?.inlayModel
92-
//todo: smaller range
93-
?.getBlockElementsInRange(0, Integer.MAX_VALUE)?.forEach {
85+
}
86+
MARK_REMOVED -> {
87+
ApplicationManager.getApplication().invokeLater {
88+
FileEditorManager.getInstance(event.sourceMark.project).selectedTextEditor?.inlayModel
89+
//todo: smaller range
90+
?.getBlockElementsInRange(0, Integer.MAX_VALUE)?.forEach {
9491
if (it.renderer is BlockInlayRenderer) {
9592
val cachedPresentation = Reflect.on(it.renderer).field("cachedPresentation").get<Any>()
9693
if (cachedPresentation is RecursivelyUpdatingRootPresentation) {
@@ -99,18 +96,21 @@ abstract class SourceInlayHintProvider : InlayHintsProvider<NoSettings> {
9996
if (delegatePresentation.presentation is DynamicTextInlayPresentation) {
10097
val dynamicPresentation = delegatePresentation.presentation as DynamicTextInlayPresentation
10198
if (dynamicPresentation.inlayMark == event.sourceMark) {
102-
it.dispose()
99+
Disposer.dispose(it)
103100
}
104101
}
105102
}
106103
}
107104
}
108105
}
109-
}
110106
}
111107
}
112108
}
113109
}
110+
111+
@Volatile
112+
@JvmField
113+
var latestInlayMarkAddedAt: Long = -1L
114114
}
115115

116116
override val key: SettingsKey<NoSettings> = SettingsKey("SourceMarker/InlayHints")
@@ -201,13 +201,13 @@ abstract class SourceInlayHintProvider : InlayHintsProvider<NoSettings> {
201201
if (virtualText.icon != null) {
202202
virtualText.icon!!.paintIcon(null, g, virtualText.iconLocation.x, virtualText.iconLocation.y)
203203
}
204-
g.font = font
204+
g.font = virtualText.font ?: font
205205
g.setRenderingHint(
206206
RenderingHints.KEY_TEXT_ANTIALIASING,
207207
AntialiasingType.getKeyForCurrentScope(false)
208208
)
209209
g.color = foreground
210-
g.drawString(virtualText.getRenderedVirtualText(), 0, ascent)
210+
g.drawString(virtualText.getRenderedVirtualText(), virtualText.xOffset, ascent)
211211
val effectColor = virtualText.textAttributes.effectColor
212212
if (effectColor != null) {
213213
g.color = effectColor

marker/src/main/kotlin/spp/jetbrains/marker/source/SourceFileMarker.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import com.intellij.openapi.util.Key
2626
import com.intellij.psi.PsiElement
2727
import com.intellij.psi.PsiFile
2828
import com.intellij.psi.PsiNameIdentifierOwner
29+
import kotlinx.coroutines.runBlocking
2930
import org.slf4j.LoggerFactory
3031
import spp.jetbrains.marker.source.mark.api.*
3132
import spp.jetbrains.marker.source.mark.api.event.SourceMarkEvent
@@ -83,9 +84,11 @@ open class SourceFileMarker(val psiFile: PsiFile) : SourceMarkProvider {
8384
}
8485
}
8586

86-
open fun clearSourceMarks() {
87+
open suspend fun clearSourceMarks() {
8788
val removed = sourceMarks.removeIf {
88-
it.dispose(false)
89+
runBlocking {
90+
it.disposeSuspend(false)
91+
}
8992
true
9093
}
9194
if (removed) refresh()

marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/ClassSourceMark.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ abstract class ClassSourceMark(
8484
false
8585
}
8686

87-
override fun apply(sourceMarkComponent: SourceMarkComponent, addToMarker: Boolean) {
87+
override fun apply(sourceMarkComponent: SourceMarkComponent, addToMarker: Boolean, editor: Editor?) {
8888
this.sourceMarkComponent = sourceMarkComponent
89-
super.apply(addToMarker)
89+
super.apply(addToMarker, editor)
9090
}
9191

92-
override fun apply(addToMarker: Boolean) {
93-
apply(configuration.componentProvider.getComponent(this), addToMarker)
92+
override fun apply(addToMarker: Boolean, editor: Editor?) {
93+
apply(configuration.componentProvider.getComponent(this), addToMarker, editor)
9494
}
9595

9696
override fun dispose(removeFromMarker: Boolean, assertRemoval: Boolean) {
@@ -99,6 +99,12 @@ abstract class ClassSourceMark(
9999
super.dispose(removeFromMarker, assertRemoval)
100100
}
101101

102+
override suspend fun disposeSuspend(removeFromMarker: Boolean, assertRemoval: Boolean) {
103+
psiClass.nameIdentifier?.putUserData(SourceKey.GutterMark, null)
104+
psiClass.nameIdentifier?.putUserData(SourceKey.InlayMark, null)
105+
super.disposeSuspend(removeFromMarker, assertRemoval)
106+
}
107+
102108
private val userData = HashMap<Any, Any>()
103109
override fun <T> getUserData(key: SourceKey<T>): T? = userData[key] as T?
104110
override fun <T> putUserData(key: SourceKey<T>, value: T?) {

marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/ExpressionSourceMark.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ abstract class ExpressionSourceMark(
8080
}
8181

8282
@Synchronized
83-
override fun apply(sourceMarkComponent: SourceMarkComponent, addToMarker: Boolean) {
83+
override fun apply(sourceMarkComponent: SourceMarkComponent, addToMarker: Boolean, editor: Editor?) {
8484
this.sourceMarkComponent = sourceMarkComponent
85-
super.apply(addToMarker)
85+
super.apply(addToMarker, editor)
8686
}
8787

88-
override fun apply(addToMarker: Boolean) {
89-
apply(configuration.componentProvider.getComponent(this), addToMarker)
88+
override fun apply(addToMarker: Boolean, editor: Editor?) {
89+
apply(configuration.componentProvider.getComponent(this), addToMarker, editor)
9090
}
9191

9292
override fun dispose(removeFromMarker: Boolean, assertRemoval: Boolean) {
@@ -98,6 +98,15 @@ abstract class ExpressionSourceMark(
9898
super.dispose(removeFromMarker, assertRemoval)
9999
}
100100

101+
override suspend fun disposeSuspend(removeFromMarker: Boolean, assertRemoval: Boolean) {
102+
when (this) {
103+
is GutterMark -> getPsiElement().putUserData(SourceKey.GutterMark, null)
104+
is InlayMark -> getPsiElement().putUserData(SourceKey.InlayMark, null)
105+
else -> throw IllegalStateException("ExpressionSourceMark is not a GutterMark or InlayMark")
106+
}
107+
super.disposeSuspend(removeFromMarker, assertRemoval)
108+
}
109+
101110
fun getParentSourceMark(): SourceMark? {
102111
return SourceMarker.getSourceMark(
103112
artifactQualifiedName.copy(

marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/MethodSourceMark.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ abstract class MethodSourceMark(
8585
}
8686

8787
@Synchronized
88-
override fun apply(sourceMarkComponent: SourceMarkComponent, addToMarker: Boolean) {
88+
override fun apply(sourceMarkComponent: SourceMarkComponent, addToMarker: Boolean, editor: Editor?) {
8989
this.sourceMarkComponent = sourceMarkComponent
90-
super.apply(addToMarker)
90+
super.apply(addToMarker, editor)
9191
}
9292

93-
override fun apply(addToMarker: Boolean) {
94-
apply(configuration.componentProvider.getComponent(this), addToMarker)
93+
override fun apply(addToMarker: Boolean, editor: Editor?) {
94+
apply(configuration.componentProvider.getComponent(this), addToMarker, editor)
9595
}
9696

9797
override fun dispose(removeFromMarker: Boolean, assertRemoval: Boolean) {
@@ -100,6 +100,12 @@ abstract class MethodSourceMark(
100100
super.dispose(removeFromMarker, assertRemoval)
101101
}
102102

103+
override suspend fun disposeSuspend(removeFromMarker: Boolean, assertRemoval: Boolean) {
104+
psiMethod.nameIdentifier?.putUserData(SourceKey.GutterMark, null)
105+
psiMethod.nameIdentifier?.putUserData(SourceKey.InlayMark, null)
106+
super.disposeSuspend(removeFromMarker, assertRemoval)
107+
}
108+
103109
private val userData = HashMap<Any, Any>()
104110
override fun <T> getUserData(key: SourceKey<T>): T? = userData[key] as T?
105111
override fun <T> putUserData(key: SourceKey<T>, value: T?) {

marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/SourceMark.kt

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import com.intellij.ui.awt.RelativePoint
4040
import com.intellij.util.ui.JBUI
4141
import kotlinx.coroutines.GlobalScope
4242
import kotlinx.coroutines.launch
43+
import kotlinx.coroutines.runBlocking
4344
import org.slf4j.LoggerFactory
4445
import spp.jetbrains.marker.SourceMarker
4546
import spp.jetbrains.marker.plugin.SourceInlayComponentProvider
@@ -119,8 +120,8 @@ interface SourceMark : JBPopupListener, MouseMotionListener, VisibleAreaListener
119120
fun setVisible(visible: Boolean)
120121

121122
fun canApply(): Boolean = configuration.applySourceMarkFilter.test(this)
122-
fun apply(sourceMarkComponent: SourceMarkComponent, addToMarker: Boolean = true)
123-
fun apply(addToMarker: Boolean = true) {
123+
fun apply(sourceMarkComponent: SourceMarkComponent, addToMarker: Boolean = true, editor: Editor? = null)
124+
fun apply(addToMarker: Boolean = true, editor: Editor? = null) {
124125
SourceMarker.getGlobalSourceMarkEventListeners().forEach(::addEventListener)
125126

126127
if (addToMarker) {
@@ -143,12 +144,12 @@ interface SourceMark : JBPopupListener, MouseMotionListener, VisibleAreaListener
143144
}
144145
} else if (this is InlayMark) {
145146
if (configuration.showComponentInlay) {
146-
val editor = FileEditorManager.getInstance(project).selectedTextEditor
147-
if (editor == null) {
147+
val selectedEditor = editor ?: FileEditorManager.getInstance(project).selectedTextEditor
148+
if (selectedEditor == null) {
148149
TODO()
149150
} else {
150-
val provider = SourceInlayComponentProvider.from(editor)
151-
val viewport = (editor as? EditorImpl)?.scrollPane?.viewport!!
151+
val provider = SourceInlayComponentProvider.from(selectedEditor)
152+
val viewport = (selectedEditor as? EditorImpl)?.scrollPane?.viewport!!
152153
var displayLineIndex = lineNumber - 1
153154
if (this is ExpressionInlayMark) {
154155
if (showAboveExpression) {
@@ -232,6 +233,24 @@ interface SourceMark : JBPopupListener, MouseMotionListener, VisibleAreaListener
232233
}
233234
}
234235

236+
suspend fun disposeSuspend(removeFromMarker: Boolean = true, assertRemoval: Boolean = true) {
237+
if (this is InlayMark) {
238+
configuration.inlayRef?.get()?.dispose()
239+
configuration.inlayRef = null
240+
}
241+
closePopup()
242+
243+
if (removeFromMarker) {
244+
if (assertRemoval) {
245+
check(sourceFileMarker.removeSourceMark(this, autoRefresh = true, autoDispose = false))
246+
} else {
247+
sourceFileMarker.removeSourceMark(this, autoRefresh = true, autoDispose = false)
248+
}
249+
}
250+
triggerEventSuspend(SourceMarkEvent(this, SourceMarkEventCode.MARK_REMOVED))
251+
clearEventListeners()
252+
}
253+
235254
fun <T> getUserData(key: SourceKey<T>): T?
236255
fun <T> putUserData(key: SourceKey<T>, value: T?)
237256
fun hasUserData(): Boolean
@@ -261,6 +280,22 @@ interface SourceMark : JBPopupListener, MouseMotionListener, VisibleAreaListener
261280
}
262281
}
263282

283+
suspend fun triggerEventSuspend(event: SourceMarkEvent) {
284+
//sync listeners
285+
getEventListeners()
286+
.filterIsInstance<SynchronousSourceMarkEventListener>()
287+
.forEach { it.handleEvent(event) }
288+
289+
//async listeners
290+
runBlocking {
291+
getEventListeners().forEach {
292+
if (it !is SynchronousSourceMarkEventListener) {
293+
it.handleEvent(event)
294+
}
295+
}
296+
}
297+
}
298+
264299
fun closePopup() {
265300
if (openedMarks.remove(this)) {
266301
log.trace("Closing popup")

0 commit comments

Comments
 (0)