Skip to content

Commit

Permalink
Merge pull request #18 from whats2000/Feature/Insert-Patial-Code
Browse files Browse the repository at this point in the history
[Feature] The fuse pipeline for apply partial code different
  • Loading branch information
whats2000 authored Dec 8, 2024
2 parents 513bca4 + f9020ea commit 57fda2a
Show file tree
Hide file tree
Showing 35 changed files with 1,487 additions and 456 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## Overview

**Version**: 0.4.4
**Version**: 0.4.5

**Status**: _Under Development_
⚠️ This project is currently in the Beta phase. Some features are still being developed, and you may encounter bugs or
Expand Down
2 changes: 1 addition & 1 deletion VSCodeExtension/code-brt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Overview

**Version**: 0.4.4
**Version**: 0.4.5

**Status**: _Under Development_
⚠️ This project is currently in the Beta phase. Some features are still being developed, and you may encounter bugs or
Expand Down
470 changes: 262 additions & 208 deletions VSCodeExtension/code-brt/package-lock.json

Large diffs are not rendered by default.

67 changes: 53 additions & 14 deletions VSCodeExtension/code-brt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"displayName": "CodeBRT",
"description": "CodeBRT, a LLM/VLM framework for code assistant with multiple models.",
"version": "0.4.4",
"version": "0.4.5",
"icon": "static/icon.ico",
"engines": {
"vscode": "^1.95.0",
Expand Down Expand Up @@ -57,14 +57,14 @@
"@babel/core": "^7.26.0",
"@babel/preset-env": "^7.26.0",
"@babel/preset-typescript": "^7.26.0",
"@dnd-kit/core": "^6.2.0",
"@dnd-kit/sortable": "^9.0.0",
"@dnd-kit/core": "^6.3.1",
"@dnd-kit/sortable": "^10.0.0",
"@google/generative-ai": "^0.21.0",
"@huggingface/inference": "^2.8.1",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.15",
"@reduxjs/toolkit": "^2.4.0",
"@swc/cli": "^0.5.1",
"@swc/core": "^1.9.3",
"@swc/cli": "^0.5.2",
"@swc/core": "^1.10.0",
"@swc/jest": "^0.2.37",
"@types/async-lock": "^1.4.2",
"@types/cheerio": "^0.22.35",
Expand All @@ -79,37 +79,37 @@
"@types/uuid": "^10.0.0",
"@types/vscode": "^1.95.0",
"@vscode/vsce": "^3.2.1",
"antd": "^5.22.2",
"antd": "^5.22.3",
"async-lock": "^1.4.1",
"axios": "^1.7.8",
"axios": "^1.7.9",
"babel-jest": "^29.7.0",
"cheerio": "^1.0.0",
"cohere-ai": "^7.14.0",
"cohere-ai": "^7.15.0",
"copy-webpack-plugin": "^12.0.2",
"css-loader": "^7.1.2",
"date-fns": "^4.1.0",
"groq-sdk": "^0.8.0",
"groq-sdk": "^0.9.0",
"isbinaryfile": "^5.0.4",
"jest": "^29.7.0",
"mammoth": "^1.8.0",
"markdown-to-text": "^0.1.1",
"node-html-markdown": "^1.3.0",
"node-mic": "^1.0.1",
"null-loader": "^4.0.1",
"ollama": "^0.5.10",
"openai": "^4.73.1",
"ollama": "^0.5.11",
"openai": "^4.76.0",
"p-wait-for": "^5.0.2",
"pdf-parse": "^1.1.1",
"pdfjs-dist": "^4.9.124",
"prettier": "3.4.1",
"pdfjs-dist": "^4.9.155",
"prettier": "3.4.2",
"prettier-plugin-organize-imports": "^4.1.0",
"promise-deferred": "^2.0.4",
"rc-tween-one": "^3.0.6",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-markdown": "^9.0.1",
"react-redux": "^9.1.2",
"react-refresh": "^0.14.2",
"react-refresh": "^0.16.0",
"react-syntax-highlighter": "^15.6.1",
"react-virtuoso": "^4.12.3",
"rehype-katex": "^7.0.1",
Expand All @@ -135,15 +135,54 @@
"activationEvents": [],
"contributes": {
"commands": [
{
"command": "code-brt.codeBRTOptions",
"title": "CodeBRT"
},
{
"command": "code-brt.triggerInlineCompletion",
"title": "Trigger Inline Completion"
},
{
"command": "code-brt.openMainView",
"title": "Open CodeBRT Chat"
},
{
"command": "code-brt.sendCodeToChat",
"title": "Send Code to Chat"
}
],
"submenus": [
{
"id": "code-brt.codeBRTSubMenu",
"label": "CodeBRT"
}
],
"menus": {
"editor/context": [
{
"submenu": "code-brt.codeBRTSubMenu",
"group": "0_code-brt"
}
],
"code-brt.codeBRTSubMenu": [
{
"command": "code-brt.triggerInlineCompletion",
"group": "CodeBRT",
"when": "editorTextFocus"
},
{
"command": "code-brt.openMainView",
"group": "CodeBRT",
"when": "editorTextFocus"
},
{
"command": "code-brt.sendCodeToChat",
"group": "CodeBRT",
"when": "editorHasSelection"
}
]
},
"keybindings": [
{
"command": "code-brt.triggerInlineCompletion",
Expand Down
5 changes: 4 additions & 1 deletion VSCodeExtension/code-brt/src/api/historyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ export class HistoryManager implements IHistoryManager {
}

writeToFileCall.parameters.content = newContent;
writeToFileCall.parameters.isCodePartial = false;

// Update the path if it's a rename operation
if (activeOperation.newPath) {
Expand Down Expand Up @@ -507,6 +508,7 @@ export class HistoryManager implements IHistoryManager {
}

writeToFileCall.parameters.content = newContent;
writeToFileCall.parameters.isCodePartial = false;

processedFiles.add(relativePath);
}
Expand All @@ -527,7 +529,8 @@ export class HistoryManager implements IHistoryManager {
continue;
}

const relativePath = parentEntry.toolCalls[0]?.parameters.relativePath;
const relativePath =
parentEntry.toolCalls[0]?.parameters.relativeFilePath;
const activeOperation = operations.find(
(op) => op.relativePath === relativePath,
);
Expand Down
2 changes: 2 additions & 0 deletions VSCodeExtension/code-brt/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export * from './viewApi';
export * from './historyManager';
export * from './registerCodeActions';
export * from './registerDiff';
export * from './registerInlineCompletion';
export * from './registerView';
Expand Down
50 changes: 50 additions & 0 deletions VSCodeExtension/code-brt/src/api/registerCodeActions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import vscode from 'vscode';

import { triggerEvent } from './registerView';

export const registerCodeActions = () => {
vscode.languages.registerCodeActionsProvider('*', {
provideCodeActions(
_document: vscode.TextDocument,
_range: vscode.Range,
_context: vscode.CodeActionContext,
_token: vscode.CancellationToken,
): vscode.ProviderResult<(vscode.CodeAction | vscode.Command)[]> {
const sendCodeToChatAction = new vscode.CodeAction(
'Refers to CodeBRT Chat',
vscode.CodeActionKind.QuickFix,
);
sendCodeToChatAction.command = {
command: 'code-brt.sendCodeToChat',
title: 'Send code to chat',
};
sendCodeToChatAction.isPreferred = true;
return [sendCodeToChatAction];
},
});

vscode.commands.registerCommand('code-brt.sendCodeToChat', () => {
const editor = vscode.window.activeTextEditor;
if (!editor) {
return;
}
const document = editor.document;
const codeText = editor.document.getText(editor.selection);
// Because the line number is 0-based, we need to add 1 to the line number
const startLine = editor.selection.start.line + 1;
const endLine = editor.selection.end.line + 1;
const codeLanguage = document.languageId;
const relativePath = vscode.workspace.asRelativePath(document.fileName);

if (codeText) {
triggerEvent('sendCodeToChat', {
id: Date.now().toString(),
codeText,
startLine,
endLine,
codeLanguage,
relativePath,
});
}
});
};
20 changes: 19 additions & 1 deletion VSCodeExtension/code-brt/src/api/settingsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import {
export class SettingsManager implements ISettingsManager {
private static instance: SettingsManager;
private readonly context: vscode.ExtensionContext;
private workspaceConfig: vscode.WorkspaceConfiguration;
private readonly localSettings: ExtensionSettingsLocal;
private readonly isMissingWorkspace: boolean;
private workspaceConfig: vscode.WorkspaceConfiguration;

private constructor(context: vscode.ExtensionContext) {
this.context = context;
Expand All @@ -25,6 +26,7 @@ export class SettingsManager implements ISettingsManager {
DEFAULT_LOCAL_SETTINGS,
);
this.localSettings = { ...DEFAULT_LOCAL_SETTINGS, ...storedSettings };
this.isMissingWorkspace = !vscode.workspace.workspaceFolders;
this.workspaceConfig = vscode.workspace.getConfiguration('code-brt');

vscode.workspace.onDidChangeConfiguration(
Expand Down Expand Up @@ -109,6 +111,22 @@ export class SettingsManager implements ISettingsManager {
(this.localSettings as any)[setting] = value;
await this.saveLocalSettings();
} else if (setting in DEFAULT_WORKSPACE_SETTINGS) {
// Check if the workspace is available
if (this.isMissingWorkspace) {
vscode.window
.showWarningMessage(
'Seems like you do not have a workspace open. ' +
'Open a workspace to save workspace settings, use agent tools, and save conversation history.',
'Open Workspace',
)
.then((selection) => {
if (selection === 'Open Workspace') {
vscode.commands.executeCommand('vscode.openFolder');
}
});
return;
}

await this.workspaceConfig.update(
setting,
value,
Expand Down
1 change: 1 addition & 0 deletions VSCodeExtension/code-brt/src/api/viewApi/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './viewApiFactory';
3 changes: 3 additions & 0 deletions VSCodeExtension/code-brt/src/api/viewApi/miscApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import { triggerEvent } from '../registerView';
import { FileOperationsProvider } from '../../utils';
import { TerminalManager } from '../../integrations';
import path from 'path';
import type { PartialCodeFuser } from '../../services/partialCodeFuser';

export const createMiscApi = (
ctx: vscode.ExtensionContext,
terminalManager: TerminalManager,
partialCodeFuser: PartialCodeFuser,
connectedViews: Partial<Record<string, vscode.WebviewView>>,
): MiscApi => {
return {
Expand Down Expand Up @@ -75,6 +77,7 @@ export const createMiscApi = (
return await ToolServiceProvider.executeToolCall(
toolCall,
terminalManager,
partialCodeFuser,
(status) => {
triggerEvent('updateStatus', status);
},
Expand Down
26 changes: 26 additions & 0 deletions VSCodeExtension/code-brt/src/api/viewApi/types/viewApi.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { ModelServiceType, ToolCallResponse } from '../../../types';
import { SettingApi } from './settingApi';
import { LanguageModelServiceApi } from './languageModelServiceApi';
import { HistoryManagerApi } from './historyManagerApi';
import { VoiceServiceApi } from './voiceServiceApi';
import { MiscApi } from './miscApi';
import { codeText } from 'micromark-core-commonmark';

/**
* Represents the API request structure for the view.
Expand Down Expand Up @@ -71,6 +73,24 @@ export type ViewApi = SettingApi &
VoiceServiceApi &
MiscApi;

/**
* The structure of the selected code to send to chat.
* @property id - The ID of the selected code.
* @property codeText - The text of the selected code.
* @property startLine - The start line of the selected code.
* @property endLine - The end line of the selected code.
* @property codeLanguage - The language of the selected code.
* @property relativePath - The relative path of the selected code.
*/
export type SelectedCode = {
id: string;
codeText: string;
startLine: number;
endLine: number;
codeLanguage: string;
relativePath: string;
};

/**
* Defines the events that the view can trigger.
*/
Expand All @@ -86,4 +106,10 @@ export type ViewEvents = {
* @param status - The status to update.
*/
updateStatus: (status: string) => void;

/**
* Send code to chat view.
* @param selectedCode - The selected code to send to chat.
*/
sendCodeToChat: (selectedCode: SelectedCode) => void;
};
31 changes: 18 additions & 13 deletions VSCodeExtension/code-brt/src/api/viewApi/viewApiFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import vscode from 'vscode';
import type { ViewApi } from './types';
import type { LoadedModelServices } from '../../services/languageModel/types';
import type { LoadedVoiceServices } from '../../services/voice/types';
import type { PartialCodeFuser } from '../../services/partialCodeFuser';
import { SettingsManager } from '../settingsManager';
import { HistoryManager } from '../historyManager';
import { TerminalManager } from '../../integrations';
Expand All @@ -12,28 +13,32 @@ import { createMiscApi } from './miscApi';
import { createSettingApi } from './settingApi';
import { createVoiceServiceApi } from './voiceServiceApi';

export const createViewApi: (
ctx: vscode.ExtensionContext,
settingsManager: SettingsManager,
historyManager: HistoryManager,
terminalManager: TerminalManager,
models: LoadedModelServices,
loadedVoiceServices: LoadedVoiceServices,
connectedViews: Partial<Record<string, vscode.WebviewView>>,
) => ViewApi = (
type ViewApiFactoryParams = {
ctx: vscode.ExtensionContext;
settingsManager: SettingsManager;
historyManager: HistoryManager;
terminalManager: TerminalManager;
partialCodeFuser: PartialCodeFuser;
models: LoadedModelServices;
voiceServices: LoadedVoiceServices;
connectedViews: Partial<Record<string, vscode.WebviewView>>;
};

export const createViewApi: (options: ViewApiFactoryParams) => ViewApi = ({
ctx,
settingsManager,
historyManager,
terminalManager,
partialCodeFuser,
models,
loadedVoiceServices,
voiceServices,
connectedViews,
) => {
}): ViewApi => {
return {
...createHistoryManagerApi(historyManager),
...createLanguageModelServiceApi(models, historyManager, settingsManager),
...createMiscApi(ctx, terminalManager, connectedViews),
...createMiscApi(ctx, terminalManager, partialCodeFuser, connectedViews),
...createSettingApi(settingsManager),
...createVoiceServiceApi(settingsManager, loadedVoiceServices),
...createVoiceServiceApi(settingsManager, voiceServices),
};
};
Loading

0 comments on commit 57fda2a

Please sign in to comment.