Update lsp to have set root path
This commit is contained in:
31
compiler/NubLang.LSP/SetRootPathCommandHandler.cs
Normal file
31
compiler/NubLang.LSP/SetRootPathCommandHandler.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using MediatR;
|
||||
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
|
||||
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
|
||||
using OmniSharp.Extensions.LanguageServer.Protocol.Workspace;
|
||||
|
||||
namespace NubLang.LSP;
|
||||
|
||||
public class SetRootPathCommandHandler(WorkspaceManager workspaceManager) : ExecuteCommandHandlerBase
|
||||
{
|
||||
protected override ExecuteCommandRegistrationOptions CreateRegistrationOptions(ExecuteCommandCapability capability, ClientCapabilities clientCapabilities)
|
||||
{
|
||||
return new ExecuteCommandRegistrationOptions
|
||||
{
|
||||
Commands = new Container<string>("nub.setRootPath")
|
||||
};
|
||||
}
|
||||
|
||||
public override Task<Unit> Handle(ExecuteCommandParams request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (request is { Command: "nub.setRootPath", Arguments.Count: > 0 })
|
||||
{
|
||||
var newRoot = request.Arguments[0].ToString();
|
||||
if (!string.IsNullOrEmpty(newRoot))
|
||||
{
|
||||
workspaceManager.SetRootPath(newRoot);
|
||||
}
|
||||
}
|
||||
|
||||
return Unit.Task;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user