Skip to content

Commit

Permalink
Add an LSP command that returns the JSON for a new Yarn Project
Browse files Browse the repository at this point in the history
  • Loading branch information
desplesda committed Jun 22, 2024
1 parent 92c285a commit 9ca7c46
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 0 additions & 1 deletion YarnSpinner.LanguageServer.Tests/CommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,5 +325,4 @@ public async Task Server_CanListProjects()
result.Should().ContainSingle(p => p.Uri!.Path.EndsWith("Project1.yarnproject"));
result.Should().ContainSingle(p => p.Uri!.Path.EndsWith("Project2.yarnproject"));
}

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

public const string GenerateDebugOutput = "yarnspinner.generateDebugOutput";

public const string GetEmptyYarnProjectJSON = "yarnspinner.getEmptyYarnProjectJSON";
}
17 changes: 17 additions & 0 deletions YarnSpinner.LanguageServer/src/Server/YarnLanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ public static LanguageServerOptions ConfigureOptions(LanguageServerOptions optio
}
);

// register 'return json for new project' command
options.OnExecuteCommand<string>(
(commandParams) => GetEmptyYarnProjectJSON(workspace, commandParams),
(_, _) => new ExecuteCommandRegistrationOptions
{
Commands = new[] { Commands.GetEmptyYarnProjectJSON },
}
);

return options;
}

Expand Down Expand Up @@ -725,5 +734,13 @@ private static Task<Container<ProjectInfo>> ListProjects(Workspace workspace, Ex
});
return Task.FromResult(Container.From(info));
}


public static Task<string> GetEmptyYarnProjectJSON(Workspace workspace, ExecuteCommandParams<string> commandParams) {

var project = new Yarn.Compiler.Project();

return Task.FromResult(project.GetJson());
}
}
}

0 comments on commit 9ca7c46

Please sign in to comment.