mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 11:53:49 +07:00
[pycharm] PY-63670 fixed HF icons class + removed custom CSS styles + minor updates
GitOrigin-RevId: 880afa74bc9a34ce192966fd6e69610107bcb0c8
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6be358058e
commit
872d741a7c
@@ -0,0 +1,20 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.python.community.impl.huggingFace;
|
||||
|
||||
import com.intellij.ui.IconManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* NOTE THIS FILE IS AUTO-GENERATED
|
||||
* DO NOT EDIT IT BY HAND, run "Generate icon classes" configuration instead
|
||||
*/
|
||||
public final class PythonCommunityImplHuggingFaceIcons {
|
||||
private static @NotNull Icon load(@NotNull String path, int cacheKey, int flags) {
|
||||
return IconManager.getInstance().loadRasterizedIcon(path, PythonCommunityImplHuggingFaceIcons.class.getClassLoader(), cacheKey, flags);
|
||||
}
|
||||
/** 14x14 */ public static final @NotNull Icon Download = load("icons/com.python.community.impl.huggingFace/download.svg", -459821553, 0);
|
||||
/** 14x14 */ public static final @NotNull Icon Like = load("icons/com.python.community.impl.huggingFace/like.svg", -1702501286, 0);
|
||||
/** 16x16 */ public static final @NotNull Icon Logo = load("icons/com.python.community.impl.huggingFace/logo.svg", 59143455, 0);
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
{
|
||||
"com": {
|
||||
"intellij": {
|
||||
"python": {
|
||||
"community": {
|
||||
"impl": {
|
||||
"huggingFace": {
|
||||
"icons": {
|
||||
"download.svg": "com/intellij/python/community/impl/huggingFace/icons/download.svg",
|
||||
"like.svg": "com/intellij/python/community/impl/huggingFace/icons/like.svg",
|
||||
"logo.svg": "com/intellij/python/community/impl/huggingFace/icons/logo.svg"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 844 B After Width: | Height: | Size: 844 B |
|
Before Width: | Height: | Size: 716 B After Width: | Height: | Size: 716 B |
|
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.7 KiB |
@@ -11,6 +11,5 @@
|
||||
<lang.inspectionSuppressor language="Python" implementationClass="com.intellij.python.community.impl.huggingFace.service.HuggingFaceTypoInspectionSuppressor"/>
|
||||
<statistics.counterUsagesCollector implementationClass="com.intellij.python.community.impl.huggingFace.service.HuggingFaceCardsUsageCollector"/>
|
||||
<statistics.validation.customValidationRule implementation="com.intellij.python.community.impl.huggingFace.service.HuggingFaceCardsUsageCollector$HuggingFacePipelineTagWhitelistRule"/>
|
||||
<iconMapper mappingFile="HuggingFaceIconMappings.json"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
@@ -8,7 +8,6 @@ object HuggingFaceConstants {
|
||||
const val HF_API_FETCH_PAGE_SIZE = 500
|
||||
const val MAX_MODELS_IN_CACHE = HF_API_FETCH_PAGE_SIZE * 20
|
||||
const val MAX_DATASETS_IN_CACHE = HF_API_FETCH_PAGE_SIZE * 20
|
||||
const val HF_EMOJI = "\uD83E\uDD17"
|
||||
const val API_FETCH_SORT_KEY = "likes"
|
||||
const val DATASET_FAKE_PIPELINE_TAG = "dataset"
|
||||
const val UNDEFINED_PIPELINE_TAG = "undefined"
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.python.community.impl.huggingFace.HuggingFaceConstants
|
||||
import com.intellij.python.community.impl.huggingFace.HuggingFaceEntityKind
|
||||
import com.intellij.python.community.impl.huggingFace.HuggingFaceUtil
|
||||
import com.intellij.python.community.impl.huggingFace.PythonCommunityImplHuggingFaceIcons
|
||||
import com.intellij.python.community.impl.huggingFace.annotation.HuggingFaceIdentifierPsiElement
|
||||
import com.intellij.python.community.impl.huggingFace.api.HuggingFaceApi.fetchOrRetrieveModelCard
|
||||
import com.intellij.python.community.impl.huggingFace.cache.HuggingFaceDatasetsCache
|
||||
@@ -20,6 +21,7 @@ import com.intellij.python.community.impl.huggingFace.service.PyHuggingFaceBundl
|
||||
import com.intellij.refactoring.suggested.createSmartPointer
|
||||
import com.jetbrains.python.psi.PyTargetExpression
|
||||
|
||||
|
||||
internal class HuggingFaceDocumentationTarget(private val myElement : PsiElement) : DocumentationTarget {
|
||||
|
||||
override fun createPointer(): Pointer<out DocumentationTarget> {
|
||||
@@ -29,12 +31,13 @@ internal class HuggingFaceDocumentationTarget(private val myElement : PsiElement
|
||||
|
||||
override fun computePresentation(): TargetPresentation {
|
||||
val elementText = when (myElement) {
|
||||
is PyTargetExpression -> "${HuggingFaceConstants.HF_EMOJI} ${HuggingFaceUtil.extractTextFromPyTargetExpression(myElement)}"
|
||||
is HuggingFaceIdentifierPsiElement -> "${HuggingFaceConstants.HF_EMOJI} ${myElement.stringValue()}"
|
||||
is PyTargetExpression -> HuggingFaceUtil.extractTextFromPyTargetExpression(myElement)
|
||||
is HuggingFaceIdentifierPsiElement -> myElement.stringValue()
|
||||
else -> PyHuggingFaceBundle.message("python.hugging.face.unknown.element")
|
||||
}
|
||||
// todo: add HF logo icon here once it is incorporated
|
||||
return TargetPresentation.builder(elementText).icon(null).presentation()
|
||||
return TargetPresentation.builder(elementText)
|
||||
.icon(PythonCommunityImplHuggingFaceIcons.Logo)
|
||||
.presentation()
|
||||
}
|
||||
|
||||
override fun computeDocumentationHint(): String = IdeBundle.message("open.url.in.browser.tooltip")
|
||||
|
||||
@@ -24,7 +24,6 @@ class HuggingFaceHtmlBuilder(
|
||||
) {
|
||||
@NlsSafe
|
||||
suspend fun build(noHeader: Boolean = false): String {
|
||||
val headChunk = HtmlChunk.tag("head").child(HuggingFaceQuickDocStyles.styleChunk())
|
||||
val cardHeaderChunk = if (noHeader) {
|
||||
HtmlChunk.empty()
|
||||
} else {
|
||||
@@ -33,7 +32,7 @@ class HuggingFaceHtmlBuilder(
|
||||
@NlsSafe val convertedHtml = readAction { DocMarkdownToHtmlConverter.convert(project, modelCardContent) }
|
||||
|
||||
val wrappedBodyContent = HtmlChunk.div()
|
||||
.setClass(HuggingFaceQuickDocStyles.HF_CONTENT_CLASS)
|
||||
.setClass(DocumentationMarkup.CLASS_CONTENT)
|
||||
.child(HtmlChunk.raw(convertedHtml))
|
||||
|
||||
val bodyChunk = HtmlChunk.tag("body")
|
||||
@@ -42,14 +41,14 @@ class HuggingFaceHtmlBuilder(
|
||||
wrappedBodyContent,
|
||||
)
|
||||
|
||||
val htmlContent = HtmlChunk.tag("html").children(headChunk, bodyChunk)
|
||||
val htmlContent = HtmlChunk.tag("html").child(bodyChunk)
|
||||
val htmlString = htmlContent.toString()
|
||||
return htmlString
|
||||
}
|
||||
|
||||
private fun generateCardHeader(modelInfo: HuggingFaceEntityBasicApiData): HtmlChunk {
|
||||
val cardTitle = modelInfo.itemId.replace("-", HuggingFaceQuickDocStyles.NBHP)
|
||||
val modelNameWithIconRow = HtmlChunk.tag("h3").child(HtmlChunk.raw(cardTitle), )
|
||||
val cardTitle = modelInfo.itemId.replace("-", NBHP)
|
||||
val modelNameWithIconRow = HtmlChunk.tag("h3").child(HtmlChunk.raw(cardTitle))
|
||||
|
||||
// modelPurpose chunk is not applicable for datasets
|
||||
val conditionalChunks = if (entityKind == HuggingFaceEntityKind.MODEL) {
|
||||
@@ -59,6 +58,8 @@ class HuggingFaceHtmlBuilder(
|
||||
listOf(HtmlChunk.text(PyHuggingFaceBundle.message("python.hugging.face.dataset")), HtmlChunk.nbsp(2))
|
||||
}
|
||||
|
||||
|
||||
|
||||
val modelInfoRow = DocumentationMarkup.GRAYED_ELEMENT
|
||||
.children(
|
||||
*conditionalChunks.toTypedArray(),
|
||||
@@ -90,9 +91,10 @@ class HuggingFaceHtmlBuilder(
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val NBHP = "‑"
|
||||
private val DOWNLOADS_ICON = HtmlChunk.tag("icon")
|
||||
.attr("src", "AllIcons.Actions.Download")
|
||||
private val LIKES_ICON = HtmlChunk.tag("icon")
|
||||
.attr(".src", "AllIcons.Toolwindows.ToolWindowFavorites")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package com.intellij.python.community.impl.huggingFace.documentation
|
||||
|
||||
import com.intellij.openapi.util.NlsSafe
|
||||
import com.intellij.openapi.util.text.HtmlChunk
|
||||
import com.intellij.python.community.impl.huggingFace.service.PyHuggingFaceBundle
|
||||
import com.intellij.ui.scale.JBUIScale
|
||||
import org.intellij.lang.annotations.Language
|
||||
|
||||
/**
|
||||
* This object provides style adjustments for Hugging Face model cards.
|
||||
*
|
||||
* While the choice of parameters may seem unusual, the quick doc render framework that we use for HF cards
|
||||
* ignores certain styles (for example, it completely ignores the width attribute in an <img> tag).
|
||||
*
|
||||
* @See com.intellij.codeInsight.documentation.DocumentationHtmlUtil.getDocumentationPaneAdditionalCssRules
|
||||
* @See com.intellij.codeInsight.documentation.render.DocRenderer
|
||||
* @See com.intellij.lang.documentation.DocumentationMarkup
|
||||
*/
|
||||
@Suppress("SpellCheckingInspection")
|
||||
object HuggingFaceQuickDocStyles { // see PY-70541
|
||||
private fun scale(value: Int): Int = JBUIScale.scale(value)
|
||||
|
||||
const val HF_PRE_TAG_CLASS = "word-break-pre-class"
|
||||
const val HF_P_TAG_CLASS = "increased-margin-p"
|
||||
const val CODE_DIV_CLASS = "code-fence-container"
|
||||
const val QUOTE_CLASS = "blockquote-inner"
|
||||
const val HF_CONTENT_CLASS = "hf-content"
|
||||
const val NBHP = "‑"
|
||||
const val HAIR_SPACE = " "
|
||||
|
||||
@Language("CSS")
|
||||
val styleRules = listOf(
|
||||
"$HF_P_TAG_CLASS { margin-top: ${scale(4)}px; margin-bottom: ${scale(6)}px; }",
|
||||
|
||||
".$CODE_DIV_CLASS { padding-top: ${scale(4)}px; padding-bottom: ${scale(4)}px; padding-left: ${scale(4)}px; " +
|
||||
"overflow-x: auto; background-color: rgba(0, 0, 0, 0.05); }",
|
||||
|
||||
".$CODE_DIV_CLASS code { padding-top: 0px; padding-bottom: 0px; padding-left: 0px; " +
|
||||
"max-width: 100%; white-space: pre-wrap; word-wrap: break-word; }",
|
||||
|
||||
".$HF_PRE_TAG_CLASS { white-space: pre-wrap; word-break: break-all; }",
|
||||
|
||||
".$QUOTE_CLASS { padding-left: ${scale(10)}px; }",
|
||||
|
||||
".$HF_CONTENT_CLASS { padding: ${scale(5)}px 0px ${scale(8)}px; max-width: 100% }",
|
||||
|
||||
"blockquote { border-left: ${scale(4)}px solid #cccccc; }",
|
||||
|
||||
"blockquote p { border-left: none; }",
|
||||
)
|
||||
|
||||
@NlsSafe
|
||||
private val styleContent = styleRules.joinToString(separator = " ")
|
||||
|
||||
fun styleChunk(): HtmlChunk = HtmlChunk.raw(PyHuggingFaceBundle.message("python.hugging.face.tags.style", styleContent))
|
||||
}
|
||||
Reference in New Issue
Block a user