Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
feat(guideline): add webview to manage guidelines (#63)
Browse files Browse the repository at this point in the history
* feat(guidelines): add management commands

* refactor(endpoint): improve endpoint configuration

* feat(guidelines): add tree view to manage guidelines

* refactor(chat): comment legacy sections
  • Loading branch information
frgfm authored Mar 5, 2024
1 parent 8177dd5 commit e5835d3
Show file tree
Hide file tree
Showing 10 changed files with 555 additions and 274 deletions.
3 changes: 3 additions & 0 deletions assets/dark/add.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/dark/edit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/light/add.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/light/edit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 69 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
"id": "quack.endpointView",
"name": "Endpoint",
"icon": "assets/dark/quack.svg",
"contextualTitle": "Endpoint",
"contextualTitle": "Endpoint configuration",
"when": "!quack.isValidEndpoint"
},
{
Expand All @@ -152,9 +152,17 @@
{
"type": "webview",
"id": "quack.chatView",
"name": "Quack Chat",
"name": "Chat",
"icon": "assets/dark/quack.svg",
"contextualTitle": "Chat"
},
{
"id": "quack.guidelineTreeView",
"name": "Coding guidelines",
"type": "tree",
"icon": "assets/dark/quack.svg",
"contextualTitle": "Guidelines",
"when": "true"
}
]
},
Expand Down Expand Up @@ -192,6 +200,48 @@
"light": "assets/light/trash.svg",
"dark": "assets/dark/trash.svg"
}
},
{
"command": "quack.createGuideline",
"category": "Quack Companion",
"title": "Create a coding guideline",
"icon": {
"light": "assets/light/add.svg",
"dark": "assets/dark/add.svg"
}
},
{
"command": "quack.listGuidelines",
"category": "Quack Companion",
"title": "List your guidelines"
},
{
"command": "quack.editGuideline",
"category": "Quack Companion",
"title": "Update your guideline content"
},
{
"command": "quack.editGuidelineItem",
"category": "Quack Companion",
"title": "Update this guideline",
"icon": {
"light": "assets/light/edit.svg",
"dark": "assets/dark/edit.svg"
}
},
{
"command": "quack.deleteGuideline",
"category": "Quack Companion",
"title": "Delete a guideline"
},
{
"command": "quack.deleteGuidelineItem",
"category": "Quack Companion",
"title": "Delete this guideline",
"icon": {
"light": "assets/light/trash.svg",
"dark": "assets/dark/trash.svg"
}
}
],
"viewsWelcome": [
Expand Down Expand Up @@ -219,6 +269,23 @@
"command": "quack.clearChatHistory",
"when": "view == quack.chatView",
"group": "navigation"
},
{
"command": "quack.createGuideline",
"when": "view == quack.guidelineTreeView",
"group": "navigation"
}
],
"view/item/context": [
{
"command": "quack.editGuidelineItem",
"when": "view == quack.guidelineTreeView && viewItem == guidelineTreeItem",
"group": "inline"
},
{
"command": "quack.deleteGuidelineItem",
"when": "view == quack.guidelineTreeView && viewItem == guidelineTreeItem",
"group": "inline"
}
]
},
Expand Down
68 changes: 68 additions & 0 deletions src/activation/activate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ import { v4 } from "uuid";

import { getExtensionVersion } from "./environmentSetup";
import { ChatViewProvider } from "../webviews/chatView";
import { GuidelineTreeProvider } from "../webviews/guidelineView";
import { verifyQuackEndpoint, verifyQuackToken } from "../util/quack";
import { setEndpoint, login, logout } from "../commands/authentication";
import { getEnvInfo } from "../commands/diagnostics";
import { sendChatMessage } from "../commands/assistant";
import {
createGuideline,
listGuidelines,
editGuideline,
deleteGuideline,
} from "../commands/guidelines";

export let extensionContext: vscode.ExtensionContext | undefined = undefined;
export let sessionId: string = v4();
Expand Down Expand Up @@ -39,6 +46,16 @@ export async function activateExtension(context: vscode.ExtensionContext) {
chatViewProvider,
),
);
const guidelineTreeProvider = new GuidelineTreeProvider(
context.extensionUri,
context,
);
context.subscriptions.push(
vscode.window.registerTreeDataProvider(
"quack.guidelineTreeView",
guidelineTreeProvider,
),
);
// Register commands and providers
// Diagnostics
context.subscriptions.push(
Expand Down Expand Up @@ -76,8 +93,59 @@ export async function activateExtension(context: vscode.ExtensionContext) {
chatViewProvider.refresh();
}),
);
// Guideline
context.subscriptions.push(
vscode.commands.registerCommand(
"quack.createGuideline",
async (input?: string) => {
await createGuideline(input, context);
guidelineTreeProvider.refresh();
},
),
);
context.subscriptions.push(
vscode.commands.registerCommand("quack.listGuidelines", async () => {
await listGuidelines(context);
}),
);
context.subscriptions.push(
vscode.commands.registerCommand(
"quack.editGuideline",
async (index?: number, content?: string) => {
await editGuideline(index, content, context);
guidelineTreeProvider.refresh();
},
),
);
context.subscriptions.push(
vscode.commands.registerCommand("quack.editGuidelineItem", async (item) => {
const index = guidelineTreeProvider.getIndexOf(item);
await editGuideline(index, undefined, context);
guidelineTreeProvider.refresh();
}),
);
context.subscriptions.push(
vscode.commands.registerCommand(
"quack.deleteGuideline",
async (index?: number) => {
await deleteGuideline(index, context);
guidelineTreeProvider.refresh();
},
),
);
context.subscriptions.push(
vscode.commands.registerCommand(
"quack.deleteGuidelineItem",
async (item) => {
const index = guidelineTreeProvider.getIndexOf(item);
await deleteGuideline(index, context);
guidelineTreeProvider.refresh();
},
),
);
// Refresh UI
chatViewProvider.refresh();
guidelineTreeProvider.refresh();
// Safety checks
let config = vscode.workspace.getConfiguration("api");
// Endpoint
Expand Down
Loading

0 comments on commit e5835d3

Please sign in to comment.