Skip to content

Commit

Permalink
Add an LSP command for getting all known projects in the workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
desplesda committed Mar 31, 2024
1 parent 337ca2d commit 8897f0f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
18 changes: 18 additions & 0 deletions YarnSpinner.LanguageServer.Tests/CommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,22 @@ public async Task Server_OnCompilingProject_GetsResult()
result.Errors.Should().BeEmpty();
result.Data.Should().NotBeEmpty();
}

[Fact]
public async Task Server_CanListProjects()
{
// Set up the server
var (client, server) = await Initialize(ConfigureClient, ConfigureServer);

var result = await client.ExecuteCommand(new ExecuteCommandParams<Container<ProjectInfo>>
{
Command = Commands.ListProjects,
Arguments = new JArray { }
});
result.Should().NotBeNullOrEmpty("because the workspace contains projects");

result.Should().ContainSingle(p => p.Uri!.Path.EndsWith("Project1.yarnproject"));
result.Should().ContainSingle(p => p.Uri!.Path.EndsWith("Project2.yarnproject"));
}

}
5 changes: 5 additions & 0 deletions YarnSpinner.LanguageServer/src/Server/Commands/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,9 @@ public static class Commands
/// The command to show a specific Yarn node in a graph view.
/// </summary>
public const string ShowNodeInGraphView = "yarn.showNodeInGraphView";

/// <summary>
/// The command to get all projects in the current workspace.
/// </summary>
public const string ListProjects = "yarnspinner.listProjects";
}
7 changes: 7 additions & 0 deletions YarnSpinner.LanguageServer/src/Server/Workspace/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@

namespace YarnLanguageServer
{
public record ProjectInfo
{
public DocumentUri? Uri { get; set; }
public IEnumerable<DocumentUri> Files { get; set; } = Array.Empty<DocumentUri>();
public bool IsImplicitProject { get; set; }
}

internal class Project
{
public IEnumerable<YarnFileData> Files => yarnFiles.Values;
Expand Down
19 changes: 19 additions & 0 deletions YarnSpinner.LanguageServer/src/Server/YarnLanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ public static LanguageServerOptions ConfigureOptions(LanguageServerOptions optio
}
);

// Register List Projects command
options.OnExecuteCommand<Container<ProjectInfo>>(
(commandParams) => ListProjects(workspace, commandParams), (_,_) => new ExecuteCommandRegistrationOptions
{
Commands = new[] { Commands.ListProjects },
}
);

return options;
}

Expand Down Expand Up @@ -706,5 +714,16 @@ private static Task<VOStringExport> ExtractVoiceoverSpreadsheet(Workspace worksp
};
return Task.FromResult(output);
}

private static Task<Container<ProjectInfo>> ListProjects(Workspace workspace, ExecuteCommandParams<Container<ProjectInfo>> commandParams)
{
var info = workspace.Projects.Select(p => new ProjectInfo
{
Uri = p.Uri,
Files = p.Files.Select(f => OmniSharp.Extensions.LanguageServer.Protocol.DocumentUri.From(f.Uri)),
IsImplicitProject = p.IsImplicitProject,
});
return Task.FromResult(Container.From(info));
}
}
}

0 comments on commit 8897f0f

Please sign in to comment.