Skip to content

Commit 69e34b9

Browse files
committed
feat: add show logs command
1 parent f9da919 commit 69e34b9

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
"command": "coderWorkspaces.rebuildWorkspace",
5555
"when": "view == coderWorkspaces"
5656
},
57+
{
58+
"command": "coderWorkspaces.showWorkspaceLogs",
59+
"when": "view == coderWorkspaces"
60+
},
5761
{
5862
"command": "coderWorkspaces.shutdownWorkspace",
5963
"group": "inline",
@@ -98,6 +102,10 @@
98102
"dark": "media/dark/refresh.svg"
99103
}
100104
},
105+
{
106+
"command": "coderWorkspaces.showWorkspaceLogs",
107+
"title": "Show Logs"
108+
},
101109
{
102110
"command": "coderWorkspaces.shutdownWorkspace",
103111
"title": "Shutdown",

src/extension.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ import {
1111
openWorkspace,
1212
shutdownWorkspace,
1313
} from "./workspaces"
14+
import { coderWorkspaceLogsDocumentProvider, handleShowLogsCommand } from "./logs"
1415

1516
export function activate(context: vscode.ExtensionContext) {
1617
preflightCheckCoderInstalled()
1718
const workspaceProvider = new CoderWorkspacesProvider()
19+
20+
vscode.commands.registerCommand("coderWorkspaces.showWorkspaceLogs", handleShowLogsCommand)
1821
vscode.window.registerTreeDataProvider("coderWorkspaces", workspaceProvider)
1922
vscode.window.registerTreeDataProvider("coderHelpFeedback", new CoderHelpProvider())
2023
vscode.commands.registerCommand("coderWorkspaces.openWorkspace", (ws: CoderWorkspace) => {
@@ -33,6 +36,8 @@ export function activate(context: vscode.ExtensionContext) {
3336
vscode.commands.registerCommand("coderWorkspaces.refreshWorkspaces", () => {
3437
workspaceProvider.refresh()
3538
})
39+
40+
vscode.workspace.registerTextDocumentContentProvider("coder", coderWorkspaceLogsDocumentProvider)
3641
}
3742

3843
const preflightCheckCoderInstalled = () => {

src/logs.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as vscode from "vscode"
2+
import * as cp from "child_process"
3+
import { CoderWorkspace } from "./workspaces"
4+
5+
export const handleShowLogsCommand = async ({ workspace }: { workspace: CoderWorkspace }) => {
6+
const uri = vscode.Uri.parse("coder:" + workspace.name)
7+
const doc = await vscode.workspace.openTextDocument(uri)
8+
await vscode.window.showTextDocument(doc, { preview: false })
9+
}
10+
11+
export const coderWorkspaceLogsDocumentProvider = new (class implements vscode.TextDocumentContentProvider {
12+
provideTextDocumentContent(uri: vscode.Uri): string {
13+
// TODO: add a --no-follow flag for cases where a build is in-progress
14+
const output = cp.execSync(`coder envs watch-build ${uri.fsPath}`)
15+
return output.toString("utf-8")
16+
}
17+
})()

0 commit comments

Comments
 (0)