Skip to content

Commit dd676b2

Browse files
committed
gen doc
1 parent 318ca25 commit dd676b2

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

src/main/java/com/tang/intellij/lua/documentation/LuaDocumentationProvider.java

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@
2828
import com.tang.intellij.lua.psi.LuaCommentOwner;
2929
import com.tang.intellij.lua.psi.LuaFuncBodyOwner;
3030
import com.tang.intellij.lua.psi.LuaNameDef;
31+
import com.tang.intellij.lua.psi.LuaParamNameDef;
3132
import org.jetbrains.annotations.Nullable;
3233

3334
import java.util.List;
35+
import java.util.Optional;
3436

3537
/**
3638
* Documentation support
@@ -40,17 +42,40 @@ public class LuaDocumentationProvider extends AbstractDocumentationProvider impl
4042

4143
@Override
4244
public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) {
45+
String doc = genDoc(element, originalElement);
46+
if (doc == null)
47+
doc = super.generateDoc(element, originalElement);
48+
return doc;
49+
}
50+
51+
@Nullable
52+
private String genDoc(PsiElement element, @Nullable PsiElement originalElement) {
4353
if (element instanceof LuaCommentOwner) {
44-
return genDocForCommentOwner((LuaCommentOwner) element);
45-
} else if (element instanceof LuaNameDef) {
54+
return genDoc((LuaCommentOwner) element);
55+
}
56+
else if (element instanceof LuaParamNameDef) {
57+
return genDoc((LuaParamNameDef) element);
58+
}
59+
else if (element instanceof LuaNameDef) {
4660
LuaCommentOwner owner = PsiTreeUtil.getParentOfType(element, LuaCommentOwner.class);
4761
if (owner != null)
48-
return genDocForCommentOwner(owner);
62+
return genDoc(owner);
4963
}
50-
return super.generateDoc(element, originalElement);
64+
return null;
65+
}
66+
67+
private String genDoc(LuaParamNameDef paramNameDef) {
68+
LuaCommentOwner owner = PsiTreeUtil.getParentOfType(paramNameDef, LuaCommentOwner.class);
69+
Optional<String> o = Optional.ofNullable(owner)
70+
.map(LuaCommentOwner::getComment)
71+
.map(t -> t.getParamDef(paramNameDef.getName()))
72+
.map(LuaDocParamDef::getCommentString)
73+
.map(LuaDocCommentString::getString)
74+
.map(PsiElement::getText);
75+
return o.orElse(null);
5176
}
5277

53-
private String genDocForCommentOwner(LuaCommentOwner owner) {
78+
private String genDoc(LuaCommentOwner owner) {
5479
StringBuilder sb = new StringBuilder();
5580
if (owner instanceof LuaFuncBodyOwner && owner instanceof PsiNameIdentifierOwner) {
5681
LuaFuncBodyOwner funcBodyOwner = (LuaFuncBodyOwner) owner;

0 commit comments

Comments
 (0)