Merge pull request #25 from covespace/filter_invliad_editor

Filter invliad editor
This commit is contained in:
boob.yang 2023-05-08 12:17:12 +08:00 committed by GitHub
commit 736ede2114
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 56 additions and 56 deletions

View File

@ -1,12 +1,10 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import ChatContextManager from '../context/contextManager'; import ChatContextManager from '../context/contextManager';
import {messageHandler} from './messageHandler';
async function addConext(message: any, panel: vscode.WebviewPanel): Promise<void> { export async function addConext(message: any, panel: vscode.WebviewPanel): Promise<void> {
const contextStr = await ChatContextManager.getInstance().processText(message.selected); const contextStr = await ChatContextManager.getInstance().processText(message.selected);
panel.webview.postMessage({ command: 'appendContext', context: contextStr }); panel.webview.postMessage({ command: 'appendContext', context: contextStr });
return; return;
} }
messageHandler.registerHandler('addContext', addConext);

View File

@ -1,14 +1,15 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { messageHandler } from './messageHandler';
export async function applyCode(text: string) { export async function applyCode(text: string) {
if (vscode.window.visibleTextEditors.length > 1) { const validVisibleTextEditors = vscode.window.visibleTextEditors.filter(editor => editor.viewColumn !== undefined);
if (validVisibleTextEditors.length > 1) {
vscode.window.showErrorMessage(`There are more then one visible text editors. Please close all but one and try again.`); vscode.window.showErrorMessage(`There are more then one visible text editors. Please close all but one and try again.`);
return; return;
} }
const editor = vscode.window.visibleTextEditors[0]; const editor = validVisibleTextEditors[0];
if (!editor) { if (!editor) {
return; return;
} }
@ -23,10 +24,9 @@ export async function applyCode(text: string) {
} }
async function codeApply(message: any, panel: vscode.WebviewPanel): Promise<void> { export async function codeApply(message: any, panel: vscode.WebviewPanel): Promise<void> {
await applyCode(message.content); await applyCode(message.content);
return; return;
} }
messageHandler.registerHandler('code_apply', codeApply);

View File

@ -1,15 +1,15 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { messageHandler } from './messageHandler';
export async function applyCodeFile(text: string) { export async function applyCodeFile(text: string) {
if (vscode.window.visibleTextEditors.length > 1) { const validVisibleTextEditors = vscode.window.visibleTextEditors.filter(editor => editor.viewColumn !== undefined);
vscode.window.showErrorMessage(`There are more then one visible text editors. Please close all but one and try again.`);
if (validVisibleTextEditors.length > 1) {
vscode.window.showErrorMessage(`2There are more then one visible text editors. Please close all but one and try again.`);
return; return;
} }
const editor = vscode.window.visibleTextEditors[0]; const editor = validVisibleTextEditors[0];
if (!editor) { if (!editor) {
return; return;
} }
@ -25,9 +25,9 @@ export async function applyCodeFile(text: string) {
}); });
} }
async function codeFileApply(message: any, panel: vscode.WebviewPanel): Promise<void> { export async function codeFileApply(message: any, panel: vscode.WebviewPanel): Promise<void> {
await applyCodeFile(message.content); await applyCodeFile(message.content);
return; return;
} }
messageHandler.registerHandler('code_file_apply', codeFileApply);

View File

@ -1,12 +1,11 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import CommandManager from '../command/commandManager'; import CommandManager from '../command/commandManager';
import {messageHandler} from './messageHandler';
async function convertCommand(message: any, panel: vscode.WebviewPanel): Promise<void> { export async function convertCommand(message: any, panel: vscode.WebviewPanel): Promise<void> {
const newText = await CommandManager.getInstance().processText(message.text); const newText = await CommandManager.getInstance().processText(message.text);
panel.webview.postMessage({ command: 'convertCommand', result: newText }); panel.webview.postMessage({ command: 'convertCommand', result: newText });
return; return;
} }
messageHandler.registerHandler('convertCommand', convertCommand);

View File

@ -1,9 +1,8 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import DtmWrapper from '../toolwrapper/dtm'; import DtmWrapper from '../toolwrapper/dtm';
import {messageHandler} from './messageHandler';
async function doCommit(message: any, panel: vscode.WebviewPanel): Promise<void> { export async function doCommit(message: any, panel: vscode.WebviewPanel): Promise<void> {
const dtmWrapper = new DtmWrapper(); const dtmWrapper = new DtmWrapper();
const commitResult = await dtmWrapper.commit(message.content); const commitResult = await dtmWrapper.commit(message.content);
@ -15,5 +14,4 @@ async function doCommit(message: any, panel: vscode.WebviewPanel): Promise<void>
return; return;
} }
messageHandler.registerHandler('doCommit', doCommit);

View File

@ -1,9 +1,8 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import DevChat, { LogOptions } from '../toolwrapper/devchat'; import DevChat, { LogOptions } from '../toolwrapper/devchat';
import {messageHandler} from './messageHandler';
async function historyMessages(message: any, panel: vscode.WebviewPanel): Promise<void> { export async function historyMessages(message: any, panel: vscode.WebviewPanel): Promise<void> {
const devChat = new DevChat(); const devChat = new DevChat();
const logOptions: LogOptions = message.options || {}; const logOptions: LogOptions = message.options || {};
@ -12,5 +11,4 @@ async function historyMessages(message: any, panel: vscode.WebviewPanel): Promis
return; return;
} }
messageHandler.registerHandler('historyMessages', historyMessages);

View File

@ -1,10 +1,24 @@
import './addContext'; import { messageHandler } from './messageHandler';
import './codeApply'; import { codeApply } from './codeApply';
import './codeFileApply'; import { codeFileApply } from './codeFileApply';
import './convertCommand'; import { convertCommand } from './convertCommand';
import './doCommit'; import { doCommit } from './doCommit';
import './historyMessages'; import { historyMessages } from './historyMessages';
import './regCommandList'; import { regCommandList } from './regCommandList';
import './regContextList'; import { regContextList } from './regContextList';
import './sendMessage'; import { sendMessage } from './sendMessage';
import './showDiff'; import { blockApply } from './showDiff';
import { showDiff } from './showDiff';
import { addConext } from './addContext';
messageHandler.registerHandler('addContext', addConext);
messageHandler.registerHandler('code_apply', codeApply);
messageHandler.registerHandler('code_file_apply', codeFileApply);
messageHandler.registerHandler('convertCommand', convertCommand);
messageHandler.registerHandler('doCommit', doCommit);
messageHandler.registerHandler('historyMessages', historyMessages);
messageHandler.registerHandler('regCommandList', regCommandList);
messageHandler.registerHandler('regContextList', regContextList);
messageHandler.registerHandler('sendMessage', sendMessage);
messageHandler.registerHandler('block_apply', blockApply);
messageHandler.registerHandler('show_diff', showDiff);

View File

@ -1,13 +1,12 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import CommandManager from '../command/commandManager'; import CommandManager from '../command/commandManager';
import {messageHandler} from './messageHandler';
async function regCommandList(message: any, panel: vscode.WebviewPanel): Promise<void> { export async function regCommandList(message: any, panel: vscode.WebviewPanel): Promise<void> {
const commandList = CommandManager.getInstance().getCommandList(); const commandList = CommandManager.getInstance().getCommandList();
panel.webview.postMessage({ command: 'regCommandList', result: commandList }); panel.webview.postMessage({ command: 'regCommandList', result: commandList });
return; return;
} }
messageHandler.registerHandler('regCommandList', regCommandList);

View File

@ -1,12 +1,11 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import ChatContextManager from '../context/contextManager'; import ChatContextManager from '../context/contextManager';
import {messageHandler} from './messageHandler';
async function regContextList(message: any, panel: vscode.WebviewPanel): Promise<void> { export async function regContextList(message: any, panel: vscode.WebviewPanel): Promise<void> {
const contextList = ChatContextManager.getInstance().getContextList(); const contextList = ChatContextManager.getInstance().getContextList();
panel.webview.postMessage({ command: 'regContextList', result: contextList }); panel.webview.postMessage({ command: 'regContextList', result: contextList });
return; return;
} }
messageHandler.registerHandler('regContextList', regContextList);

View File

@ -4,7 +4,6 @@ import * as fs from 'fs';
import * as path from 'path'; import * as path from 'path';
import DevChat from '../toolwrapper/devchat'; import DevChat from '../toolwrapper/devchat';
import CommandManager from '../command/commandManager'; import CommandManager from '../command/commandManager';
import {messageHandler} from './messageHandler';
// Add this function to messageHandler.ts // Add this function to messageHandler.ts
@ -69,7 +68,7 @@ function getInstructionFiles(): string[] {
let lastPromptHash: string | undefined; let lastPromptHash: string | undefined;
async function sendMessage(message: any, panel: vscode.WebviewPanel): Promise<void> { export async function sendMessage(message: any, panel: vscode.WebviewPanel): Promise<void> {
const devChat = new DevChat(); const devChat = new DevChat();
const newText2 = await CommandManager.getInstance().processText(message.text); const newText2 = await CommandManager.getInstance().processText(message.text);
@ -104,5 +103,5 @@ async function sendMessage(message: any, panel: vscode.WebviewPanel): Promise<vo
return; return;
} }
messageHandler.registerHandler('sendMessage', sendMessage);

View File

@ -1,16 +1,17 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import {messageHandler} from './messageHandler';
import * as path from 'path'; import * as path from 'path';
import { createTempSubdirectory } from '../util/commonUtil'; import { createTempSubdirectory } from '../util/commonUtil';
export async function diffView(code: string) { export async function diffView(code: string) {
if (vscode.window.visibleTextEditors.length > 1) { const validVisibleTextEditors = vscode.window.visibleTextEditors.filter(editor => editor.viewColumn !== undefined);
if (validVisibleTextEditors.length > 1) {
vscode.window.showErrorMessage(`There are more then one visible text editors. Please close all but one and try again.`); vscode.window.showErrorMessage(`There are more then one visible text editors. Please close all but one and try again.`);
return; return;
} }
const editor = vscode.window.visibleTextEditors[0]; const editor = validVisibleTextEditors[0];
if (!editor) { if (!editor) {
return; return;
} }
@ -46,15 +47,14 @@ export async function diffView(code: string) {
} }
async function showDiff(message: any, panel: vscode.WebviewPanel): Promise<void> { export async function showDiff(message: any, panel: vscode.WebviewPanel): Promise<void> {
diffView(message.content); diffView(message.content);
return; return;
} }
async function blockApply(message: any, panel: vscode.WebviewPanel): Promise<void> { export async function blockApply(message: any, panel: vscode.WebviewPanel): Promise<void> {
diffView(message.content); diffView(message.content);
return; return;
} }
messageHandler.registerHandler('block_apply', blockApply);
messageHandler.registerHandler('show_diff', showDiff);

View File

@ -26,14 +26,10 @@ export default class ChatPanel {
// Create a new webview panel // Create a new webview panel
private static createWebviewPanel(extensionUri: vscode.Uri): vscode.WebviewPanel { private static createWebviewPanel(extensionUri: vscode.Uri): vscode.WebviewPanel {
const column = vscode.window.activeTextEditor
? vscode.window.activeTextEditor.viewColumn
: undefined;
return vscode.window.createWebviewPanel( return vscode.window.createWebviewPanel(
'chatPanel', 'chatPanel',
'Chat', 'Chat',
column || vscode.ViewColumn.One, vscode.ViewColumn.Beside,
{ {
enableScripts: true, enableScripts: true,
localResourceRoots: [vscode.Uri.joinPath(extensionUri, 'dist')], localResourceRoots: [vscode.Uri.joinPath(extensionUri, 'dist')],

View File

@ -108,10 +108,10 @@ class DevChat {
const devchatConfig = { const devchatConfig = {
model: openaiModel, model: openaiModel,
provider: llmModel, provider: llmModel,
"tokens-per-prompt": tokensPerPrompt,
OpenAI: { OpenAI: {
temperature: openaiTemperature, temperature: openaiTemperature,
stream: openaiStream, stream: openaiStream,
"tokens-per-prompt": tokensPerPrompt
} }
} }
// write to config file // write to config file