Skip to content

Commit b761043

Browse files
committed
fix: unique artifact names
1 parent f0e896a commit b761043

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactNamingService.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,24 +98,30 @@ class JavascriptArtifactNamingService : IArtifactNamingService {
9898
}
9999

100100
private fun getStatementOrExpressionQualifiedName(element: PsiElement, type: ArtifactType): ArtifactQualifiedName {
101-
val name = if (element is PsiNamedElement) {
102-
element.name
101+
//todo: each element needs a unique name but encoding the literal text and appending the offset is not unique enough
102+
// - will need to get a unique hash from PSI or generate a unique name and store it in the PSI
103+
var expressionString = if (element is PsiNamedElement) {
104+
element.name ?: ""
103105
} else {
104-
Base64.getEncoder().encodeToString(element.toString().toByteArray())
106+
element.text ?: ""
107+
}
108+
element.textRange.startOffset.let {
109+
expressionString = "$expressionString:$it"
105110
}
111+
expressionString = Base64.getEncoder().encodeToString(expressionString.toByteArray())
106112

107113
val parentElement = element.findTopmostParentInFile {
108114
it is JSClass || (it is JSFunction && it !is JSFunctionExpression)
109115
}
110116
return if (parentElement != null) {
111117
ArtifactQualifiedName(
112-
"${getFullyQualifiedName(parentElement).identifier}#${name}",
118+
"${getFullyQualifiedName(parentElement).identifier}#${expressionString}",
113119
type = type,
114120
lineNumber = SourceMarkerUtils.getLineNumber(element)
115121
)
116122
} else {
117123
ArtifactQualifiedName(
118-
"${element.containingFile.virtualFile.path}#$name",
124+
"${element.containingFile.virtualFile.path}#$expressionString",
119125
type = type,
120126
lineNumber = SourceMarkerUtils.getLineNumber(element)
121127
)

0 commit comments

Comments
 (0)