Skip to content

Commit

Permalink
Support alias group for hover
Browse files Browse the repository at this point in the history
  • Loading branch information
Enaium committed Jan 3, 2025
1 parent 18b1f00 commit 71a2bd9
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 8 deletions.
4 changes: 2 additions & 2 deletions server/src/main/kotlin/cn/enaium/jimmer/dto/lsp/Workspace.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ data class Workspace(
})
)
)
}.get(20, TimeUnit.SECONDS)
}.get(5, TimeUnit.SECONDS)
} catch (_: TimeoutException) {
client?.notifyProgress(
ProgressParams(
Expand All @@ -65,7 +65,7 @@ data class Workspace(
)
client?.showMessage(MessageParams().apply {
message = "Resolve Dependencies timeout, please resolve dependencies manually"
type = MessageType.Error
type = MessageType.Warning
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class DocumentHoverService(documentManager: DocumentManager) : DocumentServiceAd
return CompletableFuture.completedFuture(hover)
}

private fun macro(macro: DtoParser.MicroContext) {
private fun macro(macro: DtoParser.MicroContext, pattern: DtoParser.AliasPatternContext? = null) {
val macroRange = Range(
macro.start.position(),
macro.stop.position(true)
Expand All @@ -134,7 +134,16 @@ class DocumentHoverService(documentManager: DocumentManager) : DocumentServiceAd
## ${macro.name.text}
${
props.second.filter { if (isAllReferences) isAutoReference(it) else isAutoScalar(it) }
.joinToString { "`${it.name}`" }
.joinToString {
"`${
pattern?.let { pattern ->
pattern(
it.name,
pattern
)
} ?: it.name
}`"
}
}
""".trimIndent()
), macroRange
Expand All @@ -143,7 +152,14 @@ class DocumentHoverService(documentManager: DocumentManager) : DocumentServiceAd
}
}

private fun prop(token: Token, optional: Boolean = false, required: Boolean = false, negative: Boolean = false) {
private fun prop(
token: Token,
optional: Boolean = false,
required: Boolean = false,
negative: Boolean = false,
alias: Token? = null,
pattern: DtoParser.AliasPatternContext? = null
) {
val range = Range(
token.position(),
token.position(true)
Expand All @@ -156,7 +172,13 @@ class DocumentHoverService(documentManager: DocumentManager) : DocumentServiceAd
MarkupContent(
MarkupKind.MARKDOWN,
"""
## ${prop.name}
## ${prop.name} ${
if (pattern != null) {
pattern(prop.name, pattern)
} else {
alias?.let { "`${it.text}`" } ?: ""
}
}
Trace: `${props.first}.${prop.name}`
From: `${prop.declaringType.name}`
Expand Down Expand Up @@ -186,10 +208,19 @@ class DocumentHoverService(documentManager: DocumentManager) : DocumentServiceAd
}
}

private fun positiveProp(positiveProp: DtoParser.PositivePropContext) {
private fun positiveProp(
positiveProp: DtoParser.PositivePropContext,
pattern: DtoParser.AliasPatternContext? = null
) {

positiveProp.props.forEach {
prop(it, optional = positiveProp.optional != null, required = positiveProp.required != null)
prop(
it,
optional = positiveProp.optional != null,
required = positiveProp.required != null,
alias = positiveProp.alias,
pattern = pattern
)
}

positiveProp.dtoBody()?.also { dtoBody ->
Expand All @@ -208,6 +239,52 @@ class DocumentHoverService(documentManager: DocumentManager) : DocumentServiceAd
prop.negativeProp()?.also { negativeProp ->
prop(negativeProp.prop, negative = true)
}
prop.aliasGroup()?.also { aliasGroup ->
aliasGroup.pattern?.also { pattern ->
aliasGroup.props.forEach { alias ->
alias.micro()?.also { micro ->
macro(micro, pattern)
}
alias.positiveProp()?.also { positiveProp ->
positiveProp(positiveProp, pattern)
}
}
}
}
}
}

private fun pattern(name: String, pattern: DtoParser.AliasPatternContext): String {
val original = pattern.original
val replace = pattern.replacement?.text ?: ""
return if (pattern.prefix != null) {
if (original == null) {
"`${replace}${name.replaceFirstChar { it.uppercase() }}`"
} else {
"`${
name.replaceFirst(
original.text,
replace
)
}`"
}
} else if (pattern.suffix != null) {
if (original == null) {
"`${name}${replace}`"
} else {
"`${
name.replaceFirst(
original.text,
replace
)
}`"
}
} else {
if (original != null) {
"`${name.replaceFirst(original.text, replace)}`"
} else {
""
}
}
}

Expand Down

0 comments on commit 71a2bd9

Please sign in to comment.