juliosueiras / vim-terraform-completion

A (Neo)Vim Autocompletion and linter for Terraform, a HashiCorp tool
MIT License
337 stars 24 forks source link

Have an option to disable module source search #34

Closed saurabh-hirani closed 6 years ago

saurabh-hirani commented 6 years ago

Hi,

vim-terraform-completion is a great plugin. Thank you for creating it.

When using it with terraform modules, as soon as the keyword source is written and a value is provided, the plugin tries to search git repos to give a choice to the user. If the user wants to load a local module or provide a versioned module, omnicomplete slows the user down. To get around it, I have currently commented out the following block in

.vim/bundle/vim-terraform-completion/autoload/terraformcomplete.vim

if getline(".") =~ '\s*source\s*=\s*"'
       for m in terraformcomplete#GetAllRegistryModules()
               if m.word =~ '^' . a:base
                       call add(a:res, m)
               endif
       endfor
       return a:res
endif

It would be useful if there was a flag to disable this search, while keeping the terraform_completion_keys option enabled.

juliosueiras commented 6 years ago

added the option g:terraform_registry_module_completion

saurabh-hirani commented 6 years ago

Thank you very much for the quick around time! This is a very useful feature.

yermulnik commented 3 years ago

Oh my, it took me several days to came across this issue and it literally was almost occasional hit.

Long story short: after installing vim-terraform-completion I found that editing source = lines of non-local Terraform modules throws eval:6: warning: calling URI.open via Kernel#open is deprecated, call URI.open directly or use URI#open error and freezes vim. Based on plenty of experiments I ended up at https://github.com/sparklemotion/nokogiri/issues/2066 which helped me to identify line https://github.com/juliosueiras/vim-terraform-completion/blob/master/autoload/terraformcomplete.vim#L985 as being the cause of the problem. Changing this line to d = JSON.parse(URI.open("https://registry.terraform.io/v1/modules?limit=10000&offset=#{offset}").read); (notice the openURI.open change) in terraformcomplete#GetAllRegistryModules() function helped me to eliminate the error and the function name per se led me to this issue here which has the one-size-fits-all fix to use g:terraform_registry_module_completion option to turn off the whole functionality as it indeed slows down user very much.

@juliosueiras Might worth to align vim-terraform-completion with what https://github.com/sparklemotion/nokogiri/issues/2066 is about since https://github.com/juliosueiras/vim-terraform-completion/blob/master/autoload/terraformcomplete.vim#L985 is not the only place which uses deprecated call.

Thanks!