feat: 2.18 support injected language like SQL | 支持注入语言如 SQL Fixed #68
This commit is contained in:
@@ -125,6 +125,7 @@ Show doc comment in the Project view Tree, line End, json, other
|
||||
|
||||
<h2>English Change Notes:</h2>
|
||||
<ul>
|
||||
<li>2.18 Add line-end-comment support injected language like SQL
|
||||
<li>2.17 Add External Comment support *.key.regexp and MyBatis xml demo in Git
|
||||
<li>2.16 Add line-end-comment support Rust, Ruby, PHP, C/C++/Object C, Scala, Groovy
|
||||
<li>2.15 Add line-end-comment java anno doc
|
||||
@@ -171,6 +172,7 @@ Show doc comment in the Project view Tree, line End, json, other
|
||||
|
||||
<h2>中文更新说明:</h2>
|
||||
<ul>
|
||||
<li>2.18 增加 行末注释 支持注入语言如 SQL
|
||||
<li>2.17 增加 tsv 注释 支持 *.key.regexp 与 Mybatis xml 示例在 Git
|
||||
<li>2.16 增加 行末注释 支持 Rust, Ruby, PHP, C/C++/Object C, Scala, Groovy
|
||||
<li>2.15 增加 行末注释 java 注解注释
|
||||
|
||||
@@ -4,7 +4,7 @@ plugins {
|
||||
}
|
||||
|
||||
group 'io.github.linwancen'
|
||||
version '2.17.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
|
||||
version '2.18.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@@ -95,6 +95,7 @@ patchPluginXml {
|
||||
changeNotes = """
|
||||
<h2>English Change Notes:</h2>
|
||||
<ul>
|
||||
<li>2.18 Add line-end-comment support injected language like SQL
|
||||
<li>2.17 Add External Comment support *.key.regexp and MyBatis xml demo in Git
|
||||
<li>2.16 Add line-end-comment support Rust, Ruby, PHP, C/C++/Object C, Scala, Groovy
|
||||
<li>2.15 Add line-end-comment java anno doc
|
||||
@@ -141,6 +142,7 @@ patchPluginXml {
|
||||
|
||||
<h2>中文更新说明:</h2>
|
||||
<ul>
|
||||
<li>2.18 增加 行末注释 支持注入语言如 SQL
|
||||
<li>2.17 增加 tsv 注释 支持 *.key.regexp 与 Mybatis xml 示例在 Git
|
||||
<li>2.16 增加 行末注释 支持 Rust, Ruby, PHP, C/C++/Object C, Scala, Groovy
|
||||
<li>2.15 增加 行末注释 java 注解注释
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.github.linwancen.plugin.show.bean;
|
||||
|
||||
import com.intellij.lang.injection.InjectedLanguageManager;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
@@ -15,6 +16,7 @@ public class FileInfo extends SettingsInfo {
|
||||
public final @NotNull VirtualFile file;
|
||||
public final @NotNull Document document;
|
||||
public final @NotNull Project project;
|
||||
public final @NotNull InjectedLanguageManager inject;
|
||||
|
||||
protected FileInfo(@NotNull VirtualFile file, @NotNull Document document, @NotNull Project project,
|
||||
@NotNull FuncEnum funcEnum) {
|
||||
@@ -22,6 +24,7 @@ public class FileInfo extends SettingsInfo {
|
||||
this.project = project;
|
||||
this.file = file;
|
||||
this.document = document;
|
||||
this.inject = InjectedLanguageManager.getInstance(project);
|
||||
}
|
||||
|
||||
public static @Nullable FileInfo of(@NotNull VirtualFile file, @NotNull Project project) {
|
||||
@@ -37,6 +40,10 @@ public class FileInfo extends SettingsInfo {
|
||||
if (psiFile == null) {
|
||||
return null;
|
||||
}
|
||||
return of(psiFile);
|
||||
}
|
||||
|
||||
public static @Nullable FileInfo of(@NotNull PsiFile psiFile) {
|
||||
@NotNull FileViewProvider viewProvider = psiFile.getViewProvider();
|
||||
@Nullable Document document = viewProvider.getDocument();
|
||||
if (document == null) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.intellij.psi.PsiCompiledElement;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import io.github.linwancen.plugin.show.bean.FileInfo;
|
||||
import io.github.linwancen.plugin.show.bean.LineInfo;
|
||||
import io.github.linwancen.plugin.show.bean.SettingsInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -57,7 +58,19 @@ public abstract class BaseLangDoc extends EditorLinePainter {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@Nullable BaseLangDoc lineEnd = PsiElementTo.lineEnd(element);
|
||||
@Nullable PsiElement injectedElement = info.inject.findInjectedElementAt(element.getContainingFile(), info.endOffset);
|
||||
if (injectedElement != null) {
|
||||
@Nullable FileInfo fileInfo = FileInfo.of(injectedElement.getContainingFile());
|
||||
if (fileInfo != null) {
|
||||
int lineNumber = fileInfo.document.getLineNumber(injectedElement.getTextRange().getStartOffset());
|
||||
@Nullable LineInfo lineInfo = LineInfo.of(fileInfo, lineNumber);
|
||||
if (lineInfo != null) {
|
||||
element = injectedElement;
|
||||
info = lineInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Nullable BaseLangDoc lineEnd = PsiElementTo.findLangDoc(element);
|
||||
if (lineEnd == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -162,11 +175,11 @@ public abstract class BaseLangDoc extends EditorLinePainter {
|
||||
// ignore
|
||||
}
|
||||
// support like java <-> kotlin
|
||||
@Nullable BaseLangDoc lineEnd = PsiElementTo.lineEnd(psiElement);
|
||||
if (lineEnd == null) {
|
||||
@Nullable BaseLangDoc langDoc = PsiElementTo.findLangDoc(psiElement);
|
||||
if (langDoc == null) {
|
||||
return null;
|
||||
}
|
||||
return lineEnd.resolveDocPrint(info, psiElement);
|
||||
return langDoc.resolveDocPrint(info, psiElement);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,7 +26,7 @@ public class PsiElementTo {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static BaseLangDoc lineEnd(@NotNull PsiElement element) {
|
||||
public static BaseLangDoc findLangDoc(@NotNull PsiElement element) {
|
||||
@Nullable Language language = element.getLanguage();
|
||||
while (true) {
|
||||
@Nullable BaseLangDoc lineEnd = BaseLangDoc.LANG_DOC_MAP.get(language.getID());
|
||||
|
||||
Reference in New Issue
Block a user