Skip to content

Commit 85e8dc2

Browse files
authored
Read the config file specified in the docs (#18)
* Read the config file specified in the docs Also support the config file we used to read, in case people have figured it out and are using the name that was previously used by the code * Add missing update and declaration for legacyConfigFilePath
1 parent fcff50e commit 85e8dc2

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

autoload/nodeinspect/config.vim

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
let s:configFileName = 'vim-node-config.json'
1+
let s:configFileName = 'vim-node-inspect.json'
2+
let s:legacyConfigFileName = 'vim-node-config.json'
23

34
function! s:removeSessionKeys(session,...)
45
for uvar in a:000
@@ -34,20 +35,32 @@ function! s:ReplaceMacros(str)
3435
return replaced
3536
endfunction
3637

38+
function s:getReadableConfigFile(path)
39+
let configFilePath = a:path . '/' . s:configFileName
40+
if filereadable(configFilePath)
41+
return configFilePath
42+
endif
43+
let legacyConfigFilePath = a:path . '/' . s:legacyConfigFileName
44+
if filereadable(legacyConfigFilePath)
45+
return legacyConfigFilePath
46+
endif
47+
return v:false
48+
endfunction
49+
3750
" find the config file path. if its not in the currend working directory, try
3851
" going up from the current buffer directory. Returns the directory or empty
3952
" string if failed to find the config file.
4053
function s:GetConfigFilePath()
41-
let configFilePath = getcwd() . '/' . s:configFileName
42-
if filereadable(configFilePath)
54+
let configFilePath = s:getReadableConfigFile(getcwd())
55+
if configFilePath
4356
return configFilePath
4457
endif
4558
" if the file is not found in pwd and the script is a decedant, try going up
4659
let expandString = '%:p:h'
4760
let traverseDir = expand(expandString)
4861
while stridx(traverseDir, getcwd()) != -1
49-
let configFilePath = traverseDir . '/' . s:configFileName
50-
if filereadable(configFilePath)
62+
let configFilePath = s:getReadableConfigFile(traverseDir)
63+
if configFilePath
5164
return configFilePath
5265
endif
5366
let expandString = expandString . ':h'

0 commit comments

Comments
 (0)