@@ -127,21 +127,21 @@ function cargo.get_config_root_dir(config, file_name, callback)
127
127
end
128
128
end
129
129
130
- --- @param buf_name ? string
131
- --- @return string edition
132
- function cargo .get_rustc_edition (buf_name )
130
+ --- @param callback fun ( edition : string )
131
+ function cargo .get_rustc_edition (callback )
133
132
local config = require (' rustaceanvim.config.internal' )
134
- buf_name = buf_name or vim .api .nvim_buf_get_name (0 )
133
+ local buf_name = vim .api .nvim_buf_get_name (0 )
135
134
local path = vim .fs .dirname (buf_name )
136
- local _ , cargo_metadata = get_cargo_metadata (path )
137
- local default_edition = config .tools .rustc .default_edition
138
- if not cargo_metadata then
139
- return default_edition
140
- end
141
- local package = vim .iter (cargo_metadata .packages or {}):find (function (pkg )
142
- return type (pkg .edition ) == ' string'
135
+ get_cargo_metadata (path , function (_ , cargo_metadata )
136
+ local default_edition = config .tools .rustc .default_edition
137
+ if not cargo_metadata then
138
+ return callback (default_edition )
139
+ end
140
+ local pkg = vim .iter (cargo_metadata .packages or {}):find (function (p )
141
+ return type (p .edition ) == ' string'
142
+ end )
143
+ return callback (pkg and pkg .edition or default_edition )
143
144
end )
144
- return package and package .edition or default_edition
145
145
end
146
146
147
147
return cargo
0 commit comments