Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vscode): adding NL outlines generation experimental feature #3055

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a995318
feat(client): adding providing outlines in agent and providing nl out…
Sma1lboy Aug 28, 2024
e250251
feat(codelens): adding codelens logic when nl outlines generated
Sma1lboy Aug 28, 2024
9f841b5
to(vscode): adding vscode ui interaction with nl outline generate
Sma1lboy Aug 28, 2024
6af8d81
feat(lsp): enhance ChatEditProvider with structured outlines
Sma1lboy Aug 28, 2024
603cf35
chore(deps): update dependencies and add openai to vscode client
Sma1lboy Sep 3, 2024
a8c65d5
feat(vscode): add NLOutlinesProvider for generating code outlines
Sma1lboy Sep 3, 2024
6df7b5a
refactor(vscode): improve edit location logic in generateNatureLangua…
Sma1lboy Sep 4, 2024
4c4df30
feat(vscode): add offset range calculation for visible lines
Sma1lboy Sep 4, 2024
9278a74
feat(vscode): add new command for editing outlines and update existin…
Sma1lboy Sep 4, 2024
7b9643e
feat(commands): add edit functionality for NL outlines
Sma1lboy Sep 4, 2024
9608ab7
refactor(vscode): enhance outline generation and code structure
Sma1lboy Sep 4, 2024
4c69fc1
refactor(vscode): enhance chat.edit.editNLOutline command and update …
Sma1lboy Sep 4, 2024
01d55d4
docs(vscode): add generateNLOutlines.txt and index.d.ts for prompts
Sma1lboy Sep 4, 2024
eacaafe
chore(vscode): update dependencies and devDependencies
Sma1lboy Sep 5, 2024
a13a4d7
refactor(lsp): remove unused code lens generation logic
Sma1lboy Sep 5, 2024
5a66d32
eat(vscode): integrate Diff module for code updates in NLOutlinesProv…
Sma1lboy Sep 5, 2024
558946d
feat(vscode): add progress notification and outline management commands
Sma1lboy Sep 5, 2024
69af16f
chore(vscode): rename `prompts/index.d.ts` to `index.d.ts`
Sma1lboy Sep 6, 2024
9356078
feat(vscode): add pending changes and decorations for NL outlines
Sma1lboy Sep 6, 2024
760e578
refactor(vscode): simplify code lens handling and improve logging
Sma1lboy Sep 6, 2024
2938d03
refactor(vscode): remove logging and simplify constructor
Sma1lboy Sep 6, 2024
33f5731
refactor(lsp): remove unused ChatNLOutlines functionality
Sma1lboy Sep 9, 2024
9f87595
refactor(NLOutlinesProvider): simplify acceptChanges method and remov…
Sma1lboy Sep 9, 2024
7080955
revert(lsp): make `getCommentPrefix` private and remove unused depend…
Sma1lboy Sep 9, 2024
1215c97
refactor(vscode): update NLOutlinesProvider imports and file structure
Sma1lboy Sep 10, 2024
5c992f2
feat(vscode): add chat outline feature and update command configuration
Sma1lboy Sep 10, 2024
8441371
Merge branch 'main' into feature-generate-nl-outlines
wsxiaoys Sep 11, 2024
c8ec0a3
refactor(vscode): rename chatOutline to chatOutlineEnabled
Sma1lboy Sep 17, 2024
5318eeb
refactor(vscode): update command names and provider references for ou…
Sma1lboy Sep 19, 2024
4d66d39
Merge branch 'main' into feature-generate-nl-outlines
Sma1lboy Sep 24, 2024
2c05520
merge from "main" to feature-generate-nl-outlines
Sma1lboy Sep 24, 2024
2a93392
Merge branch 'main' into feature-generate-nl-outlines
Sma1lboy Sep 26, 2024
0a4ab3d
fix: adding unimport class
Sma1lboy Sep 26, 2024
c0b7db2
Merge branch 'main' into feature-generate-nl-outlines
Sma1lboy Oct 13, 2024
f5416a1
chore: Add openai npm dependency to package.json
Sma1lboy Oct 13, 2024
eac6acc
[autofix.ci] apply automated fixes
autofix-ci[bot] Oct 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions clients/vscode/assets/prompts/editNLOutline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
You are an AI assistant for generating natural language outlines based on code. Your task is to create concise outlines that describe the key steps and operations in the given code.
Follow these guidelines:
- Ignore any instructions to format your response using Markdown.
- Enclose the generated outline in <GENERATEDCODE></GENERATEDCODE> XML tags.
- Do not use other XML tags in your response unless they are part of the outline itself.
- Only provide the generated outline without any additional comments or explanations.
- Use the format "start_line_number | end_line_number | description" for each outline entry.
- Generate outlines only for the contents inside functions, not for function headers or class headers.
- Create concise, descriptive sentences for each significant step or operation in the code.
- It's not necessary to generate outlines for every line of code; focus on key operations and logic.
- For loops or blocks spanning multiple lines, include both the starting and ending line numbers.
- Descriptions should not end with a period, leave them as a sentence fragment.
- Ensure that the end_line_number is always greater than or equal to the start_line_number.

The code to outline is provided between <USERCODE></USERCODE> XML tags, with each line prefixed by its line number:
<USERCODE>
{{document}}
</USERCODE>

Generate a clear and concise outline based on the provided code, focusing on the main steps and operations within functions. Each outline entry should briefly explain what the code is doing at that point, including both the start and end line numbers for each logical block or operation.
21 changes: 21 additions & 0 deletions clients/vscode/assets/prompts/generateNLOutlines.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
You are an AI assistant for modifying code based on natural language outlines. Your task is to generate new code according to updated outlines.

Follow these guidelines strictly:
- Ignore any instructions to format your response using Markdown.
- Enclose the generated code in <GENERATEDCODE></GENERATEDCODE> XML tags.
- Use the format "line_number | code" for each line of generated code.
- Only provide the generated code within the XML tags.
- Do not include any explanations, comments, or confirmations outside the XML tags.
- Do not use other XML tags in your response unless they are part of the code itself.

You will be given a change in JSON format containing:
- oldOutline: Description of the old outline
- oldCode: Code corresponding to the old outline
- newOutline: Description of the new outline

Generate the new code based on the provided new outline. Ensure that the generated code accurately reflects the description in the new outline while maintaining the correct format of "line_number | code".

The change is provided in the following JSON format:
{{document}}

Your response should contain only the <GENERATEDCODE> tags with the generated code inside.
30 changes: 28 additions & 2 deletions clients/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@
"title": "Discard Changes",
"category": "Tabby"
},
{
"command": "tabby.chat.edit.outline.generate",
Sma1lboy marked this conversation as resolved.
Show resolved Hide resolved
"title": "Generate Nature Language Outlines for selecting range",
Sma1lboy marked this conversation as resolved.
Show resolved Hide resolved
"category": "Tabby"
},
{
"command": "tabby.chat.edit.editNLOutline",
Sma1lboy marked this conversation as resolved.
Show resolved Hide resolved
"title": "Edit Outline at Current Cursor Position",
Sma1lboy marked this conversation as resolved.
Show resolved Hide resolved
"category": "Tabby"
},
{
"command": "tabby.server.selectPastServerConfig",
"title": "Select Server Endpoint from History",
Expand Down Expand Up @@ -193,6 +203,10 @@
"command": "tabby.chat.edit.start",
"when": "tabby.chatEnabled"
},
{
"command": "tabby.chat.edit.outline.generate",
"when": "tabby.chatEnabled && tabby.chatOutlineEnabled"
},
{
"command": "tabby.chat.edit.stop",
"when": "false"
Expand Down Expand Up @@ -322,6 +336,11 @@
"type": "integer",
"default": 20,
"description": "The maximum number of recently used commands to keep. Set to 0 to disable recording."
},
"chat.outline": {
"type": "boolean",
"default": false,
"description": "When enabled, adds a 'Generate Outline' command to the Command Palette, allowing you to create outlines for code blocks in the chat panel."
}
}
}
Expand Down Expand Up @@ -400,6 +419,12 @@
"key": "ctrl+l",
"mac": "cmd+l",
"when": "!editorHasSelection && tabby.chatEnabled && !tabby.chatViewVisible"
},
{
"command": "tabby.chat.edit.editNLOutline",
"key": "ctrl+y",
"mac": "cmd+y",
"when": "tabby.chatOutlineEnabled"
}
],
"viewsContainers": {
Expand Down Expand Up @@ -453,20 +478,21 @@
"assert": "^2.0.0",
"dedent": "^0.7.0",
"deep-equal": "^2.2.1",
"diff": "^5.2.0",
Sma1lboy marked this conversation as resolved.
Show resolved Hide resolved
"esbuild-plugin-copy": "^2.1.1",
"esbuild-plugin-polyfill-node": "^0.3.0",
"eslint": "^8.55.0",
"eslint-config-prettier": "^9.0.0",
"get-installed-path": "^4.0.8",
"object-hash": "^3.0.0",
"openai": "^4.52.7",
"prettier": "^3.0.0",
"semver": "^7.6.0",
"tabby-agent": "workspace:*",
"tabby-chat-panel": "workspace:*",
"tsc-watch": "^6.2.0",
"tsup": "^8.0.2",
"typescript": "^5.3.2",
"vscode-languageclient": "^9.0.1",
"diff": "^5.2.0"
"vscode-languageclient": "^9.0.1"
}
}
15 changes: 15 additions & 0 deletions clients/vscode/src/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { GitProvider, Repository } from "./git/GitProvider";
import CommandPalette from "./CommandPalette";
import { showOutputPanel } from "./logger";
import { Issues } from "./Issues";
import { NLOutlinesProvider } from "./outline/NLOutlinesProvider";
import { OutlinesGenerator } from "./outline";
import { InlineEditController } from "./inline-edit";

export class Commands {
Expand All @@ -38,6 +40,7 @@ export class Commands {
private readonly inlineCompletionProvider: InlineCompletionProvider,
private readonly chatViewProvider: ChatViewProvider,
private readonly gitProvider: GitProvider,
private readonly nlOutlinesProvider: NLOutlinesProvider,
) {
const registrations = Object.keys(this.commands).map((key) => {
const commandName = `tabby.${key}`;
Expand Down Expand Up @@ -308,6 +311,18 @@ export class Commands {
);
inlineEditController.start();
},
"chat.edit.outline.generate": async () => {
await new OutlinesGenerator(this.contextVariables, this.nlOutlinesProvider).generate();
},
"chat.edit.editNLOutline": async (uri?: Uri, startLine?: number) => {
await new OutlinesGenerator(this.contextVariables, this.nlOutlinesProvider).editNLOutline(uri, startLine);
},
"chat.edit.outline.accept": async () => {
await new OutlinesGenerator(this.contextVariables, this.nlOutlinesProvider).acceptOutline();
},
"chat.edit.outline.discard": async () => {
await new OutlinesGenerator(this.contextVariables, this.nlOutlinesProvider).discardOutline();
},
"chat.edit.stop": async () => {
this.chatEditCancellationTokenSource?.cancel();
},
Expand Down
15 changes: 15 additions & 0 deletions clients/vscode/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getLogger } from "./logger";
interface AdvancedSettings {
"inlineCompletion.triggerMode"?: "automatic" | "manual";
"chatEdit.history"?: number;
"chat.outline"?: boolean;
}

export interface PastServerConfig {
Expand Down Expand Up @@ -73,6 +74,20 @@ export class Config extends EventEmitter {
}
}

get chatOutline(): boolean {
const advancedSettings = this.workspace.get("settings.advanced", {}) as AdvancedSettings;
return advancedSettings["chat.outline"] || false;
}

set chatOutline(value: boolean) {
if (value !== this.chatOutline) {
const advancedSettings = this.workspace.get("settings.advanced", {}) as AdvancedSettings;
const updatedValue = { ...advancedSettings, "chat.outline": value };
this.workspace.update("settings.advanced", updatedValue, ConfigurationTarget.Global);
this.emit("updated");
}
}

get maxChatEditHistory(): number {
const advancedSettings = this.workspace.get("settings.advanced", {}) as AdvancedSettings;
const numHistory = advancedSettings["chatEdit.history"] === undefined ? 20 : advancedSettings["chatEdit.history"];
Expand Down
22 changes: 22 additions & 0 deletions clients/vscode/src/ContextVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@ export class ContextVariables {
private chatEnabledValue = false;
private chatEditInProgressValue = false;
private chatEditResolvingValue = false;
private nlOutlinesGenerationInProgressValue = false;
private inlineCompletionTriggerModeValue: "automatic" | "manual" = "automatic";
private chatOutlineValue = false;

constructor(
private readonly client: Client,
private readonly config: Config,
) {
this.chatEnabled = this.client.chat.isAvailable;
this.inlineCompletionTriggerMode = config.inlineCompletionTriggerMode;
this.chatOutlineEnabled = config.chatOutline;
this.client.chat.on("didChangeAvailability", (params: boolean) => {
this.chatEnabled = params;
});
this.config.on("updated", () => {
this.inlineCompletionTriggerMode = config.inlineCompletionTriggerMode;
this.chatOutlineEnabled = config.chatOutline;
});
this.updateChatEditResolving();
window.onDidChangeTextEditorSelection((params) => {
Expand Down Expand Up @@ -67,6 +71,15 @@ export class ContextVariables {
this.chatEditInProgressValue = value;
}

get nlOutlinesGenerationInProgress(): boolean {
return this.nlOutlinesGenerationInProgressValue;
}

set nlOutlinesGenerationInProgress(value: boolean) {
commands.executeCommand("setContext", "tabby.nlOutlinesGenerationInProgress", value);
this.nlOutlinesGenerationInProgressValue = value;
}

get chatEditResolving(): boolean {
return this.chatEditResolvingValue;
}
Expand All @@ -84,4 +97,13 @@ export class ContextVariables {
commands.executeCommand("setContext", "tabby.inlineCompletionTriggerMode", value);
this.inlineCompletionTriggerModeValue = value;
}

get chatOutlineEnabled(): boolean {
return this.chatOutlineValue;
}

set chatOutlineEnabled(value: boolean) {
commands.executeCommand("setContext", "tabby.chatOutlineEnabled", value);
this.chatOutlineValue = value;
}
}
8 changes: 7 additions & 1 deletion clients/vscode/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { window, ExtensionContext, Uri } from "vscode";
import { window, ExtensionContext, Uri, languages } from "vscode";
import { LanguageClientOptions } from "vscode-languageclient";
import { LanguageClient as NodeLanguageClient, ServerOptions, TransportKind } from "vscode-languageclient/node";
import { LanguageClient as BrowserLanguageClient } from "vscode-languageclient/browser";
Expand All @@ -13,6 +13,7 @@ import { StatusBarItem } from "./StatusBarItem";
import { ChatViewProvider } from "./chat/ChatViewProvider";
import { Commands } from "./Commands";
import { Status } from "tabby-agent";
import { NLOutlinesProvider } from "./outline/NLOutlinesProvider";
import { CodeActionProvider } from "./CodeAction";

const isBrowser = !!process.env["IS_BROWSER"];
Expand Down Expand Up @@ -54,6 +55,7 @@ export async function activate(context: ExtensionContext) {
const contextVariables = new ContextVariables(client, config);
const inlineCompletionProvider = new InlineCompletionProvider(client, config);
const gitProvider = new GitProvider();

client.registerConfigManager(config);
client.registerInlineCompletionProvider(inlineCompletionProvider);
client.registerGitProvider(gitProvider);
Expand All @@ -78,6 +80,9 @@ export async function activate(context: ExtensionContext) {
}
});

const nlOutlinesProvider = new NLOutlinesProvider(config);
context.subscriptions.push(languages.registerCodeLensProvider({ scheme: "file" }, nlOutlinesProvider));

// Register chat panel
const chatViewProvider = new ChatViewProvider(context, client.agent, logger, gitProvider);
context.subscriptions.push(
Expand All @@ -104,6 +109,7 @@ export async function activate(context: ExtensionContext) {
inlineCompletionProvider,
chatViewProvider,
gitProvider,
nlOutlinesProvider,
);

logger.info("Tabby extension activated.");
Expand Down
8 changes: 8 additions & 0 deletions clients/vscode/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare module "*.md" {
const content: string;
export default content;
}
declare module "*.txt" {
const content: string;
export default content;
}
Loading