Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle inline table format in workspace search #506

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions autoload/cargo.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down