diff --git a/.github/workflows/resource-check.yml b/.github/workflows/resource-check.yml new file mode 100644 index 00000000..201820cd --- /dev/null +++ b/.github/workflows/resource-check.yml @@ -0,0 +1,28 @@ +name: Static Resource Checking +on: + push: + branches: [ master ] + pull_request: + +jobs: + static-resource-checks: + runs-on: ubuntu-latest + steps: + - name: Fetch Sources + uses: actions/checkout@v4 + + - name: Check Static Resources + run: | + declare -A resources + # Add each resource as a key, value pair, mapping the local resource to the reference file (which should be stored in the lanaguage server repository). For example: + # resources[""]="" + resources["plugin/src/main/resources/ui/html/ScanSummaryInit.html"]="https://raw.githubusercontent.com/snyk/snyk-ls/refs/heads/main/shared_ide_resources/ui/html/ScanSummaryInit.html" + for key in ${!resources[@]}; do + candidate=$(sha512sum $key | awk {'print $1'}) + candidate=${candidate:="null"} + reference=$(curl -s ${resources[$key]} | sha512sum | awk {'print $1'}) + echo "Candidate file $key has sha512sum $candidate" + echo "Reference file ${resources[$key]} has sha512sum $reference" + [[ $candidate == $reference ]] + done + diff --git a/plugin/src/main/java/io/snyk/eclipse/plugin/html/BaseHtmlProvider.java b/plugin/src/main/java/io/snyk/eclipse/plugin/html/BaseHtmlProvider.java index 0a070b3f..a587ce41 100644 --- a/plugin/src/main/java/io/snyk/eclipse/plugin/html/BaseHtmlProvider.java +++ b/plugin/src/main/java/io/snyk/eclipse/plugin/html/BaseHtmlProvider.java @@ -6,6 +6,8 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.jface.resource.ColorRegistry; +import org.eclipse.jface.resource.FontRegistry; +import org.eclipse.jface.resource.JFaceResources; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.RGB; import org.eclipse.ui.PlatformUI; @@ -102,6 +104,7 @@ public String replaceCssVariables(String html) { htmlStyled = htmlStyled.replace("", css); htmlStyled = htmlStyled.replace("var(--default-font)", " ui-sans-serif, \"SF Pro Text\", \"Segoe UI\", \"Ubuntu\", Tahoma, Geneva, Verdana, sans-serif;"); + htmlStyled = htmlStyled.replace("var(--main-font-size)", getScaledFontSize()); // Replace CSS variables with actual color values htmlStyled = htmlStyled.replace("var(--text-color)", @@ -132,6 +135,19 @@ public String replaceCssVariables(String html) { return htmlStyled; } + private String getScaledFontSize() { + int defaultHeight; + try { + defaultHeight = getCurrentTheme().getFontRegistry().getFontData(JFaceResources.TEXT_FONT)[0].getHeight(); + } catch (IllegalStateException e) { + defaultHeight = 13; + } + // Language server HTML assumes a base font size of 10px. The default Eclipse font size is 17px (13pt), so we + // apply a scaling factor here. This ensures that HTML fonts scale correctly if the user changes the text size. + int scaledHeight = (int) (defaultHeight / 1.7); + return scaledHeight + "pt"; + } + public String getColorAsHex(String colorKey, String defaultColor) { if (Preferences.getInstance().isTest()) { return "";