1.8 Add line-end-comment for json | 增加从同后缀的类中读取 json 行末注释
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package io.github.linwancen.plugin.show.line;
|
||||
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.json.JsonLanguage;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.FileViewProvider;
|
||||
@@ -8,6 +8,8 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiIdentifier;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import io.github.linwancen.plugin.show.doc.JsonDocUtils;
|
||||
import io.github.linwancen.plugin.show.settings.AppSettingsState;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class LineDocLeftToRightUtils {
|
||||
@@ -44,16 +46,23 @@ public class LineDocLeftToRightUtils {
|
||||
offset++;
|
||||
}
|
||||
offset += startOffset;
|
||||
PsiElement element = viewProvider.findElementAt(offset);
|
||||
if (element == null) {
|
||||
return null;
|
||||
}
|
||||
AppSettingsState instance = AppSettingsState.getInstance();
|
||||
if (instance.inJson && element.getLanguage().is(JsonLanguage.INSTANCE)) {
|
||||
return JsonDocUtils.jsonDoc(element, startOffset, endOffset);
|
||||
}
|
||||
if (startWithSymbol) {
|
||||
startOffset = 0;
|
||||
}
|
||||
PsiElement element = viewProvider.findElementAt(offset, JavaLanguage.INSTANCE);
|
||||
return nextDoc(element, startOffset, endOffset);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiDocComment nextDoc(PsiElement element, int startOffset, int endOffset) {
|
||||
while (element != null && element.getTextRange().getEndOffset() < endOffset) {
|
||||
while (element.getTextRange().getEndOffset() < endOffset) {
|
||||
if (element instanceof PsiIdentifier) {
|
||||
PsiDocComment psiDocComment = LineDocUtils.elementDoc(element, element, startOffset, endOffset);
|
||||
if (psiDocComment != null) {
|
||||
@@ -61,6 +70,9 @@ public class LineDocLeftToRightUtils {
|
||||
}
|
||||
}
|
||||
element = PsiTreeUtil.nextVisibleLeaf(element);
|
||||
if (element == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package io.github.linwancen.plugin.show.line;
|
||||
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.json.JsonLanguage;
|
||||
import com.intellij.psi.FileViewProvider;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiIdentifier;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import io.github.linwancen.plugin.show.doc.JsonDocUtils;
|
||||
import io.github.linwancen.plugin.show.settings.AppSettingsState;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class LineDocRightToLeftUtils {
|
||||
@@ -15,10 +17,11 @@ public class LineDocRightToLeftUtils {
|
||||
@Nullable
|
||||
public static PsiDocComment rightDoc(FileViewProvider viewProvider, int startOffset, int endOffset) {
|
||||
// End is always white, can not -1 because @see class.name need it
|
||||
PsiElement element = viewProvider.findElementAt(endOffset, JavaLanguage.INSTANCE);
|
||||
PsiElement element = viewProvider.findElementAt(endOffset);
|
||||
if (element == null) {
|
||||
return null;
|
||||
}
|
||||
AppSettingsState instance = AppSettingsState.getInstance();
|
||||
PsiElement identifier;
|
||||
PsiDocComment psiDocComment;
|
||||
while (true) {
|
||||
@@ -27,6 +30,9 @@ public class LineDocRightToLeftUtils {
|
||||
identifier = null;
|
||||
}
|
||||
if (identifier == null || identifier instanceof PsiIdentifier) {
|
||||
if (instance.inJson && element.getLanguage().is(JsonLanguage.INSTANCE)) {
|
||||
return JsonDocUtils.jsonDoc(element, startOffset, endOffset);
|
||||
}
|
||||
psiDocComment = LineDocUtils.elementDoc(element, identifier, startOffset, endOffset);
|
||||
if (psiDocComment != null) {
|
||||
return psiDocComment;
|
||||
|
||||
@@ -16,32 +16,33 @@ class LineDocUtils {
|
||||
int startOffset, int endOffset) {
|
||||
AppSettingsState instance = AppSettingsState.getInstance();
|
||||
if (element != null) {
|
||||
PsiDocComment executableDoc = elementDoc(element, startOffset, endOffset, instance);
|
||||
if (executableDoc != null) {
|
||||
return executableDoc;
|
||||
PsiDocComment elementDoc = elementDoc(element, startOffset, endOffset, instance);
|
||||
if (elementDoc != null) {
|
||||
return elementDoc;
|
||||
}
|
||||
}
|
||||
if (instance.showLineEndCommentForRef) {
|
||||
if (instance.fromRef) {
|
||||
return refDoc(psiIdentifier, endOffset);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiDocComment elementDoc(PsiElement element, int startOffset, int endOffset, AppSettingsState instance) {
|
||||
if (instance.showLineEndCommentForCall) {
|
||||
private static PsiDocComment elementDoc(PsiElement element, int startOffset, int endOffset,
|
||||
AppSettingsState instance) {
|
||||
if (instance.fromCall) {
|
||||
PsiDocComment executableDoc = parentMethodDoc(element, startOffset, endOffset);
|
||||
if (executableDoc != null) {
|
||||
return executableDoc;
|
||||
}
|
||||
}
|
||||
if (instance.showLineEndCommentForNew) {
|
||||
if (instance.fromNew) {
|
||||
PsiDocComment newDoc = parentNewDoc(element, startOffset);
|
||||
if (newDoc != null) {
|
||||
return newDoc;
|
||||
}
|
||||
}
|
||||
if (instance.showLineEndCommentForRef) {
|
||||
if (instance.fromRef) {
|
||||
return docRefDoc(element);
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user