2020-04-27 21:38:35 +01:00
|
|
|
const std = @import("std");
|
2020-11-06 08:08:20 +00:00
|
|
|
// LSP types
|
2020-04-27 21:38:35 +01:00
|
|
|
const json = std.json;
|
|
|
|
|
|
|
|
pub const Position = struct {
|
2020-11-06 08:08:20 +00:00
|
|
|
line: i64,
|
|
|
|
character: i64,
|
2020-04-27 21:38:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
pub const Range = struct {
|
2020-07-05 23:32:14 +01:00
|
|
|
start: Position,
|
|
|
|
end: Position,
|
2020-04-27 21:38:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
pub const Location = struct {
|
2020-11-06 08:08:20 +00:00
|
|
|
uri: []const u8,
|
|
|
|
range: Range,
|
2020-04-27 21:38:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Id of a request
|
|
|
|
pub const RequestId = union(enum) {
|
2020-11-06 08:08:20 +00:00
|
|
|
String: []const u8,
|
|
|
|
Integer: i64,
|
|
|
|
Float: f64,
|
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-09-25 22:24:10 +01:00
|
|
|
SemanticTokensFull: struct { data: []const u32 },
|
2020-06-16 20:02:31 +01:00
|
|
|
TextEdits: []TextEdit,
|
2020-07-05 23:32:14 +01:00
|
|
|
Locations: []Location,
|
2020-06-27 01:16:14 +01:00
|
|
|
WorkspaceEdit: WorkspaceEdit,
|
2020-11-06 08:08:20 +00:00
|
|
|
InitializeResult: InitializeResult,
|
2020-04-27 21:38:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/// JSONRPC notifications
|
|
|
|
pub const Notification = struct {
|
2020-11-06 08:08:20 +00:00
|
|
|
pub const Params = union(enum) {
|
|
|
|
LogMessage: struct {
|
|
|
|
type: MessageType,
|
|
|
|
message: []const u8,
|
|
|
|
},
|
|
|
|
PublishDiagnostics: struct {
|
|
|
|
uri: []const u8,
|
|
|
|
diagnostics: []Diagnostic,
|
|
|
|
},
|
|
|
|
ShowMessage: struct {
|
|
|
|
type: MessageType,
|
|
|
|
message: []const u8,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
jsonrpc: []const u8 = "2.0",
|
|
|
|
method: []const u8,
|
|
|
|
params: Params,
|
2020-04-27 21:38:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/// JSONRPC response
|
|
|
|
pub const Response = struct {
|
2020-11-06 08:08:20 +00:00
|
|
|
jsonrpc: []const u8 = "2.0",
|
2020-04-27 21:38:35 +01:00
|
|
|
id: RequestId,
|
|
|
|
result: ResponseParams,
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Type of a debug message
|
2020-11-06 08:08:20 +00:00
|
|
|
pub const MessageType = enum(i64) {
|
2020-04-27 21:38:35 +01:00
|
|
|
Error = 1,
|
|
|
|
Warning = 2,
|
|
|
|
Info = 3,
|
|
|
|
Log = 4,
|
|
|
|
|
|
|
|
pub fn jsonStringify(
|
|
|
|
value: MessageType,
|
|
|
|
options: json.StringifyOptions,
|
2020-07-12 20:12:09 +01:00
|
|
|
out_stream: anytype,
|
2020-04-27 21:38:35 +01:00
|
|
|
) !void {
|
|
|
|
try json.stringify(@enumToInt(value), options, out_stream);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-11-06 08:08:20 +00:00
|
|
|
pub const DiagnosticSeverity = enum(i64) {
|
2020-04-27 21:38:35 +01:00
|
|
|
Error = 1,
|
|
|
|
Warning = 2,
|
|
|
|
Information = 3,
|
|
|
|
Hint = 4,
|
|
|
|
|
|
|
|
pub fn jsonStringify(
|
|
|
|
value: DiagnosticSeverity,
|
|
|
|
options: json.StringifyOptions,
|
2020-07-12 20:12:09 +01:00
|
|
|
out_stream: anytype,
|
2020-04-27 21:38:35 +01:00
|
|
|
) !void {
|
|
|
|
try json.stringify(@enumToInt(value), options, out_stream);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
pub const Diagnostic = struct {
|
|
|
|
range: Range,
|
|
|
|
severity: DiagnosticSeverity,
|
2020-11-06 08:08:20 +00:00
|
|
|
code: []const u8,
|
|
|
|
source: []const u8,
|
|
|
|
message: []const u8,
|
2020-04-27 21:38:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
pub const TextDocument = struct {
|
2020-11-06 08:08:20 +00:00
|
|
|
uri: []const u8,
|
2020-05-07 15:58:31 +01:00
|
|
|
// This is a substring of mem starting at 0
|
2020-11-06 08:08:20 +00:00
|
|
|
text: []const u8,
|
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-06-27 01:16:14 +01:00
|
|
|
pub const WorkspaceEdit = struct {
|
|
|
|
changes: ?std.StringHashMap([]TextEdit),
|
|
|
|
|
|
|
|
pub fn jsonStringify(
|
|
|
|
self: WorkspaceEdit,
|
|
|
|
options: std.json.StringifyOptions,
|
2020-07-12 20:12:09 +01:00
|
|
|
writer: anytype,
|
2020-06-27 01:16:14 +01:00
|
|
|
) @TypeOf(writer).Error!void {
|
|
|
|
try writer.writeByte('{');
|
|
|
|
if (self.changes) |changes| {
|
|
|
|
try writer.writeAll("\"changes\": {");
|
|
|
|
var it = changes.iterator();
|
|
|
|
var idx: usize = 0;
|
|
|
|
while (it.next()) |entry| : (idx += 1) {
|
|
|
|
if (idx != 0) try writer.writeAll(", ");
|
|
|
|
|
|
|
|
try writer.writeByte('"');
|
|
|
|
try writer.writeAll(entry.key);
|
|
|
|
try writer.writeAll("\":");
|
|
|
|
try std.json.stringify(entry.value, options, writer);
|
|
|
|
}
|
|
|
|
try writer.writeByte('}');
|
|
|
|
}
|
|
|
|
try writer.writeByte('}');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-04-27 21:38:35 +01:00
|
|
|
pub const TextEdit = struct {
|
|
|
|
range: Range,
|
2020-11-06 08:08:20 +00:00
|
|
|
newText: []const u8,
|
2020-05-02 17:43:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
pub const MarkupContent = struct {
|
2020-11-06 08:08:20 +00:00
|
|
|
pub const Kind = enum(u1) {
|
|
|
|
PlainText = 0,
|
|
|
|
Markdown = 1,
|
|
|
|
|
|
|
|
pub fn jsonStringify(
|
|
|
|
value: Kind,
|
|
|
|
options: json.StringifyOptions,
|
|
|
|
out_stream: anytype,
|
|
|
|
) !void {
|
|
|
|
const str = switch (value) {
|
|
|
|
.PlainText => "plaintext",
|
|
|
|
.Markdown => "markdown",
|
|
|
|
};
|
|
|
|
try json.stringify(str, options, out_stream);
|
|
|
|
}
|
|
|
|
};
|
2020-04-27 21:38:35 +01:00
|
|
|
|
2020-11-06 08:08:20 +00:00
|
|
|
kind: Kind = .Markdown,
|
|
|
|
value: []const u8,
|
|
|
|
};
|
2020-04-27 21:38:35 +01:00
|
|
|
|
|
|
|
pub const CompletionList = struct {
|
2020-11-06 08:08:20 +00:00
|
|
|
isIncomplete: bool,
|
2020-05-07 12:36:40 +01:00
|
|
|
items: []const CompletionItem,
|
2020-04-27 21:38:35 +01:00
|
|
|
};
|
|
|
|
|
2020-11-06 08:08:20 +00:00
|
|
|
pub const InsertTextFormat = enum(i64) {
|
2020-04-28 03:59:28 +01:00
|
|
|
PlainText = 1,
|
|
|
|
Snippet = 2,
|
|
|
|
|
|
|
|
pub fn jsonStringify(
|
|
|
|
value: InsertTextFormat,
|
|
|
|
options: json.StringifyOptions,
|
2020-07-12 20:12:09 +01:00
|
|
|
out_stream: anytype,
|
2020-04-28 03:59:28 +01:00
|
|
|
) !void {
|
|
|
|
try json.stringify(@enumToInt(value), options, out_stream);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-04-27 21:38:35 +01:00
|
|
|
pub const CompletionItem = struct {
|
2020-11-06 08:08:20 +00:00
|
|
|
const Kind = enum(i64) {
|
|
|
|
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: Kind,
|
|
|
|
options: json.StringifyOptions,
|
|
|
|
out_stream: anytype,
|
|
|
|
) !void {
|
|
|
|
try json.stringify(@enumToInt(value), options, out_stream);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
label: []const u8,
|
|
|
|
kind: Kind,
|
2020-07-08 02:05:44 +01:00
|
|
|
textEdit: ?TextEdit = null,
|
2020-11-06 08:08:20 +00:00
|
|
|
filterText: ?[]const u8 = null,
|
|
|
|
insertText: ?[]const u8 = null,
|
|
|
|
insertTextFormat: ?InsertTextFormat = .PlainText,
|
|
|
|
detail: ?[]const u8 = null,
|
2020-07-08 02:05:44 +01:00
|
|
|
documentation: ?MarkupContent = null,
|
2020-05-28 01:39:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
pub const DocumentSymbol = struct {
|
2020-11-06 08:08:20 +00:00
|
|
|
const Kind = 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: Kind,
|
|
|
|
options: json.StringifyOptions,
|
|
|
|
out_stream: anytype,
|
|
|
|
) !void {
|
|
|
|
try json.stringify(@enumToInt(value), options, out_stream);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
name: []const u8,
|
|
|
|
detail: ?[]const u8 = null,
|
|
|
|
kind: Kind,
|
2020-06-29 23:34:21 +01:00
|
|
|
deprecated: bool = false,
|
|
|
|
range: Range,
|
|
|
|
selectionRange: Range,
|
2020-07-07 09:57:02 +01:00
|
|
|
children: []const DocumentSymbol = &[_]DocumentSymbol{},
|
2020-05-28 01:39:36 +01:00
|
|
|
};
|
2020-06-08 23:18:12 +01:00
|
|
|
|
2020-11-06 08:08:20 +00:00
|
|
|
pub const WorkspaceFolder = struct {
|
|
|
|
uri: []const u8,
|
|
|
|
name: []const u8,
|
2020-06-29 23:34:21 +01:00
|
|
|
};
|
|
|
|
|
2020-11-06 08:08:20 +00:00
|
|
|
// Only includes options we set in our initialize result.
|
|
|
|
const InitializeResult = struct {
|
2020-11-06 08:24:37 +00:00
|
|
|
offsetEncoding: []const u8,
|
2020-11-06 08:08:20 +00:00
|
|
|
capabilities: struct {
|
|
|
|
signatureHelpProvider: struct {
|
|
|
|
triggerCharacters: []const []const u8,
|
|
|
|
},
|
|
|
|
textDocumentSync: enum {
|
|
|
|
None = 0,
|
|
|
|
Full = 1,
|
|
|
|
Incremental = 2,
|
|
|
|
|
|
|
|
pub fn jsonStringify(
|
|
|
|
value: @This(),
|
|
|
|
options: json.StringifyOptions,
|
|
|
|
out_stream: anytype,
|
|
|
|
) !void {
|
|
|
|
try json.stringify(@enumToInt(value), options, out_stream);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
renameProvider: bool,
|
|
|
|
completionProvider: struct {
|
|
|
|
resolveProvider: bool,
|
|
|
|
triggerCharacters: []const []const u8,
|
|
|
|
},
|
|
|
|
documentHighlightProvider: bool,
|
|
|
|
hoverProvider: bool,
|
|
|
|
codeActionProvider: bool,
|
|
|
|
declarationProvider: bool,
|
|
|
|
definitionProvider: bool,
|
|
|
|
typeDefinitionProvider: bool,
|
|
|
|
implementationProvider: bool,
|
|
|
|
referencesProvider: bool,
|
|
|
|
documentSymbolProvider: bool,
|
|
|
|
colorProvider: bool,
|
|
|
|
documentFormattingProvider: bool,
|
|
|
|
documentRangeFormattingProvider: bool,
|
|
|
|
foldingRangeProvider: bool,
|
|
|
|
selectionRangeProvider: bool,
|
|
|
|
workspaceSymbolProvider: bool,
|
|
|
|
rangeProvider: bool,
|
|
|
|
documentProvider: bool,
|
|
|
|
workspace: struct {
|
|
|
|
workspaceFolders: struct {
|
|
|
|
supported: bool,
|
|
|
|
changeNotifications: bool,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
semanticTokensProvider: struct {
|
|
|
|
documentProvider: bool,
|
|
|
|
legend: struct {
|
|
|
|
tokenTypes: []const []const u8,
|
|
|
|
tokenModifiers: []const []const u8,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
serverInfo: struct {
|
|
|
|
name: []const u8,
|
|
|
|
version: ?[]const u8 = null,
|
|
|
|
},
|
2020-06-08 23:18:12 +01:00
|
|
|
};
|