-
-
Notifications
You must be signed in to change notification settings - Fork 408
Expand file tree
/
Copy pathdid_open.zig
More file actions
39 lines (31 loc) · 1.69 KB
/
Copy pathdid_open.zig
File metadata and controls
39 lines (31 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! Handler for LSP `textDocument/didOpen` notifications.
const std = @import("std");
const Allocator = std.mem.Allocator;
/// Handler for `textDocument/didOpen` notifications.
pub fn handler(comptime ServerType: type) type {
return struct {
pub fn call(self: *ServerType, params_value: ?std.json.Value) Allocator.Error!void {
const params = params_value orelse return;
if (std.meta.activeTag(params) != .object) return;
const obj = params.object;
const text_doc_value = obj.get("textDocument") orelse return;
if (std.meta.activeTag(text_doc_value) != .object) return;
const text_doc = text_doc_value.object;
const uri_value = text_doc.get("uri") orelse return;
if (std.meta.activeTag(uri_value) != .string) return;
const uri = uri_value.string;
const text_value = text_doc.get("text") orelse return;
if (std.meta.activeTag(text_value) != .string) return;
const text = text_value.string;
const version_value = text_doc.get("version") orelse std.json.Value{ .integer = 0 };
const version: i64 = if (std.meta.activeTag(version_value) == .integer)
version_value.integer
else if (std.meta.activeTag(version_value) == .float and std.math.isFinite(version_value.float) and version_value.float >= @as(f64, @floatFromInt(std.math.minInt(i64))) and version_value.float < @as(f64, @floatFromInt(std.math.maxInt(i64))))
@intFromFloat(version_value.float)
else
0;
try self.doc_store.upsert(uri, version, text);
self.onDocumentChanged(uri);
}
};
}