Check if .vim directory exists before use

Update `build#dir()` to check for the existence of the `.vim` directory
containing `coc_settings.json` before attempting to read the file. If it
doesn't exist then create it.
This commit is contained in:
Kenneth Benzie 2021-02-03 22:47:16 +00:00
parent bf6deaf1ed
commit eb1a4a71d8

View File

@ -37,8 +37,12 @@ function! build#dir(...) abort
if exists('l:dir')
" Set build directory and restart YouCompleteMe.
let $BUILD_DIR = getcwd().'/'.substitute(l:dir, '\/$', '', '')
" TODO: Check .vim/coc-settings.json exists, create it if not
let l:coc_settings = json_decode(join(readfile('.vim/coc-settings.json'), ''))
let l:coc_settings = {}
if isdirectory('.vim')
let l:coc_settings = json_decode(join(readfile('.vim/coc-settings.json'), ''))
else
call mkdir('.vim')
endif
let l:coc_settings['clangd.compilationDatabasePath'] = $BUILD_DIR
let l:coc_settings['cmake.lsp.buildDirectory'] = $BUILD_DIR
call writefile([json_encode(l:coc_settings)], '.vim/coc-settings.json')