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

Use multiline Strings for view HTML literals #40

Merged
merged 6 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,54 @@ 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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

@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