From 205e32b7fa2aa0f4cbae22110e6f0b283997030a Mon Sep 17 00:00:00 2001 From: Jon Manning Date: Tue, 14 Nov 2023 13:22:11 +1100 Subject: [PATCH] Warn the user if they open a workspace with no root folder. Part of a fix for #361. --- .../src/Server/Workspace/Workspace.cs | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/YarnSpinner.LanguageServer/src/Server/Workspace/Workspace.cs b/YarnSpinner.LanguageServer/src/Server/Workspace/Workspace.cs index 5a8f3f5e1..0ed7a856e 100644 --- a/YarnSpinner.LanguageServer/src/Server/Workspace/Workspace.cs +++ b/YarnSpinner.LanguageServer/src/Server/Workspace/Workspace.cs @@ -31,6 +31,12 @@ public class Workspace : INotificationSender, IActionSource, IConfigurationSourc public IWindowLanguageServer? Window => LanguageServer?.Window; + /// + /// Have we shown a warning about the workspace having no root folder? + /// (We only want to show it once.) + /// + private bool hasShownNullRootWarning = false; + /// /// Gets the projects that include the file at . /// @@ -102,7 +108,20 @@ internal void ReloadWorkspace() var projects = new List(); - if (this.Root != null) + if (this.Root == null) + { + // We don't have a root folder. The language server won't be + // able to find any additional resources, so we should warn the + // user about this. (This can happen when the user double-clicks + // on a file in Unity, which will open the file directly in VS + // Code without a root folder.) + if (hasShownNullRootWarning == false) + { + LanguageServer?.Window.ShowWarning($"This window does not have a folder to work in. Yarn Spinner features will not work as expected. [Open your project's folder](command:vscode.openFolder) for full feature support."); + hasShownNullRootWarning = true; + } + } + else { // Find all .yarnprojects in the root and create Projects out of // them