Skip to content

Commit c9494a4

Browse files
committed
Fix review comments
1 parent 9580a4c commit c9494a4

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/FolderContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ export class FolderContext implements vscode.Disposable {
288288

289289
/** Return `true` if package folder has a playground provider */
290290
hasPlaygroundProvider() {
291-
return this.testExplorer !== undefined;
291+
return this.playgroundProvider !== undefined;
292292
}
293293

294294
static uriName(uri: vscode.Uri): string {

src/playgrounds/LSPPlaygroundsDiscovery.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// SPDX-License-Identifier: Apache-2.0
1212
//
1313
//===----------------------------------------------------------------------===//
14+
import { FolderContext } from "../FolderContext";
1415
import { checkExperimentalCapability } from "../sourcekit-lsp/LanguageClientManager";
1516
import { LanguageClientManager } from "../sourcekit-lsp/LanguageClientManager";
1617
import { Playground, WorkspacePlaygroundsRequest } from "../sourcekit-lsp/extensions";
@@ -25,10 +26,12 @@ export { Playground };
2526
* these results.
2627
*/
2728
export class LSPPlaygroundsDiscovery {
28-
constructor(private languageClient: LanguageClientManager) {}
29+
private languageClient: LanguageClientManager;
30+
private toolchainVersion: Version;
2931

30-
private get toolchainVersion(): Version {
31-
return this.languageClient.folderContext.toolchain.swiftVersion;
32+
constructor(folderContext: FolderContext) {
33+
this.languageClient = folderContext.languageClientManager;
34+
this.toolchainVersion = folderContext.toolchain.swiftVersion;
3235
}
3336

3437
/**

src/playgrounds/PlaygroundProvider.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface PlaygroundChangeEvent {
3232
* these results.
3333
*/
3434
export class PlaygroundProvider implements vscode.Disposable {
35+
private hasFetched: boolean = false;
3536
private fetchPromise: Promise<Playground[]> | undefined;
3637
private documentPlaygrounds: Map<string, Playground[]> = new Map();
3738
private didChangePlaygroundsEmitter: vscode.EventEmitter<PlaygroundChangeEvent> =
@@ -40,7 +41,7 @@ export class PlaygroundProvider implements vscode.Disposable {
4041
constructor(private folderContext: FolderContext) {}
4142

4243
private get lspPlaygroundDiscovery(): LSPPlaygroundsDiscovery {
43-
return new LSPPlaygroundsDiscovery(this.folderContext.languageClientManager);
44+
return new LSPPlaygroundsDiscovery(this.folderContext);
4445
}
4546

4647
private get logger(): SwiftLogger {
@@ -79,6 +80,8 @@ export class PlaygroundProvider implements vscode.Disposable {
7980
async getWorkspacePlaygrounds(): Promise<Playground[]> {
8081
if (this.fetchPromise) {
8182
return await this.fetchPromise;
83+
} else if (!this.hasFetched) {
84+
await this.fetch();
8285
}
8386
return Array.from(this.documentPlaygrounds.values()).flatMap(v => v);
8487
}
@@ -112,6 +115,11 @@ export class PlaygroundProvider implements vscode.Disposable {
112115
this.didChangePlaygroundsEmitter.event;
113116

114117
async fetch() {
118+
this.hasFetched = true;
119+
if (this.fetchPromise) {
120+
await this.fetchPromise;
121+
return;
122+
}
115123
if (!(await this.lspPlaygroundDiscovery.supportsPlaygrounds())) {
116124
this.logger.debug(
117125
`Fetching playgrounds not supported by the language server`,

0 commit comments

Comments
 (0)