From 54e7d1da8b6beb5d37a2a04abb6a77bd8c60b10f Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Sat, 7 Jan 2023 20:21:20 +0000 Subject: [PATCH] fix compile errors when targeting wasm (#886) * fix compile errors when targeting wasm * update known-folders --- src/DocumentStore.zig | 10 +++++++--- src/Server.zig | 16 +++++++++++----- src/configuration.zig | 1 + src/known-folders | 2 +- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/DocumentStore.zig b/src/DocumentStore.zig index 318bd1a..4f1f04f 100644 --- a/src/DocumentStore.zig +++ b/src/DocumentStore.zig @@ -224,7 +224,7 @@ pub fn applySave(self: *DocumentStore, handle: *const Handle) !void { const tracy_zone = tracy.trace(@src()); defer tracy_zone.end(); - if (isBuildFile(handle.uri)) { + if (std.process.can_spawn and isBuildFile(handle.uri)) { const build_file = self.build_files.getPtr(handle.uri).?; const build_config = loadBuildConfiguration(self.allocator, build_file.*, self.config.*) catch |err| { @@ -647,7 +647,9 @@ fn createDocument(self: *DocumentStore, uri: Uri, text: [:0]u8, open: bool) erro handle.import_uris = try self.collectImportUris(handle); handle.cimports = try self.collectCIncludes(handle); - if (self.config.zig_exe_path != null and isBuildFile(handle.uri) and !isInStd(handle.uri)) { + if (!std.process.can_spawn or self.config.zig_exe_path == null) return handle; + + if (isBuildFile(handle.uri) and !isInStd(handle.uri)) { const gop = try self.build_files.getOrPut(self.allocator, uri); errdefer |err| { self.build_files.swapRemoveAt(gop.index); @@ -658,7 +660,7 @@ fn createDocument(self: *DocumentStore, uri: Uri, text: [:0]u8, open: bool) erro gop.value_ptr.* = try self.createBuildFile(duped_uri); gop.key_ptr.* = gop.value_ptr.uri; } - } else if (self.config.zig_exe_path != null and !isBuiltinFile(handle.uri) and !isInStd(handle.uri)) blk: { + } else if (!isBuiltinFile(handle.uri) and !isInStd(handle.uri)) blk: { // log.debug("Going to walk down the tree towards: {s}", .{uri}); // walk down the tree towards the uri. When we hit build.zig files @@ -831,6 +833,8 @@ pub fn resolveCImport(self: *DocumentStore, handle: Handle, node: Ast.Node.Index const tracy_zone = tracy.trace(@src()); defer tracy_zone.end(); + if (!std.process.can_spawn) return null; + const index = std.mem.indexOfScalar(Ast.Node.Index, handle.cimports.items(.node), node).?; const hash: Hash = handle.cimports.items(.hash)[index]; diff --git a/src/Server.zig b/src/Server.zig index 6cd02b3..728f4f5 100644 --- a/src/Server.zig +++ b/src/Server.zig @@ -1712,6 +1712,7 @@ fn initializeHandler(server: *Server, request: types.InitializeParams) Error!typ server.status = .initializing; if (server.config.zig_exe_path) |exe_path| blk: { + if (!std.process.can_spawn) break :blk; // TODO avoid having to call getZigEnv twice // once in init and here const env = configuration.getZigEnv(server.allocator, exe_path) orelse break :blk; @@ -1962,7 +1963,8 @@ fn openDocumentHandler(server: *Server, notification: types.DidOpenTextDocumentP const handle = try server.document_store.openDocument(notification.textDocument.uri, notification.textDocument.text); - if (server.client_capabilities.supports_publish_diagnostics) { + if (server.client_capabilities.supports_publish_diagnostics) blk: { + if (!std.process.can_spawn) break :blk; const diagnostics = try server.generateDiagnostics(handle); server.sendNotification("textDocument/publishDiagnostics", diagnostics); } @@ -1978,7 +1980,8 @@ fn changeDocumentHandler(server: *Server, notification: types.DidChangeTextDocum try server.document_store.refreshDocument(handle.uri, new_text); - if (server.client_capabilities.supports_publish_diagnostics) { + if (server.client_capabilities.supports_publish_diagnostics) blk: { + if (!std.process.can_spawn) break :blk; const diagnostics = try server.generateDiagnostics(handle.*); server.sendNotification("textDocument/publishDiagnostics", diagnostics); } @@ -1994,7 +1997,7 @@ fn saveDocumentHandler(server: *Server, notification: types.DidSaveTextDocumentP const handle = server.document_store.getHandle(uri) orelse return; try server.document_store.applySave(handle); - if (server.getAutofixMode() == .on_save) { + if (std.process.can_spawn and server.getAutofixMode() == .on_save) { var text_edits = try server.autofix(allocator, handle); var workspace_edit = types.WorkspaceEdit{ .changes = .{} }; @@ -2028,6 +2031,7 @@ fn willSaveWaitUntilHandler(server: *Server, request: types.WillSaveTextDocument const handle = server.document_store.getHandle(request.textDocument.uri) orelse return null; + if (!std.process.can_spawn) return null; var text_edits = try server.autofix(allocator, handle); return try text_edits.toOwnedSlice(allocator); @@ -2192,7 +2196,8 @@ fn hoverHandler(server: *Server, request: types.HoverParams) Error!?types.Hover }; // TODO: Figure out a better solution for comptime interpreter diags - if (server.client_capabilities.supports_publish_diagnostics) { + if (server.client_capabilities.supports_publish_diagnostics) blk: { + if (!std.process.can_spawn) break :blk; const diagnostics = try server.generateDiagnostics(handle.*); server.sendNotification("textDocument/publishDiagnostics", diagnostics); } @@ -2464,7 +2469,8 @@ fn codeActionHandler(server: *Server, request: types.CodeActionParams) Error!?[] // as of right now, only ast-check errors may get a code action var diagnostics = std.ArrayListUnmanaged(types.Diagnostic){}; - if (server.config.enable_ast_check_diagnostics and handle.tree.errors.len == 0) { + if (server.config.enable_ast_check_diagnostics and handle.tree.errors.len == 0) blk: { + if (!std.process.can_spawn) break :blk; getAstCheckDiagnostics(server, handle.*, &diagnostics) catch |err| { log.err("failed to run ast-check: {}", .{err}); return error.InternalError; diff --git a/src/configuration.zig b/src/configuration.zig index 908b21c..b7f00d3 100644 --- a/src/configuration.zig +++ b/src/configuration.zig @@ -55,6 +55,7 @@ pub fn loadFromFolder(allocator: std.mem.Allocator, folder_path: []const u8) ?Co /// Invoke this once all config values have been changed. pub fn configChanged(config: *Config, allocator: std.mem.Allocator, builtin_creation_dir: ?[]const u8) !void { + if (!std.process.can_spawn) return; // Find the zig executable in PATH find_zig: { if (config.zig_exe_path) |exe_path| { diff --git a/src/known-folders b/src/known-folders index 24845b0..6b37490 160000 --- a/src/known-folders +++ b/src/known-folders @@ -1 +1 @@ -Subproject commit 24845b0103e611c108d6bc334231c464e699742c +Subproject commit 6b37490ac7285133bf09441850b8102c9728a776