@@ -233,177 +233,4 @@ class LuaFile(override val uri: FileURI) : VirtualFileBase(uri), ILuaFile, Virtu
233233 }
234234 }
235235 }
236-
237- fun getInlayHint (): MutableList <InlayHint > {
238- val paramHints = mutableListOf<RenderRange >()
239- val localHints = mutableListOf<RenderRange >()
240- val overrideHints = mutableListOf<RenderRange >()
241- val file = this
242-
243- psi?.acceptChildren(object : LuaRecursiveVisitor () {
244- override fun visitClassMethodDef (o : LuaClassMethodDef ) {
245- if (LuaSettings .instance.overrideHint) {
246- val context = SearchContext .get(o.project)
247- val classType = o.guessClassType(context)
248- if (classType != null ) {
249- TyClass .processSuperClass(classType, context) { sup ->
250- val id = o.classMethodName.id
251- if (id != null ) {
252- val member = sup.findMember(id.text, context)
253- if (member != null ) {
254- val funcBody = o.children.find { it is LuaFuncBody }
255- if (funcBody is LuaFuncBody ) {
256- var fchild = funcBody.firstChild
257- while (fchild != funcBody.lastChild) {
258- if (fchild.text == " )" ) {
259- overrideHints.add(
260- RenderRange (
261- fchild.textRange.toRange(file),
262- " override" ,
263- " ${sup.className} #${member.name} "
264- )
265- )
266-
267- return @processSuperClass false
268- }
269-
270- fchild = fchild.nextSibling
271- }
272- }
273- }
274- }
275- true
276- }
277- }
278- }
279- o.acceptChildren(this )
280- }
281-
282- override fun visitLocalDef (o : LuaLocalDef ) {
283- if (o.parent is LuaExprStat ) // non-complete stat
284- return
285- if (LuaSettings .instance.localHint) {
286- val nameList = o.nameList
287- o.exprList?.exprList.let { _ ->
288- nameList?.nameDefList?.forEach {
289- it.nameRange?.let { nameRange ->
290- // 这个类型联合的名字太长对大多数情况都不是必要的,将进行必要的裁剪
291- val gussType = it.guessType(SearchContext .get(o.project))
292- val displayName = gussType.displayName
293- when {
294- displayName.startsWith(" fun" ) -> {
295- localHints.add(RenderRange (nameRange.toRange(file), " function" ))
296- }
297- displayName.startsWith(' [' ) -> {
298- // ignore
299- }
300- else -> {
301- val unexpectedNameIndex = displayName.indexOf(" |[" )
302- when (unexpectedNameIndex) {
303- - 1 -> {
304- localHints.add(RenderRange (nameRange.toRange(file), displayName))
305- }
306- else -> {
307- localHints.add(
308- RenderRange (
309- nameRange.toRange(file),
310- displayName.substring(0 , unexpectedNameIndex)
311- )
312- )
313- }
314- }
315- }
316- }
317- }
318- }
319- }
320- }
321- o.acceptChildren(this )
322- }
323-
324- override fun visitCallExpr (callExpr : LuaCallExpr ) {
325- if (LuaSettings .instance.paramHint) {
326- var activeParameter = 0
327- var nCommas = 0
328- val literalMap = mutableMapOf<Int , Int >()
329- callExpr.args.firstChild?.let { firstChild ->
330- var child: PsiElement ? = firstChild
331- while (child != null ) {
332- if (child.node.elementType == LuaTypes .COMMA ) {
333- activeParameter++
334- nCommas++
335- } else if (child.node.elementType == LuaTypes .LITERAL_EXPR
336- || child.node.elementType == LuaTypes .TABLE_EXPR
337- || child.node.elementType == LuaTypes .CLOSURE_EXPR
338- || child.node.elementType == LuaTypes .BINARY_EXPR
339- ) {
340- paramHints.add(RenderRange (child.textRange.toRange(file), null ))
341- literalMap[activeParameter] = paramHints.size - 1 ;
342- }
343-
344- child = child.nextSibling
345- }
346- }
347-
348- callExpr.guessParentType(SearchContext .get(callExpr.project)).let { parentType ->
349- parentType.each { ty ->
350- if (ty is ITyFunction ) {
351- val sig = ty.findPerfectSignature(callExpr)
352- var index = 0 ;
353-
354- sig.params.forEach { pi ->
355- literalMap[index]?.let {
356- paramHints[it].hint = pi.name
357- }
358- index++
359- }
360-
361- if (sig.hasVarargs() && LuaSettings .instance.varargHint) {
362- for (paramIndex in literalMap.keys) {
363- if (paramIndex >= index) {
364- literalMap[paramIndex]?.let {
365- paramHints[it].hint = " var" + (paramIndex - index).toString()
366- }
367- }
368- }
369- }
370- }
371- }
372- }
373- }
374- }
375- })
376-
377- val inlayHints = mutableListOf<InlayHint >()
378- if (paramHints.isNotEmpty()) {
379- for (paramHint in paramHints) {
380- if (paramHint.hint != null ) {
381- val hint = InlayHint (paramHint.range.start, Either .forLeft(" ${paramHint.hint} :" ))
382- hint.kind = InlayHintKind .Parameter
383- hint.paddingRight = true
384- inlayHints.add(hint)
385- }
386- }
387- }
388- if (localHints.isNotEmpty()) {
389- for (localHint in localHints) {
390- val hint = InlayHint (localHint.range.end, Either .forLeft(" :${localHint.hint} " ))
391- hint.kind = InlayHintKind .Type
392- hint.paddingLeft = true
393- inlayHints.add(hint)
394- }
395- }
396- if (overrideHints.isNotEmpty()) {
397- for (overrideHint in overrideHints) {
398- val hint = InlayHint (overrideHint.range.end, Either .forLeft(overrideHint.hint))
399- hint.paddingLeft = true
400- if (overrideHint.data != null ){
401- hint.data = overrideHint.data
402- }
403-
404- inlayHints.add(hint)
405- }
406- }
407- return inlayHints
408- }
409236}
0 commit comments