|
1 | 1 | using System.Text.Json; |
2 | 2 | using EmmyLua.LanguageServer.Framework.Protocol.JsonRpc; |
3 | 3 | using EmmyLua.LanguageServer.Framework.Protocol.Message.Client.ApplyWorkspaceEdit; |
| 4 | +using EmmyLua.LanguageServer.Framework.Protocol.Message.Client.LogMessage; |
4 | 5 | using EmmyLua.LanguageServer.Framework.Protocol.Message.Client.PublishDiagnostics; |
5 | 6 | using EmmyLua.LanguageServer.Framework.Protocol.Message.Client.Registration; |
6 | 7 | using EmmyLua.LanguageServer.Framework.Protocol.Message.Client.ShowMessage; |
| 8 | +using EmmyLua.LanguageServer.Framework.Protocol.Message.Client.Telemetry; |
7 | 9 | using EmmyLua.LanguageServer.Framework.Protocol.Message.Configuration; |
| 10 | +using EmmyLua.LanguageServer.Framework.Protocol.Message.Progress; |
8 | 11 | using EmmyLua.LanguageServer.Framework.Protocol.Model; |
| 12 | +using EmmyLua.LanguageServer.Framework.Protocol.Model.Union; |
| 13 | +using EmmyLua.LanguageServer.Framework.Protocol.Model.WorkDoneProgress; |
9 | 14 |
|
10 | 15 | namespace EmmyLua.LanguageServer.Framework.Server; |
11 | 16 |
|
@@ -46,6 +51,38 @@ public Task ShowMessage(ShowMessageParams @params) |
46 | 51 | return server.SendNotification(notification); |
47 | 52 | } |
48 | 53 |
|
| 54 | + public async Task<MessageActionItem?> ShowMessageRequest(ShowMessageRequestParams @params, CancellationToken token) |
| 55 | + { |
| 56 | + var document = JsonSerializer.SerializeToDocument(@params, server.JsonSerializerOptions); |
| 57 | + var response = await server.SendRequest("window/showMessageRequest", document, token); |
| 58 | + return response?.Deserialize<MessageActionItem>(server.JsonSerializerOptions); |
| 59 | + } |
| 60 | + |
| 61 | + public Task LogMessage(LogMessageParams @params) |
| 62 | + { |
| 63 | + var document = JsonSerializer.SerializeToDocument(@params, server.JsonSerializerOptions); |
| 64 | + var notification = new NotificationMessage("window/logMessage", document); |
| 65 | + return server.SendNotification(notification); |
| 66 | + } |
| 67 | + |
| 68 | + public Task LogMessage(MessageType type, string message) |
| 69 | + { |
| 70 | + return LogMessage(new LogMessageParams { Type = type, Message = message }); |
| 71 | + } |
| 72 | + |
| 73 | + public Task LogError(string message) => LogMessage(MessageType.Error, message); |
| 74 | + public Task LogWarning(string message) => LogMessage(MessageType.Warning, message); |
| 75 | + public Task LogInfo(string message) => LogMessage(MessageType.Info, message); |
| 76 | + public Task LogDebug(string message) => LogMessage(MessageType.Debug, message); |
| 77 | + |
| 78 | + public Task TelemetryEvent(object? data) |
| 79 | + { |
| 80 | + var @params = new TelemetryEventParams { Data = data }; |
| 81 | + var document = JsonSerializer.SerializeToDocument(@params, server.JsonSerializerOptions); |
| 82 | + var notification = new NotificationMessage("telemetry/event", document); |
| 83 | + return server.SendNotification(notification); |
| 84 | + } |
| 85 | + |
49 | 86 | public Task PublishDiagnostics(PublishDiagnosticsParams @params) |
50 | 87 | { |
51 | 88 | var document = JsonSerializer.SerializeToDocument(@params, server.JsonSerializerOptions); |
@@ -78,4 +115,62 @@ public async Task RefreshDiagnostics() |
78 | 115 | var response = server.SendRequest(method, document, token); |
79 | 116 | return await response; |
80 | 117 | } |
| 118 | + |
| 119 | + // Work Done Progress Support |
| 120 | + |
| 121 | + /// <summary> |
| 122 | + /// Create a work done progress token and request the client to show progress UI. |
| 123 | + /// </summary> |
| 124 | + public async Task<StringOrInt> CreateWorkDoneProgress(StringOrInt token, CancellationToken cancellationToken = default) |
| 125 | + { |
| 126 | + var @params = new WorkDoneProgressCreateParams { Token = token }; |
| 127 | + var document = JsonSerializer.SerializeToDocument(@params, server.JsonSerializerOptions); |
| 128 | + await server.SendRequest("window/workDoneProgress/create", document, cancellationToken); |
| 129 | + return token; |
| 130 | + } |
| 131 | + |
| 132 | + /// <summary> |
| 133 | + /// Report progress begin. |
| 134 | + /// </summary> |
| 135 | + public Task ReportProgress(StringOrInt token, WorkDoneProgressBegin value) |
| 136 | + { |
| 137 | + var @params = new ProgressParams |
| 138 | + { |
| 139 | + Token = token.StringValue ?? token.IntValue.ToString(), |
| 140 | + Value = value |
| 141 | + }; |
| 142 | + var document = JsonSerializer.SerializeToDocument(@params, server.JsonSerializerOptions); |
| 143 | + var notification = new NotificationMessage("$/progress", document); |
| 144 | + return server.SendNotification(notification); |
| 145 | + } |
| 146 | + |
| 147 | + /// <summary> |
| 148 | + /// Report progress update. |
| 149 | + /// </summary> |
| 150 | + public Task ReportProgress(StringOrInt token, WorkDoneProgressReport value) |
| 151 | + { |
| 152 | + var @params = new ProgressParams |
| 153 | + { |
| 154 | + Token = token.StringValue ?? token.IntValue.ToString(), |
| 155 | + Value = value |
| 156 | + }; |
| 157 | + var document = JsonSerializer.SerializeToDocument(@params, server.JsonSerializerOptions); |
| 158 | + var notification = new NotificationMessage("$/progress", document); |
| 159 | + return server.SendNotification(notification); |
| 160 | + } |
| 161 | + |
| 162 | + /// <summary> |
| 163 | + /// Report progress end. |
| 164 | + /// </summary> |
| 165 | + public Task ReportProgress(StringOrInt token, WorkDoneProgressEnd value) |
| 166 | + { |
| 167 | + var @params = new ProgressParams |
| 168 | + { |
| 169 | + Token = token.StringValue ?? token.IntValue.ToString(), |
| 170 | + Value = value |
| 171 | + }; |
| 172 | + var document = JsonSerializer.SerializeToDocument(@params, server.JsonSerializerOptions); |
| 173 | + var notification = new NotificationMessage("$/progress", document); |
| 174 | + return server.SendNotification(notification); |
| 175 | + } |
81 | 176 | } |
0 commit comments