Compare commits
No commits in common. "739b2a776fd4dc734e1664845b0874feb3dad211" and "6d58ecb324957b48c0fa1c8bfe44b643bc26e7f0" have entirely different histories.
739b2a776f
...
6d58ecb324
2 changed files with 3 additions and 59 deletions
60
src/LSP.zig
60
src/LSP.zig
|
@ -125,10 +125,6 @@ const Process = struct {
|
|||
log_file: ?std.fs.File = null,
|
||||
next_id: i32 = 0,
|
||||
requests: std.StringHashMap(tp.pid),
|
||||
state: enum { init, running } = .init,
|
||||
init_queue: ?std.ArrayListUnmanaged(struct { tp.pid, []const u8, []const u8, InitQueueType }) = null,
|
||||
|
||||
const InitQueueType = enum { request, notify };
|
||||
|
||||
const Receiver = tp.Receiver(*Process);
|
||||
|
||||
|
@ -165,7 +161,6 @@ const Process = struct {
|
|||
}
|
||||
|
||||
fn deinit(self: *Process) void {
|
||||
self.free_init_queue();
|
||||
var i = self.requests.iterator();
|
||||
while (i.next()) |req| {
|
||||
self.allocator.free(req.key_ptr.*);
|
||||
|
@ -241,24 +236,12 @@ const Process = struct {
|
|||
var code: u32 = 0;
|
||||
var cbor_id: []const u8 = "";
|
||||
|
||||
if (try cbor.match(m.buf, .{ "REQ", "initialize", tp.extract(&bytes) })) {
|
||||
try self.send_request(from, "initialize", bytes);
|
||||
} else if (try cbor.match(m.buf, .{ "REQ", tp.extract(&method), tp.extract(&bytes) })) {
|
||||
switch (self.state) {
|
||||
.init => try self.append_init_queue(from, method, bytes, .request), //queue requests
|
||||
.running => try self.send_request(from, method, bytes),
|
||||
}
|
||||
if (try cbor.match(m.buf, .{ "REQ", tp.extract(&method), tp.extract(&bytes) })) {
|
||||
try self.send_request(from, method, bytes);
|
||||
} else if (try cbor.match(m.buf, .{ "RSP", tp.extract_cbor(&cbor_id), tp.extract_cbor(&bytes) })) {
|
||||
try self.send_response(cbor_id, bytes);
|
||||
} else if (try cbor.match(m.buf, .{ "NTFY", "initialized", tp.extract(&bytes) })) {
|
||||
self.state = .running;
|
||||
try self.send_notification("initialized", bytes);
|
||||
try self.replay_init_queue();
|
||||
} else if (try cbor.match(m.buf, .{ "NTFY", tp.extract(&method), tp.extract(&bytes) })) {
|
||||
switch (self.state) {
|
||||
.init => try self.append_init_queue(from, method, bytes, .notify), //queue requests
|
||||
.running => try self.send_notification(method, bytes),
|
||||
}
|
||||
try self.send_notification(method, bytes);
|
||||
} else if (try cbor.match(m.buf, .{"close"})) {
|
||||
self.write_log("### LSP close ###\n", .{});
|
||||
try self.close();
|
||||
|
@ -282,43 +265,6 @@ const Process = struct {
|
|||
}
|
||||
}
|
||||
|
||||
fn append_init_queue(self: *Process, from: tp.pid_ref, method: []const u8, bytes: []const u8, type_: InitQueueType) !void {
|
||||
const queue = if (self.init_queue) |*queue| queue else blk: {
|
||||
self.init_queue = .empty;
|
||||
break :blk &self.init_queue.?;
|
||||
};
|
||||
const p = try queue.addOne(self.allocator);
|
||||
p.* = .{
|
||||
from.clone(),
|
||||
try self.allocator.dupe(u8, method),
|
||||
try self.allocator.dupe(u8, bytes),
|
||||
type_,
|
||||
};
|
||||
}
|
||||
|
||||
fn replay_init_queue(self: *Process) !void {
|
||||
defer self.free_init_queue();
|
||||
if (self.init_queue) |*queue| {
|
||||
for (queue.items) |*p|
|
||||
switch (p[3]) {
|
||||
.request => try self.send_request(p[0].ref(), p[1], p[2]),
|
||||
.notify => try self.send_notification(p[1], p[2]),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn free_init_queue(self: *Process) void {
|
||||
if (self.init_queue) |*queue| {
|
||||
for (queue.items) |*p| {
|
||||
p[0].deinit();
|
||||
self.allocator.free(p[1]);
|
||||
self.allocator.free(p[2]);
|
||||
}
|
||||
queue.deinit(self.allocator);
|
||||
}
|
||||
self.init_queue = null;
|
||||
}
|
||||
|
||||
fn receive_lsp_message(self: *Process, cb: []const u8) Error!void {
|
||||
var iter = cb;
|
||||
|
||||
|
|
|
@ -116,7 +116,6 @@
|
|||
["0", "move_begin"],
|
||||
["^", "smart_move_begin"],
|
||||
["$", "move_end"],
|
||||
[":", "open_command_palette"],
|
||||
|
||||
["p", ["paste_internal_vim"], ["enter_mode", "normal"]],
|
||||
["P", ["paste_internal_vim"], ["enter_mode", "normal"]],
|
||||
|
@ -154,7 +153,6 @@
|
|||
["0", "move_begin"],
|
||||
["^", "smart_move_begin"],
|
||||
["$", "move_end"],
|
||||
[":", "open_command_palette"],
|
||||
|
||||
["p", ["paste_internal_vim"], ["enter_mode", "normal"]],
|
||||
["P", ["paste_internal_vim"], ["enter_mode", "normal"]],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue