Skip to content

Commit 062bf1d

Browse files
authored
feat: add new code review mode (#197)
1 parent 90f6003 commit 062bf1d

File tree

6 files changed

+683
-28
lines changed

6 files changed

+683
-28
lines changed

media/chat.css

+21
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,24 @@ button.sidebar__chat-assistant--chat-bubble-text--code-action-button:hover {
403403
.sidebar__textarea-send-button--disabled svg {
404404
opacity: 0.2;
405405
}
406+
407+
.sidebar__branch-form {
408+
display: grid;
409+
grid-template-columns: min-content auto;
410+
align-items: center;
411+
}
412+
413+
.sidebar__branch-form label {
414+
margin-right: 10px;
415+
font-weight: bold;
416+
}
417+
418+
.columnOne {
419+
grid-column: 1/2;
420+
grid-row: auto;
421+
}
422+
423+
.columnTwo {
424+
grid-column: 2/2;
425+
grid-row: auto;
426+
}

package.json

+22
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@
6767
"contextualTitle": "Recipes",
6868
"when": "sourcery.features.coding_assistant"
6969
},
70+
{
71+
"id": "sourcery.code_review",
72+
"name": "Code Review",
73+
"type": "webview",
74+
"icon": "sourcery-icon.png",
75+
"contextualTitle": "Code Review",
76+
"when": "sourcery.features.coding_assistant && sourcery.features.code_review"
77+
},
7078
{
7179
"id": "sourcery.rules",
7280
"name": "Rules",
@@ -229,6 +237,11 @@
229237
"title": "Clear",
230238
"category": "Sourcery"
231239
},
240+
{
241+
"command": "sourcery.chat.clearCodeReview",
242+
"title": "Clear",
243+
"category": "Sourcery"
244+
},
232245
{
233246
"command": "sourcery.chat.ask",
234247
"title": "Ask Sourcery",
@@ -286,6 +299,11 @@
286299
"command": "sourcery.chat.clearChat",
287300
"when": "view == sourcery.chat",
288301
"group": "navigation"
302+
},
303+
{
304+
"command": "sourcery.chat.clearCodeReview",
305+
"when": "view == sourcery.code_review",
306+
"group": "navigation"
289307
}
290308
],
291309
"view/item/context": [
@@ -360,6 +378,10 @@
360378
"command": "sourcery.chat.clearChat",
361379
"when": "false"
362380
},
381+
{
382+
"command": "sourcery.chat.clearCodeReview",
383+
"when": "false"
384+
},
363385
{
364386
"command": "sourcery.chat.ask",
365387
"when": "sourcery.features.coding_assistant"

src/chat.ts

+34-25
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ marked.use(
1616
})
1717
);
1818

19-
enum ChatResultOutcome {
19+
export enum ChatResultOutcome {
2020
Success = "success",
2121
Error = "error",
2222
Finished = "finished",
2323
}
2424

25-
enum ChatResultRole {
25+
export enum ChatResultRole {
2626
Assistant = "assistant",
2727
User = "user",
2828
}
2929

30-
type ChatResult = {
30+
export type ChatResult = {
3131
outcome: ChatResultOutcome;
3232
textContent: string;
3333
role: ChatResultRole;
@@ -38,15 +38,21 @@ export type ChatRequestData = {
3838
message: string;
3939
};
4040

41+
export type CodeReviewRequestData = {
42+
kind: "review_request";
43+
main: string;
44+
current: string;
45+
};
46+
4147
export type RecipeRequestData = {
4248
kind: "recipe_request";
4349
name: string;
4450
id: string;
4551
};
4652

4753
export type ChatRequest = {
48-
type: "recipe_request" | "chat_request";
49-
data: ChatRequestData | RecipeRequestData;
54+
type: "recipe_request" | "chat_request" | "review_request";
55+
data: ChatRequestData | RecipeRequestData | CodeReviewRequestData;
5056
context_range?: any;
5157
};
5258

@@ -60,7 +66,7 @@ export type OpenLinkRequest = {
6066
link: string;
6167
};
6268

63-
type InsertAtCursorInstruction = {
69+
export type InsertAtCursorInstruction = {
6470
type: "insert_at_cursor";
6571
content: string;
6672
};
@@ -214,7 +220,7 @@ export class ChatProvider implements vscode.WebviewViewProvider {
214220
this._currentAssistantMessage = result.textContent;
215221
}
216222

217-
let sanitized = this.renderAssistantMessage(this._currentAssistantMessage);
223+
let sanitized = renderAssistantMessage(this._currentAssistantMessage);
218224

219225
this._view.webview.postMessage({
220226
command: "add_result",
@@ -226,23 +232,6 @@ export class ChatProvider implements vscode.WebviewViewProvider {
226232
});
227233
}
228234

229-
private renderAssistantMessage(message: string) {
230-
// Send the whole message we've been streamed so far to the webview,
231-
// after converting from markdown to html
232-
233-
const rendered = marked(message, {
234-
gfm: true,
235-
breaks: true,
236-
mangle: false,
237-
headerIds: false,
238-
});
239-
240-
// Allow any classes on span and code blocks or highlightjs classes get removed
241-
return sanitizeHtml(rendered, {
242-
allowedClasses: { span: false, code: false },
243-
});
244-
}
245-
246235
public clearChat() {
247236
this._view.webview.postMessage({ command: "clear_chat" });
248237
this._currentAssistantMessage = "";
@@ -316,7 +305,6 @@ export class ChatProvider implements vscode.WebviewViewProvider {
316305
<section id="message-container" class="sidebar__section-container active" data-section="chat-assistant">
317306
<ul class="sidebar__chat-assistant--dialogue-container">
318307
319-
<li id="anchor"></li>
320308
</ul>
321309
</section>
322310
<footer class="sidebar__chat-assistant--footer">
@@ -344,3 +332,24 @@ export class ChatProvider implements vscode.WebviewViewProvider {
344332
</html>`;
345333
}
346334
}
335+
336+
export function renderAssistantMessage(message: string) {
337+
// Send the whole message we've been streamed so far to the webview,
338+
// after converting from markdown to html
339+
340+
const rendered = marked(message, {
341+
gfm: true,
342+
breaks: true,
343+
mangle: false,
344+
headerIds: false,
345+
});
346+
347+
// Allow any classes on span and code blocks or highlightjs classes get removed
348+
return sanitizeHtml(rendered, {
349+
allowedTags: sanitizeHtml.defaults.allowedTags.concat([
350+
"details",
351+
"summary",
352+
]),
353+
allowedClasses: { span: false, code: false },
354+
});
355+
}

0 commit comments

Comments
 (0)