Skip to content

Commit 56f808d

Browse files
feat: use shared static html resource and add checks to keep resources in sync (#258)
1 parent 67e3473 commit 56f808d

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

.github/workflows/resource-check.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Static Resource Checking
2+
on:
3+
push:
4+
branches: [ master ]
5+
pull_request:
6+
7+
jobs:
8+
static-resource-checks:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Fetch Sources
12+
uses: actions/checkout@v4
13+
14+
- name: Check Static Resources
15+
run: |
16+
declare -A resources
17+
# 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:
18+
# resources["<path_to_local_file>"]="<url_of_reference_file>"
19+
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"
20+
for key in ${!resources[@]}; do
21+
candidate=$(sha512sum $key | awk {'print $1'})
22+
candidate=${candidate:="null"}
23+
reference=$(curl -s ${resources[$key]} | sha512sum | awk {'print $1'})
24+
echo "Candidate file $key has sha512sum $candidate"
25+
echo "Reference file ${resources[$key]} has sha512sum $reference"
26+
[[ $candidate == $reference ]]
27+
done
28+

plugin/src/main/java/io/snyk/eclipse/plugin/html/BaseHtmlProvider.java

+16
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import org.eclipse.core.runtime.Platform;
88
import org.eclipse.jface.resource.ColorRegistry;
9+
import org.eclipse.jface.resource.FontRegistry;
10+
import org.eclipse.jface.resource.JFaceResources;
911
import org.eclipse.swt.graphics.Color;
1012
import org.eclipse.swt.graphics.RGB;
1113
import org.eclipse.ui.PlatformUI;
@@ -102,6 +104,7 @@ public String replaceCssVariables(String html) {
102104
htmlStyled = htmlStyled.replace("<style nonce=\"ideNonce\" data-ide-style></style>", css);
103105
htmlStyled = htmlStyled.replace("var(--default-font)",
104106
" ui-sans-serif, \"SF Pro Text\", \"Segoe UI\", \"Ubuntu\", Tahoma, Geneva, Verdana, sans-serif;");
107+
htmlStyled = htmlStyled.replace("var(--main-font-size)", getScaledFontSize());
105108

106109
// Replace CSS variables with actual color values
107110
htmlStyled = htmlStyled.replace("var(--text-color)",
@@ -132,6 +135,19 @@ public String replaceCssVariables(String html) {
132135
return htmlStyled;
133136
}
134137

138+
private String getScaledFontSize() {
139+
int defaultHeight;
140+
try {
141+
defaultHeight = getCurrentTheme().getFontRegistry().getFontData(JFaceResources.TEXT_FONT)[0].getHeight();
142+
} catch (IllegalStateException e) {
143+
defaultHeight = 13;
144+
}
145+
// Language server HTML assumes a base font size of 10px. The default Eclipse font size is 17px (13pt), so we
146+
// apply a scaling factor here. This ensures that HTML fonts scale correctly if the user changes the text size.
147+
int scaledHeight = (int) (defaultHeight / 1.7);
148+
return scaledHeight + "pt";
149+
}
150+
135151
public String getColorAsHex(String colorKey, String defaultColor) {
136152
if (Preferences.getInstance().isTest()) {
137153
return "";

0 commit comments

Comments
 (0)