Fix plugin directory resolution for plugin managers
Use resolve() to properly handle symbolic links when determining the plugin installation directory. Add fallback to search in &runtimepath if the licenses directory is not found in the primary location. This fixes issues when the plugin is installed via plugin managers like vim-plug, packer.nvim, lazy.nvim, etc., where the plugin directory may not be directly relative to the working directory. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
+22
-2
@@ -86,9 +86,19 @@ function! s:GetCommentStyle(filetype) abort
|
||||
endfunction
|
||||
|
||||
function! s:AddLicenseHeader(license) abort
|
||||
let plugin_dir = fnamemodify(expand('<sfile>'), ':h:h')
|
||||
let plugin_dir = fnamemodify(resolve(expand('<sfile>')), ':h:h')
|
||||
let license_file = plugin_dir . '/licenses/' . a:license . '.txt'
|
||||
|
||||
if !filereadable(license_file)
|
||||
for runtime_path in split(&runtimepath, ',')
|
||||
let alt_license_file = runtime_path . '/licenses/' . a:license . '.txt'
|
||||
if filereadable(alt_license_file)
|
||||
let license_file = alt_license_file
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
|
||||
if !filereadable(license_file)
|
||||
echohl ErrorMsg
|
||||
echo 'License file not found: ' . license_file
|
||||
@@ -131,9 +141,19 @@ function! s:AddLicenseHeader(license) abort
|
||||
endfunction
|
||||
|
||||
function! s:CompleteFiletype(A, L, P) abort
|
||||
let plugin_dir = fnamemodify(expand('<sfile>'), ':h:h')
|
||||
let plugin_dir = fnamemodify(resolve(expand('<sfile>')), ':h:h')
|
||||
let licenses_dir = plugin_dir . '/licenses/'
|
||||
|
||||
if !isdirectory(licenses_dir)
|
||||
for runtime_path in split(&runtimepath, ',')
|
||||
let alt_licenses_dir = runtime_path . '/licenses/'
|
||||
if isdirectory(alt_licenses_dir)
|
||||
let licenses_dir = alt_licenses_dir
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
|
||||
if !isdirectory(licenses_dir)
|
||||
return []
|
||||
endif
|
||||
|
||||
Reference in New Issue
Block a user