Skip to content

fix: open from sidebar with agent #99

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

Merged
merged 1 commit into from
May 10, 2023
Merged
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
17 changes: 12 additions & 5 deletions src/workspacesProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export class WorkspaceProvider implements vscode.TreeDataProvider<vscode.TreeIte
if (element) {
if (element instanceof WorkspaceTreeItem) {
const agents = extractAgents(element.workspace)
const agentTreeItems = agents.map((agent) => new AgentTreeItem(agent, element.watchMetadata))
const agentTreeItems = agents.map(
(agent) => new AgentTreeItem(agent, element.workspaceOwner, element.workspaceName, element.watchMetadata),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just pass element directly into the AgentTreeItem?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, you could instantiate an agentTreeItem without a WorkspaceTreeItem, but it doesn't matter in practice. Thank you for the suggestion I will squeeze this in later :)

)
return Promise.resolve(agentTreeItems)
} else if (element instanceof AgentTreeItem) {
const savedMetadata = this.agentMetadata[element.agent.id] || []
Expand Down Expand Up @@ -138,15 +140,20 @@ export class OpenableTreeItem extends vscode.TreeItem {
}

class AgentTreeItem extends OpenableTreeItem {
constructor(public readonly agent: WorkspaceAgent, watchMetadata = false) {
constructor(
public readonly agent: WorkspaceAgent,
workspaceOwner: string,
workspaceName: string,
watchMetadata = false,
) {
const label = agent.name
const detail = `Status: ${agent.status}`
super(
label,
detail,
watchMetadata ? vscode.TreeItemCollapsibleState.Collapsed : vscode.TreeItemCollapsibleState.None,
"",
"",
workspaceOwner,
workspaceName,
agent.name,
agent.expanded_directory,
"coderAgent",
Expand Down Expand Up @@ -174,7 +181,7 @@ export class WorkspaceTreeItem extends OpenableTreeItem {
workspace.name,
undefined,
agents[0]?.expanded_directory,
"coderWorkspaceMultipleAgents",
agents.length > 1 ? "coderWorkspaceMultipleAgents" : "coderWorkspaceSingleAgent",
)
}
}