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

Initial support for Inlay Param Exclude list... #399

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,20 @@ import com.intellij.codeInsight.hints.Option
import com.intellij.psi.PsiElement
import com.intellij.psi.util.PsiTreeUtil
import com.tang.intellij.lua.psi.*
import com.tang.intellij.lua.lang.*
import com.tang.intellij.lua.search.SearchContext
import com.tang.intellij.lua.ty.*
import java.util.*
import com.tang.intellij.lua.LuaBundle
import com.tang.intellij.lua.psi.impl.LuaListArgsImpl
import java.util.stream.Collectors

/**

* Created by TangZX on 2016/12/14.
*/
class LuaParameterHintsProvider : InlayParameterHintsProvider {

companion object {
private val ARGS_HINT = Option("lua.hints.show_args_type",
"Show argument name hints",
Expand Down Expand Up @@ -81,24 +86,21 @@ class LuaParameterHintsProvider : InlayParameterHintsProvider {
list.add(InlayInfo(paramInfo.name, expr.node.startOffset))
true
}
}
else if (psi is LuaParamNameDef) {
} else if (psi is LuaParamNameDef) {
if (PARAMETER_TYPE_HINT.get()) {
val type = psi.guessType(SearchContext.get(psi.project))
if (!Ty.isInvalid(type)) {
return listOf(InlayInfo("$TYPE_INFO_PREFIX${type.displayName}", psi.textOffset + psi.textLength))
}
}
}
else if (psi is LuaNameDef) {
} else if (psi is LuaNameDef) {
if (LOCAL_VARIABLE_HINT.get()) {
val type = psi.guessType(SearchContext.get(psi.project))
if (!Ty.isInvalid(type)) {
return listOf(InlayInfo("$TYPE_INFO_PREFIX${type.displayName}", psi.textOffset + psi.textLength))
}
}
}
else if (psi is LuaFuncBodyOwner) {
} else if (psi is LuaFuncBodyOwner) {
val paren = psi.funcBody?.rparen
if (FUNCTION_HINT.get() && paren != null) {
val type = psi.guessReturnType(SearchContext.get(psi.project))
Expand All @@ -111,14 +113,24 @@ class LuaParameterHintsProvider : InlayParameterHintsProvider {
return list
}

override fun getHintInfo(psiElement: PsiElement): HintInfo? = null
override fun getHintInfo(callExpression: PsiElement): HintInfo? {
if (callExpression !is LuaCallExpr) {
return null
} else {
val tyFunc = TyUnion.find(callExpression.guessParentType(SearchContext.get(callExpression.getProject())), ITyFunction::class.java) ?: return null;
val signature = tyFunc.findPerfectSignature(callExpression)
return HintInfo.MethodInfo(callExpression.expr.text, signature.params.map { param -> param.name });
}
}

override fun getBlacklistExplanationHTML(): String {
return LuaBundle.message("inlay.hints.blacklist.pattern.explanation")
}

override fun getDefaultBlackList(): Set<String> {
return HashSet()
}

override fun isBlackListSupported() = false

override fun getSupportedOptions(): List<Option> {
return listOf(ARGS_HINT, LOCAL_VARIABLE_HINT, PARAMETER_TYPE_HINT, FUNCTION_HINT)
}
Expand Down
12 changes: 11 additions & 1 deletion src/main/resources/LuaBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,14 @@ ui.settings.show_words=Show &words in file
ui.settings.type_safety=Type safety
ui.settings.enforce_type_safety=Enforce type safety
ui.settings.strict_nil_checks=Strict nil checks
ui.settings.require_like_function_names=&Require-like function names:
ui.settings.require_like_function_names=&Require-like function names:
inlay.hints.blacklist.pattern.explanation=<html> \
To disable hints for a function use the appropriate pattern: \
<p> \
<code><b>math.*<b></code><br> \
<code><b>*.insert*<b></code><br> \
<code>(*_)</code> - single parameter function where the parameter name ends with <i>_</i><br /> \
<code>(key, value)</code> - functions with parameters <i>key</i> and <i>value</i><br /> \
<code>*.put(key, value)</code> - <i>put</i> functions with <i>key</i> and <i>value</i> parameters \
</p> \
</html>