Skip to content

Commit 0bb7b95

Browse files
Simplify multi-root for now
1 parent 10c20af commit 0bb7b95

4 files changed

Lines changed: 16 additions & 64 deletions

File tree

.vscode-test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default defineConfig({
2828
"**/appDiscovery.js",
2929
"**/vscodeFileSystem.js",
3030
"**/telemetry/vscode.js",
31-
"**/webview/logs/webview.js",
31+
"**/cloud/ui/panel/webview.js",
3232
],
3333
reporter: ["text", "html", "json-summary"],
3434
output: "./coverage",

esbuild.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ async function main() {
5050

5151
const testEntryPoints = !production ? globSync("src/test/**/*.test.ts") : []
5252
const sourceEntryPoints = noBundleForCoverage
53-
? globSync("src/**/*.ts").filter(
54-
(f) => f !== "src/cloud/ui/panel/webview.ts",
55-
)
53+
? globSync("src/**/*.ts")
5654
: ["src/extension.ts"]
5755

5856
// Shared esbuild options

src/cloud/commands/logs.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { log } from "../../utils/logger"
33
import { trackCloudLogsOpened } from "../../utils/telemetry"
44
import { type ApiService, type AppLogEntry, StreamLogError } from "../api"
55
import type { ConfigService } from "../config"
6-
import { pickWorkspaceFolder } from "../ui/pickers"
76

87
const DEFAULT_TAIL = 100
98
export const LOGS_VIEW_ID = "fastapi-cloud-logs"
@@ -87,7 +86,7 @@ export function formatLogEntry(entry: AppLogEntry): string {
8786
function getLevelChipsHtml(): string {
8887
return FILTER_CHIPS.map(
8988
({ level, label }) =>
90-
` <div class="level-item" data-level="${level}"><span>${label}</span><span class="check">✓</span></div>`,
89+
`<div class="level-item" data-level="${level}"><span>${label}</span><span class="check">✓</span></div>`,
9190
).join("\n")
9291
}
9392

@@ -125,7 +124,7 @@ export function getWebviewHtml(
125124
<div class="filter-row">
126125
<label for="level-list">Log Level</label>
127126
<div class="level-list" id="level-list">
128-
${getLevelChipsHtml()}
127+
${getLevelChipsHtml()}
129128
</div>
130129
</div>
131130
<div class="filter-row">
@@ -146,8 +145,6 @@ ${getLevelChipsHtml()}
146145
</html>`
147146
}
148147

149-
// --- Provider ---
150-
151148
export class LogsViewProvider implements vscode.WebviewViewProvider {
152149
private view: vscode.WebviewView | undefined
153150
private activeAbortController: AbortController | undefined
@@ -211,20 +208,13 @@ export class LogsViewProvider implements vscode.WebviewViewProvider {
211208
if (config?.app_id) return activeFolder
212209
}
213210

214-
// Check which folders have linked configs
215-
const configuredUris: vscode.Uri[] = []
211+
// Active folder not linked — use the first configured folder
216212
for (const folder of workspaceFolders) {
217213
const config = await this.configService.getConfig(folder.uri)
218-
if (config?.app_id) configuredUris.push(folder.uri)
214+
if (config?.app_id) return folder.uri
219215
}
220216

221-
if (configuredUris.length === 0) return activeFolder
222-
if (configuredUris.length === 1) return configuredUris[0]
223-
224-
// Multiple linked folders — let the user pick
225-
return pickWorkspaceFolder("Select workspace to stream logs from", (uri) =>
226-
configuredUris.some((u) => u.toString() === uri.toString()),
227-
)
217+
return activeFolder
228218
}
229219

230220
async streamLogs(options?: { since?: string; tail?: number }): Promise<void> {

src/test/cloud/commands/logs.test.ts

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,6 @@ suite("cloud/commands/logs", () => {
8282
})
8383
})
8484

85-
suite("stopStreaming", () => {
86-
test("sends streamingState false", () => {
87-
const { provider } = createProvider()
88-
const { view, messages } = createWebviewView()
89-
90-
provider.resolveWebviewView(view)
91-
provider.stopStreaming()
92-
93-
const stateMsg = messages.find((m) => m.type === "streamingState")
94-
assert.ok(stateMsg)
95-
assert.strictEqual(stateMsg.streaming, false)
96-
})
97-
})
98-
9985
suite("streamLogs", () => {
10086
test("shows error when no workspace folder", async () => {
10187
const { provider } = createProvider(() => null)
@@ -153,7 +139,6 @@ suite("cloud/commands/logs", () => {
153139
assert.ok(logMessages[0].html.includes("line 1"))
154140
assert.ok(logMessages[1].html.includes("line 2"))
155141

156-
// Verify stream ended message
157142
const statusMessages = messages.filter((m) => m.type === "status")
158143
assert.ok(statusMessages.some((m) => m.text === "Stream ended."))
159144
})
@@ -346,7 +331,7 @@ suite("cloud/commands/logs", () => {
346331
assert.strictEqual(opts.appId, "a2")
347332
})
348333

349-
test("shows picker when multiple folders are configured", async () => {
334+
test("uses first configured folder when active folder is not linked", async () => {
350335
Object.defineProperty(vscode.workspace, "workspaceFolders", {
351336
value: [folder1, folder2, folder3],
352337
configurable: true,
@@ -358,7 +343,6 @@ suite("cloud/commands/logs", () => {
358343
const { view } = createWebviewView()
359344
provider.resolveWebviewView(view)
360345

361-
// Active folder has no config, workspace2 and workspace3 do
362346
configService.getConfig.withArgs(workspace1).resolves(null)
363347
configService.getConfig.withArgs(workspace2).resolves({
364348
app_id: "a2",
@@ -369,37 +353,23 @@ suite("cloud/commands/logs", () => {
369353
team_id: "t1",
370354
})
371355

372-
// User picks workspace3
373-
const quickPickStub = sinon
374-
.stub(vscode.window, "showQuickPick")
375-
.resolves({ label: "workspace3", uri: workspace3 } as any)
376-
377-
// After picker, configService.getConfig is called again for the selected folder
378-
configService.getConfig.withArgs(workspace3).resolves({
379-
app_id: "a3",
380-
team_id: "t1",
381-
})
382-
383356
async function* emptyStream() {}
384357
apiService.streamAppLogs.returns(emptyStream())
385358
sinon.stub(vscode.commands, "executeCommand").resolves()
386359

387360
await provider.streamLogs()
388361

389-
assert.ok(quickPickStub.calledOnce)
390362
const opts = apiService.streamAppLogs.firstCall.args[0]
391-
assert.strictEqual(opts.appId, "a3")
363+
assert.strictEqual(opts.appId, "a2")
392364
})
393365

394-
test("does not stream when user cancels picker", async () => {
366+
test("uses first configured folder when no active folder", async () => {
395367
Object.defineProperty(vscode.workspace, "workspaceFolders", {
396-
value: [folder1, folder2, folder3],
368+
value: [folder1, folder2],
397369
configurable: true,
398370
})
399371

400-
const { provider, configService, apiService } = createProvider(
401-
() => workspace1,
402-
)
372+
const { provider, configService, apiService } = createProvider(() => null)
403373
const { view } = createWebviewView()
404374
provider.resolveWebviewView(view)
405375

@@ -408,17 +378,15 @@ suite("cloud/commands/logs", () => {
408378
app_id: "a2",
409379
team_id: "t1",
410380
})
411-
configService.getConfig.withArgs(workspace3).resolves({
412-
app_id: "a3",
413-
team_id: "t1",
414-
})
415381

416-
sinon.stub(vscode.window, "showQuickPick").resolves(undefined)
382+
async function* emptyStream() {}
383+
apiService.streamAppLogs.returns(emptyStream())
417384
sinon.stub(vscode.commands, "executeCommand").resolves()
418385

419386
await provider.streamLogs()
420387

421-
assert.ok(!apiService.streamAppLogs.called)
388+
const opts = apiService.streamAppLogs.firstCall.args[0]
389+
assert.strictEqual(opts.appId, "a2")
422390
})
423391

424392
test("shows error when no folders have configs in multi-root", async () => {
@@ -453,7 +421,6 @@ suite("cloud/commands/logs", () => {
453421
provider.resolveWebviewView(view)
454422
configService.getConfig.resolves({ app_id: "a1", team_id: "t1" })
455423

456-
// Create a stream that blocks forever
457424
let abortSignal: AbortSignal | undefined
458425
async function* blockingStream() {
459426
abortSignal = apiService.streamAppLogs.firstCall.args[0].signal
@@ -462,17 +429,14 @@ suite("cloud/commands/logs", () => {
462429
message: "first",
463430
level: "info",
464431
}
465-
// Would block here, but dispose should abort
466432
await new Promise(() => {})
467433
}
468434
apiService.streamAppLogs.returns(blockingStream())
469435

470436
sinon.stub(vscode.commands, "executeCommand").resolves()
471437

472-
// Start streaming (don't await - it will block)
473438
void provider.streamLogs()
474439

475-
// Give the stream time to start
476440
await new Promise((r) => setTimeout(r, 10))
477441

478442
provider.dispose()

0 commit comments

Comments
 (0)