Skip to content

Commit

Permalink
Use multiline Strings for view HTML literals (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
breedloj authored Sep 26, 2024
1 parent 383e6cf commit 3fa71dc
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 75 deletions.
11 changes: 5 additions & 6 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,15 @@
<version>10.17.0</version>
</dependency>
</dependencies>
<configuration>
<configLocation>checkstyle.xml</configLocation>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
</configuration>
<executions>
<execution>
<id>checkstyle-validation</id>
<phase>validate</phase>
<configuration>
<configLocation>checkstyle.xml</configLocation>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<includes>src/**/*.java</includes>
</configuration>
<goals>
<goal>check</goal>
</goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ public void sendMessageToChatUI(final Browser browser, final ChatUIInboundComman
});
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static CompletableFuture<ChatMessageProvider> createAsync() {
.thenApply(ChatMessageProvider::new);
}

private ChatMessageProvider(AmazonQLspServer amazonQLspServer) {
private ChatMessageProvider(final AmazonQLspServer amazonQLspServer) {
this.amazonQLspServer = amazonQLspServer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ public void executeCallbackForCodeReference() {
codeReferenceAcceptanceCallback.onCallback(selectedSuggestion, startLine);
}
}
public void setVerticalIndent(int line, int height) {

public void setVerticalIndent(final int line, final int height) {
var widget = viewer.getTextWidget();
widget.setLineVerticalIndent(line, height);
unsetVerticalIndent = () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ public final void handleCommand(final ParsedCommand parsedCommand, final Browser
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,49 +55,55 @@ public Object function(final Object[] arguments) {

private String getContent() {
String jsFile = PluginUtils.getAwsDirectory(LspConstants.LSP_SUBDIRECTORY).resolve("amazonq-ui.js").toString();
return String.format("<!DOCTYPE html>\n"
+ "<html lang=\"en\">\n"
+ "<head>\n"
+ " <meta charset=\"UTF-8\">\n"
+ " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n"
+ " <title>Chat UI</title>\n"
+ " %s\n"
+ "</head>\n"
+ "<body>\n"
+ " %s\n"
+ "</body>\n"
+ "</html>", generateCss(), generateJS(jsFile));
return String.format("""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chat UI</title>
%s
</head>
<body>
%s
</body>
</html>
""", generateCss(), generateJS(jsFile));
}

private String generateCss() {
return "<style>\n"
+ " body,\n"
+ " html {\n"
+ " background-color: var(--mynah-color-bg);\n"
+ " color: var(--mynah-color-text-default);\n"
+ " height: 100vh;\n"
+ " width: 100%%;\n"
+ " overflow: hidden;\n"
+ " margin: 0;\n"
+ " padding: 0;\n"
+ " }\n"
+ " textarea:placeholder-shown {\n"
+ " line-height: 1.5rem;\n"
+ " }"
+ " </style>";
return """
<style>
body,
html {
background-color: var(--mynah-color-bg);
color: var(--mynah-color-text-default);
height: 100vh;
width: 100%%;
overflow: hidden;
margin: 0;
padding: 0;
}
textarea:placeholder-shown {
line-height: 1.5rem;
}
</style>
""";
}

private String generateJS(final String jsEntrypoint) {
return String.format("<script type=\"text/javascript\" src=\"%s\" defer onload=\"init()\"></script>\n"
+ " <script type=\"text/javascript\">\n"
+ " const init = () => {\n"
+ " amazonQChat.createChat({\n"
+ " postMessage: (message) => {\n"
+ " ideCommand(JSON.stringify(message));\n"
+ " }\n"
+ " });\n"
+ " }\n"
+ " </script>", jsEntrypoint);
return String.format("""
<script type="text/javascript" src="%s" defer onload="init()"></script>
<script type="text/javascript">
const init = () => {
amazonQChat.createChat({
postMessage: (message) => {
ideCommand(JSON.stringify(message));
}
});
}
</script>
""", jsEntrypoint);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,16 @@ private void createQuestionSection(final Composite container) {
CustomRadioButton negativeSentimentButton = createCustomRadioButton(sentimentContainer, "icons/FrownyFace.png", "Unsatisfied", SWT.NONE, false);
positiveSentimentButton.getRadioButton().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
negativeSentimentButton.getRadioButton().setSelection(false);
selectedSentiment = Sentiment.POSITIVE;
public void widgetSelected(final SelectionEvent e) {
negativeSentimentButton.getRadioButton().setSelection(false);
selectedSentiment = Sentiment.POSITIVE;
}
});
negativeSentimentButton.getRadioButton().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
positiveSentimentButton.getRadioButton().setSelection(false);
selectedSentiment = Sentiment.NEGATIVE;
public void widgetSelected(final SelectionEvent e) {
positiveSentimentButton.getRadioButton().setSelection(false);
selectedSentiment = Sentiment.NEGATIVE;
}
});

Expand Down Expand Up @@ -280,7 +280,8 @@ private void createSeparator(final Composite parent) {
separatorLabel.setLayoutData(separatorGithubLayout);
}

private CustomRadioButton createCustomRadioButton(final Composite parent, final String imagePath, final String text, final int style, final boolean isSelected) {
private CustomRadioButton createCustomRadioButton(final Composite parent, final String imagePath,
final String text, final int style, final boolean isSelected) {
CustomRadioButton button = new CustomRadioButton(parent, loadImage(imagePath), text, style);
button.getRadioButton().setSelection(isSelected);
return button;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,28 @@ protected void handleAuthStatusChange(final boolean isLoggedIn) {
private String getContent() {
try {
URL jsFile = PluginUtils.getResource("webview/build/assets/js/getStart.js");
return String.format("<!DOCTYPE html>\n"
+ "<html>\n"
+ " <head>\n"
+ " <title>AWS Q</title>\n"
+ " </head>\n"
+ " <body class=\"jb-light\">\n"
+ " <div id=\"app\"></div>\n"
+ " <script type=\"text/javascript\" src=\"%s\"></script>\n"
+ " <script>\n"
+ " window.addEventListener('DOMContentLoaded', function() {\n"
+ " const ideApi = {\n"
+ " postMessage(message) {\n"
+ " ideCommand(JSON.stringify(message));\n"
+ " }\n"
+ " };\n"
+ " window.ideApi = ideApi;\n"
+ " });\n"
+ " </script>\n"
+ " </body>\n"
+ "</html>", jsFile.toString());
return String.format("""
<!DOCTYPE html>
<html>
<head>
<title>AWS Q</title>
</head>
<body class="jb-light">
<div id="app"></div>
<script type="text/javascript" src="%s"></script>
<script>
window.addEventListener('DOMContentLoaded', function() {
const ideApi = {
postMessage(message) {
ideCommand(JSON.stringify(message));
}
};
window.ideApi = ideApi;
});
</script>
</body>
</html>
""", jsFile.toString());
} catch (IOException e) {
return "Failed to load JS";
}
Expand Down

0 comments on commit 3fa71dc

Please sign in to comment.