Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug #209 #122 #217

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
42aff70
Fixed messy code issues when hooking OutputDebugView API
luchuanbaker May 24, 2018
8077dc1
Merge branch 'master' of https://github.com/EmmyLua/IntelliJ-EmmyLua
luchuanbaker May 29, 2018
345f96a
Merge branch 'master' of https://github.com/EmmyLua/IntelliJ-EmmyLua
luchuanbaker Jun 1, 2018
049e732
Merge branch 'master' of https://github.com/EmmyLua/IntelliJ-EmmyLua
luchuanbaker Jun 14, 2018
f6a433b
Merge branch 'master' of https://github.com/EmmyLua/IntelliJ-EmmyLua
luchuanbaker Jun 16, 2018
30cb520
Merge branch 'master' of https://github.com/EmmyLua/IntelliJ-EmmyLua
luchuanbaker Jul 6, 2018
a8ec906
Merge branch 'master' of https://github.com/EmmyLua/IntelliJ-EmmyLua
luchuanbaker Jul 9, 2018
042f98c
Merge branch 'master' of https://github.com/EmmyLua/IntelliJ-EmmyLua
luchuanbaker Jul 11, 2018
691a5d0
Merge branch 'master' of https://github.com/EmmyLua/IntelliJ-EmmyLua
luchuanbaker Jul 20, 2018
d660400
Merge branch 'master' of https://github.com/EmmyLua/IntelliJ-EmmyLua
luchuanbaker Jul 31, 2018
91163fc
Merge branch 'master' of https://github.com/EmmyLua/IntelliJ-EmmyLua
luchuanbaker Aug 4, 2018
f2171ad
Merge branch 'master' of https://github.com/EmmyLua/IntelliJ-EmmyLua
luchuanbaker Aug 21, 2018
da19268
Merge branch 'master' of https://github.com/EmmyLua/IntelliJ-EmmyLua
luchuanbaker Aug 28, 2018
2c18e94
Merge branch 'master' of https://github.com/EmmyLua/IntelliJ-EmmyLua
luchuanbaker Sep 6, 2018
d34f793
Merge branch 'master' of https://github.com/EmmyLua/IntelliJ-EmmyLua
luchuanbaker Nov 12, 2018
755af45
Merge branch 'master' of https://github.com/EmmyLua/IntelliJ-EmmyLua
luchuanbaker Dec 11, 2018
be15108
Merge branch 'master' of https://github.com/EmmyLua/IntelliJ-EmmyLua
luchuanbaker Dec 14, 2018
cc96266
Merge branch 'master' of https://github.com/EmmyLua/IntelliJ-EmmyLua
luchuanbaker Jan 8, 2019
b9c1876
1、fix bug #209, #122
luchuanbaker Jan 8, 2019
8e2a8ea
恢复成与原始版本一样
luchuanbaker Jan 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ import com.intellij.codeInsight.lookup.LookupElement
import com.intellij.lang.parameterInfo.*
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.util.Processor
import com.tang.intellij.lua.psi.LuaArgs
import com.tang.intellij.lua.psi.LuaCallExpr
import com.tang.intellij.lua.psi.LuaListArgs
import com.tang.intellij.lua.psi.LuaTypes
import com.tang.intellij.lua.psi.*
import com.tang.intellij.lua.psi.impl.LuaIndexExprImpl
import com.tang.intellij.lua.search.SearchContext
import com.tang.intellij.lua.ty.*

Expand Down Expand Up @@ -52,7 +50,26 @@ class LuaParameterInfoHandler : ParameterInfoHandler<LuaArgs, ParameterInfoType>
if (luaArgs != null) {
val callExpr = luaArgs.parent as LuaCallExpr
val isColonStyle = callExpr.isMethodColonCall
val type = callExpr.guessParentType(SearchContext(context.project))
val searchContext = SearchContext(context.project)
var type = callExpr.guessParentType(searchContext)
// for chain
// add by clu on 添加对t.data.sayHello()方法的提示支持
if (type == Ty.UNKNOWN) {
val children = luaArgs.parent.children
if (children.isNotEmpty()) {
(children[0] as? LuaIndexExpr).let {
if (it != null && it.name != null) {
val functions = resolveTypeByRoot(it, it.name!!, searchContext)
if (functions.isNotEmpty()) {
(functions[0] as? LuaIndexExpr)?.let {
type = it.guessType(searchContext)
}
}
}
}
}
}
// end
val list = mutableListOf<ParameterInfoType>()
TyUnion.each(type) { ty ->
if (ty is ITyFunction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,34 @@ open class LuaXTable(L: Long, process: LuaAttachDebugProcessBase)
children.add(value)
}

// fix https://github.com/EmmyLua/IntelliJ-EmmyLua/issues/122
private fun removeNonNumberChars(str: String): String {
return str.replace("[", "").replace("]", "")
}

private fun sort() {
deep = true
val sortList = mutableListOf<LuaXValue>()
val numberList = mutableListOf<LuaXValue>()
val notNumberList = mutableListOf<LuaXValue>()
children.forEach {
if (it is LuaXFunction) {
functionList.add(it)
} else sortList.add(it)
} else {
if (removeNonNumberChars(it.name!!).toLongOrNull() == null) {
notNumberList.add(it)
} else {
numberList.add(it)
}
}
}
val list = XValueChildrenList()
if (!functionList.isEmpty())
list.add(functionList.name, functionList)
sortList.sortBy { it.name }
sortList.forEach { list.add(it.name, it) }
numberList.sortBy { removeNonNumberChars(it.name!!).toLong() }
notNumberList.sortBy { it.name!!.toUpperCase() }

notNumberList.forEach { list.add(it.name, it) }
numberList.forEach { list.add(it.name, it) }
childrenList = list
}

Expand All @@ -112,14 +127,19 @@ open class LuaXTable(L: Long, process: LuaAttachDebugProcessBase)

process.bridge.eval(L, evalExpr, frame.stack, 2, object : LuaAttachBridgeBase.EvalCallback {
override fun onResult(result: DMRespEvaluate) {
val value = result.resultNode.value
if (value is LuaXTable) {
value.children.forEach {
add(it)
// add lua error to evaluate view
/*if (result.success && result.resultNode.success) {*/
val value = result.resultNode.value
if (value is LuaXTable) {
value.children.forEach {
add(it)
}
}
}
sort()
node.addChildren(childrenList!!, true)
sort()
node.addChildren(childrenList!!, true)
/*} else {
node.setErrorMessage(if (!result.success) "error" else result.resultNode.error)
}*/
}
})
} else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ import com.intellij.lang.documentation.DocumentationProvider
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiManager
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.util.Processor
import com.tang.intellij.lua.comment.psi.LuaDocTagClass
import com.tang.intellij.lua.comment.psi.LuaDocTagField
import com.tang.intellij.lua.editor.completion.LuaDocumentationLookupElement
import com.tang.intellij.lua.psi.*
import com.tang.intellij.lua.search.SearchContext
import com.tang.intellij.lua.stubs.LuaIndexExprType
import com.tang.intellij.lua.stubs.index.LuaClassIndex
import com.tang.intellij.lua.stubs.index.LuaClassMemberIndex
import com.tang.intellij.lua.ty.*

/**
Expand Down Expand Up @@ -100,14 +103,31 @@ class LuaDocumentationProvider : AbstractDocumentationProvider(), DocumentationP

private fun renderClassMember(sb: StringBuilder, classMember: LuaClassMember) {
val context = SearchContext(classMember.project)
val parentType = classMember.guessClassType(context)
var parentType = classMember.guessClassType(context)
// for chain
// add by clu on 2019-1-3 15:12:43 添加对a.b.c.d.e.f = 123中.f的parent,.e的获取支持(document中)
if (parentType == null) {
(classMember as? LuaIndexExpr)?.let {
val parentLuaIndexExpr = PsiTreeUtil.getStubChildOfType(it, LuaIndexExpr::class.java)
if (parentLuaIndexExpr != null) {
val definitions = resolveTypeByRoot(parentLuaIndexExpr, parentLuaIndexExpr.name!!, context)
if (definitions.isNotEmpty()) {
(definitions[0] as? LuaIndexExpr)?.let {
parentType = it.guessType(context) as? ITyClass
}
}
}
}
}
// end
val ty = classMember.guessType(context)
val tyRenderer = renderer

renderDefinition(sb) {
//base info
if (parentType != null) {
renderTy(sb, parentType, tyRenderer)
// for chain, add: as ITyClass
renderTy(sb, parentType as ITyClass, tyRenderer)
with(sb) {
when (ty) {
is TyFunction -> {
Expand All @@ -122,9 +142,12 @@ class LuaDocumentationProvider : AbstractDocumentationProvider(), DocumentationP
}
}
} else {
// add by clu on 2019年1月3日15:11:41 添加对a.b.c.d.e.f = 123这种格式的.f的document的支持
//NameExpr
if (classMember is LuaNameExpr) {
val nameExpr: LuaNameExpr = classMember
// for chain add: || classMember is LuaIndexExpr
if (classMember is LuaNameExpr || classMember is LuaIndexExpr) {
//val nameExpr: LuaNameExpr = classMember
val nameExpr = classMember as LuaExpr
with(sb) {
append(nameExpr.name)
when (ty) {
Expand All @@ -136,8 +159,15 @@ class LuaDocumentationProvider : AbstractDocumentationProvider(), DocumentationP
}
}

val stat = nameExpr.parent.parent // VAR_LIST ASSIGN_STAT
if (stat is LuaAssignStat) renderComment(sb, stat.comment, tyRenderer)
// 排除LuaIndexExpr
// for chain
if (classMember is LuaNameExpr) {
// end
val stat = nameExpr.parent.parent // VAR_LIST ASSIGN_STAT
if (stat is LuaAssignStat) renderComment(sb, stat.comment, tyRenderer)
// for chain
}
// end
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

package com.tang.intellij.lua.editor.completion

import com.google.common.collect.LinkedHashMultimap
import com.intellij.codeInsight.completion.CompletionInitializationContext
import com.intellij.codeInsight.completion.CompletionResultSet
import com.intellij.codeInsight.completion.CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED
import com.intellij.codeInsight.completion.PrefixMatcher
import com.intellij.codeInsight.completion.PrioritizedLookupElement
import com.intellij.codeInsight.lookup.LookupElement
Expand All @@ -27,6 +29,8 @@ import com.intellij.util.Processor
import com.tang.intellij.lua.lang.LuaIcons
import com.tang.intellij.lua.psi.*
import com.tang.intellij.lua.search.SearchContext
import com.tang.intellij.lua.stubs.LuaIndexExprType
import com.tang.intellij.lua.stubs.index.LuaClassMemberIndex
import com.tang.intellij.lua.ty.*

enum class MemberCompletionMode {
Expand Down Expand Up @@ -61,6 +65,71 @@ open class ClassMemberCompletionProvider : LuaCompletionProvider() {
if (!Ty.isInvalid(prefixType)) {
complete(isColon, project, contextTy, prefixType, completionResultSet, completionResultSet.prefixMatcher, null)
}

// for chain
// 多级t.data.name的提示
// 查找并t.data占位类型,并扩展到结果中
// val list = LuaIndexExprType.getAllKnownIndexLuaExprType(indexExpr, searchContext)
LuaIndexExprType.getAllKnownIndexLuaExprType(indexExpr, searchContext).forEach {
val baseType = it.key
val indexExprNames = it.value
TyUnion.each(baseType, {
if (it is ITyClass) {
// it类型是:118@F_LuaTest_src_test_t.lua
// 获取118@F_LuaTest_src_test_t.lua.__data类型
val parentClassNameOfCurrentIndexExpr = LuaIndexExprType.getFiledNameAsClassName(it.className, indexExprNames.toTypedArray(), indexExprNames.size)

val all = LuaClassMemberIndex.instance.get(parentClassNameOfCurrentIndexExpr.hashCode(), searchContext.project, searchContext.getScope())
val suggestDotCountMap = LinkedHashMultimap.create<Int, LuaIndexExpr>()
val inputText = indexExpr.text.replace(".$DUMMY_IDENTIFIER_TRIMMED", "") // t.data.
all.forEach {
val completeText = it.text // t.data.name.a.b
if (it is LuaIndexExpr) {
suggestDotCountMap.put(completeText.replace(inputText, "").count { it == '.' }, it)
}
}

suggestDotCountMap.keys().sorted().forEach {
suggestDotCountMap.get(it).forEach {
var suggestText = it.text.replaceFirst(inputText, "")
if (suggestText[0] == '.') {
suggestText = suggestText.substring(1)
}

val funType = it.guessType(searchContext)
if (funType is ITyFunction) {
val luaIndexExpr = it as LuaIndexExpr
val funName = it.name!!
resolveTypeByRoot(it, it.name!!, searchContext).forEach {
// 遍历所有方法
funType.process(Processor {
val element = TyFunctionLookupElement(funName,
luaIndexExpr,
it,
true,
isColon,
funType,
LuaIcons.CLASS_METHOD)

element.handler = SignatureInsertHandler(it, isColon)
element.setTailText(" [${funName}]")
completionResultSet.addElement(element)
true
})
}
} else {
if (!isColon) {
val element = LookupElementFactory.createGuessableLookupElement(suggestText, it, funType, LuaIcons.CLASS_FIELD) as LuaTypeGuessableLookupElement
completionResultSet.addElement(element)
}
}
}
}
}
})
}
// end

//smart
val nameExpr = indexExpr.prefixExpr
if (nameExpr is LuaNameExpr) {
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/com/tang/intellij/lua/psi/LuaPsiResolveUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ import com.intellij.psi.util.PsiTreeUtil
import com.intellij.util.Processor
import com.tang.intellij.lua.Constants
import com.tang.intellij.lua.search.SearchContext
import com.tang.intellij.lua.stubs.LuaIndexExprType
import com.tang.intellij.lua.stubs.index.LuaClassMemberIndex
import com.tang.intellij.lua.ty.ITy
import com.tang.intellij.lua.ty.ITyClass
import com.tang.intellij.lua.ty.TyUnion

fun resolveLocal(ref: LuaNameExpr, context: SearchContext? = null) = resolveLocal(ref.name, ref, context)

Expand Down Expand Up @@ -147,9 +151,59 @@ fun resolve(indexExpr: LuaIndexExpr, idString: String, context: SearchContext):
return@Processor false
true
})
// for chain
// add by clu on 2018-12-29 16:25:34 添加对无上下文的元素的支持t.data.name
val typeByRoot = resolveTypeByRoot(indexExpr, idString, context)
if (typeByRoot.isNotEmpty()) {
return typeByRoot.first()
}
// end
return ret
}

// for chain
/**
* t.data.name,直接通过name的父类型找自己肯定找不到的,因为对t.data, name进行indexStub的时候,t.data类型还没有index,
* 因此无法找到name的父类型t.data,自然就没有存储t.data和name的关系了,因此需要通过t找到t.data,然后再找t.__data找到name即可
* 目前本方法只返回第一个PsiElement
*/
fun resolveTypeByRoot(indexExpr: LuaIndexExpr, idString: String, context: SearchContext): Array<PsiElement> {
val all = mutableListOf<PsiElement>()
LuaIndexExprType.getAllKnownIndexLuaExprType(indexExpr, context).forEach {
val baseType = it.key
val indexExprNames = it.value
val matches = mutableListOf<PsiElement>()
TyUnion.each(baseType, {
if (it is ITyClass) {
// it类型是:118@F_LuaTest_src_test_t.lua
// 获取118@F_LuaTest_src_test_t.lua.__data类型的idString属性
val parentClassNameOfCurrentIndexExpr = LuaIndexExprType.getFiledNameAsClassName(it.className, indexExprNames.toTypedArray(), indexExprNames.size)
LuaClassMemberIndex.process(parentClassNameOfCurrentIndexExpr, idString, context, Processor {
if (it.text.endsWith("." + idString)) {
matches.add(it)
}
true
})

// 只要最短的
if (matches.isNotEmpty()) {
// 只要1个
return@each
}
}
})

// 只要1个
if (matches.isNotEmpty()) {
matches.sortBy { it.text.length }
all.add(matches.first())
return@forEach
}
}
return all.toTypedArray()
}
// end

/**
* 找到 require 的文件路径
* @param pathString 参数字符串 require "aa.bb.cc"
Expand Down
Loading