Add welcome.html for displaying when no Git repo is open

This commit adds a new welcome.html file to display a message to the
user when no Git repository is open. The message informs the user that
DevChat is designed for answering questions about Git repositories and
asks them to open a Git repository folder to start using DevChat.
This commit is contained in:
bobo.yang 2023-05-16 22:06:43 +08:00
parent 0b6d783fb1
commit 0742e54f98
5 changed files with 68 additions and 14 deletions

View File

@ -2,7 +2,7 @@
"name": "devchat",
"displayName": "DevChat",
"description": "Write prompts, not code",
"version": "0.0.33",
"version": "0.0.34",
"icon": "assets/devchat.png",
"publisher": "merico",
"engines": {

View File

@ -10,6 +10,22 @@ interface LoadHistoryMessages {
entries: Array<LogEntry>;
}
function welcomeMessage(): LogEntry {
// create default logEntry to show welcome message
return {
hash: 'message',
user: 'system',
date: '',
request: 'How to use DevChat?',
response: `
DevChat provides an editing operation method through problem driven development. You can start the journey of using DevChat from the following aspects.
1. Right click to select a file or a piece of code to add to DevChat and try asking AI about the file/code.
2. Use the+button in DevChat to select a git diff message and try using "/commit_message" command to generate a commit message.
`,
context: []
} as LogEntry;
}
regInMessage({command: 'historyMessages', options: { skip: 0, maxCount: 0 }});
regOutMessage({command: 'loadHistoryMessages', entries: [{hash: '',user: '',date: '',request: '',response: '',context: [{content: '',role: ''}]}]});
export async function historyMessages(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> {
@ -50,7 +66,7 @@ export async function historyMessages(message: any, panel: vscode.WebviewPanel|v
const loadHistoryMessages: LoadHistoryMessages = {
command: 'loadHistoryMessages',
entries: logEntriesFlat,
entries: logEntries.length>0? logEntriesFlat : [welcomeMessage()],
};
MessageHandler.sendMessage(panel, loadHistoryMessages);

View File

@ -1,13 +1,17 @@
import * as vscode from 'vscode';
import * as path from 'path';
import WebviewManager from './webviewManager';
import '../handler/loadHandlers';
import handleMessage from '../handler/messageHandler';
import { createChatDirectoryAndCopyInstructionsSync } from '../init/chatConfig';
import ExtensionContextHolder from '../util/extensionContext';
import CustomCommands from '../command/customCommand';
export class DevChatViewProvider implements vscode.WebviewViewProvider {
private _view?: vscode.WebviewView;
private _webviewManager: WebviewManager|undefined;
private _webviewManager: WebviewManager | undefined;
constructor(private readonly _context: vscode.ExtensionContext) {
// Subscribe to the onDidChangeWorkspaceFolders event
@ -17,13 +21,22 @@ export class DevChatViewProvider implements vscode.WebviewViewProvider {
public view() {
return this._view;
}
resolveWebviewView(webviewView: vscode.WebviewView, context: vscode.WebviewViewResolveContext, _token: vscode.CancellationToken): void {
this._view = webviewView;
this._webviewManager = new WebviewManager(webviewView.webview, this._context.extensionUri);
this.registerEventListeners();
// 创建 .chat 目录并复制 workflows
createChatDirectoryAndCopyInstructionsSync(ExtensionContextHolder.context?.extensionUri!);
const workspaceDir = vscode.workspace.workspaceFolders?.[0].uri.fsPath;
if (workspaceDir) {
const workflowsDir = path.join(workspaceDir!, '.chat', 'workflows');
CustomCommands.getInstance().parseCommands(workflowsDir);
}
this._view = webviewView;
this._webviewManager = new WebviewManager(webviewView.webview, this._context.extensionUri);
this.registerEventListeners();
}
private registerEventListeners() {
@ -41,9 +54,9 @@ export class DevChatViewProvider implements vscode.WebviewViewProvider {
private onDidChangeWorkspaceFolders(event: vscode.WorkspaceFoldersChangeEvent): void {
// Check if any folder was added or removed
if (event.added.length > 0 || event.removed.length > 0) {
// Update the webviewView content
vscode.window.showInformationMessage(`onDidChangeWorkspaceFolders`);
// this.updateWebviewContent();
// Update the webviewView content
vscode.window.showInformationMessage(`onDidChangeWorkspaceFolders`);
// this.updateWebviewContent();
}
}
@ -58,4 +71,4 @@ export class DevChatViewProvider implements vscode.WebviewViewProvider {
// }
// }
}
}

View File

@ -1 +1,21 @@
<p>You need open a folder before DevChat!</p>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome to DevChat</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
padding: 50px;
}
</style>
</head>
<body>
<h1>Welcome to DevChat</h1>
<p>DevChat is designed for prompts drive development about your Git repository.</p>
<p>Please open a Git repository folder to start using DevChat.</p>
</body>
</html>

View File

@ -159,6 +159,11 @@ const webviewConfig = {
filename: 'index.html',
chunks: ['index']
}),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'src', 'welcome.html'),
filename: 'welcome.html',
chunks: ['welcome']
}),
new CopyWebpackPlugin({
patterns: [
{ from: 'assets', to: 'assets' },