diff --git a/.nvim.lua b/.nvim.lua index fe7f2610..9982de80 100644 --- a/.nvim.lua +++ b/.nvim.lua @@ -4,59 +4,63 @@ local cwd = vim.fn.getcwd() -- Load the local config file if it exists local f, err = loadfile(".nvim.local.lua") if not err then - local ok, err_f = pcall(f) - if not ok then - vim.print(err_f) - end + local ok, err_f = pcall(f) + if not ok then + vim.print(err_f) + end else - vim.lsp.config("zls", { - cmd = { cwd .. "/tools/zls.sh" }, - }) - vim.lsp.enable("zls") + vim.lsp.config("zls", { + cmd = { cwd .. "/tools/zls.sh" }, + }) + vim.lsp.enable("zls") - function runFixAll() - local bufnr = vim.api.nvim_get_current_buf() - for _, client in ipairs(vim.lsp.get_clients({ bufnr = bufnr, name = "zls" })) do - -- Request each action after applying the previous action's edits. - for _, kind in ipairs({ "source.fixAll", "source.organizeImports" }) do - local params = vim.lsp.util.make_range_params(0, client.offset_encoding) - params.context = { only = { kind }, diagnostics = {} } - local response = client:request_sync("textDocument/codeAction", params, 2000, bufnr) - if response and not response.err then - for _, action in ipairs(response.result or {}) do - if action.edit then - vim.lsp.util.apply_workspace_edit(action.edit, client.offset_encoding) - end - if action.command then - client:exec_cmd(type(action.command) == "table" and action.command or action, - { bufnr = bufnr }) - end - end - end - end - end - end + function runFixAll() + local params = vim.lsp.util.make_range_params() + params.context = { + only = { "source.fixAll" }, + diagnostics = {}, + } - vim.api.nvim_create_autocmd("BufWritePre", { - pattern = { "*.zig", "*.zon" }, - callback = runFixAll, - }) + -- Send synchronous request (timeout 2 seconds) + local responses = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, 1000) + if not responses then + return + end - local ok, conform = pcall(require, "conform") + for _, resp in pairs(responses) do + for _, action in ipairs(resp.result or {}) do + -- If action has edits, apply them + if action.edit then + vim.lsp.util.apply_workspace_edit(action.edit, "utf-16") + end + -- If the action has a command, execute it + if action.command then + vim.lsp.buf.execute_command(action.command) + end + end + end + end - if ok then - conform.formatters_by_ft.bzl = { "buildifier" } - conform.formatters.buildifier = { - command = cwd .. "/tools/buildifier.sh", - } + vim.api.nvim_create_autocmd("BufWritePre", { + pattern = { "*.zig", "*.zon" }, + callback = runFixAll, + }) - vim.api.nvim_create_autocmd("FileType", { - pattern = "bzl", - callback = function() - vim.keymap.set("n", "f", function() - conform.format() - end, { remap = false, silent = true }) - end, - }) - end + local ok, conform = pcall(require, "conform") + + if ok then + conform.formatters_by_ft.bzl = { "buildifier" } + conform.formatters.buildifier = { + command = cwd .. "/tools/buildifier.sh", + } + + vim.api.nvim_create_autocmd("FileType", { + pattern = "bzl", + callback = function() + vim.keymap.set("n", "f", function() + conform.format() + end, { remap = false, silent = true }) + end, + }) + end end diff --git a/zml/tensor.zig b/zml/tensor.zig index a09a5d38..ee084835 100644 --- a/zml/tensor.zig +++ b/zml/tensor.zig @@ -282,7 +282,13 @@ pub const Tensor = struct { pub fn toMemory(self: Tensor, kind: Memory.Kind) Tensor { const ctx = Compiler.current(); switch (ctx.platform.target) { - .cpu, .neuron, .metal => return self, + .cpu, .neuron, .metal => { + // A single memory needs no copy, but the result must still be a distinct + // tensor: `reuseBuffer` donations are keyed by tensor id. + var res = _result(self._shape, self.value()); + res._shape._sharding = self._shape._sharding; + return res; + }, .cuda, .rocm, .tpu, .oneapi, .furiosa => {}, }