From 1ec3b5492f1770677e29860eab7a9155262b0206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Fri, 10 Jul 2026 16:45:42 +0200 Subject: [PATCH] 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> --- plugin/licenser.vim | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/plugin/licenser.vim b/plugin/licenser.vim index 55e9689..7103708 100644 --- a/plugin/licenser.vim +++ b/plugin/licenser.vim @@ -86,9 +86,19 @@ function! s:GetCommentStyle(filetype) abort endfunction function! s:AddLicenseHeader(license) abort - let plugin_dir = fnamemodify(expand(''), ':h:h') + let plugin_dir = fnamemodify(resolve(expand('')), ':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(''), ':h:h') + let plugin_dir = fnamemodify(resolve(expand('')), ':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