From eb1a4a71d8a8c831bdac102f38b76486f51ecaca Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Wed, 3 Feb 2021 22:47:16 +0000 Subject: [PATCH] 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. --- autoload/build.vim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/autoload/build.vim b/autoload/build.vim index b449caf..a389436 100644 --- a/autoload/build.vim +++ b/autoload/build.vim @@ -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')