Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
"command": "opencode.insertFileReference",
"title": "OpenCode: Insert File Reference"
},
{
"command": "opencode.addToThread",
"title": "OpenCode: Add to Thread"
},
{
"command": "opencode.installSkill",
"title": "OpenCode: Install Skill"
Expand Down Expand Up @@ -152,6 +156,16 @@
"command": "opencode.sendSelection",
"when": "editorHasSelection",
"group": "opencode"
},
{
"command": "opencode.addToThread",
"group": "opencode"
}
],
"explorer/context": [
{
"command": "opencode.addToThread",
"group": "opencode"
}
]
},
Expand Down
93 changes: 93 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import { StatusBarProvider } from "./providers/StatusBarProvider";
import { PlanViewProvider } from "./providers/PlanViewProvider";
import { DiffReviewProvider } from "./providers/DiffReviewProvider";
import { ConfigFilesProvider, type ConfigFile } from "./providers/ConfigFilesProvider";

Check warning on line 35 in src/extension.ts

View workflow job for this annotation

GitHub Actions / verify

'ConfigFile' is defined but never used
import { SkillManagementService } from "./services/SkillManagementService";
import { SkillsPanelProvider } from "./providers/SkillsPanelProvider";
import { createLogger, logger } from "./utils/Logger";
Expand Down Expand Up @@ -150,7 +150,7 @@
export async function activate(context: vscode.ExtensionContext) {
setupConsoleSuppression(context);

const activationStartTime = Date.now();

Check warning on line 153 in src/extension.ts

View workflow job for this annotation

GitHub Actions / verify

'activationStartTime' is assigned a value but never used
log.info("Extension activation started", {
version: context.extension.packageJSON.version,
extensionId: context.extension.id,
Expand Down Expand Up @@ -425,6 +425,99 @@
),
);

// ============================================================================
// COMMAND: opencode.addToThread
// ============================================================================
// Purpose: Add editor selection, whole file, or explorer file(s)/folder(s)
// to the active chat thread as context.
// Invocation contexts:
// - Editor right-click (with or without selection)
// - Explorer right-click on file(s) or folder(s)
// - Command palette
// Integration: Adds context via ChatViewProvider.addContext()
// ============================================================================
context.subscriptions.push(
vscode.commands.registerCommand(
"opencode.addToThread",
async (input?: vscode.Uri | vscode.Uri[]) => {
const uris = input
? Array.isArray(input)
? input
: [input]
: [];

if (uris.length === 0) {
const editor = vscode.window.activeTextEditor;
if (!editor) {
vscode.window.showWarningMessage("No active editor or file selected");
return;
}
const file = vscode.workspace.asRelativePath(editor.document.uri);
const selection = editor.document.getText(editor.selection);
if (selection && selection.trim().length > 0) {
const startLine = editor.selection.start.line + 1;
const endLine = editor.selection.end.line + 1;
const lineInfo =
startLine === endLine ? `${startLine}` : `${startLine}-${endLine}`;
await chatViewProvider.addContext({
file,
lineInfo,
content: selection,
languageId: editor.document.languageId,
});
} else {
await chatViewProvider.addContext({
file,
languageId: editor.document.languageId,
});
}
await vscode.commands.executeCommand("opencode.chatView.focus");
return;
}

const MAX_FILES = 50;
const collectedUris: vscode.Uri[] = [];
for (const uri of uris) {
try {
const stat = await vscode.workspace.fs.stat(uri);
if (stat.type === vscode.FileType.Directory) {
const relPattern = new vscode.RelativePattern(uri, "**/*");
const found = await vscode.workspace.findFiles(
relPattern,
"**/{node_modules,.git,dist,build,out,.next,.cache}/**",
MAX_FILES - collectedUris.length,
);
collectedUris.push(...found);
} else {
collectedUris.push(uri);
}
} catch {
collectedUris.push(uri);
}
if (collectedUris.length >= MAX_FILES) break;
}

if (collectedUris.length === 0) {
vscode.window.showWarningMessage("No files found to add");
return;
}

if (collectedUris.length > MAX_FILES) {
vscode.window.showWarningMessage(
`Too many files (${collectedUris.length}). Added first ${MAX_FILES}.`,
);
collectedUris.length = MAX_FILES;
}

for (const fileUri of collectedUris) {
const file = vscode.workspace.asRelativePath(fileUri);
await chatViewProvider.addContext({ file });
}
await vscode.commands.executeCommand("opencode.chatView.focus");
},
),
);

// ============================================================================
// COMMAND: opencode.showPlan
// ============================================================================
Expand Down
Loading
Loading