Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use shared html resource and add checks to keep resources in sync #258

Merged
merged 9 commits into from
Feb 10, 2025
28 changes: 28 additions & 0 deletions .github/workflows/resource-check.yml
Original file line number Diff line number Diff line change
@@ -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["<path_to_local_file>"]="<url_of_reference_file>"
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

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -102,6 +104,7 @@ public String replaceCssVariables(String html) {
htmlStyled = htmlStyled.replace("<style nonce=\"ideNonce\" data-ide-style></style>", 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)",
Expand Down Expand Up @@ -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 "";
Expand Down