From 61de7c3ebbe1eb478140cf24841fb606f2fa51f9 Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Mon, 22 Jan 2024 19:33:29 -0800 Subject: [PATCH] Handle inline table format in workspace search Fix issue where search would fail to find workspace Cargo.toml if the workspace table was specified with inline format. --- autoload/cargo.vim | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/autoload/cargo.vim b/autoload/cargo.vim index a95a57f9..1e292554 100644 --- a/autoload/cargo.vim +++ b/autoload/cargo.vim @@ -39,10 +39,41 @@ function! cargo#nearestCargo(is_getcwd) abort endfunction function! cargo#nearestWorkspaceCargo(is_getcwd) abort + " Workspaces can be defined by two formats: + " Inline tables: + " + " workspace = { resolver = "2", members = [ "subcrate1", "subcrate2" ] } + " + " Normal tables + " + " [workspace] + " resolver = "2" + " members = [ "subcrate1", "subcrate2" ] + " + " We must take care in parsing the inline tables. It is only a valid + " workspace config if it's in the top level of the config. We don't want + " to accidentally capture entries named 'workspace' inside tables, for + " example: + " + " [dependencies] + " workspace = "0.4.2" let l:nearest = s:nearest_cargo(a:is_getcwd) while l:nearest !=# '' + let l:top_level_config = 1 for l:line in readfile(l:nearest, '', 0x100) + if l:line =~# '^\s*[' + " Found some table definition, we're no longer parsing the top + " level config + let l:top_level_config = 0 + endif + if l:line =~# '\s*workspace\s*=' + if l:top_level_config + " workspace using inline table format + return l:nearest + endif + endif if l:line =~# '\V[workspace]' + " workspace using normal table format return l:nearest endif endfor