2020-04-27 21:38:35 +01:00
|
|
|
// Collection of JSONRPC and LSP structs, enums, and unions
|
|
|
|
|
|
|
|
const std = @import("std");
|
|
|
|
const json = std.json;
|
|
|
|
|
|
|
|
// JSON Types
|
|
|
|
|
|
|
|
pub const String = []const u8;
|
|
|
|
pub const Integer = i64;
|
|
|
|
pub const Float = f64;
|
|
|
|
pub const Bool = bool;
|
|
|
|
pub const Array = json.Array;
|
|
|
|
pub const Object = json.ObjectMap;
|
|
|
|
// pub const Any = @TypeOf(var);
|
|
|
|
|
|
|
|
// Basic structures
|
|
|
|
|
|
|
|
pub const DocumentUri = String;
|
|
|
|
|
|
|
|
pub const Position = struct {
|
|
|
|
line: Integer,
|
|
|
|
character: Integer
|
|
|
|
};
|
|
|
|
|
|
|
|
pub const Range = struct {
|
|
|
|
start: Position,
|
|
|
|
end: Position
|
|
|
|
};
|
|
|
|
|
|
|
|
pub const Location = struct {
|
|
|
|
uri: DocumentUri,
|
|
|
|
range: Range
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Id of a request
|
|
|
|
pub const RequestId = union(enum) {
|
|
|
|
String: String,
|
|
|
|
Integer: Integer,
|
|
|
|
Float: Float,
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Params of a request
|
2020-05-19 20:09:00 +01:00
|
|
|
pub const RequestParams = void;
|
2020-04-27 21:38:35 +01:00
|
|
|
|
|
|
|
pub const NotificationParams = union(enum) {
|
|
|
|
LogMessageParams: LogMessageParams,
|
2020-06-08 23:18:12 +01:00
|
|
|
PublishDiagnosticsParams: PublishDiagnosticsParams,
|
|
|
|
ShowMessageParams: ShowMessageParams
|
2020-04-27 21:38:35 +01:00
|
|
|
};
|
|
|
|
|
2020-05-25 23:51:50 +01:00
|
|
|
/// Hover response
|
|
|
|
pub const Hover = struct {
|
2020-06-03 09:23:14 +01:00
|
|
|
contents: MarkupContent,
|
2020-05-25 23:51:50 +01:00
|
|
|
};
|
|
|
|
|
2020-04-27 21:38:35 +01:00
|
|
|
/// Params of a response (result)
|
|
|
|
pub const ResponseParams = union(enum) {
|
2020-05-18 21:19:23 +01:00
|
|
|
CompletionList: CompletionList,
|
|
|
|
Location: Location,
|
2020-05-25 23:51:50 +01:00
|
|
|
Hover: Hover,
|
2020-06-13 19:20:04 +01:00
|
|
|
DocumentSymbols: []DocumentSymbol,
|
2020-06-16 00:14:39 +01:00
|
|
|
SemanticTokens: struct { data: []u32 },
|
2020-04-27 21:38:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/// JSONRPC error
|
|
|
|
pub const Error = struct {
|
|
|
|
code: Integer,
|
|
|
|
message: String,
|
|
|
|
data: String,
|
|
|
|
};
|
|
|
|
|
|
|
|
/// JSONRPC request
|
|
|
|
pub const Request = struct {
|
|
|
|
jsonrpc: String = "2.0",
|
|
|
|
method: String,
|
|
|
|
id: ?RequestId = RequestId{.Integer = 0},
|
|
|
|
params: RequestParams
|
|
|
|
};
|
|
|
|
|
|
|
|
/// JSONRPC notifications
|
|
|
|
pub const Notification = struct {
|
|
|
|
jsonrpc: String = "2.0",
|
|
|
|
method: String,
|
|
|
|
params: NotificationParams
|
|
|
|
};
|
|
|
|
|
|
|
|
/// JSONRPC response
|
|
|
|
pub const Response = struct {
|
|
|
|
jsonrpc: String = "2.0",
|
2020-05-14 20:57:31 +01:00
|
|
|
// @"error": ?Error = null,
|
2020-04-27 21:38:35 +01:00
|
|
|
id: RequestId,
|
|
|
|
result: ResponseParams,
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Type of a debug message
|
|
|
|
pub const MessageType = enum(Integer) {
|
|
|
|
Error = 1,
|
|
|
|
Warning = 2,
|
|
|
|
Info = 3,
|
|
|
|
Log = 4,
|
|
|
|
|
|
|
|
pub fn jsonStringify(
|
|
|
|
value: MessageType,
|
|
|
|
options: json.StringifyOptions,
|
|
|
|
out_stream: var,
|
|
|
|
) !void {
|
|
|
|
try json.stringify(@enumToInt(value), options, out_stream);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Params for a LogMessage Notification (window/logMessage)
|
|
|
|
pub const LogMessageParams = struct {
|
|
|
|
@"type": MessageType,
|
|
|
|
message: String
|
|
|
|
};
|
|
|
|
|
|
|
|
pub const DiagnosticSeverity = enum(Integer) {
|
|
|
|
Error = 1,
|
|
|
|
Warning = 2,
|
|
|
|
Information = 3,
|
|
|
|
Hint = 4,
|
|
|
|
|
|
|
|
pub fn jsonStringify(
|
|
|
|
value: DiagnosticSeverity,
|
|
|
|
options: json.StringifyOptions,
|
|
|
|
out_stream: var,
|
|
|
|
) !void {
|
|
|
|
try json.stringify(@enumToInt(value), options, out_stream);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
pub const Diagnostic = struct {
|
|
|
|
range: Range,
|
|
|
|
severity: DiagnosticSeverity,
|
|
|
|
code: String,
|
|
|
|
source: String,
|
|
|
|
message: String,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub const PublishDiagnosticsParams = struct {
|
|
|
|
uri: DocumentUri,
|
|
|
|
diagnostics: []Diagnostic
|
|
|
|
};
|
|
|
|
|
|
|
|
pub const TextDocument = struct {
|
|
|
|
uri: DocumentUri,
|
2020-05-07 15:58:31 +01:00
|
|
|
// This is a substring of mem starting at 0
|
2020-04-27 21:38:35 +01:00
|
|
|
text: String,
|
2020-05-07 15:58:31 +01:00
|
|
|
// This holds the memory that we have actually allocated.
|
|
|
|
mem: []u8,
|
2020-04-27 21:38:35 +01:00
|
|
|
|
2020-05-08 11:50:21 +01:00
|
|
|
pub fn positionToIndex(self: TextDocument, position: Position) !usize {
|
2020-04-27 21:38:35 +01:00
|
|
|
var split_iterator = std.mem.split(self.text, "\n");
|
|
|
|
|
|
|
|
var line: i64 = 0;
|
|
|
|
while (line < position.line) : (line += 1) {
|
|
|
|
_ = split_iterator.next() orelse return error.InvalidParams;
|
|
|
|
}
|
|
|
|
|
|
|
|
var index = @intCast(i64, split_iterator.index.?) + position.character;
|
|
|
|
|
|
|
|
if (index < 0 or index >= @intCast(i64, self.text.len)) {
|
|
|
|
return error.InvalidParams;
|
|
|
|
}
|
|
|
|
|
|
|
|
return @intCast(usize, index);
|
|
|
|
}
|
2020-05-13 15:10:20 +01:00
|
|
|
|
|
|
|
pub fn getLine(self: TextDocument, target_line: usize) ![]const u8 {
|
|
|
|
var split_iterator = std.mem.split(self.text, "\n");
|
|
|
|
|
|
|
|
var line: i64 = 0;
|
|
|
|
while (line < target_line) : (line += 1) {
|
|
|
|
_ = split_iterator.next() orelse return error.InvalidParams;
|
|
|
|
}
|
|
|
|
if (split_iterator.next()) |next| {
|
|
|
|
return next;
|
|
|
|
} else return error.InvalidParams;
|
|
|
|
}
|
2020-04-27 21:38:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
pub const TextEdit = struct {
|
|
|
|
range: Range,
|
|
|
|
newText: String,
|
|
|
|
};
|
|
|
|
|
2020-05-02 17:43:26 +01:00
|
|
|
pub const MarkupKind = enum(u1) {
|
|
|
|
PlainText = 0, // plaintext
|
|
|
|
Markdown = 1, // markdown
|
|
|
|
|
|
|
|
pub fn jsonStringify(
|
|
|
|
value: MarkupKind,
|
|
|
|
options: json.StringifyOptions,
|
|
|
|
out_stream: var,
|
|
|
|
) !void {
|
2020-05-17 15:39:04 +01:00
|
|
|
const str = switch (value) {
|
|
|
|
.PlainText => "plaintext",
|
|
|
|
.Markdown => "markdown",
|
|
|
|
};
|
|
|
|
try json.stringify(str, options, out_stream);
|
2020-05-02 17:43:26 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
pub const MarkupContent = struct {
|
|
|
|
kind: MarkupKind = MarkupKind.Markdown,
|
|
|
|
value: String
|
|
|
|
};
|
|
|
|
|
2020-04-27 21:38:35 +01:00
|
|
|
// pub const TextDocumentIdentifier = struct {
|
|
|
|
// uri: DocumentUri,
|
|
|
|
// };
|
|
|
|
|
|
|
|
// pub const CompletionTriggerKind = enum(Integer) {
|
|
|
|
// Invoked = 1,
|
|
|
|
// TriggerCharacter = 2,
|
|
|
|
// TriggerForIncompleteCompletions = 3,
|
|
|
|
|
|
|
|
// pub fn jsonStringify(
|
|
|
|
// value: CompletionTriggerKind,
|
|
|
|
// options: json.StringifyOptions,
|
|
|
|
// out_stream: var,
|
|
|
|
// ) !void {
|
|
|
|
// try json.stringify(@enumToInt(value), options, out_stream);
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
|
|
|
|
pub const CompletionList = struct {
|
|
|
|
isIncomplete: Bool,
|
2020-05-07 12:36:40 +01:00
|
|
|
items: []const CompletionItem,
|
2020-04-27 21:38:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
pub const CompletionItemKind = enum(Integer) {
|
|
|
|
Text = 1,
|
|
|
|
Method = 2,
|
|
|
|
Function = 3,
|
|
|
|
Constructor = 4,
|
|
|
|
Field = 5,
|
|
|
|
Variable = 6,
|
|
|
|
Class = 7,
|
|
|
|
Interface = 8,
|
|
|
|
Module = 9,
|
|
|
|
Property = 10,
|
|
|
|
Unit = 11,
|
|
|
|
Value = 12,
|
|
|
|
Enum = 13,
|
|
|
|
Keyword = 14,
|
|
|
|
Snippet = 15,
|
|
|
|
Color = 16,
|
|
|
|
File = 17,
|
|
|
|
Reference = 18,
|
|
|
|
Folder = 19,
|
|
|
|
EnumMember = 20,
|
|
|
|
Constant = 21,
|
|
|
|
Struct = 22,
|
|
|
|
Event = 23,
|
|
|
|
Operator = 24,
|
|
|
|
TypeParameter = 25,
|
|
|
|
|
|
|
|
pub fn jsonStringify(
|
|
|
|
value: CompletionItemKind,
|
|
|
|
options: json.StringifyOptions,
|
|
|
|
out_stream: var,
|
|
|
|
) !void {
|
|
|
|
try json.stringify(@enumToInt(value), options, out_stream);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-04-28 03:59:28 +01:00
|
|
|
pub const InsertTextFormat = enum(Integer) {
|
|
|
|
PlainText = 1,
|
|
|
|
Snippet = 2,
|
|
|
|
|
|
|
|
pub fn jsonStringify(
|
|
|
|
value: InsertTextFormat,
|
|
|
|
options: json.StringifyOptions,
|
|
|
|
out_stream: var,
|
|
|
|
) !void {
|
|
|
|
try json.stringify(@enumToInt(value), options, out_stream);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-04-27 21:38:35 +01:00
|
|
|
pub const CompletionItem = struct {
|
|
|
|
label: String,
|
|
|
|
kind: CompletionItemKind,
|
|
|
|
textEdit: ?TextEdit = null,
|
2020-04-28 03:59:28 +01:00
|
|
|
filterText: ?String = null,
|
|
|
|
insertText: ?String = null,
|
2020-05-02 17:43:26 +01:00
|
|
|
insertTextFormat: ?InsertTextFormat = InsertTextFormat.PlainText,
|
|
|
|
|
|
|
|
detail: ?String = null,
|
|
|
|
documentation: ?MarkupContent = null
|
2020-04-27 21:38:35 +01:00
|
|
|
// filterText: String = .NotDefined,
|
|
|
|
};
|
2020-05-28 01:39:36 +01:00
|
|
|
|
|
|
|
const SymbolKind = enum {
|
|
|
|
File = 1,
|
|
|
|
Module = 2,
|
|
|
|
Namespace = 3,
|
|
|
|
Package = 4,
|
|
|
|
Class = 5,
|
|
|
|
Method = 6,
|
|
|
|
Property = 7,
|
|
|
|
Field = 8,
|
|
|
|
Constructor = 9,
|
|
|
|
Enum = 10,
|
|
|
|
Interface = 11,
|
|
|
|
Function = 12,
|
|
|
|
Variable = 13,
|
|
|
|
Constant = 14,
|
|
|
|
String = 15,
|
|
|
|
Number = 16,
|
|
|
|
Boolean = 17,
|
|
|
|
Array = 18,
|
|
|
|
Object = 19,
|
|
|
|
Key = 20,
|
|
|
|
Null = 21,
|
|
|
|
EnumMember = 22,
|
|
|
|
Struct = 23,
|
|
|
|
Event = 24,
|
|
|
|
Operator = 25,
|
|
|
|
TypeParameter = 26,
|
|
|
|
|
|
|
|
pub fn jsonStringify(
|
|
|
|
value: SymbolKind,
|
|
|
|
options: json.StringifyOptions,
|
|
|
|
out_stream: var,
|
|
|
|
) !void {
|
|
|
|
try json.stringify(@enumToInt(value), options, out_stream);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
pub const DocumentSymbol = struct {
|
2020-06-08 23:18:12 +01:00
|
|
|
name: String,
|
|
|
|
detail: ?String = null,
|
2020-05-28 01:39:36 +01:00
|
|
|
kind: SymbolKind,
|
|
|
|
deprecated: bool = false,
|
|
|
|
range: Range,
|
|
|
|
selectionRange: Range,
|
|
|
|
children: []DocumentSymbol = &[_]DocumentSymbol{}
|
|
|
|
};
|
2020-06-08 23:18:12 +01:00
|
|
|
|
|
|
|
pub const ShowMessageParams = struct {
|
|
|
|
@"type": MessageType,
|
|
|
|
message: String
|
|
|
|
};
|