mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[quickdoc] Rewritten AdvancedSettings for quick doc syntax highlighting
GitOrigin-RevId: 417fd46685e07552478d4ee74ad88e64ca967d4d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e965e1b0aa
commit
0114e14502
@@ -5,16 +5,14 @@ import com.intellij.codeInsight.AnnotationTargetUtil;
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
import com.intellij.ide.highlighter.JavaHighlightingColors;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.lang.documentation.DocumentationSettings;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
|
||||
import com.intellij.openapi.editor.richcopy.HtmlSyntaxInfoUtil;
|
||||
import com.intellij.openapi.options.advanced.AdvancedSettings;
|
||||
import com.intellij.openapi.project.IndexNotReadyException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.MathUtil;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import one.util.streamex.StreamEx;
|
||||
@@ -77,10 +75,6 @@ public final class AnnotationDocGenerator {
|
||||
return AnnotationUtil.isInferredAnnotation(myAnnotation);
|
||||
}
|
||||
|
||||
private static float getHighlightingSaturation() {
|
||||
return MathUtil.clamp(AdvancedSettings.getInt("documentation.components.doc.syntax.highlighting.saturation"), 0, 100) * 0.01f;
|
||||
}
|
||||
|
||||
private static void appendStyledSpan(
|
||||
boolean doSyntaxHighlighting,
|
||||
@NotNull StringBuilder buffer,
|
||||
@@ -88,7 +82,7 @@ public final class AnnotationDocGenerator {
|
||||
@Nullable String value
|
||||
) {
|
||||
if (doSyntaxHighlighting) {
|
||||
HtmlSyntaxInfoUtil.appendStyledSpan(buffer, attributesKey, value, getHighlightingSaturation());
|
||||
HtmlSyntaxInfoUtil.appendStyledSpan(buffer, attributesKey, value, DocumentationSettings.getHighlightingSaturation());
|
||||
}
|
||||
else {
|
||||
buffer.append(value);
|
||||
@@ -104,7 +98,7 @@ public final class AnnotationDocGenerator {
|
||||
) {
|
||||
if (doSyntaxHighlighting) {
|
||||
HtmlSyntaxInfoUtil.appendHighlightedByLexerAndEncodedAsHtmlCodeSnippet(
|
||||
buffer, project, language, codeSnippet, getHighlightingSaturation());
|
||||
buffer, project, language, codeSnippet, DocumentationSettings.getHighlightingSaturation());
|
||||
}
|
||||
else if (codeSnippet != null) {
|
||||
buffer.append(StringUtil.escapeXmlEntities(codeSnippet));
|
||||
@@ -146,7 +140,7 @@ public final class AnnotationDocGenerator {
|
||||
String styledName = styledNameBuilder.toString();
|
||||
JavaDocInfoGeneratorFactory.getBuilder(myContext.getProject())
|
||||
.setIsGenerationForRenderedDoc(isForRenderedDoc)
|
||||
.setDoSyntaxHighlighting(doSyntaxHighlighting)
|
||||
.setDoHighlightSignatures(doSyntaxHighlighting)
|
||||
.create()
|
||||
.generateLink(buffer, myTargetClass, styledName, format == AnnotationFormat.JavaDocComplete);
|
||||
}
|
||||
@@ -242,7 +236,7 @@ public final class AnnotationDocGenerator {
|
||||
}
|
||||
JavaDocInfoGeneratorFactory.getBuilder(field.getProject())
|
||||
.setIsGenerationForRenderedDoc(isForRenderedDoc)
|
||||
.setDoSyntaxHighlighting(doSyntaxHighlighting)
|
||||
.setDoHighlightSignatures(doSyntaxHighlighting)
|
||||
.create()
|
||||
.generateLink(buffer, text, aClass != null ? aClass.getName() + '.' + field.getName() : null, memberValue, false);
|
||||
}
|
||||
|
||||
@@ -8,11 +8,14 @@ import com.intellij.codeInsight.CodeInsightBundle;
|
||||
import com.intellij.codeInsight.ExceptionUtil;
|
||||
import com.intellij.codeInsight.documentation.DocumentationManagerProtocol;
|
||||
import com.intellij.codeInsight.documentation.DocumentationManagerUtil;
|
||||
import com.intellij.diagnostic.Checks;
|
||||
import com.intellij.java.JavaBundle;
|
||||
import com.intellij.javadoc.JavadocGeneratorRunProfile;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.lang.documentation.DocumentationMarkup;
|
||||
import com.intellij.lang.documentation.DocumentationSettings;
|
||||
import com.intellij.lang.documentation.DocumentationSettings.InlineCodeHighlightingMode;
|
||||
import com.intellij.lang.java.JavaDocumentationProvider;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
|
||||
@@ -20,10 +23,8 @@ import com.intellij.openapi.editor.HighlighterColors;
|
||||
import com.intellij.openapi.editor.colors.CodeInsightColors;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsManager;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsScheme;
|
||||
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
|
||||
import com.intellij.openapi.editor.markup.TextAttributes;
|
||||
import com.intellij.openapi.editor.richcopy.HtmlSyntaxInfoUtil;
|
||||
import com.intellij.openapi.options.advanced.AdvancedSettings;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.project.IndexNotReadyException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -45,7 +46,10 @@ import com.intellij.psi.impl.source.tree.JavaElementType;
|
||||
import com.intellij.psi.javadoc.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.util.*;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ArrayUtilRt;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import kotlin.text.StringsKt;
|
||||
import org.jdom.Element;
|
||||
@@ -115,12 +119,23 @@ public class JavaDocInfoGenerator {
|
||||
private final @Nullable JavaSdkVersion mySdkVersion;
|
||||
|
||||
private final boolean myIsRendered;
|
||||
private final boolean myDoSyntaxHighlighting;
|
||||
private final boolean myDoHighlightInlineCodeBlocks;
|
||||
private final boolean myDoHighlightLinks;
|
||||
private final boolean myDoHighlightSignatures;
|
||||
private final boolean myDoHighlightCodeBlocks;
|
||||
private final InlineCodeHighlightingMode myInlineCodeBlocksHighlightingMode;
|
||||
private final boolean myDoSemanticHighlightingOfLinks;
|
||||
private final float myHighlightingSaturation;
|
||||
|
||||
public JavaDocInfoGenerator(@NotNull Project project, @Nullable PsiElement element) {
|
||||
this(project, element, new JavaDocHighlightingManagerImpl(), false, true, true, true);
|
||||
this(
|
||||
project,
|
||||
element,
|
||||
new JavaDocHighlightingManagerImpl(),
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
InlineCodeHighlightingMode.AS_DEFAULT_CODE,
|
||||
false,
|
||||
1.0F);
|
||||
}
|
||||
|
||||
public JavaDocInfoGenerator(
|
||||
@@ -128,17 +143,21 @@ public class JavaDocInfoGenerator {
|
||||
@Nullable PsiElement element,
|
||||
@NotNull JavaDocHighlightingManager highlightingManager,
|
||||
boolean isGenerationForRenderedDoc,
|
||||
boolean doSyntaxHighlighting,
|
||||
boolean doHighlightInlineCodeBlocks,
|
||||
boolean doHighlightLinks
|
||||
boolean doHighlightSignatures,
|
||||
boolean doHighlightCodeBlocks,
|
||||
@NotNull InlineCodeHighlightingMode inlineCodeBlocksHighlightingMode,
|
||||
boolean doSemanticHighlightingOfLinks,
|
||||
float highlightingSaturationFactor
|
||||
) {
|
||||
myProject = project;
|
||||
myElement = element;
|
||||
myIsRendered = isGenerationForRenderedDoc;
|
||||
myHighlightingManager = highlightingManager;
|
||||
myDoSyntaxHighlighting = doSyntaxHighlighting;
|
||||
myDoHighlightInlineCodeBlocks = doHighlightInlineCodeBlocks;
|
||||
myDoHighlightLinks = doHighlightLinks;
|
||||
myDoHighlightSignatures = doHighlightSignatures;
|
||||
myDoHighlightCodeBlocks = doHighlightCodeBlocks;
|
||||
myInlineCodeBlocksHighlightingMode = inlineCodeBlocksHighlightingMode;
|
||||
myDoSemanticHighlightingOfLinks = doSemanticHighlightingOfLinks;
|
||||
myHighlightingSaturation = highlightingSaturationFactor;
|
||||
|
||||
Sdk jdk = JavadocGeneratorRunProfile.getSdk(myProject);
|
||||
mySdkVersion = jdk == null ? null : JavaSdk.getInstance().getVersion(jdk);
|
||||
@@ -148,20 +167,24 @@ public class JavaDocInfoGenerator {
|
||||
return myIsRendered;
|
||||
}
|
||||
|
||||
public boolean doSyntaxHighlighting() {
|
||||
return myDoSyntaxHighlighting;
|
||||
public boolean doHighlightSignatures() {
|
||||
return myDoHighlightSignatures;
|
||||
}
|
||||
|
||||
public boolean doHighlightInlineCodeBlocks() {
|
||||
return myDoHighlightInlineCodeBlocks;
|
||||
public boolean doHighlightCodeBlocks() {
|
||||
return myDoHighlightCodeBlocks;
|
||||
}
|
||||
|
||||
public boolean doHighlightLinks() {
|
||||
return myDoHighlightLinks;
|
||||
public @NotNull InlineCodeHighlightingMode getInlineCodeHighlightingMode() {
|
||||
return myInlineCodeBlocksHighlightingMode;
|
||||
}
|
||||
|
||||
public boolean doSemanticHighlightingOfLinks() {
|
||||
return myDoSemanticHighlightingOfLinks;
|
||||
}
|
||||
|
||||
public float getHighlightingSaturation() {
|
||||
return MathUtil.clamp(AdvancedSettings.getInt("documentation.components.doc.syntax.highlighting.saturation"), 0, 100) * 0.01f;
|
||||
return myHighlightingSaturation;
|
||||
}
|
||||
|
||||
public @NotNull JavaDocHighlightingManager getHighlightingManager() {
|
||||
@@ -169,11 +192,12 @@ public class JavaDocInfoGenerator {
|
||||
}
|
||||
|
||||
protected @NotNull StringBuilder appendStyledSpan(
|
||||
boolean doHighlighting,
|
||||
@NotNull StringBuilder buffer,
|
||||
@NotNull TextAttributes attributes,
|
||||
@Nullable String value
|
||||
) {
|
||||
if (doSyntaxHighlighting()) {
|
||||
if (doHighlighting) {
|
||||
HtmlSyntaxInfoUtil.appendStyledSpan(buffer, attributes, value, getHighlightingSaturation());
|
||||
}
|
||||
else {
|
||||
@@ -182,13 +206,22 @@ public class JavaDocInfoGenerator {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
protected @NotNull StringBuilder appendStyledSpan(
|
||||
@NotNull StringBuilder buffer,
|
||||
@NotNull TextAttributes attributes,
|
||||
@Nullable String value
|
||||
) {
|
||||
return appendStyledSpan(doHighlightSignatures(), buffer, attributes, value);
|
||||
}
|
||||
|
||||
protected @NotNull StringBuilder appendHighlightedByLexerAndEncodedAsHtmlCodeSnippet(
|
||||
boolean doHighlighting,
|
||||
@NotNull StringBuilder buffer,
|
||||
@NotNull Project project,
|
||||
@NotNull Language language,
|
||||
@Nullable String codeSnippet
|
||||
) {
|
||||
if (doSyntaxHighlighting()) {
|
||||
if (doHighlighting) {
|
||||
HtmlSyntaxInfoUtil.appendHighlightedByLexerAndEncodedAsHtmlCodeSnippet(
|
||||
buffer, project, language, codeSnippet, getHighlightingSaturation());
|
||||
}
|
||||
@@ -201,8 +234,8 @@ public class JavaDocInfoGenerator {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public @NotNull String getStyledSpan(@NotNull TextAttributes attributes, @Nullable String value) {
|
||||
return appendStyledSpan(new StringBuilder(), attributes, value).toString();
|
||||
protected @NotNull String getStyledSpan(boolean doHighlighting, @NotNull TextAttributes attributes, @Nullable String value) {
|
||||
return appendStyledSpan(doHighlighting, new StringBuilder(), attributes, value).toString();
|
||||
}
|
||||
|
||||
public @NotNull String getHighlightedByLexerAndEncodedAsHtmlCodeSnippet(
|
||||
@@ -210,7 +243,7 @@ public class JavaDocInfoGenerator {
|
||||
@NotNull Language language,
|
||||
@Nullable String codeSnippet
|
||||
) {
|
||||
return appendHighlightedByLexerAndEncodedAsHtmlCodeSnippet(new StringBuilder(), project, language, codeSnippet).toString();
|
||||
return appendHighlightedByLexerAndEncodedAsHtmlCodeSnippet(true, new StringBuilder(), project, language, codeSnippet).toString();
|
||||
}
|
||||
|
||||
private static InheritDocProvider<PsiElement[]> mapProvider(InheritDocProvider<PsiDocTag> i, boolean dropFirst) {
|
||||
@@ -589,7 +622,7 @@ public class JavaDocInfoGenerator {
|
||||
}
|
||||
|
||||
if (!isRendered()) {
|
||||
new NonCodeAnnotationGenerator(aClass, buffer).explainAnnotations(isRendered(), doSyntaxHighlighting());
|
||||
new NonCodeAnnotationGenerator(aClass, buffer).explainAnnotations(isRendered(), doHighlightSignatures());
|
||||
}
|
||||
buffer.append(DocumentationMarkup.SECTIONS_END);
|
||||
}
|
||||
@@ -792,7 +825,7 @@ public class JavaDocInfoGenerator {
|
||||
|
||||
if (!isRendered()) {
|
||||
JavaDocColorUtil.appendColorPreview(field, buffer);
|
||||
new NonCodeAnnotationGenerator(field, buffer).explainAnnotations(isRendered(), doSyntaxHighlighting());
|
||||
new NonCodeAnnotationGenerator(field, buffer).explainAnnotations(isRendered(), doHighlightSignatures());
|
||||
}
|
||||
|
||||
buffer.append(DocumentationMarkup.SECTIONS_END);
|
||||
@@ -988,7 +1021,8 @@ public class JavaDocInfoGenerator {
|
||||
if (trunc) {
|
||||
text = text.substring(0, index);
|
||||
}
|
||||
appendHighlightedByLexerAndEncodedAsHtmlCodeSnippet(buffer, initializer.getProject(), initializer.getLanguage(), text);
|
||||
appendHighlightedByLexerAndEncodedAsHtmlCodeSnippet(
|
||||
doHighlightSignatures(), buffer, initializer.getProject(), initializer.getLanguage(), text);
|
||||
if (trunc) {
|
||||
buffer.append("...");
|
||||
}
|
||||
@@ -1059,7 +1093,7 @@ public class JavaDocInfoGenerator {
|
||||
}
|
||||
for (AnnotationDocGenerator anno : generators) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
anno.generateAnnotation(buf, AnnotationFormat.JavaDocShort, generateLink, isRendered(), doSyntaxHighlighting());
|
||||
anno.generateAnnotation(buf, AnnotationFormat.JavaDocShort, generateLink, isRendered(), doHighlightSignatures());
|
||||
len += StringUtil.unescapeXmlEntities(StringUtil.stripHtml(buf.toString(), true)).length() + 1;
|
||||
buffer.append(buf);
|
||||
buffer.append(NBSP);
|
||||
@@ -1078,7 +1112,7 @@ public class JavaDocInfoGenerator {
|
||||
AnnotationFormat format = place == SignaturePlace.Javadoc ? AnnotationFormat.JavaDocShort : AnnotationFormat.ToolTip;
|
||||
for (AnnotationDocGenerator anno : AnnotationDocGenerator.getAnnotationsToShow(owner)) {
|
||||
if (ignoreNonSourceAnnotations && (anno.isInferred() || anno.isExternal())) continue;
|
||||
anno.generateAnnotation(buffer, format, generateLink, isRendered(), doSyntaxHighlighting());
|
||||
anno.generateAnnotation(buffer, format, generateLink, isRendered(), doHighlightSignatures());
|
||||
|
||||
buffer.append(NBSP);
|
||||
if (splitAnnotations) buffer.append('\n');
|
||||
@@ -1133,7 +1167,7 @@ public class JavaDocInfoGenerator {
|
||||
}
|
||||
|
||||
buffer.append(DocumentationMarkup.SECTIONS_START);
|
||||
new NonCodeAnnotationGenerator(parameter, buffer).explainAnnotations(isRendered(), doSyntaxHighlighting());
|
||||
new NonCodeAnnotationGenerator(parameter, buffer).explainAnnotations(isRendered(), doHighlightSignatures());
|
||||
buffer.append(DocumentationMarkup.SECTIONS_END);
|
||||
}
|
||||
|
||||
@@ -1209,7 +1243,8 @@ public class JavaDocInfoGenerator {
|
||||
startHeaderSection(buffer, JavaBundle.message(aClass.isInterface() ? "javadoc.description.copied.from.interface"
|
||||
: "javadoc.description.copied.from.class"))
|
||||
.append("<p>");
|
||||
generateLink(buffer, aClass, getStyledSpan(getHighlightingManager().getClassDeclarationAttributes(aClass),
|
||||
generateLink(buffer, aClass, getStyledSpan(doSemanticHighlightingOfLinks(),
|
||||
getHighlightingManager().getClassDeclarationAttributes(aClass),
|
||||
JavaDocUtil.getShortestClassName(aClass, method)),
|
||||
false);
|
||||
buffer.append(BR_TAG);
|
||||
@@ -1228,7 +1263,8 @@ public class JavaDocInfoGenerator {
|
||||
if (fieldDocComment != null && !isEmptyDescription(fieldDocComment)) {
|
||||
startHeaderSection(buffer, JavaBundle.message("javadoc.description.copied.from.field"))
|
||||
.append("<p>");
|
||||
generateLink(buffer, field, getStyledSpan(getHighlightingManager().getFieldDeclarationAttributes(field), field.getName()),
|
||||
generateLink(buffer, field, getStyledSpan(doSemanticHighlightingOfLinks(),
|
||||
getHighlightingManager().getFieldDeclarationAttributes(field), field.getName()),
|
||||
false);
|
||||
buffer.append(BR_TAG);
|
||||
generateValue(buffer, fieldDocComment.getDescriptionElements(), ourEmptyElementsProvider);
|
||||
@@ -1263,7 +1299,7 @@ public class JavaDocInfoGenerator {
|
||||
}
|
||||
|
||||
if (!isRendered()) {
|
||||
new NonCodeAnnotationGenerator(method, buffer).explainAnnotations(isRendered(), doSyntaxHighlighting());
|
||||
new NonCodeAnnotationGenerator(method, buffer).explainAnnotations(isRendered(), doHighlightSignatures());
|
||||
}
|
||||
|
||||
buffer.append(DocumentationMarkup.SECTIONS_END);
|
||||
@@ -1513,29 +1549,37 @@ public class JavaDocInfoGenerator {
|
||||
buffer.setLength(lastNonWhite + 1);
|
||||
}
|
||||
|
||||
buffer.append(isRendered() ? "<code style='font-size:96%;'>" : "<code>");
|
||||
buffer.append(isRendered() ? "<code style='font-size:" + DocumentationSettings.getMonospaceFontSizeCorrection() + "%;'>" : "<code>");
|
||||
int pos = buffer.length();
|
||||
|
||||
StringBuilder codeSnippetBuilder = new StringBuilder();
|
||||
generateLiteralValue(codeSnippetBuilder, tag, false);
|
||||
String codeSnippet = codeSnippetBuilder.toString();
|
||||
if (isCodeBlock) {
|
||||
codeSnippet = StringsKt.trimIndent(codeSnippet);
|
||||
}
|
||||
|
||||
if (isCodeBlock || doHighlightInlineCodeBlocks()) {
|
||||
if (isCodeBlock && doHighlightCodeBlocks()
|
||||
|| !isCodeBlock && getInlineCodeHighlightingMode() == InlineCodeHighlightingMode.SEMANTIC_HIGHLIGHTING) {
|
||||
// highlights code by lexer
|
||||
codeSnippetBuilder.setLength(0);
|
||||
appendHighlightedByLexerAndEncodedAsHtmlCodeSnippet(
|
||||
codeSnippetBuilder, tag.getProject(), tag.getLanguage(), codeSnippet);
|
||||
appendHighlightedByLexerAndEncodedAsHtmlCodeSnippet(true, codeSnippetBuilder, tag.getProject(), tag.getLanguage(), codeSnippet);
|
||||
codeSnippet = codeSnippetBuilder.toString();
|
||||
}
|
||||
|
||||
if (isCodeBlock && doHighlightCodeBlocks()
|
||||
|| !isCodeBlock && getInlineCodeHighlightingMode() != InlineCodeHighlightingMode.NO_HIGHLIGHTING) {
|
||||
// highlights plain code as HighlighterColors.TEXT
|
||||
codeSnippetBuilder.setLength(0);
|
||||
TextAttributes codeAttributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(HighlighterColors.TEXT).clone();
|
||||
codeAttributes.setBackgroundColor(null);
|
||||
appendStyledSpan(codeSnippetBuilder, codeAttributes, codeSnippet);
|
||||
appendStyledSpan(true, codeSnippetBuilder, codeAttributes, codeSnippet);
|
||||
codeSnippet = codeSnippetBuilder.toString();
|
||||
}
|
||||
|
||||
if (isCodeBlock) {
|
||||
// indent code block
|
||||
codeSnippet = Arrays.stream(codeSnippet.split(BR_TAG))
|
||||
codeSnippet = Arrays.stream(codeSnippet.contains(BR_TAG) ? codeSnippet.split(BR_TAG) : codeSnippet.split("\n"))
|
||||
.map(it -> " " + it)
|
||||
.collect(Collectors.joining(BR_TAG));
|
||||
}
|
||||
@@ -2002,10 +2046,12 @@ public class JavaDocInfoGenerator {
|
||||
StringBuilder methodBuffer = new StringBuilder();
|
||||
generateLink(
|
||||
methodBuffer, superMethod,
|
||||
getStyledSpan(getHighlightingManager().getMethodDeclarationAttributes(superMethod), superMethod.getName()), false);
|
||||
getStyledSpan(doSemanticHighlightingOfLinks(),
|
||||
getHighlightingManager().getMethodDeclarationAttributes(superMethod), superMethod.getName()), false);
|
||||
StringBuilder classBuffer = new StringBuilder();
|
||||
generateLink(classBuffer, superClass,
|
||||
getStyledSpan(getHighlightingManager().getClassDeclarationAttributes(superClass), superClass.getName()), false);
|
||||
getStyledSpan(doSemanticHighlightingOfLinks(),
|
||||
getHighlightingManager().getClassDeclarationAttributes(superClass), superClass.getName()), false);
|
||||
if (superClass.isInterface()) {
|
||||
buffer.append(JavaBundle.message("javadoc.method.in.interface", methodBuffer.toString(), classBuffer.toString()));
|
||||
}
|
||||
@@ -2066,7 +2112,7 @@ public class JavaDocInfoGenerator {
|
||||
buffer.append("<font color=red>").append(label).append("</font>");
|
||||
}
|
||||
else {
|
||||
generateLink(buffer, target, doHighlightLinks() ? tryHighlightLinkLabel(target, label) : label, plainLink);
|
||||
generateLink(buffer, target, doSemanticHighlightingOfLinks() ? tryHighlightLinkLabel(target, label) : label, plainLink);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2089,11 +2135,12 @@ public class JavaDocInfoGenerator {
|
||||
}
|
||||
|
||||
private @NotNull String tryHighlightLinkLabel(@NotNull PsiElement element, @NotNull String label) {
|
||||
Checks.require(doSemanticHighlightingOfLinks());
|
||||
if (element instanceof PsiClass) {
|
||||
return getStyledSpan(tuneAttributesForLink(getHighlightingManager().getClassDeclarationAttributes((PsiClass)element)), label);
|
||||
return getStyledSpan(true, tuneAttributesForLink(getHighlightingManager().getClassDeclarationAttributes((PsiClass)element)), label);
|
||||
}
|
||||
if (element instanceof PsiPackage) {
|
||||
return getStyledSpan(tuneAttributesForLink(getHighlightingManager().getClassNameAttributes()), label);
|
||||
return getStyledSpan(true, tuneAttributesForLink(getHighlightingManager().getClassNameAttributes()), label);
|
||||
}
|
||||
else if (element instanceof PsiMethod) {
|
||||
return tryHighlightLinkOnClassMember(
|
||||
@@ -2113,6 +2160,7 @@ public class JavaDocInfoGenerator {
|
||||
@NotNull TextAttributes labelAttributes,
|
||||
@NotNull String label
|
||||
) {
|
||||
Checks.require(doSemanticHighlightingOfLinks());
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
int openParenIndex = label.indexOf("(");
|
||||
if (openParenIndex == -1) openParenIndex = label.length();
|
||||
@@ -2122,14 +2170,15 @@ public class JavaDocInfoGenerator {
|
||||
TextAttributes containingClassAttributes =
|
||||
containingClass != null ? getHighlightingManager().getClassDeclarationAttributes(containingClass)
|
||||
: getHighlightingManager().getClassNameAttributes();
|
||||
appendStyledSpan(buffer, containingClassAttributes, label.substring(0, classNameIndex));
|
||||
appendStyledSpan(buffer, getHighlightingManager().getDotAttributes(), ".");
|
||||
containingClassAttributes = tuneAttributesForLink(containingClassAttributes);
|
||||
appendStyledSpan(true, buffer, containingClassAttributes, label.substring(0, classNameIndex));
|
||||
appendStyledSpan(true, buffer, getHighlightingManager().getDotAttributes(), ".");
|
||||
}
|
||||
classNameIndex++;
|
||||
appendStyledSpan(buffer, labelAttributes, label.substring(classNameIndex, openParenIndex));
|
||||
appendStyledSpan(true, buffer, labelAttributes, label.substring(classNameIndex, openParenIndex));
|
||||
if (openParenIndex == label.length()) return buffer.toString();
|
||||
appendHighlightedByLexerAndEncodedAsHtmlCodeSnippet(
|
||||
buffer, member.getProject(), member.getLanguage(), label.substring(openParenIndex));
|
||||
true, buffer, member.getProject(), member.getLanguage(), label.substring(openParenIndex));
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
@@ -2570,13 +2619,13 @@ public class JavaDocInfoGenerator {
|
||||
@Override
|
||||
public void visitExpression(PsiExpression expression) {
|
||||
appendHighlightedByLexerAndEncodedAsHtmlCodeSnippet(
|
||||
myBuffer, expression.getProject(), expression.getLanguage(), expression.getText());
|
||||
doHighlightSignatures(), myBuffer, expression.getProject(), expression.getLanguage(), expression.getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitReferenceExpression(PsiReferenceExpression expression) {
|
||||
appendHighlightedByLexerAndEncodedAsHtmlCodeSnippet(
|
||||
myBuffer, expression.getProject(), expression.getLanguage(), expression.getText());
|
||||
doHighlightSignatures(), myBuffer, expression.getProject(), expression.getLanguage(), expression.getText());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+33
-27
@@ -1,9 +1,9 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInsight.javadoc;
|
||||
|
||||
import com.intellij.lang.documentation.DocumentationSettings;
|
||||
import com.intellij.lang.documentation.DocumentationSettings.InlineCodeHighlightingMode;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
|
||||
import com.intellij.openapi.options.advanced.AdvancedSettings;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -17,17 +17,16 @@ public class JavaDocInfoGeneratorFactory {
|
||||
}
|
||||
|
||||
protected JavaDocInfoGenerator createImpl(@NotNull Project project, @Nullable PsiElement element) {
|
||||
EditorSettingsExternalizable.getInstance();
|
||||
EditorSettingsExternalizable.getInstance();
|
||||
EditorSettingsExternalizable.getInstance();
|
||||
return new JavaDocInfoGenerator(
|
||||
project,
|
||||
element,
|
||||
JavaDocHighlightingManagerImpl.getInstance(),
|
||||
false,
|
||||
AdvancedSettings.getBoolean("documentation.components.enable.doc.syntax.highlighting"),
|
||||
AdvancedSettings.getBoolean("documentation.components.enable.doc.syntax.highlighting.of.inline.code.blocks"),
|
||||
AdvancedSettings.getBoolean("documentation.components.enable.doc.syntax.highlighting.of.links"));
|
||||
DocumentationSettings.isHighlightingOfQuickDocSignaturesEnabled(),
|
||||
DocumentationSettings.isHighlightingOfCodeBlocksEnabled(),
|
||||
DocumentationSettings.getInlineCodeHighlightingMode(),
|
||||
DocumentationSettings.isSemanticHighlightingOfLinksEnabled(),
|
||||
DocumentationSettings.getHighlightingSaturation());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -45,12 +44,11 @@ public class JavaDocInfoGeneratorFactory {
|
||||
private @Nullable PsiElement myElement;
|
||||
private @NotNull JavaDocHighlightingManager myManager = new JavaDocHighlightingManagerImpl();
|
||||
private boolean myIsRendered = false;
|
||||
private boolean myDoHighlighting =
|
||||
AdvancedSettings.getBoolean("documentation.components.enable.doc.syntax.highlighting");
|
||||
private boolean myDoHighlightBlocks =
|
||||
AdvancedSettings.getBoolean("documentation.components.enable.doc.syntax.highlighting.of.inline.code.blocks");
|
||||
private boolean myDoHighlightLinks =
|
||||
AdvancedSettings.getBoolean("documentation.components.enable.doc.syntax.highlighting.of.inline.code.blocks");
|
||||
private boolean myDoHighlightSignatures = DocumentationSettings.isHighlightingOfQuickDocSignaturesEnabled();
|
||||
private boolean myDoHighlightCodeBlocks = DocumentationSettings.isHighlightingOfCodeBlocksEnabled();
|
||||
private @NotNull InlineCodeHighlightingMode myInlineCodeBlocksHighlightingMode = DocumentationSettings.getInlineCodeHighlightingMode();
|
||||
private boolean myDoSemanticHighlightingOfLinks = DocumentationSettings.isSemanticHighlightingOfLinksEnabled();
|
||||
private float myHighlightingSaturation = DocumentationSettings.getHighlightingSaturation();
|
||||
|
||||
private JavaDocInfoGeneratorBuilder(@NotNull Project project) {
|
||||
myProject = project;
|
||||
@@ -71,34 +69,42 @@ public class JavaDocInfoGeneratorFactory {
|
||||
return this;
|
||||
}
|
||||
|
||||
public JavaDocInfoGeneratorBuilder setDoSyntaxHighlighting(boolean doHighlighting) {
|
||||
myDoHighlighting = doHighlighting;
|
||||
public JavaDocInfoGeneratorBuilder setDoHighlightSignatures(boolean doHighlighting) {
|
||||
myDoHighlightSignatures = doHighlighting;
|
||||
return this;
|
||||
}
|
||||
|
||||
public JavaDocInfoGeneratorBuilder setDoHighlightInlineCodeBlocks(boolean doHighlightBlocks) {
|
||||
myDoHighlightBlocks = doHighlightBlocks;
|
||||
public JavaDocInfoGeneratorBuilder setDoHighlightCodeBlocks(boolean doHighlighting) {
|
||||
myDoHighlightCodeBlocks = doHighlighting;
|
||||
return this;
|
||||
}
|
||||
|
||||
public JavaDocInfoGeneratorBuilder setDoHighlightLinks(boolean doHighlightLinks) {
|
||||
myDoHighlightLinks = doHighlightLinks;
|
||||
public JavaDocInfoGeneratorBuilder setDoInlineCodeHighlightingMode(@NotNull InlineCodeHighlightingMode mode) {
|
||||
myInlineCodeBlocksHighlightingMode = mode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public JavaDocInfoGeneratorBuilder setDoSemanticHighlightingOfLinks(boolean doHighlightLinks) {
|
||||
myDoSemanticHighlightingOfLinks = doHighlightLinks;
|
||||
return this;
|
||||
}
|
||||
|
||||
public JavaDocInfoGeneratorBuilder setHighlightingSaturationFactor(float saturationFactor) {
|
||||
myHighlightingSaturation = saturationFactor;
|
||||
return this;
|
||||
}
|
||||
|
||||
public JavaDocInfoGenerator create() {
|
||||
if (!myDoHighlighting) {
|
||||
myDoHighlightBlocks = false;
|
||||
myDoHighlightLinks = false;
|
||||
}
|
||||
return new JavaDocInfoGenerator(
|
||||
myProject,
|
||||
myElement,
|
||||
myManager,
|
||||
myIsRendered,
|
||||
myDoHighlighting,
|
||||
myDoHighlightBlocks,
|
||||
myDoHighlightLinks);
|
||||
myDoHighlightSignatures,
|
||||
myDoHighlightCodeBlocks,
|
||||
myInlineCodeBlocksHighlightingMode,
|
||||
myDoSemanticHighlightingOfLinks,
|
||||
myHighlightingSaturation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,14 +17,13 @@ import com.intellij.lang.CodeDocumentationAwareCommenter;
|
||||
import com.intellij.lang.LanguageCommenters;
|
||||
import com.intellij.lang.documentation.CodeDocumentationProvider;
|
||||
import com.intellij.lang.documentation.CompositeDocumentationProvider;
|
||||
import com.intellij.lang.documentation.DocumentationSettings;
|
||||
import com.intellij.lang.documentation.ExternalDocumentationProvider;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
|
||||
import com.intellij.openapi.editor.markup.TextAttributes;
|
||||
import com.intellij.openapi.editor.richcopy.HtmlSyntaxInfoUtil;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.options.advanced.AdvancedSettings;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.project.IndexNotReadyException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -47,7 +46,6 @@ import com.intellij.psi.infos.CandidateInfo;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import com.intellij.psi.javadoc.PsiDocTag;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.util.MathUtil;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.Url;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -82,8 +80,8 @@ public class JavaDocumentationProvider implements CodeDocumentationProvider, Ext
|
||||
@NotNull TextAttributes attributes,
|
||||
@Nullable String value
|
||||
) {
|
||||
if (doSyntaxHighlighting()) {
|
||||
HtmlSyntaxInfoUtil.appendStyledSpan(buffer, attributes, value, getHighlightingSaturation());
|
||||
if (DocumentationSettings.isHighlightingOfQuickDocSignaturesEnabled()) {
|
||||
HtmlSyntaxInfoUtil.appendStyledSpan(buffer, attributes, value, DocumentationSettings.getHighlightingSaturation());
|
||||
}
|
||||
else {
|
||||
buffer.append(value);
|
||||
@@ -96,7 +94,7 @@ public class JavaDocumentationProvider implements CodeDocumentationProvider, Ext
|
||||
@Nullable String value,
|
||||
String @NotNull ... properties
|
||||
) {
|
||||
if (doSyntaxHighlighting()) {
|
||||
if (DocumentationSettings.isHighlightingOfQuickDocSignaturesEnabled()) {
|
||||
HtmlSyntaxInfoUtil.appendStyledSpan(buffer, value, properties);
|
||||
}
|
||||
else {
|
||||
@@ -104,14 +102,6 @@ public class JavaDocumentationProvider implements CodeDocumentationProvider, Ext
|
||||
}
|
||||
}
|
||||
|
||||
protected static boolean doSyntaxHighlighting() {
|
||||
return AdvancedSettings.getBoolean("documentation.components.enable.doc.syntax.highlighting");
|
||||
}
|
||||
|
||||
protected static float getHighlightingSaturation() {
|
||||
return MathUtil.clamp(AdvancedSettings.getInt("documentation.components.doc.syntax.highlighting.saturation"), 0, 100) * 0.01f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nls String getQuickNavigateInfo(PsiElement element, PsiElement originalElement) {
|
||||
return QuickDocUtil.inferLinkFromFullDocumentation(this, element, originalElement,
|
||||
@@ -228,10 +218,7 @@ public class JavaDocumentationProvider implements CodeDocumentationProvider, Ext
|
||||
}
|
||||
|
||||
private static JavaDocInfoGenerator getDocInfoGenerator(@NotNull Project project, boolean isGenerationForRenderedDoc) {
|
||||
return JavaDocInfoGeneratorFactory.getBuilder(project)
|
||||
.setIsGenerationForRenderedDoc(isGenerationForRenderedDoc)
|
||||
.setDoSyntaxHighlighting(doSyntaxHighlighting())
|
||||
.create();
|
||||
return JavaDocInfoGeneratorFactory.getBuilder(project).setIsGenerationForRenderedDoc(isGenerationForRenderedDoc).create();
|
||||
}
|
||||
|
||||
public static @Nls String generateClassInfo(PsiClass aClass) {
|
||||
@@ -313,7 +300,6 @@ public class JavaDocumentationProvider implements CodeDocumentationProvider, Ext
|
||||
JavaDocInfoGeneratorFactory.getBuilder(aClass.getProject())
|
||||
.setIsGenerationForRenderedDoc(false)
|
||||
.setHighlightingManager(highlightingManager)
|
||||
.setDoSyntaxHighlighting(doSyntaxHighlighting())
|
||||
.create()
|
||||
.generateType(buffer, refs[i], aClass, false, true);
|
||||
|
||||
@@ -697,7 +683,6 @@ public class JavaDocumentationProvider implements CodeDocumentationProvider, Ext
|
||||
JavaDocInfoGenerator generator = JavaDocInfoGeneratorFactory.getBuilder(target.getProject())
|
||||
.setPsiElement(target)
|
||||
.setIsGenerationForRenderedDoc(true)
|
||||
.setDoSyntaxHighlighting(doSyntaxHighlighting())
|
||||
.create();
|
||||
return JavaDocExternalFilter.filterInternalDocInfo(generator.generateRenderedDocInfo());
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
<html><head><base href="placeholder"></head><body><div class='definition'><pre><span style="color:#808000;">@</span><a href="psi_element://Bar"><code><span style="color:#808000;">Bar</span></code></a><span style="">(</span><a href="psi_element://Baz#CONST"><code><span style="color:#000000;">Baz</span><span style="">.</span><span style="color:#660e7a;font-style:italic;">CONST</span></code></a><span style="">, </span><span style="">value</span><span style=""> = </span><span style="">{</span><a href="psi_element://Baz#CONST"><code><span style="color:#000000;">Baz</span><span style="">.</span><span style="color:#660e7a;font-style:italic;">CONST</span></code></a><span style="">}</span><span style="">)</span>
|
||||
<html><head><base href="placeholder"></head><body><div class='definition'><pre><span style="color:#808000;">@</span><a href="psi_element://Bar"><code><span style="color:#808000;">Bar</span></code></a><span style="">(</span><a href="psi_element://Baz#CONST"><code><span style="color:#0000ff;">Baz</span><span style="">.</span><span style="color:#660e7a;font-style:italic;">CONST</span></code></a><span style="">, </span><span style="">value</span><span style=""> = </span><span style="">{</span><a href="psi_element://Baz#CONST"><code><span style="color:#0000ff;">Baz</span><span style="">.</span><span style="color:#660e7a;font-style:italic;">CONST</span></code></a><span style="">}</span><span style="">)</span>
|
||||
<span style="color:#000080;font-weight:bold;">class</span> <span style="color:#000000;">Foo</span></pre></div><table class='sections'></table>
|
||||
+1
-1
@@ -57,4 +57,4 @@
|
||||
Unicode code points (i.e., characters), in addition to those for
|
||||
dealing with Unicode code units (i.e., <code>char</code> values).
|
||||
|
||||
</div><table class='sections'><p><tr><td valign='top' class='section'><p>Since:</td><td valign='top'><p>JDK1.0</td><tr><td valign='top' class='section'><p>See Also:</td><td valign='top'><p><a href="psi_element://java.lang.Object#toString()"><code><span style="color:#000000;">Object</span><span style="">.</span><span style="color:#0000ff;">toString</span><span style="">()</span></code></a>,<br><a href="psi_element://java.lang.StringBuffer"><code><span style="color:#0000ff;">StringBuffer</span></code></a>,<br><a href="psi_element://java.lang.StringBuilder"><code><span style="color:#0000ff;">StringBuilder</span></code></a>,<br><font color=red>java.nio.charset.Charset</font></td></table>
|
||||
</div><table class='sections'><p><tr><td valign='top' class='section'><p>Since:</td><td valign='top'><p>JDK1.0</td><tr><td valign='top' class='section'><p>See Also:</td><td valign='top'><p><a href="psi_element://java.lang.Object#toString()"><code><span style="color:#0000ff;">Object</span><span style="">.</span><span style="color:#0000ff;">toString</span><span style="">()</span></code></a>,<br><a href="psi_element://java.lang.StringBuffer"><code><span style="color:#0000ff;">StringBuffer</span></code></a>,<br><a href="psi_element://java.lang.StringBuilder"><code><span style="color:#0000ff;">StringBuilder</span></code></a>,<br><font color=red>java.nio.charset.Charset</font></td></table>
|
||||
@@ -1 +1 @@
|
||||
<html><head><base href="placeholder"></head><body><div class='definition'><pre><span style="color:#20999d;">E</span> <span style="color:#000000;">remove</span><span style="">(</span><br> <a href="psi_element://java.lang.Integer"><code><span style="color:#0000ff;">Integer</span></code></a> <span style="">idx</span><br><span style="">)</span></pre></div><table class='sections'><p><tr><td valign='top' class='section'><p>See Also:</td><td valign='top'><p><a href="psi_element://TestImpl#remove(java.lang.Number)"><code><span style="color:#000000;">TestImpl</span><span style="">.</span><span style="color:#0000ff;">remove</span><span style="">(Number)</span></code></a></td></table>
|
||||
<html><head><base href="placeholder"></head><body><div class='definition'><pre><span style="color:#20999d;">E</span> <span style="color:#000000;">remove</span><span style="">(</span><br> <a href="psi_element://java.lang.Integer"><code><span style="color:#0000ff;">Integer</span></code></a> <span style="">idx</span><br><span style="">)</span></pre></div><table class='sections'><p><tr><td valign='top' class='section'><p>See Also:</td><td valign='top'><p><a href="psi_element://TestImpl#remove(java.lang.Number)"><code><span style="color:#0000ff;">TestImpl</span><span style="">.</span><span style="color:#0000ff;">remove</span><span style="">(Number)</span></code></a></td></table>
|
||||
@@ -1 +1 @@
|
||||
<html><head><base href="placeholder"></head><body><div class='definition'><pre><span style="color:#20999d;">E</span> <span style="color:#000000;">remove</span><span style="">(</span><br> <span style="color:#000080;font-weight:bold;">int</span> <span style="">idx</span><br><span style="">)</span></pre></div><table class='sections'><p><tr><td valign='top' class='section'><p>See Also:</td><td valign='top'><p><a href="psi_element://TestImpl#remove(int)"><code><span style="color:#000000;">TestImpl</span><span style="">.</span><span style="color:#0000ff;">remove</span><span style="">(</span><span style="color:#000080;font-weight:bold;">int</span><span style="">)</span></code></a></td></table>
|
||||
<html><head><base href="placeholder"></head><body><div class='definition'><pre><span style="color:#20999d;">E</span> <span style="color:#000000;">remove</span><span style="">(</span><br> <span style="color:#000080;font-weight:bold;">int</span> <span style="">idx</span><br><span style="">)</span></pre></div><table class='sections'><p><tr><td valign='top' class='section'><p>See Also:</td><td valign='top'><p><a href="psi_element://TestImpl#remove(int)"><code><span style="color:#0000ff;">TestImpl</span><span style="">.</span><span style="color:#0000ff;">remove</span><span style="">(</span><span style="color:#000080;font-weight:bold;">int</span><span style="">)</span></code></a></td></table>
|
||||
@@ -157,7 +157,7 @@ class JavaDocumentationTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
def doc = new JavaDocumentationProvider().generateDoc(method, null)
|
||||
|
||||
def expected =
|
||||
"<div class=\'definition\'><pre><span style=\"color:#000080;font-weight:bold;\">public</span> <span style=\"color:#000080;font-weight:bold;\">void</span> <span style=\"color:#000000;\">m</span><span style=\"\">(</span><span style=\"\">)</span></pre></div><div class=\'content\'>\n For example, <a href=\"psi_element://java.lang.String#String(byte[], int, int, java.lang.String)\"><code><span style=\"color:#000000;\">String</span><span style=\"\">.</span><span style=\"color:#0000ff;\">String</span><span style=\"\">(</span><span style=\"color:#000080;font-weight:bold;\">byte</span><span style=\"\">[], </span><span style=\"color:#000080;font-weight:bold;\">int</span><span style=\"\">, </span><span style=\"color:#000080;font-weight:bold;\">int</span><span style=\"\">, String)</span></code></a>.\n </div><table class=\'sections\'></table>"
|
||||
"<div class=\'definition\'><pre><span style=\"color:#000080;font-weight:bold;\">public</span> <span style=\"color:#000080;font-weight:bold;\">void</span> <span style=\"color:#000000;\">m</span><span style=\"\">(</span><span style=\"\">)</span></pre></div><div class=\'content\'>\n For example, <a href=\"psi_element://java.lang.String#String(byte[], int, int, java.lang.String)\"><code><span style=\"color:#0000ff;\">String</span><span style=\"\">.</span><span style=\"color:#0000ff;\">String</span><span style=\"\">(</span><span style=\"color:#000080;font-weight:bold;\">byte</span><span style=\"\">[], </span><span style=\"color:#000080;font-weight:bold;\">int</span><span style=\"\">, </span><span style=\"color:#000080;font-weight:bold;\">int</span><span style=\"\">, String)</span></code></a>.\n </div><table class=\'sections\'></table>"
|
||||
|
||||
assert doc == expected
|
||||
}
|
||||
|
||||
@@ -212,3 +212,7 @@ file.write.error=Cannot write to file {0}.
|
||||
file.delete.root.error=Cannot delete root file {0}.
|
||||
|
||||
jar.modification.not.supported.error=Cannot modify archive file {0}
|
||||
|
||||
documentation.settings.inline.code.highlighting.mode.no.highlighting=No highlighting
|
||||
documentation.settings.inline.code.highlighting.mode.as.default.code=As plain code
|
||||
documentation.settings.inline.code.highlighting.mode.semantic.highlighting=With keywords highlighted
|
||||
@@ -0,0 +1,78 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.lang.documentation;
|
||||
|
||||
import com.intellij.analysis.AnalysisBundle;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.options.advanced.AdvancedSettings;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.util.MathUtil;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
@ApiStatus.Experimental
|
||||
public class DocumentationSettings {
|
||||
|
||||
private DocumentationSettings() {
|
||||
}
|
||||
|
||||
public static boolean isHighlightingOfQuickDocSignaturesEnabled() {
|
||||
return ApplicationManager.getApplication().isUnitTestMode()
|
||||
|| AdvancedSettings.getBoolean("documentation.components.enable.doc.highlighting.of.quick.doc.signatures");
|
||||
}
|
||||
|
||||
public static boolean isHighlightingOfCodeBlocksEnabled() {
|
||||
return ApplicationManager.getApplication().isUnitTestMode()
|
||||
|| AdvancedSettings.getBoolean("documentation.components.enable.doc.highlighting.of.code.blocks");
|
||||
}
|
||||
|
||||
public static boolean isSemanticHighlightingOfLinksEnabled() {
|
||||
return ApplicationManager.getApplication().isUnitTestMode()
|
||||
|| AdvancedSettings.getBoolean("documentation.components.enable.doc.semantic.highlighting.of.links");
|
||||
}
|
||||
|
||||
public static @NotNull InlineCodeHighlightingMode getInlineCodeHighlightingMode() {
|
||||
return ApplicationManager.getApplication().isUnitTestMode()
|
||||
? InlineCodeHighlightingMode.SEMANTIC_HIGHLIGHTING
|
||||
: AdvancedSettings.getEnum("documentation.components.doc.inline.code.highlighting.mode", InlineCodeHighlightingMode.class);
|
||||
}
|
||||
|
||||
public static float getHighlightingSaturation() {
|
||||
return ApplicationManager.getApplication().isUnitTestMode()
|
||||
? 1.0f
|
||||
: MathUtil.clamp(AdvancedSettings.getInt("documentation.components.doc.highlighting.saturation"), 0, 100) * 0.01F;
|
||||
}
|
||||
|
||||
/**
|
||||
* Swing HTML Editor Kit processes values in percents of 'font-size' css property really weirdly
|
||||
* and even in not a cross-platform way.
|
||||
* So we have to do some hacks to align fonts.
|
||||
*/
|
||||
public static int getMonospaceFontSizeCorrection() {
|
||||
return SystemInfo.isWin10OrNewer && !ApplicationManager.getApplication().isUnitTestMode() ? 90 : 96;
|
||||
}
|
||||
|
||||
|
||||
public enum InlineCodeHighlightingMode {
|
||||
NO_HIGHLIGHTING {
|
||||
@Override
|
||||
public String toString() {
|
||||
return AnalysisBundle.message("documentation.settings.inline.code.highlighting.mode.no.highlighting");
|
||||
}
|
||||
},
|
||||
|
||||
AS_DEFAULT_CODE {
|
||||
@Override
|
||||
public String toString() {
|
||||
return AnalysisBundle.message("documentation.settings.inline.code.highlighting.mode.as.default.code");
|
||||
}
|
||||
},
|
||||
|
||||
SEMANTIC_HIGHLIGHTING {
|
||||
@Override
|
||||
public String toString() {
|
||||
return AnalysisBundle.message("documentation.settings.inline.code.highlighting.mode.semantic.highlighting");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -2,6 +2,7 @@
|
||||
package com.intellij.codeInsight.documentation;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.psi.PsiElement;
|
||||
|
||||
public class DocumentationManagerUtil {
|
||||
@@ -23,7 +24,7 @@ public class DocumentationManagerUtil {
|
||||
buffer.append(refText);
|
||||
buffer.append("\">");
|
||||
if (!plainLink) {
|
||||
buffer.append(isRendered ? "<code style='font-size:96%;'>" : "<code>");
|
||||
buffer.append(isRendered ? "<code style='font-size:" + getMonospaceFontSizeCorrection() + "%;'>" : "<code>");
|
||||
}
|
||||
buffer.append(label);
|
||||
if (!plainLink) {
|
||||
@@ -32,6 +33,10 @@ public class DocumentationManagerUtil {
|
||||
buffer.append("</a>");
|
||||
}
|
||||
|
||||
private static int getMonospaceFontSizeCorrection() {
|
||||
return SystemInfo.isWin10OrNewer && !ApplicationManager.getApplication().isUnitTestMode() ? 90 : 96;
|
||||
}
|
||||
|
||||
public static void createHyperlink(StringBuilder buffer, String refText, String label, boolean plainLink) {
|
||||
getInstance().createHyperlinkImpl(buffer, null, refText, label, plainLink, false);
|
||||
}
|
||||
|
||||
@@ -828,11 +828,12 @@ advanced.setting.editor.open.tabs.in.main.window=Open declaration source called
|
||||
advanced.setting.editor.open.tabs.in.main.window.description=When navigating to a method/class/variable declaration from a tab in the detached window, new tabs will be opened in the main IDE window. Overrides 'Open declaration source in the same tab'.
|
||||
advanced.setting.ide.macos.disable.native.shortcut.symbols=Use words instead of symbols for macOS keyboard shortcuts
|
||||
advanced.setting.ide.macos.disable.native.shortcut.symbols.description=Change shortcut symbols \u238B, \u232B, \u2325, and others to Esc, Backspace, Option, etc
|
||||
advanced.setting.documentation.components.enable.doc.syntax.highlighting=Enable code highlighting in documentation components
|
||||
advanced.setting.documentation.components.enable.doc.syntax.highlighting.of.inline.code.blocks=Highlight inline code blocks
|
||||
advanced.setting.documentation.components.enable.doc.syntax.highlighting.of.links=Highlight links on code elements
|
||||
advanced.setting.documentation.components.doc.syntax.highlighting.saturation=Highlighting saturation
|
||||
advanced.setting.documentation.components.doc.syntax.highlighting.saturation.description=Allows reducing saturation of highlighting colors in order to lower distraction from the main code. Here 100 is the normal saturation (bright tones) and 0 is zero saturation (grey tones)
|
||||
advanced.setting.documentation.components.enable.doc.highlighting.of.quick.doc.signatures=Highlight code elements' signatures
|
||||
advanced.setting.documentation.components.enable.doc.highlighting.of.code.blocks=Highlight multiline code blocks
|
||||
advanced.setting.documentation.components.enable.doc.semantic.highlighting.of.links=Enable semantic highlighting of links on code elements
|
||||
advanced.setting.documentation.components.doc.inline.code.highlighting.mode=Inline code highlighting mode
|
||||
advanced.setting.documentation.components.doc.highlighting.saturation=Highlighting saturation
|
||||
advanced.setting.documentation.components.doc.highlighting.saturation.description=Allows reducing saturation of highlighting colors in order to lower distraction from the main code. Here 100 is the normal saturation (bright tones) and 0 is zero saturation (grey tones)
|
||||
group.advanced.settings.other=Other
|
||||
group.advanced.settings.ide=IDE
|
||||
group.advanced.settings.ui=User Interface
|
||||
|
||||
+13
-1
@@ -1,7 +1,9 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInsight.documentation;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.impl.EditorCssFontResolver;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.ui.ColorUtil;
|
||||
import com.intellij.util.ui.JBHtmlEditorKit;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
@@ -30,6 +32,15 @@ public final class DocumentationHtmlEditorKit extends JBHtmlEditorKit {
|
||||
return myHtmlFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Swing HTML Editor Kit processes values in percents of 'font-size' css property really weirdly
|
||||
* and even in not a cross-platform way.
|
||||
* So we have to do some hacks to align fonts.
|
||||
*/
|
||||
private static int getMonospaceFontSizeCorrection() {
|
||||
return SystemInfo.isWin10OrNewer && !ApplicationManager.getApplication().isUnitTestMode() ? 96 : 100;
|
||||
}
|
||||
|
||||
private static void prepareCSS(@NotNull JBHtmlEditorKit editorKit) {
|
||||
editorKit.setFontResolver(EditorCssFontResolver.getGlobalInstance());
|
||||
|
||||
@@ -38,7 +49,8 @@ public final class DocumentationHtmlEditorKit extends JBHtmlEditorKit {
|
||||
String linkColor = ColorUtil.toHtmlColor(JBUI.CurrentTheme.Link.Foreground.ENABLED);
|
||||
String borderColor = ColorUtil.toHtmlColor(UIUtil.getTooltipSeparatorColor());
|
||||
String sectionColor = ColorUtil.toHtmlColor(SECTION_COLOR);
|
||||
String editorFontStyle = "{font-family:\"" + EditorCssFontResolver.EDITOR_FONT_NAME_NO_LIGATURES_PLACEHOLDER + "\";}";
|
||||
String editorFontStyle = "{font-family:\"" + EditorCssFontResolver.EDITOR_FONT_NAME_NO_LIGATURES_PLACEHOLDER +
|
||||
"\";font-size:" + getMonospaceFontSizeCorrection() + "%;}";
|
||||
|
||||
StyleSheet styleSheet = editorKit.getStyleSheet();
|
||||
styleSheet.addRule("tt" + editorFontStyle);
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInsight.documentation;
|
||||
|
||||
import com.intellij.codeInsight.documentation.render.DocRenderManager;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.options.advanced.AdvancedSettingsChangeListener;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.startup.StartupActivity;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
@ApiStatus.Experimental
|
||||
public final class DocumentationSettingsListener implements StartupActivity {
|
||||
|
||||
@Override
|
||||
public void runActivity(@NotNull Project project) {
|
||||
ApplicationManager.getApplication().getMessageBus()
|
||||
.connect()
|
||||
.subscribe(AdvancedSettingsChangeListener.TOPIC, new AdvancedSettingsChangeListener() {
|
||||
@Override
|
||||
public void advancedSettingChanged(@NotNull String id, @NotNull Object oldValue, @NotNull Object newValue) {
|
||||
if (StringUtil.startsWith(id, "documentation.components")) {
|
||||
DocRenderManager.resetAllEditorsToDefaultState();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1452,6 +1452,7 @@
|
||||
<recoveryAction implementation="com.intellij.util.indexing.RefreshIndexableFilesAction"/>
|
||||
|
||||
<postStartupActivity implementation="com.intellij.lang.documentation.ide.impl.DocumentationAutoPopup"/>
|
||||
<postStartupActivity implementation="com.intellij.codeInsight.documentation.DocumentationSettingsListener"/>
|
||||
<lang.documentationLinkResolver implementation="com.intellij.lang.documentation.psi.PsiDocumentationLinkResolver"/>
|
||||
<getDataRule key="documentation.targets"
|
||||
implementationClass="com.intellij.lang.documentation.ide.impl.DocumentationTargetsDataRule"/>
|
||||
|
||||
@@ -1306,10 +1306,11 @@
|
||||
<advancedSetting id="terminal.escape.moves.focus.to.editor" default="true" groupKey="group.advanced.settings.terminal"/>
|
||||
<advancedSetting id="terminal.type.ahead" default="true" groupKey="group.advanced.settings.terminal"/>
|
||||
<advancedSetting id="terminal.type.ahead.latency.threshold" default="100" groupKey="group.advanced.settings.terminal"/>
|
||||
<advancedSetting id="documentation.components.enable.doc.syntax.highlighting" default="true" groupKey="group.advanced.settings.documentation.components"/>
|
||||
<advancedSetting id="documentation.components.enable.doc.syntax.highlighting.of.inline.code.blocks" default="true" groupKey="group.advanced.settings.documentation.components"/>
|
||||
<advancedSetting id="documentation.components.enable.doc.syntax.highlighting.of.links" default="true" groupKey="group.advanced.settings.documentation.components"/>
|
||||
<advancedSetting id="documentation.components.doc.syntax.highlighting.saturation" default="65" groupKey="group.advanced.settings.documentation.components"/>
|
||||
<advancedSetting id="documentation.components.enable.doc.highlighting.of.quick.doc.signatures" default="true" groupKey="group.advanced.settings.documentation.components"/>
|
||||
<advancedSetting id="documentation.components.enable.doc.highlighting.of.code.blocks" default="true" groupKey="group.advanced.settings.documentation.components"/>
|
||||
<advancedSetting id="documentation.components.enable.doc.semantic.highlighting.of.links" default="false" groupKey="group.advanced.settings.documentation.components"/>
|
||||
<advancedSetting id="documentation.components.doc.inline.code.highlighting.mode" enumClass="com.intellij.lang.documentation.DocumentationSettings$InlineCodeHighlightingMode" default="AS_DEFAULT_CODE" groupKey="group.advanced.settings.documentation.components"/>
|
||||
<advancedSetting id="documentation.components.doc.highlighting.saturation" default="65" groupKey="group.advanced.settings.documentation.components"/>
|
||||
|
||||
<backgroundPostStartupActivity implementation="com.intellij.ide.plugins.DependencyFeatureCollector"/>
|
||||
<projectService serviceInterface="com.intellij.presentation.FilePresentationService"
|
||||
|
||||
@@ -2,21 +2,26 @@
|
||||
package git4idea.annotate;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.options.advanced.AdvancedSettingsChangeListener;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
|
||||
import git4idea.util.GitFileUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
public final class GitAdvancedSettingsListener {
|
||||
|
||||
public static void registerListener(@NotNull Project project, @NotNull Disposable disposable) {
|
||||
project.getMessageBus().connect(disposable).subscribe(AdvancedSettingsChangeListener.TOPIC, new AdvancedSettingsChangeListener() {
|
||||
@Override
|
||||
public void advancedSettingChanged(@NotNull String id, @NotNull Object oldValue, @NotNull Object newValue) {
|
||||
if (id.equals(GitFileUtils.READ_CONTENT_WITH)) {
|
||||
ProjectLevelVcsManager.getInstance(project).getContentRevisionCache().clearConstantCache();
|
||||
ApplicationManager.getApplication().getMessageBus()
|
||||
.connect(disposable)
|
||||
.subscribe(AdvancedSettingsChangeListener.TOPIC, new AdvancedSettingsChangeListener() {
|
||||
@Override
|
||||
public void advancedSettingChanged(@NotNull String id, @NotNull Object oldValue, @NotNull Object newValue) {
|
||||
if (id.equals(GitFileUtils.READ_CONTENT_WITH)) {
|
||||
ProjectLevelVcsManager.getInstance(project).getContentRevisionCache().clearConstantCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+2
-8
@@ -3,10 +3,9 @@ package org.jetbrains.plugins.groovy.lang.documentation;
|
||||
|
||||
import com.intellij.codeInsight.javadoc.JavaDocInfoGeneratorFactory;
|
||||
import com.intellij.ide.highlighter.JavaHighlightingColors;
|
||||
import com.intellij.lang.documentation.DocumentationSettings;
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
|
||||
import com.intellij.openapi.editor.richcopy.HtmlSyntaxInfoUtil;
|
||||
import com.intellij.openapi.options.advanced.AdvancedSettings;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiAnnotation;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -15,7 +14,6 @@ import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.MethodSignature;
|
||||
import com.intellij.util.ArrayUtilRt;
|
||||
import com.intellij.util.MathUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.GroovyBundle;
|
||||
@@ -135,10 +133,6 @@ public final class GroovyPresentationUtil {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static float getHighlightingSaturation() {
|
||||
return MathUtil.clamp(AdvancedSettings.getInt("documentation.components.doc.syntax.highlighting.saturation"), 0, 100) * 0.01f;
|
||||
}
|
||||
|
||||
private static @NotNull StringBuilder appendStyledSpan(
|
||||
boolean doHighlighting,
|
||||
@NotNull StringBuilder buffer,
|
||||
@@ -146,7 +140,7 @@ public final class GroovyPresentationUtil {
|
||||
@Nullable String value
|
||||
) {
|
||||
if (doHighlighting) {
|
||||
HtmlSyntaxInfoUtil.appendStyledSpan(buffer, attributesKey, value, getHighlightingSaturation());
|
||||
HtmlSyntaxInfoUtil.appendStyledSpan(buffer, attributesKey, value, DocumentationSettings.getHighlightingSaturation());
|
||||
}
|
||||
else {
|
||||
buffer.append(value);
|
||||
|
||||
+11
-6
@@ -2,6 +2,7 @@
|
||||
package org.jetbrains.plugins.groovy.lang.documentation;
|
||||
|
||||
import com.intellij.codeInsight.javadoc.JavaDocInfoGenerator;
|
||||
import com.intellij.lang.documentation.DocumentationSettings;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiRecursiveElementWalkingVisitor;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
@@ -14,18 +15,22 @@ public class GroovyDocInfoGenerator extends JavaDocInfoGenerator {
|
||||
public GroovyDocInfoGenerator(
|
||||
PsiElement element,
|
||||
boolean isGenerationForRenderedDoc,
|
||||
boolean doSyntaxHighlighting,
|
||||
boolean doHighlightInlineCodeBlocks,
|
||||
boolean doHighlightLinks
|
||||
boolean doHighlightSignatures,
|
||||
boolean doHighlightCodeBlocks,
|
||||
@NotNull DocumentationSettings.InlineCodeHighlightingMode inlineCodeBlocksHighlightingMode,
|
||||
boolean doSemanticHighlightingOfLinks,
|
||||
float highlightingSaturationFactor
|
||||
) {
|
||||
super(
|
||||
element.getProject(),
|
||||
element,
|
||||
GroovyDocHighlightingManager.getInstance(),
|
||||
isGenerationForRenderedDoc,
|
||||
doSyntaxHighlighting,
|
||||
doHighlightInlineCodeBlocks,
|
||||
doHighlightLinks);
|
||||
doHighlightSignatures,
|
||||
doHighlightCodeBlocks,
|
||||
inlineCodeBlocksHighlightingMode,
|
||||
doSemanticHighlightingOfLinks,
|
||||
highlightingSaturationFactor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+12
-27
@@ -12,12 +12,11 @@ import com.intellij.lang.CodeDocumentationAwareCommenter;
|
||||
import com.intellij.lang.LanguageCommenters;
|
||||
import com.intellij.lang.documentation.CodeDocumentationProvider;
|
||||
import com.intellij.lang.documentation.CompositeDocumentationProvider;
|
||||
import com.intellij.lang.documentation.DocumentationSettings;
|
||||
import com.intellij.lang.documentation.ExternalDocumentationProvider;
|
||||
import com.intellij.lang.java.JavaDocumentationProvider;
|
||||
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
|
||||
import com.intellij.openapi.editor.markup.TextAttributes;
|
||||
import com.intellij.openapi.editor.richcopy.HtmlSyntaxInfoUtil;
|
||||
import com.intellij.openapi.options.advanced.AdvancedSettings;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.text.HtmlChunk;
|
||||
@@ -26,7 +25,6 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiFormatUtil;
|
||||
import com.intellij.psi.util.PsiFormatUtilBase;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.MathUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -78,8 +76,8 @@ public class GroovyDocumentationProvider implements CodeDocumentationProvider, E
|
||||
@NotNull TextAttributes attributes,
|
||||
@Nullable String value
|
||||
) {
|
||||
if (doSyntaxHighlighting()) {
|
||||
HtmlSyntaxInfoUtil.appendStyledSpan(buffer, attributes, value, getHighlightingSaturation());
|
||||
if (DocumentationSettings.isHighlightingOfQuickDocSignaturesEnabled()) {
|
||||
HtmlSyntaxInfoUtil.appendStyledSpan(buffer, attributes, value, DocumentationSettings.getHighlightingSaturation());
|
||||
}
|
||||
else {
|
||||
buffer.append(value);
|
||||
@@ -91,7 +89,7 @@ public class GroovyDocumentationProvider implements CodeDocumentationProvider, E
|
||||
@Nullable String value,
|
||||
String @NotNull ... properties
|
||||
) {
|
||||
if (doSyntaxHighlighting()) {
|
||||
if (DocumentationSettings.isHighlightingOfQuickDocSignaturesEnabled()) {
|
||||
HtmlSyntaxInfoUtil.appendStyledSpan(buffer, value, properties);
|
||||
}
|
||||
else {
|
||||
@@ -99,22 +97,6 @@ public class GroovyDocumentationProvider implements CodeDocumentationProvider, E
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean doSyntaxHighlighting() {
|
||||
return AdvancedSettings.getBoolean("documentation.components.enable.doc.syntax.highlighting");
|
||||
}
|
||||
|
||||
private static boolean doHighlightingOfInlineCodeBlocksEnabled() {
|
||||
return AdvancedSettings.getBoolean("documentation.components.enable.doc.syntax.highlighting.of.inline.code.blocks");
|
||||
}
|
||||
|
||||
private static boolean doHighlightingOfLinksEnabled() {
|
||||
return AdvancedSettings.getBoolean("documentation.components.enable.doc.syntax.highlighting.of.links");
|
||||
}
|
||||
|
||||
private static float getHighlightingSaturation() {
|
||||
return MathUtil.clamp(AdvancedSettings.getInt("documentation.components.doc.syntax.highlighting.saturation"), 0, 100) * 0.01f;
|
||||
}
|
||||
|
||||
private static PsiSubstitutor calcSubstitutor(PsiElement originalElement) {
|
||||
PsiSubstitutor substitutor = PsiSubstitutor.EMPTY;
|
||||
if (originalElement instanceof GrReferenceExpression) {
|
||||
@@ -171,7 +153,9 @@ public class GroovyDocumentationProvider implements CodeDocumentationProvider, E
|
||||
PsiParameter parameter = parameters[i];
|
||||
if (i > 0) appendStyledSpan(buffer, GroovyDocHighlightingManager.getInstance().getCommaAttributes(), ", ");
|
||||
if (parameter instanceof GrParameter) {
|
||||
GroovyPresentationUtil.appendParameterPresentation((GrParameter)parameter, substitutor, TypePresentation.LINK, buffer, doSyntaxHighlighting());
|
||||
GroovyPresentationUtil.appendParameterPresentation(
|
||||
(GrParameter)parameter, substitutor, TypePresentation.LINK, buffer,
|
||||
DocumentationSettings.isHighlightingOfQuickDocSignaturesEnabled());
|
||||
}
|
||||
else {
|
||||
PsiType type = parameter.getType();
|
||||
@@ -314,7 +298,6 @@ public class GroovyDocumentationProvider implements CodeDocumentationProvider, E
|
||||
JavaDocInfoGeneratorFactory.getBuilder(context.getProject())
|
||||
.setHighlightingManager(GroovyDocHighlightingManager.getInstance())
|
||||
.setIsGenerationForRenderedDoc(isRendered)
|
||||
.setDoSyntaxHighlighting(doSyntaxHighlighting())
|
||||
.create()
|
||||
.generateType(buffer, type, context);
|
||||
}
|
||||
@@ -427,9 +410,11 @@ public class GroovyDocumentationProvider implements CodeDocumentationProvider, E
|
||||
return new GroovyDocInfoGenerator(
|
||||
element,
|
||||
isGenerationForRenderedDoc,
|
||||
doSyntaxHighlighting(),
|
||||
doHighlightingOfInlineCodeBlocksEnabled(),
|
||||
doHighlightingOfLinksEnabled());
|
||||
DocumentationSettings.isHighlightingOfQuickDocSignaturesEnabled(),
|
||||
DocumentationSettings.isHighlightingOfCodeBlocksEnabled(),
|
||||
DocumentationSettings.getInlineCodeHighlightingMode(),
|
||||
DocumentationSettings.isSemanticHighlightingOfLinksEnabled(),
|
||||
DocumentationSettings.getHighlightingSaturation());
|
||||
}
|
||||
|
||||
protected static @Nls @Nullable String generateExternalJavaDoc(@NotNull PsiElement element) {
|
||||
|
||||
@@ -8,23 +8,20 @@ import com.intellij.codeInsight.javadoc.JavaDocExternalFilter
|
||||
import com.intellij.codeInsight.javadoc.JavaDocInfoGeneratorFactory
|
||||
import com.intellij.lang.documentation.AbstractDocumentationProvider
|
||||
import com.intellij.lang.documentation.DocumentationMarkup.*
|
||||
import com.intellij.lang.documentation.DocumentationSettings
|
||||
import com.intellij.lang.java.JavaDocumentationProvider
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.editor.colors.EditorColorsManager
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey
|
||||
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
|
||||
import com.intellij.openapi.editor.markup.TextAttributes
|
||||
import com.intellij.openapi.editor.richcopy.HtmlSyntaxInfoUtil
|
||||
import com.intellij.openapi.options.advanced.AdvancedSettings.Companion.getBoolean
|
||||
import com.intellij.openapi.options.advanced.AdvancedSettings.Companion.getInt
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.NlsSafe
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.impl.compiled.ClsMethodImpl
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.intellij.util.MathUtil
|
||||
import org.jetbrains.annotations.Nls
|
||||
import org.jetbrains.kotlin.asJava.LightClassUtil
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightDeclaration
|
||||
@@ -231,12 +228,17 @@ class KotlinDocumentationProvider : AbstractDocumentationProvider() {
|
||||
KotlinIdeDescriptorRendererHighlightingManager.Companion.Attributes
|
||||
|
||||
private fun createHighlightingManager(project: Project?): KotlinIdeDescriptorRendererHighlightingManager<KotlinIdeDescriptorRendererHighlightingManager.Companion.Attributes> {
|
||||
if (!doSyntaxHighlighting) {
|
||||
if (!DocumentationSettings.isHighlightingOfQuickDocSignaturesEnabled()) {
|
||||
return KotlinIdeDescriptorRendererHighlightingManager.NO_HIGHLIGHTING
|
||||
}
|
||||
return object : KotlinIdeDescriptorRendererHighlightingManager<TextAttributesAdapter> {
|
||||
override fun StringBuilder.appendHighlighted(value: String, attributes: TextAttributesAdapter) {
|
||||
HtmlSyntaxInfoUtil.appendStyledSpan(this, attributes.attributes, value, highlightingSaturation)
|
||||
HtmlSyntaxInfoUtil.appendStyledSpan(
|
||||
this,
|
||||
attributes.attributes,
|
||||
value,
|
||||
DocumentationSettings.getHighlightingSaturation()
|
||||
)
|
||||
}
|
||||
|
||||
override fun StringBuilder.appendCodeSnippetHighlightedByLexer(codeSnippet: String) {
|
||||
@@ -245,7 +247,7 @@ class KotlinDocumentationProvider : AbstractDocumentationProvider() {
|
||||
project!!,
|
||||
KotlinLanguage.INSTANCE,
|
||||
codeSnippet,
|
||||
highlightingSaturation
|
||||
DocumentationSettings.getHighlightingSaturation()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -285,11 +287,6 @@ class KotlinDocumentationProvider : AbstractDocumentationProvider() {
|
||||
.eraseTypeParameter()
|
||||
}
|
||||
|
||||
private val doSyntaxHighlighting: Boolean get() = getBoolean("documentation.components.enable.doc.syntax.highlighting")
|
||||
|
||||
private val highlightingSaturation: Float
|
||||
get() = MathUtil.clamp(getInt("documentation.components.doc.syntax.highlighting.saturation"), 0, 100) * 0.01f
|
||||
|
||||
private fun StringBuilder.appendHighlighted(
|
||||
value: String,
|
||||
attributesBuilder: KotlinIdeDescriptorRendererHighlightingManager<KotlinIdeDescriptorRendererHighlightingManager.Companion.Attributes>.()
|
||||
|
||||
@@ -5,22 +5,19 @@ package org.jetbrains.kotlin.idea.kdoc
|
||||
import com.intellij.codeInsight.documentation.DocumentationManagerUtil
|
||||
import com.intellij.lang.Language
|
||||
import com.intellij.lang.documentation.DocumentationMarkup.*
|
||||
import com.intellij.lang.documentation.DocumentationSettings
|
||||
import com.intellij.lang.documentation.DocumentationSettings.InlineCodeHighlightingMode
|
||||
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors
|
||||
import com.intellij.openapi.editor.HighlighterColors
|
||||
import com.intellij.openapi.editor.colors.CodeInsightColors
|
||||
import com.intellij.openapi.editor.colors.EditorColorsManager
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey
|
||||
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
|
||||
import com.intellij.openapi.editor.markup.TextAttributes
|
||||
import com.intellij.openapi.editor.richcopy.HtmlSyntaxInfoUtil
|
||||
import com.intellij.openapi.options.advanced.AdvancedSettings
|
||||
import com.intellij.openapi.options.advanced.AdvancedSettings.Companion.getBoolean
|
||||
import com.intellij.openapi.options.advanced.AdvancedSettings.Companion.getInt
|
||||
import com.intellij.openapi.project.DumbService
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.util.MathUtil
|
||||
import org.intellij.markdown.IElementType
|
||||
import org.intellij.markdown.MarkdownElementTypes
|
||||
import org.intellij.markdown.MarkdownTokenTypes
|
||||
@@ -47,17 +44,6 @@ import org.jetbrains.kotlin.psi.psiUtil.getChildrenOfType
|
||||
|
||||
object KDocRenderer {
|
||||
|
||||
private val doSyntaxHighlighting: Boolean get() = getBoolean("documentation.components.enable.doc.syntax.highlighting")
|
||||
|
||||
private val doHighlightInlineCodeBlocks: Boolean
|
||||
get() = getBoolean("documentation.components.enable.doc.syntax.highlighting.of.inline.code.blocks")
|
||||
|
||||
private val doHighlightLinks: Boolean
|
||||
get() = getBoolean("documentation.components.enable.doc.syntax.highlighting.of.links")
|
||||
|
||||
private val highlightingSaturation: Float get() =
|
||||
MathUtil.clamp(getInt("documentation.components.doc.syntax.highlighting.saturation"), 0, 100) * 0.01f
|
||||
|
||||
fun StringBuilder.appendKDocContent(docComment: KDocTag): StringBuilder =
|
||||
append(markdownToHtml(docComment, allowSingleParagraph = true))
|
||||
|
||||
@@ -128,10 +114,10 @@ object KDocRenderer {
|
||||
pathSegment.first().isLowerCase() -> DefaultLanguageHighlighterColors.IDENTIFIER
|
||||
else -> KotlinHighlightingColors.CLASS
|
||||
}
|
||||
appendStyledSpan(doHighlightLinks, segmentAttributes, pathSegment)
|
||||
appendStyledSpan(doHighlightLinks, KotlinHighlightingColors.DOT, ".")
|
||||
appendStyledSpan(DocumentationSettings.isSemanticHighlightingOfLinksEnabled(), segmentAttributes, pathSegment)
|
||||
appendStyledSpan(DocumentationSettings.isSemanticHighlightingOfLinksEnabled(), KotlinHighlightingColors.DOT, ".")
|
||||
}
|
||||
appendStyledSpan(doHighlightLinks, lastSegmentAttributes, elementName)
|
||||
appendStyledSpan(DocumentationSettings.isSemanticHighlightingOfLinksEnabled(), lastSegmentAttributes, elementName)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +167,13 @@ object KDocRenderer {
|
||||
else -> trimCommonIndent(target.extractExampleText()).htmlEscape()
|
||||
}
|
||||
this@appendSamplesList.appendHighlightedByLexerAndEncodedAsHtmlCodeSnippet(
|
||||
doSyntaxHighlighting, subjectLink.project, KotlinLanguage.INSTANCE, codeSnippet
|
||||
when (DocumentationSettings.isHighlightingOfCodeBlocksEnabled()) {
|
||||
true -> InlineCodeHighlightingMode.SEMANTIC_HIGHLIGHTING
|
||||
false -> InlineCodeHighlightingMode.NO_HIGHLIGHTING
|
||||
},
|
||||
subjectLink.project,
|
||||
KotlinLanguage.INSTANCE,
|
||||
codeSnippet
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -249,7 +241,7 @@ object KDocRenderer {
|
||||
if (subjectName != null) {
|
||||
append("<p><code>")
|
||||
when (val link = it.getChildrenOfType<KDocLink>().firstOrNull()) {
|
||||
null -> appendStyledSpan(doHighlightLinks, titleAttributes, subjectName)
|
||||
null -> appendStyledSpan(DocumentationSettings.isSemanticHighlightingOfLinksEnabled(), titleAttributes, subjectName)
|
||||
else -> appendHyperlink(link)
|
||||
}
|
||||
append("</code>")
|
||||
@@ -342,9 +334,9 @@ object KDocRenderer {
|
||||
val startDelimiter = node.child(MarkdownTokenTypes.BACKTICK)?.text
|
||||
if (startDelimiter != null) {
|
||||
val text = node.text.substring(startDelimiter.length).removeSuffix(startDelimiter)
|
||||
sb.append("<code style='font-size:96%;'>")
|
||||
sb.append("<code style='font-size:${DocumentationSettings.getMonospaceFontSizeCorrection()}%;'>")
|
||||
sb.appendHighlightedByLexerAndEncodedAsHtmlCodeSnippet(
|
||||
doHighlightInlineCodeBlocks,
|
||||
DocumentationSettings.getInlineCodeHighlightingMode(),
|
||||
comment.project,
|
||||
KotlinLanguage.INSTANCE,
|
||||
text
|
||||
@@ -414,7 +406,10 @@ object KDocRenderer {
|
||||
MarkdownTokenTypes.CODE_LINE,
|
||||
MarkdownTokenTypes.CODE_FENCE_CONTENT -> {
|
||||
sb.appendHighlightedByLexerAndEncodedAsHtmlCodeSnippet(
|
||||
doSyntaxHighlighting,
|
||||
when (DocumentationSettings.isHighlightingOfCodeBlocksEnabled()) {
|
||||
true -> InlineCodeHighlightingMode.SEMANTIC_HIGHLIGHTING
|
||||
false -> InlineCodeHighlightingMode.NO_HIGHLIGHTING
|
||||
},
|
||||
comment.project,
|
||||
guessLanguage(currentCodeFenceLang) ?: KotlinLanguage.INSTANCE,
|
||||
nodeText
|
||||
@@ -522,7 +517,7 @@ object KDocRenderer {
|
||||
|
||||
private fun StringBuilder.appendStyledSpan(doHighlighting: Boolean, attributesKey: TextAttributesKey, value: String?): StringBuilder {
|
||||
if (doHighlighting) {
|
||||
HtmlSyntaxInfoUtil.appendStyledSpan(this, attributesKey, value, highlightingSaturation)
|
||||
HtmlSyntaxInfoUtil.appendStyledSpan(this, attributesKey, value, DocumentationSettings.getHighlightingSaturation())
|
||||
} else {
|
||||
append(value)
|
||||
}
|
||||
@@ -531,7 +526,7 @@ object KDocRenderer {
|
||||
|
||||
private fun StringBuilder.appendStyledSpan(doHighlighting: Boolean, attributes: TextAttributes, value: String?): StringBuilder {
|
||||
if (doHighlighting) {
|
||||
HtmlSyntaxInfoUtil.appendStyledSpan(this, attributes, value, highlightingSaturation)
|
||||
HtmlSyntaxInfoUtil.appendStyledSpan(this, attributes, value, DocumentationSettings.getHighlightingSaturation())
|
||||
} else {
|
||||
append(value)
|
||||
}
|
||||
@@ -539,23 +534,27 @@ object KDocRenderer {
|
||||
}
|
||||
|
||||
private fun StringBuilder.appendHighlightedByLexerAndEncodedAsHtmlCodeSnippet(
|
||||
doHighlighting: Boolean,
|
||||
highlightingMode: InlineCodeHighlightingMode,
|
||||
project: Project,
|
||||
language: Language,
|
||||
codeSnippet: String
|
||||
): StringBuilder {
|
||||
val codeSnippetBuilder = StringBuilder()
|
||||
if (doHighlighting) { // highlight code by lexer
|
||||
if (highlightingMode == InlineCodeHighlightingMode.SEMANTIC_HIGHLIGHTING) { // highlight code by lexer
|
||||
HtmlSyntaxInfoUtil.appendHighlightedByLexerAndEncodedAsHtmlCodeSnippet(
|
||||
codeSnippetBuilder, project, language, codeSnippet, false, highlightingSaturation
|
||||
codeSnippetBuilder, project, language, codeSnippet, false, DocumentationSettings.getHighlightingSaturation()
|
||||
)
|
||||
} else {
|
||||
codeSnippetBuilder.append(StringUtil.escapeXmlEntities(codeSnippet))
|
||||
}
|
||||
// set code text color as editor default code color instead of doc component text color
|
||||
val codeAttributes = EditorColorsManager.getInstance().globalScheme.getAttributes(HighlighterColors.TEXT).clone()
|
||||
codeAttributes.backgroundColor = null
|
||||
appendStyledSpan(doHighlighting, codeAttributes, codeSnippetBuilder.toString())
|
||||
if (highlightingMode != InlineCodeHighlightingMode.NO_HIGHLIGHTING) {
|
||||
// set code text color as editor default code color instead of doc component text color
|
||||
val codeAttributes = EditorColorsManager.getInstance().globalScheme.getAttributes(HighlighterColors.TEXT).clone()
|
||||
codeAttributes.backgroundColor = null
|
||||
appendStyledSpan(true, codeAttributes, codeSnippetBuilder.toString())
|
||||
} else {
|
||||
append(codeSnippetBuilder.toString())
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -31,8 +31,8 @@ class JavadocNavigationTest() : KotlinLightCodeInsightFixtureTestCase() {
|
||||
val docInfo = JavaDocInfoGenerator(project, psiClass).generateDocInfo(emptyList())
|
||||
Assert.assertEquals(
|
||||
"""<div class='definition'><pre><span style="color:#000080;font-weight:bold;">class</span> <span style="color:#000000;">ExtMethod</span>
|
||||
<span style="color:#000080;font-weight:bold;">extends</span> <a href="psi_element://Super"><code><span style="color:#0000ff;">Super</span></code></a></pre></div><div class='content'>
|
||||
<a href="psi_element://Project#guessDir()"><code><span style="color:#0000ff;">directory</span></code></a>
|
||||
<span style="color:#000080;font-weight:bold;">extends</span> <a href="psi_element://Super"><code>Super</code></a></pre></div><div class='content'>
|
||||
<a href="psi_element://Project#guessDir()"><code>directory</code></a>
|
||||
</div><table class='sections'><p></table>""", docInfo)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user