Skip to content

Commit 51cfd0e

Browse files
authored
merge dev (#717)
* archive media * should be only place that needs null check * revert to dynamic * fixes #701 * use readme for unreleased * verify oldest version * bump vertx * determine locale * translate * bump * impl guide marks * #610 * url can be censored * fix modified check * dev id will always be system * ability to get sw version * #695 * sw 9 uses endpoint_resp_time instead of endpoint_avg * basic py coding for LCP * basic py coding for LCP
1 parent bc7ef06 commit 51cfd0e

40 files changed

+721
-94
lines changed

marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMArtifactCreationService.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ class JVMArtifactCreationService : ArtifactCreationService {
7373
if (gutterMark == null) {
7474
gutterMark = fileMarker.createMethodSourceMark(
7575
element.parent as PsiNameIdentifierOwner,
76-
JVMMarkerUtils.getFullyQualifiedName(element.parent.toUElement() as UMethod),
7776
SourceMark.Type.GUTTER
7877
) as MethodGutterMark
7978
return if (autoApply) {

marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMArtifactNamingService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class JVMArtifactNamingService : ArtifactNamingService {
4646
}
4747
}
4848

49-
override fun getClassQualifiedNames(psiFile: PsiFile): List<ArtifactQualifiedName> {
49+
override fun getQualifiedClassNames(psiFile: PsiFile): List<ArtifactQualifiedName> {
5050
return when (psiFile) {
5151
is PsiClassOwner -> psiFile.classes.map {
5252
ArtifactQualifiedName(it.qualifiedName!!, type = ArtifactType.CLASS)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Source++, the open-source live coding platform.
3+
* Copyright (C) 2022 CodeBrig, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published
7+
* by the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
package spp.jetbrains.marker.jvm
19+
20+
import com.intellij.openapi.application.ApplicationManager
21+
import com.intellij.psi.JavaRecursiveElementVisitor
22+
import com.intellij.psi.PsiMethod
23+
import com.intellij.psi.PsiNameIdentifierOwner
24+
import spp.jetbrains.marker.plugin.SourceGuideProvider
25+
import spp.jetbrains.marker.source.SourceFileMarker
26+
import spp.jetbrains.marker.source.mark.api.SourceMark
27+
28+
class JVMGuideProvider : SourceGuideProvider {
29+
30+
override fun determineGuideMarks(fileMarker: SourceFileMarker) {
31+
fileMarker.psiFile.acceptChildren(object : JavaRecursiveElementVisitor() {
32+
override fun visitMethod(method: PsiMethod) {
33+
super.visitMethod(method)
34+
35+
ApplicationManager.getApplication().runReadAction {
36+
fileMarker.createMethodSourceMark(
37+
method as PsiNameIdentifierOwner, SourceMark.Type.GUIDE
38+
).apply(true)
39+
}
40+
}
41+
})
42+
}
43+
}

marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/psi/EndpointDetector.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,12 @@ class EndpointDetector(val vertx: Vertx) {
141141
private suspend fun determineEndpointName(sourceMark: MethodSourceMark): Future<Optional<DetectedEndpoint>> {
142142
return withContext(Dispatchers.Default) {
143143
ApplicationManager.getApplication().runReadAction(Computable {
144-
determineEndpointName(sourceMark.getPsiMethod().toUElement() as UMethod)
144+
val uMethod = sourceMark.getPsiMethod().toUElement() as UMethod?
145+
if (uMethod != null) {
146+
determineEndpointName(sourceMark.getPsiMethod().toUElement() as UMethod)
147+
} else { //todo: python functions don't have UMethod
148+
Future.succeededFuture(Optional.empty())
149+
}
145150
})
146151
}
147152
}

marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/psi/LoggerDetector.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,14 @@ class LoggerDetector(val vertx: Vertx) {
9292
log.trace("Found logger statements: $loggerStatements")
9393
loggerStatements
9494
} else {
95-
val foundLoggerStatements = getOrFindLoggerStatements(sourceMark.getPsiMethod().toUElement() as UMethod).await()
96-
sourceMark.putUserData(LOGGER_STATEMENTS, foundLoggerStatements)
97-
foundLoggerStatements
95+
val uMethod = sourceMark.getPsiMethod().toUElement() as UMethod?
96+
if (uMethod != null) {
97+
val foundLoggerStatements = getOrFindLoggerStatements(uMethod).await()
98+
sourceMark.putUserData(LOGGER_STATEMENTS, foundLoggerStatements)
99+
foundLoggerStatements
100+
} else { //todo: python functions don't have UMethod
101+
emptyList()
102+
}
98103
}
99104
}
100105

marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/source/JVMMarkerUtils.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ object JVMMarkerUtils {
326326
log.trace("createMethodGutterMark: $element")
327327
val gutterMark = fileMarker.createMethodSourceMark(
328328
element.parent as PsiNameIdentifierOwner,
329-
getFullyQualifiedName(element.parent.toUElement() as UMethod),
330329
SourceMark.Type.GUTTER
331330
) as MethodGutterMark
332331
return if (autoApply) {
@@ -357,7 +356,6 @@ object JVMMarkerUtils {
357356
log.trace("createMethodInlayMark: $element")
358357
val inlayMark = fileMarker.createMethodSourceMark(
359358
element.parent as PsiNameIdentifierOwner,
360-
getFullyQualifiedName(element.parent.toUElement() as UMethod),
361359
SourceMark.Type.INLAY
362360
) as MethodInlayMark
363361
return if (autoApply) {
@@ -400,7 +398,6 @@ object JVMMarkerUtils {
400398
return if (inlayMark == null) {
401399
inlayMark = fileMarker.createMethodSourceMark(
402400
element.parent as PsiNameIdentifierOwner,
403-
getFullyQualifiedName(element.parent.toUElement() as UMethod),
404401
SourceMark.Type.INLAY
405402
) as MethodInlayMark
406403
return if (autoApply) {
@@ -456,7 +453,6 @@ object JVMMarkerUtils {
456453
}
457454
gutterMark = fileMarker.createClassSourceMark(
458455
element.parent as PsiNameIdentifierOwner,
459-
getFullyQualifiedName(uClass),
460456
SourceMark.Type.GUTTER
461457
) as ClassGutterMark
462458
return if (autoApply) {

marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonArtifactNamingService.kt

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package spp.jetbrains.marker.py
1919

2020
import com.intellij.psi.PsiElement
2121
import com.intellij.psi.PsiFile
22+
import com.intellij.psi.util.parentOfType
23+
import com.jetbrains.python.psi.*
2224
import spp.jetbrains.marker.ArtifactNamingService
2325
import spp.protocol.artifact.ArtifactQualifiedName
2426
import spp.protocol.artifact.ArtifactType
@@ -32,13 +34,43 @@ import spp.protocol.artifact.ArtifactType
3234
class PythonArtifactNamingService : ArtifactNamingService {
3335

3436
override fun getFullyQualifiedName(element: PsiElement): ArtifactQualifiedName {
35-
return ArtifactQualifiedName(
36-
element.containingFile.name, null, ArtifactType.CLASS
37-
) //todo: include method name when possible?
37+
return when (element) {
38+
is PyClass -> {
39+
ArtifactQualifiedName(element.qualifiedName!!, null, ArtifactType.CLASS)
40+
}
41+
is PyFunction -> {
42+
val parentQualifiedName = PyPsiFacade.getInstance(element.project)
43+
.findShortestImportableName(element.containingFile.virtualFile, element)
44+
val qualifiedName = element.qualifiedName ?: "$parentQualifiedName.${element.name}"
45+
ArtifactQualifiedName("$qualifiedName()", null, ArtifactType.METHOD)
46+
}
47+
is PyStatement, is PyStatementList -> getStatementOrExpressionQualifiedName(element, ArtifactType.STATEMENT)
48+
else -> getStatementOrExpressionQualifiedName(element, ArtifactType.EXPRESSION)
49+
}
3850
}
3951

40-
//todo: method name could be better
41-
override fun getClassQualifiedNames(psiFile: PsiFile): List<ArtifactQualifiedName> {
42-
return listOf(ArtifactQualifiedName(psiFile.virtualFile.path, type = ArtifactType.CLASS))
52+
private fun getStatementOrExpressionQualifiedName(element: PsiElement, type: ArtifactType): ArtifactQualifiedName {
53+
val parentFunction = element.parentOfType<PyFunction>()
54+
return if (parentFunction != null) {
55+
val parentQualifiedName = PyPsiFacade.getInstance(element.project)
56+
.findShortestImportableName(element.containingFile.virtualFile, element)
57+
val qualifiedName = parentFunction.qualifiedName ?: "$parentQualifiedName.${parentFunction.name!!}"
58+
ArtifactQualifiedName("$qualifiedName()", null, type)
59+
} else {
60+
val qName = PyPsiFacade.getInstance(element.project)
61+
.findShortestImportableName(element.containingFile.virtualFile, element)
62+
ArtifactQualifiedName("$qName", null, type)
63+
}
64+
}
65+
66+
override fun getQualifiedClassNames(psiFile: PsiFile): List<ArtifactQualifiedName> {
67+
val classQualifiedNames = mutableListOf<ArtifactQualifiedName>()
68+
psiFile.acceptChildren(object : PyRecursiveElementVisitor() {
69+
override fun visitPyClass(node: PyClass) {
70+
super.visitPyClass(node)
71+
classQualifiedNames.add(ArtifactQualifiedName(node.qualifiedName!!, type = ArtifactType.CLASS))
72+
}
73+
})
74+
return classQualifiedNames
4375
}
4476
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Source++, the open-source live coding platform.
3+
* Copyright (C) 2022 CodeBrig, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published
7+
* by the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
package spp.jetbrains.marker.py
19+
20+
import com.intellij.openapi.application.ApplicationManager
21+
import com.intellij.psi.PsiNameIdentifierOwner
22+
import com.jetbrains.python.psi.PyFunction
23+
import com.jetbrains.python.psi.PyRecursiveElementVisitor
24+
import spp.jetbrains.marker.plugin.SourceGuideProvider
25+
import spp.jetbrains.marker.source.SourceFileMarker
26+
import spp.jetbrains.marker.source.mark.api.SourceMark
27+
28+
class PythonGuideProvider : SourceGuideProvider {
29+
30+
override fun determineGuideMarks(fileMarker: SourceFileMarker) {
31+
fileMarker.psiFile.acceptChildren(object : PyRecursiveElementVisitor() {
32+
override fun visitPyFunction(function: PyFunction) {
33+
super.visitPyFunction(function)
34+
35+
ApplicationManager.getApplication().runReadAction {
36+
fileMarker.createMethodSourceMark(
37+
function as PsiNameIdentifierOwner, SourceMark.Type.GUIDE
38+
).apply(true)
39+
}
40+
}
41+
})
42+
}
43+
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,5 @@ import spp.protocol.artifact.ArtifactQualifiedName
3030
interface ArtifactNamingService {
3131

3232
fun getFullyQualifiedName(element: PsiElement): ArtifactQualifiedName
33-
34-
fun getClassQualifiedNames(psiFile: PsiFile): List<ArtifactQualifiedName>
33+
fun getQualifiedClassNames(psiFile: PsiFile): List<ArtifactQualifiedName>
3534
}

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ import com.google.common.collect.ImmutableList
2121
import com.google.common.collect.Lists
2222
import com.google.common.collect.Maps
2323
import com.intellij.psi.PsiFile
24+
import kotlinx.coroutines.GlobalScope
25+
import kotlinx.coroutines.launch
2426
import org.slf4j.LoggerFactory
27+
import spp.jetbrains.marker.plugin.SourceGuideProvider
2528
import spp.jetbrains.marker.source.SourceFileMarker
2629
import spp.jetbrains.marker.source.mark.api.SourceMark
2730
import spp.jetbrains.marker.source.mark.api.event.SourceMarkEventListener
@@ -43,6 +46,7 @@ object SourceMarker {
4346
@Volatile
4447
var enabled = true
4548
val configuration: SourceMarkerConfiguration = SourceMarkerConfiguration()
49+
lateinit var guideProvider: SourceGuideProvider
4650
lateinit var namingService: ArtifactNamingService
4751
lateinit var creationService: ArtifactCreationService
4852
lateinit var scopeService: ArtifactScopeService
@@ -86,14 +90,18 @@ object SourceMarker {
8690
availableSourceFileMarkers.putIfAbsent(psiFile.hashCode(), fileMarker)
8791
fileMarker = availableSourceFileMarkers[psiFile.hashCode()]!!
8892
psiFile.putUserData(SourceFileMarker.KEY, fileMarker)
93+
94+
GlobalScope.launch {
95+
guideProvider.determineGuideMarks(fileMarker)
96+
}
8997
return fileMarker
9098
}
9199

92100
fun getSourceFileMarker(classQualifiedName: String): SourceFileMarker? {
93101
check(enabled) { "SourceMarker disabled" }
94102

95103
return availableSourceFileMarkers.values.find {
96-
namingService.getClassQualifiedNames(it.psiFile).find { it.identifier.contains(classQualifiedName) } != null
104+
namingService.getQualifiedClassNames(it.psiFile).find { it.identifier.contains(classQualifiedName) } != null
97105
}
98106
}
99107

@@ -105,7 +113,7 @@ object SourceMarker {
105113
type = ArtifactType.CLASS
106114
)
107115
return availableSourceFileMarkers.values.find {
108-
namingService.getClassQualifiedNames(it.psiFile).contains(classArtifactQualifiedName)
116+
namingService.getQualifiedClassNames(it.psiFile).contains(classArtifactQualifiedName)
109117
}
110118
}
111119

0 commit comments

Comments
 (0)