Skip to content

Commit caba5de

Browse files
committed
优化inlay hint
1 parent 04304ee commit caba5de

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

EmmyLua-LS/src/main/kotlin/com/tang/vscode/LuaLanguageServer.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,7 @@ class LuaLanguageServer : LanguageServer, LanguageClientAware {
139139

140140
this.client = luaClient
141141
}
142+
143+
override fun setTrace(params: SetTraceParams) {
144+
}
142145
}

EmmyLua-LS/src/main/kotlin/com/tang/vscode/api/impl/LuaFile.kt

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ import com.tang.intellij.lua.ty.hasVarargs
2424
import com.tang.lsp.*
2525
import com.tang.vscode.RenderRange
2626
import com.tang.vscode.diagnostics.DiagnosticsService
27-
import org.eclipse.lsp4j.Diagnostic
28-
import org.eclipse.lsp4j.DidChangeTextDocumentParams
29-
import org.eclipse.lsp4j.InlayHint
30-
import org.eclipse.lsp4j.InlayHintKind
27+
import org.eclipse.lsp4j.*
3128
import org.eclipse.lsp4j.jsonrpc.CancelChecker
3229
import org.eclipse.lsp4j.jsonrpc.messages.Either
3330
import java.util.concurrent.locks.ReentrantReadWriteLock
@@ -259,7 +256,25 @@ class LuaFile(override val uri: FileURI) : VirtualFileBase(uri), ILuaFile, Virtu
259256
var fchild = funcBody.firstChild
260257
while (fchild != funcBody.lastChild) {
261258
if (fchild.text == ")") {
262-
overrideHints.add(RenderRange(fchild.textRange.toRange(file), null))
259+
// var location: Location? = null
260+
// val resolve = member.reference?.resolve()
261+
// if (resolve != null) {
262+
// val sourceFile = resolve.containingFile?.virtualFile as? LuaFile
263+
// val range = resolve.nameRange
264+
// if (range != null && sourceFile != null)
265+
// location = Location(
266+
// sourceFile.uri.toString(),
267+
// range.toRange(sourceFile)
268+
// )
269+
//
270+
// }
271+
overrideHints.add(
272+
RenderRange(
273+
fchild.textRange.toRange(file),
274+
" override "
275+
)
276+
)
277+
263278
return@processSuperClass true
264279
}
265280

@@ -383,12 +398,24 @@ class LuaFile(override val uri: FileURI) : VirtualFileBase(uri), ILuaFile, Virtu
383398
for (localHint in localHints) {
384399
val hint = InlayHint(localHint.range.end, Either.forLeft(":${localHint.hint}"))
385400
hint.kind = InlayHintKind.Type
401+
hint.paddingLeft = true
386402
inlayHints.add(hint)
387403
}
388404
}
389405
if (overrideHints.isNotEmpty()) {
390406
for (overrideHint in overrideHints) {
391-
inlayHints.add(InlayHint(overrideHint.range.end, Either.forLeft(" override ")))
407+
if(overrideHint.location == null) {
408+
val hint = InlayHint(overrideHint.range.end, Either.forLeft(overrideHint.hint))
409+
hint.paddingLeft = true
410+
inlayHints.add(hint)
411+
}
412+
else{
413+
val hintPart = InlayHintLabelPart(overrideHint.hint)
414+
hintPart.location = overrideHint.location
415+
val hint = InlayHint(overrideHint.range.end, Either.forRight(listOf(hintPart)))
416+
hint.paddingLeft = true
417+
inlayHints.add(hint)
418+
}
392419
}
393420
}
394421
return inlayHints

EmmyLua-LS/src/main/kotlin/com/tang/vscode/rpc.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.tang.vscode
33
import com.google.gson.JsonArray
44
import com.google.gson.JsonObject
55
import com.tang.lsp.FileURI
6+
import org.eclipse.lsp4j.Location
67
import org.eclipse.lsp4j.Range
78

89
enum class AnnotatorType {
@@ -18,7 +19,7 @@ enum class AnnotatorType {
1819

1920
data class AnnotatorParams(val uri: String)
2021

21-
data class RenderRange(val range: Range, var hint: String?)
22+
data class RenderRange(val range: Range, var hint: String?, val location: Location? = null)
2223

2324
data class Annotator(val uri: String, val ranges: List<RenderRange>, val type: AnnotatorType)
2425

0 commit comments

Comments
 (0)