Respond to shutdown request
This commit is contained in:
parent
8beedb0384
commit
20ec7470bb
@ -1510,6 +1510,7 @@ pub const DocumentScope = struct {
|
|||||||
for (self.scopes) |scope| {
|
for (self.scopes) |scope| {
|
||||||
scope.decls.deinit();
|
scope.decls.deinit();
|
||||||
allocator.free(scope.uses);
|
allocator.free(scope.uses);
|
||||||
|
allocator.free(scope.tests);
|
||||||
}
|
}
|
||||||
allocator.free(self.scopes);
|
allocator.free(self.scopes);
|
||||||
}
|
}
|
||||||
|
@ -629,6 +629,7 @@ fn stdUriFromLibPath(allocator: *std.mem.Allocator, zig_lib_path: ?[]const u8) !
|
|||||||
pub fn deinit(self: *DocumentStore) void {
|
pub fn deinit(self: *DocumentStore) void {
|
||||||
var entry_iterator = self.handles.iterator();
|
var entry_iterator = self.handles.iterator();
|
||||||
while (entry_iterator.next()) |entry| {
|
while (entry_iterator.next()) |entry| {
|
||||||
|
entry.value.document_scope.deinit(self.allocator);
|
||||||
self.allocator.free(entry.value.document.mem);
|
self.allocator.free(entry.value.document.mem);
|
||||||
|
|
||||||
for (entry.value.import_uris.items) |uri| {
|
for (entry.value.import_uris.items) |uri| {
|
||||||
@ -638,8 +639,6 @@ pub fn deinit(self: *DocumentStore) void {
|
|||||||
entry.value.import_uris.deinit();
|
entry.value.import_uris.deinit();
|
||||||
self.allocator.free(entry.key);
|
self.allocator.free(entry.key);
|
||||||
self.allocator.destroy(entry.value);
|
self.allocator.destroy(entry.value);
|
||||||
|
|
||||||
entry.value.document_scope.deinit(self.allocator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.handles.deinit();
|
self.handles.deinit();
|
||||||
|
19
src/main.zig
19
src/main.zig
@ -839,7 +839,9 @@ fn configFromUriOr(uri: []const u8, default: Config) Config {
|
|||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn processJsonRpc(parser: *std.json.Parser, json: []const u8, config: Config) !void {
|
// TODO Rewrite this, use a ComptimeStringMap that points to a fn pointer + Param type to decode into and pass to the function
|
||||||
|
// Split into multiple files?
|
||||||
|
fn processJsonRpc(parser: *std.json.Parser, json: []const u8, config: Config, keep_running: *bool) !void {
|
||||||
var tree = try parser.parse(json);
|
var tree = try parser.parse(json);
|
||||||
defer tree.deinit();
|
defer tree.deinit();
|
||||||
|
|
||||||
@ -920,6 +922,10 @@ fn processJsonRpc(parser: *std.json.Parser, json: []const u8, config: Config) !v
|
|||||||
|
|
||||||
std.debug.warn("{}\n", .{client_capabilities});
|
std.debug.warn("{}\n", .{client_capabilities});
|
||||||
try respondGeneric(id, initialize_response);
|
try respondGeneric(id, initialize_response);
|
||||||
|
} else if (std.mem.eql(u8, method, "shutdown")) {
|
||||||
|
keep_running.* = false;
|
||||||
|
// Technically we shoudl deinitialize first and send possible errors to the client
|
||||||
|
try respondGeneric(id, null_result_response);
|
||||||
} else if (std.mem.eql(u8, method, "initialized")) {
|
} else if (std.mem.eql(u8, method, "initialized")) {
|
||||||
// All gucci
|
// All gucci
|
||||||
} else if (std.mem.eql(u8, method, "$/cancelRequest")) {
|
} else if (std.mem.eql(u8, method, "$/cancelRequest")) {
|
||||||
@ -1240,6 +1246,11 @@ pub fn main() anyerror!void {
|
|||||||
allocator = &debug_alloc_state.allocator;
|
allocator = &debug_alloc_state.allocator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer if (debug_alloc) |dbg| {
|
||||||
|
std.debug.warn("Finished cleanup, last allocation info.\n", .{});
|
||||||
|
std.debug.warn("{}\n", .{dbg.info});
|
||||||
|
};
|
||||||
|
|
||||||
// Init global vars
|
// Init global vars
|
||||||
const in_stream = std.io.getStdIn().inStream();
|
const in_stream = std.io.getStdIn().inStream();
|
||||||
stdout = std.io.bufferedOutStream(std.io.getStdOut().outStream());
|
stdout = std.io.bufferedOutStream(std.io.getStdOut().outStream());
|
||||||
@ -1271,7 +1282,6 @@ pub fn main() anyerror!void {
|
|||||||
|
|
||||||
// Find the zig executable in PATH
|
// Find the zig executable in PATH
|
||||||
var zig_exe_path: ?[]const u8 = null;
|
var zig_exe_path: ?[]const u8 = null;
|
||||||
defer if (zig_exe_path) |exe_path| allocator.free(exe_path);
|
|
||||||
|
|
||||||
find_zig: {
|
find_zig: {
|
||||||
if (config.zig_exe_path) |exe_path| {
|
if (config.zig_exe_path) |exe_path| {
|
||||||
@ -1343,7 +1353,8 @@ pub fn main() anyerror!void {
|
|||||||
var json_parser = std.json.Parser.init(allocator, false);
|
var json_parser = std.json.Parser.init(allocator, false);
|
||||||
defer json_parser.deinit();
|
defer json_parser.deinit();
|
||||||
|
|
||||||
while (true) {
|
var keep_running = true;
|
||||||
|
while (keep_running) {
|
||||||
const headers = readRequestHeader(allocator, in_stream) catch |err| {
|
const headers = readRequestHeader(allocator, in_stream) catch |err| {
|
||||||
std.debug.warn("{}; exiting!", .{@errorName(err)});
|
std.debug.warn("{}; exiting!", .{@errorName(err)});
|
||||||
return;
|
return;
|
||||||
@ -1352,7 +1363,7 @@ pub fn main() anyerror!void {
|
|||||||
const buf = try allocator.alloc(u8, headers.content_length);
|
const buf = try allocator.alloc(u8, headers.content_length);
|
||||||
defer allocator.free(buf);
|
defer allocator.free(buf);
|
||||||
try in_stream.readNoEof(buf);
|
try in_stream.readNoEof(buf);
|
||||||
try processJsonRpc(&json_parser, buf, config);
|
try processJsonRpc(&json_parser, buf, config, &keep_running);
|
||||||
json_parser.reset();
|
json_parser.reset();
|
||||||
|
|
||||||
if (debug_alloc) |dbg| {
|
if (debug_alloc) |dbg| {
|
||||||
|
Loading…
Reference in New Issue
Block a user