@@ -73,7 +73,7 @@ local find_nix_fmt = function(opts, done)
73
73
74
74
local eval_nix_formatter = [[
75
75
let
76
- currentSystem = "]] .. nix_current_system .. [[ ";
76
+ system = "]] .. nix_current_system .. [[ ";
77
77
# Various functions vendored from nixpkgs lib (to avoid adding a
78
78
# dependency on nixpkgs).
79
79
lib = rec {
@@ -89,15 +89,17 @@ local find_nix_fmt = function(opts, done)
89
89
};
90
90
in
91
91
formatterBySystem:
92
- if formatterBySystem ? ${currentSystem} then
93
- let
94
- formatter = formatterBySystem.${currentSystem};
95
- drv = formatter.drvPath;
96
- bin = lib.getExe formatter;
97
- in
98
- drv + "\n" + bin + "\n"
99
- else
100
- ""
92
+ builtins.toJSON (
93
+ if formatterBySystem ? ${system} then
94
+ let
95
+ formatter = formatterBySystem.${system};
96
+ drv = formatter.drvPath;
97
+ bin = lib.getExe formatter;
98
+ in
99
+ { inherit drv bin; }
100
+ else
101
+ { error = "this flake does not define a formatter for system: ${system}"; }
102
+ )
101
103
]]
102
104
103
105
client .send_progress_notification (NOTIFICATION_TOKEN , {
@@ -128,19 +130,18 @@ local find_nix_fmt = function(opts, done)
128
130
return
129
131
end
130
132
131
- if # stdout_lines == 0 then
133
+ local stdout = table.concat (stdout_lines , " \n " )
134
+ local result = vim .json .decode (stdout )
135
+
136
+ if result .error ~= nil then
132
137
vim .defer_fn (function ()
133
- log :warn (
134
- string.format (" this flake does not define a formatter for your system: %s" , nix_current_system )
135
- )
138
+ log :warn (result .error )
136
139
end , 0 )
137
140
return
138
141
end
139
142
140
- -- stdout has 2 lines of output:
141
- -- 1. drv path
142
- -- 2. exe path
143
- local drv_path , nix_fmt_path = unpack (stdout_lines )
143
+ local drv_path = result .drv
144
+ local nix_fmt_path = result .bin
144
145
return drv_path , nix_fmt_path
145
146
end
146
147
0 commit comments