3
3
import io .snyk .eclipse .plugin .preferences .Preferences ;
4
4
5
5
public class CodeHtmlProvider extends BaseHtmlProvider {
6
- private static CodeHtmlProvider instance = new CodeHtmlProvider ();
6
+ private static CodeHtmlProvider instance = new CodeHtmlProvider ();
7
7
8
8
public static CodeHtmlProvider getInstance () {
9
9
synchronized (CodeHtmlProvider .class ) {
@@ -16,61 +16,80 @@ public static CodeHtmlProvider getInstance() {
16
16
return instance ;
17
17
}
18
18
19
- @ Override
20
- public String getInitScript () {
21
- String themeScript = getThemeScript ();
22
- String initScript = super .getInitScript ();
23
- return initScript + "\n " + """
24
- function navigateToIssue(e, target) {
25
- e.preventDefault();
26
- var filePath = target.getAttribute('file-path');
27
- var startLine = target.getAttribute('start-line');
28
- var endLine = target.getAttribute('end-line');
29
- var startCharacter = target.getAttribute('start-character');
30
- var endCharacter = target.getAttribute('end-character');
31
- window.openInEditor(filePath, startLine, endLine, startCharacter, endCharacter);
32
- }
33
- var navigatableLines = document.getElementsByClassName('data-flow-clickable-row');
34
- for(var i = 0; i < navigatableLines.length; i++) {
35
- navigatableLines[i].onclick = function(e) {
36
- navigateToIssue(e, this);
37
- return false;
38
- };
39
- }
40
- if(document.getElementById('position-line')) {
41
- document.getElementById('position-line').onclick = function(e) {
42
- var target = navigatableLines[0];
43
- if(target) {
44
- navigateToIssue(e, target);
45
- }
46
- }
47
- }
48
- // Disable AIfix
49
- if(document.getElementById('ai-fix-wrapper') && document.getElementById('no-ai-fix-wrapper')){
50
- document.getElementById('ai-fix-wrapper').className = 'hidden';
51
- document.getElementById('no-ai-fix-wrapper').className = '';
52
- }
53
- """ + themeScript ;
54
- }
19
+ @ Override
20
+ public String getInitScript () {
21
+ String themeScript = getThemeScript ();
22
+ String initScript = super .getInitScript ();
23
+ return initScript + "\n " + """
24
+ function navigateToIssue(e, target) {
25
+ e.preventDefault();
26
+ var filePath = target.getAttribute('file-path');
27
+ var startLine = target.getAttribute('start-line');
28
+ var endLine = target.getAttribute('end-line');
29
+ var startCharacter = target.getAttribute('start-character');
30
+ var endCharacter = target.getAttribute('end-character');
31
+ window.openInEditor(filePath, startLine, endLine, startCharacter, endCharacter);
32
+ }
33
+ var navigatableLines = document.getElementsByClassName('data-flow-clickable-row');
34
+ for(var i = 0; i < navigatableLines.length; i++) {
35
+ navigatableLines[i].onclick = function(e) {
36
+ navigateToIssue(e, this);
37
+ return false;
38
+ };
39
+ }
40
+ if(document.getElementById('position-line')) {
41
+ document.getElementById('position-line').onclick = function(e) {
42
+ var target = navigatableLines[0];
43
+ if(target) {
44
+ navigateToIssue(e, target);
45
+ }
46
+ }
47
+ }
48
+ """ + themeScript ;
49
+ }
50
+
51
+ private String getThemeScript () {
52
+ if (Preferences .getInstance ().isTest ()) {
53
+ return "" ;
54
+ }
55
+
56
+ String themeScript = "var isDarkTheme = " + isDarkTheme () + ";\n "
57
+ + "document.body.classList.add(isDarkTheme ? 'dark' : 'light');" ;
58
+ return themeScript ;
59
+ }
60
+
61
+ @ Override
62
+ public String replaceCssVariables (String html ) {
63
+ String htmlStyled = super .replaceCssVariables (html );
64
+
65
+ // Replace CSS variables with actual color values
66
+ htmlStyled = htmlStyled .replace ("var(--example-line-removed-color)" ,
67
+ super .getColorAsHex ("DELETION_COLOR" , "#ff0000" ));
68
+ htmlStyled = htmlStyled .replace ("var(--example-line-added-color)" ,
69
+ super .getColorAsHex ("ADDITION_COLOR" , "#00ff00" ));
70
+ htmlStyled = htmlStyled .replace ("var(--generated-ai-fix-button-background-color)" ,
71
+ super .getColorAsHex ("BUTTON_COLOR" , "#375578" ));
72
+ htmlStyled = htmlStyled .replace ("var(--disabled-background-color)" ,
73
+ super .getColorAsHex ("org.eclipse.ui.workbench.ACTIVE_TAB_OUTER_KEYLINE_COLOR" , "#CCCCCC" ));
55
74
56
- private String getThemeScript () {
57
- if (Preferences .getInstance ().isTest ()) {
58
- return "" ;
59
- }
75
+ String htmlWithScripts = replaceAIFixScripts (htmlStyled );
60
76
61
- String themeScript = "var isDarkTheme = " + isDarkTheme () + ";\n " +
62
- "document.body.classList.add(isDarkTheme ? 'dark' : 'light');" ;
63
- return themeScript ;
64
- }
77
+ return htmlWithScripts ;
78
+ }
79
+
80
+ private String replaceAIFixScripts (String html ) {
81
+ String htmlWithAiFixScripts = html .replace ("${ideGenerateAIFix}" , getGenerateAiFixScript ());
82
+ htmlWithAiFixScripts = htmlWithAiFixScripts .replace ("${ideApplyAIFix}" , getApplyAiFixScript ());
83
+
84
+ return htmlWithAiFixScripts ;
85
+ }
65
86
66
- @ Override
67
- public String replaceCssVariables ( String html ) {
68
- String htmlStyled = super . replaceCssVariables ( html );
69
-
70
- // Replace CSS variables with actual color values
71
- htmlStyled = htmlStyled . replace ( "var(--example-line-removed-color)" , super . getColorAsHex ( "DELETION_COLOR" , "#ff0000" )) ;
72
- htmlStyled = htmlStyled . replace ( "var(--example-line-added-color)" , super . getColorAsHex ( "ADDITION_COLOR" , "#00ff00" ));
87
+ private String getGenerateAiFixScript () {
88
+ return "window.ideGenAIFix(generateFixQueryString) \n ;" ;
89
+ }
90
+
91
+ private String getApplyAiFixScript () {
92
+ return "window.ideApplyFix(fixId); \n " ;
93
+ }
73
94
74
- return htmlStyled ;
75
- }
76
95
}
0 commit comments