Skip to content

Commit 2c5fd59

Browse files
committed
feat(plugin browse): support go,gomod,gosum
1 parent 0240fa5 commit 2c5fd59

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

autoload/aceforeverd/keymap/browse.vim

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
let g:browse_fmt_pattern = {
2+
\ 'go': 'https://pkg.go.dev/%s',
3+
\ 'gomod': 'https://%s',
4+
\ 'gosum': 'https://%s',
5+
\ '*': 'https://github.com/%s',
6+
\ }
17

28
function! aceforeverd#keymap#browse#try_open() abort
39
let l:uri_list = aceforeverd#keymap#browse#get_uri()
@@ -17,8 +23,14 @@ function! aceforeverd#keymap#browse#get_uri() abort
1723
return []
1824
endif
1925

26+
let l:fmt = get(g:browse_fmt_pattern, &filetype, get(g:browse_fmt_pattern, '*', ''))
27+
if l:fmt == ''
28+
echomsg 'no fmt patern specified for filetype ' . &filetype
29+
return []
30+
endif
31+
2032
let l:matched_list = []
21-
call substitute(getline('.'), l:pattern, '\=add(l:matched_list, submatch(0))', 'g')
33+
call substitute(getline('.'), l:pattern, '\=add(l:matched_list, printf(l:fmt, submatch(0)))', 'g')
2234
return l:matched_list
2335
endfunction
2436

@@ -30,7 +42,7 @@ function! aceforeverd#keymap#browse#open(uris) abort
3042
endif
3143

3244
if type(a:uris) == v:t_string
33-
call aceforeverd#keymap#browse#open_uri('https://github.com/' .. a:uris)
45+
call aceforeverd#keymap#browse#open_uri(a:uris)
3446
elseif len(a:uris) == 1
3547
call aceforeverd#keymap#browse#open(a:uris[0])
3648
else

autoload/aceforeverd/keymap/essential.vim

+7
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ function! aceforeverd#keymap#essential#setup() abort
6161
autocmd!
6262
autocmd FileType vim,lua,tmux let b:uri_pattern = '[''"]\zs[^''"/ ]\+\/[^''"/ ]\+\ze[''"]'
6363
autocmd FileType yaml let b:uri_pattern = 'uses:\s\+\zs[^@]\+\/[^@]\+\ze'
64+
65+
" ^domain/sub[/sub ...]
66+
" since we want remove the optional version suffix (v\d+) in the url, it's important to use '{-}' to match subpath as few as possible,
67+
" then the suffix removed selection (if exists) if preferred in regex engine
68+
autocmd FileType gosum let b:uri_pattern = '\v^\zs[[:alnum:]_-]+(\.([[:alnum:]_-])+)+(\/[[:alnum:]_\.-]+){-}(\ze\/v\d+|\ze)\s+v.*'
69+
autocmd FileType gomod let b:uri_pattern = '\v\zs[[:alnum:]_-]+(\.([[:alnum:]_-])+)+(\/[[:alnum:]_\.-]+){-}(\ze\/v\d+|\ze)\s+v.*'
70+
autocmd FileType go let b:uri_pattern = '\v"\zs([[:alnum:]\._-]+)(\/([[:alnum:]\._-])+)*\ze"'
6471
augroup END
6572

6673
nnoremap <silent> zS :<c-u>call aceforeverd#util#syn_query()<cr>

lua/aceforeverd/keymap/plugin_browse.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ function M.select_browse_plugin(plugin_list)
1919
vim.ui.select(plugin_list, {
2020
prompt = 'select a plugin',
2121
format_item = function(item)
22-
return 'https://github.com/' .. item
22+
return item
2323
end,
2424
}, function(choice)
2525
if choice ~= nil then
26-
vim.api.nvim_call_function('plugin_browse#open', { choice })
26+
vim.api.nvim_call_function('aceforeverd#keymap#browse#open', { choice })
2727
end
2828
end)
2929
end

0 commit comments

Comments
 (0)