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:
2026-07-10 16:45:42 +02:00
parent 82a8f01fe1
commit 1ec3b5492f
+22 -2
View File
@@ -86,9 +86,19 @@ function! s:GetCommentStyle(filetype) abort
endfunction endfunction
function! s:AddLicenseHeader(license) abort 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' 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) if !filereadable(license_file)
echohl ErrorMsg echohl ErrorMsg
echo 'License file not found: ' . license_file echo 'License file not found: ' . license_file
@@ -131,9 +141,19 @@ function! s:AddLicenseHeader(license) abort
endfunction endfunction
function! s:CompleteFiletype(A, L, P) abort 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/' 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) if !isdirectory(licenses_dir)
return [] return []
endif endif