74 lines
2.4 KiB
C#
74 lines
2.4 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using JsonRpc.Standard;
|
|
using JsonRpc.Standard.Contracts;
|
|
using JsonRpc.Standard.Server;
|
|
using LanguageServer.VsCode.Contracts;
|
|
using Newtonsoft.Json.Linq;
|
|
// ReSharper disable UnusedMember.Global
|
|
|
|
namespace UpsilonLanguageServer.Services
|
|
{
|
|
public class InitializationService : UpsilonLanguageServiceBase
|
|
{
|
|
|
|
[JsonRpcMethod(AllowExtensionData = true)]
|
|
public InitializeResult Initialize(int processId, Uri rootUri, ClientCapabilities capabilities,
|
|
JToken initializationOptions = null, string trace = null)
|
|
{
|
|
if (rootUri != null)
|
|
{
|
|
var configPath = rootUri.AbsolutePath + "/.upsilon";
|
|
var typesConfigFile = configPath + "/types.json";
|
|
if (File.Exists(typesConfigFile))
|
|
{
|
|
BoundTypeParser.LoadBoundTypes(File.ReadAllText(typesConfigFile));
|
|
}
|
|
var staticConfigFile = configPath + "/static.json";
|
|
if (File.Exists(staticConfigFile))
|
|
{
|
|
BoundTypeParser.LoadStaticVariables(File.ReadAllText(staticConfigFile));
|
|
}
|
|
}
|
|
return new InitializeResult(new ServerCapabilities
|
|
{
|
|
HoverProvider = true,
|
|
SignatureHelpProvider = new SignatureHelpOptions("()"),
|
|
CompletionProvider = new CompletionOptions(true, ""),
|
|
TextDocumentSync = new TextDocumentSyncOptions
|
|
{
|
|
OpenClose = true,
|
|
WillSave = true,
|
|
Change = TextDocumentSyncKind.Incremental
|
|
},
|
|
});
|
|
}
|
|
|
|
[JsonRpcMethod(IsNotification = true)]
|
|
public async Task Initialized()
|
|
{
|
|
await Client.Window.ShowMessage(MessageType.Info, "Upsilon Language Server Initialized");
|
|
}
|
|
|
|
[JsonRpcMethod]
|
|
public void Shutdown()
|
|
{
|
|
|
|
}
|
|
|
|
[JsonRpcMethod(IsNotification = true)]
|
|
public void Exit()
|
|
{
|
|
Client.Window.ShowMessage(MessageType.Info, "Upsilon Language Server exited");
|
|
Session.StopServer();
|
|
}
|
|
|
|
[JsonRpcMethod("$/cancelRequest", IsNotification = true)]
|
|
public void CancelRequest(MessageId id)
|
|
{
|
|
RequestContext.Features.Get<IRequestCancellationFeature>().TryCancel(id);
|
|
}
|
|
}
|
|
}
|