From 82cf1b4276f9aa7235e6b2dc4210c059b4511c8f Mon Sep 17 00:00:00 2001 From: Andrew Robinson Hodges Date: Thu, 6 Feb 2025 09:42:44 +0000 Subject: [PATCH 1/8] use shared html resource and add checks to keep resources in sync --- .github/workflows/resource-check.yml | 28 ++++++++++++++++++ .../eclipse/plugin/html/BaseHtmlProvider.java | 1 + .../resources/ui/html/ScanSummaryInit.html | 29 +++++++++++++------ 3 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/resource-check.yml diff --git a/.github/workflows/resource-check.yml b/.github/workflows/resource-check.yml new file mode 100644 index 00000000..7c135d74 --- /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 kay, value pair, mapping the local resource to the reference wile (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=$(sha1sum $key | awk {'print $1'}) + candidate=${candidate:="null"} + reference=$(curl -s ${resources[$key]} | sha1sum | awk {'print $1'}) + echo "Candidate file $key has sha1sum $candidate" + echo "Reference file ${resources[$key]} has sha1sum $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..f0d2f610 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 @@ -102,6 +102,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)", "10px"); // Replace CSS variables with actual color values htmlStyled = htmlStyled.replace("var(--text-color)", diff --git a/plugin/src/main/resources/ui/html/ScanSummaryInit.html b/plugin/src/main/resources/ui/html/ScanSummaryInit.html index 01616e67..21ebd2b4 100644 --- a/plugin/src/main/resources/ui/html/ScanSummaryInit.html +++ b/plugin/src/main/resources/ui/html/ScanSummaryInit.html @@ -1,16 +1,30 @@ - + ${ideStyle} From be936fb8ba198ddee45fa975e166f9ace93a7a8d Mon Sep 17 00:00:00 2001 From: Andrew Robinson Hodges Date: Thu, 6 Feb 2025 10:39:36 +0000 Subject: [PATCH 2/8] switch to sha512sum for file hashing in resource checks --- .github/workflows/resource-check.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/resource-check.yml b/.github/workflows/resource-check.yml index 7c135d74..bbf88e68 100644 --- a/.github/workflows/resource-check.yml +++ b/.github/workflows/resource-check.yml @@ -20,8 +20,8 @@ jobs: for key in ${!resources[@]}; do candidate=$(sha1sum $key | awk {'print $1'}) candidate=${candidate:="null"} - reference=$(curl -s ${resources[$key]} | sha1sum | awk {'print $1'}) - echo "Candidate file $key has sha1sum $candidate" + reference=$(curl -s ${resources[$key]} | sha512sum | awk {'print $1'}) + echo "Candidate file $key has sha512sum $candidate" echo "Reference file ${resources[$key]} has sha1sum $reference" [[ $candidate == $reference ]] done From fa3717fb8b2d22740a6ce19507c01b39d2eba340 Mon Sep 17 00:00:00 2001 From: Andrew Robinson Hodges Date: Thu, 6 Feb 2025 10:41:26 +0000 Subject: [PATCH 3/8] switch to sha512sum for file hashing in resource checks --- .github/workflows/resource-check.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/resource-check.yml b/.github/workflows/resource-check.yml index bbf88e68..f5db6b6f 100644 --- a/.github/workflows/resource-check.yml +++ b/.github/workflows/resource-check.yml @@ -18,11 +18,11 @@ jobs: # 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=$(sha1sum $key | awk {'print $1'}) + 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 sha1sum $reference" + echo "Reference file ${resources[$key]} has sha512sum $reference" [[ $candidate == $reference ]] done From cfb502d172dcf12f76c8ae1d259f1456829c8c24 Mon Sep 17 00:00:00 2001 From: Andrew Robinson Hodges Date: Mon, 10 Feb 2025 13:24:00 +0000 Subject: [PATCH 4/8] fix: calculate html font size from Eclipse defaults --- .github/workflows/resource-check.yml | 2 +- .../snyk/eclipse/plugin/html/BaseHtmlProvider.java | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/resource-check.yml b/.github/workflows/resource-check.yml index f5db6b6f..201820cd 100644 --- a/.github/workflows/resource-check.yml +++ b/.github/workflows/resource-check.yml @@ -14,7 +14,7 @@ jobs: - name: Check Static Resources run: | declare -A resources - # Add each resource as a kay, value pair, mapping the local resource to the reference wile (which should be stored in the lanaguage server repository). For example: + # 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 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 f0d2f610..f97dd3f1 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,7 +6,9 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.jface.resource.ColorRegistry; +import org.eclipse.jface.resource.JFaceResources; import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.graphics.RGB; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.themes.ITheme; @@ -102,7 +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)", "10px"); + htmlStyled = htmlStyled.replace("var(--main-font-size)", getScaledFontSize()); // Replace CSS variables with actual color values htmlStyled = htmlStyled.replace("var(--text-color)", @@ -133,6 +135,14 @@ public String replaceCssVariables(String html) { return htmlStyled; } + private String getScaledFontSize() { + int defaultHeight = getCurrentTheme().getFontRegistry().getFontData(JFaceResources.TEXT_FONT)[0].getHeight(); + // 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 String.valueOf(scaledHeight) + "pt"; + } + public String getColorAsHex(String colorKey, String defaultColor) { if (Preferences.getInstance().isTest()) { return ""; @@ -162,7 +172,7 @@ private ColorRegistry getColorRegistry() { } ITheme currentTheme = getCurrentTheme(); colorRegistry = currentTheme.getColorRegistry(); - return colorRegistry; + return colorRegistry; } private ITheme currentTheme; From 459d05bb6186ffa4893229a7828cb50de5ea4088 Mon Sep 17 00:00:00 2001 From: Andrew Robinson Hodges Date: Mon, 10 Feb 2025 13:28:36 +0000 Subject: [PATCH 5/8] fix: whitespace --- .../java/io/snyk/eclipse/plugin/html/BaseHtmlProvider.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 f97dd3f1..5af45c0a 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 @@ -140,7 +140,7 @@ private String getScaledFontSize() { // 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 String.valueOf(scaledHeight) + "pt"; + return scaledHeight + "pt"; } public String getColorAsHex(String colorKey, String defaultColor) { @@ -172,7 +172,7 @@ private ColorRegistry getColorRegistry() { } ITheme currentTheme = getCurrentTheme(); colorRegistry = currentTheme.getColorRegistry(); - return colorRegistry; + return colorRegistry; } private ITheme currentTheme; From d183695b705059db0ee5935350faff6d5abc4090 Mon Sep 17 00:00:00 2001 From: Andrew Robinson Hodges Date: Mon, 10 Feb 2025 13:37:41 +0000 Subject: [PATCH 6/8] fix: remove unused import --- .../main/java/io/snyk/eclipse/plugin/html/BaseHtmlProvider.java | 1 - 1 file changed, 1 deletion(-) 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 5af45c0a..4cd523b5 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 @@ -8,7 +8,6 @@ import org.eclipse.jface.resource.ColorRegistry; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.graphics.RGB; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.themes.ITheme; From 2d15d02f4e1caae051950d04a7a1d4ce4a3f91e8 Mon Sep 17 00:00:00 2001 From: Andrew Robinson Hodges Date: Mon, 10 Feb 2025 13:50:26 +0000 Subject: [PATCH 7/8] fix: fall back to default font registry if workspace is not available --- .../io/snyk/eclipse/plugin/html/BaseHtmlProvider.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 4cd523b5..9d3075d4 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,7 @@ 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; @@ -135,7 +136,15 @@ public String replaceCssVariables(String html) { } private String getScaledFontSize() { - int defaultHeight = getCurrentTheme().getFontRegistry().getFontData(JFaceResources.TEXT_FONT)[0].getHeight(); + FontRegistry registry; + // Use the theme registry, if available. This may not be the case for unit tests. + try { + registry = getCurrentTheme().getFontRegistry(); + } catch (IllegalStateException e) { + registry = JFaceResources.getFontRegistry(); + } + + int defaultHeight = registry.getFontData(JFaceResources.TEXT_FONT)[0].getHeight(); // 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); From c2fa611e6e68dd7bd138a75a056470be5826f16b Mon Sep 17 00:00:00 2001 From: Andrew Robinson Hodges Date: Mon, 10 Feb 2025 14:06:03 +0000 Subject: [PATCH 8/8] fix: fall back to default font size if workspace is not available --- .../io/snyk/eclipse/plugin/html/BaseHtmlProvider.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) 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 9d3075d4..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 @@ -136,15 +136,12 @@ public String replaceCssVariables(String html) { } private String getScaledFontSize() { - FontRegistry registry; - // Use the theme registry, if available. This may not be the case for unit tests. + int defaultHeight; try { - registry = getCurrentTheme().getFontRegistry(); + defaultHeight = getCurrentTheme().getFontRegistry().getFontData(JFaceResources.TEXT_FONT)[0].getHeight(); } catch (IllegalStateException e) { - registry = JFaceResources.getFontRegistry(); + defaultHeight = 13; } - - int defaultHeight = registry.getFontData(JFaceResources.TEXT_FONT)[0].getHeight(); // 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);