@@ -15,6 +15,7 @@ import * as vscode from "vscode";
1515
1616import { FolderContext } from "../FolderContext" ;
1717import { FolderOperation , WorkspaceContext } from "../WorkspaceContext" ;
18+ import { SwiftLogger } from "../logging/SwiftLogger" ;
1819import { LSPPlaygroundsDiscovery , Playground } from "./LSPPlaygroundsDiscovery" ;
1920
2021export { Playground } ;
@@ -42,6 +43,10 @@ export class PlaygroundProvider implements vscode.Disposable {
4243 return new LSPPlaygroundsDiscovery ( this . folderContext . languageClientManager ) ;
4344 }
4445
46+ private get logger ( ) : SwiftLogger {
47+ return this . folderContext . workspaceContext . logger ;
48+ }
49+
4550 /**
4651 * Create folder observer that creates a PlaygroundProvider when a folder is added and
4752 * discovers available playgrounds when the folder is in focus
@@ -107,14 +112,28 @@ export class PlaygroundProvider implements vscode.Disposable {
107112 this . didChangePlaygroundsEmitter . event ;
108113
109114 async fetch ( ) {
115+ if ( ! ( await this . lspPlaygroundDiscovery . supportsPlaygrounds ( ) ) ) {
116+ this . logger . debug (
117+ `Fetching playgrounds not supported by the language server` ,
118+ this . folderContext . name
119+ ) ;
120+ return ;
121+ }
110122 this . fetchPromise = this . lspPlaygroundDiscovery . getWorkspacePlaygrounds ( ) ;
111- const playgrounds = await this . fetchPromise ;
112- this . documentPlaygrounds . clear ( ) ;
113- for ( const playground of playgrounds ) {
114- const uri = playground . location . uri ;
115- this . documentPlaygrounds . set (
116- uri ,
117- ( this . documentPlaygrounds . get ( uri ) ?? [ ] ) . concat ( playground )
123+ try {
124+ const playgrounds = await this . fetchPromise ;
125+ this . documentPlaygrounds . clear ( ) ;
126+ for ( const playground of playgrounds ) {
127+ const uri = playground . location . uri ;
128+ this . documentPlaygrounds . set (
129+ uri ,
130+ ( this . documentPlaygrounds . get ( uri ) ?? [ ] ) . concat ( playground )
131+ ) ;
132+ }
133+ } catch ( error ) {
134+ this . logger . error (
135+ `Failed to fetch workspace playgrounds: ${ error } ` ,
136+ this . folderContext . name
118137 ) ;
119138 }
120139 this . fetchPromise = undefined ;
0 commit comments