Skip to content

Make it possible to extend code path with configurable wildcard #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion autoload/erlang_complete.erl
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ parse_args(["--basedir", BaseDir|OtherArgs], Acc) ->
parse_args(["--basedir"], _Acc) ->
log_error("Argument needed after '--basedir'.~n", []),
halt(2);
parse_args(["--extend-code-path-wildcard", BaseDir|OtherArgs], Acc) ->
put(extend_code_path_wildcard, BaseDir),
parse_args(OtherArgs, Acc);
parse_args(["--extend-code-path-wildcard"], _Acc) ->
log_error("Argument needed after '--extend-code-path-wildcard'.~n", []),
halt(2);
parse_args(["--"|PosPars], Acc) ->
PosPars ++ Acc;
parse_args([[$-|_] = Arg|_], _Acc) ->
Expand Down Expand Up @@ -295,9 +301,19 @@ load_build_info(Path) ->
% same as AppRoot).
ProjectRoot = get_project_root(BuildSystem, BuildFiles, AppRoot),
BuildSystemOpts = load_build_files(BuildSystem, ProjectRoot, BuildFiles),

add_code_paths(),
{AppRoot, ProjectRoot, BuildSystemOpts}.

add_code_paths() ->
case get(extend_code_path_wildcard) of
undefined ->
ok;
"" ->
ok;
Wildcard ->
code:add_pathsa(filelib:wildcard(Wildcard))
end.

%%------------------------------------------------------------------------------
%% @doc Traverse the directory structure upwards until is_app_root matches.
%% @end
Expand Down
10 changes: 8 additions & 2 deletions autoload/erlang_complete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
" Contributors: kTT (http://github.com/kTT)
" Ricardo Catalinas Jiménez <[email protected]>
" Eduardo Lopez (http://github.com/tapichu)
" Kjell Winblad (https://dupwin.se)
" License: Vim license

" Completion program path
Expand Down Expand Up @@ -47,6 +48,9 @@ if !exists('g:erlang_completion_extend_arity')
let g:erlang_completion_extend_arity = 1
end

if !exists('g:erlang_completion_extend_code_path_wildcard')
let g:erlang_completion_extend_code_path_wildcard = ""
end
" Modules cache used to speed up the completion.
"
" This dictionary contains completion items that represent functions exported
Expand Down Expand Up @@ -415,7 +419,8 @@ function s:ErlangFindExternalFunc(module, base)
let compl_words = []
let output = system('escript ' . fnameescape(s:erlang_complete_file) .
\' list-functions ' . fnameescape(a:module) .
\' --basedir ' . fnameescape(expand('%:p:h')))
\' --basedir ' . fnameescape(expand('%:p:h')) .
\' --extend-code-path-wildcard ' . fnameescape(g:erlang_completion_extend_code_path_wildcard))
let output_lines = split(output, '\n')

" There are two possibilities:
Expand Down Expand Up @@ -546,7 +551,8 @@ function s:ErlangFindLocalFunc(base)
" Find modules that start with `base`.
let modules = system('escript ' . fnameescape(s:erlang_complete_file) .
\' list-modules ' .
\' --basedir ' . fnameescape(expand('%:p:h')))
\' --basedir ' . fnameescape(expand('%:p:h')) .
\' --extend-code-path-wildcard ' . fnameescape(g:erlang_completion_extend_code_path_wildcard))
for module in split(modules, '\n')
if module =~# base
let compl_item = s:CreateComplItem('module', module)
Expand Down
15 changes: 14 additions & 1 deletion doc/vim-erlang-omnicomplete.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ g:erlang_completion_nonzero_arity_paren

list_to_atom(
<
g:erlang_completion_extend_arity g:erlang_completion_extend_arity
g:erlang_completion_extend_arity *g:erlang_completion_extend_arity*
Determines how to display functions where only the arity is known.

a. If set to `0`, such functions will be displayed with their arity,
Expand All @@ -156,6 +156,19 @@ g:erlang_completion_extend_arity g:erlang_completion_extend_arity

< The default value is `1`.

*g:erlang_completion_extend_code_path_wildcard*
g:erlang_completion_extend_code_path_wildcard
Specifies a wildcard to be used to extend the code path
list that is used when searching for modules. All directories that
matches the wildcard will be added to the code path list. See the
documentation of the Erlang function `filelib:wildcard/1` for the
syntax of wildcards. This option is useful when you have a
non-standard directory structure for your Erlang projects.

Example:

`let g:erlang_completion_extend_code_path_wildcard = './_build/*/lib/*/ebin'`

==============================================================================
CONFIGURATION REBAR3 *vim-erlang-omnicomplete-config-rebar3*

Expand Down