Skip to content

Commit

Permalink
Warn the user if they open a workspace with no root folder.
Browse files Browse the repository at this point in the history
Part of a fix for #361.
  • Loading branch information
desplesda committed Nov 14, 2023
1 parent f8f734a commit 205e32b
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion YarnSpinner.LanguageServer/src/Server/Workspace/Workspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public class Workspace : INotificationSender, IActionSource, IConfigurationSourc

public IWindowLanguageServer? Window => LanguageServer?.Window;

/// <summary>
/// Have we shown a warning about the workspace having no root folder?
/// (We only want to show it once.)
/// </summary>
private bool hasShownNullRootWarning = false;

/// <summary>
/// Gets the projects that include the file at <paramref name="uri"/>.
/// </summary>
Expand Down Expand Up @@ -102,7 +108,20 @@ internal void ReloadWorkspace()

var projects = new List<Project>();

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
Expand Down

0 comments on commit 205e32b

Please sign in to comment.