vim-tags 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/plugin/vim-tags.vim +16 -11
  3. data/plugins.rb +43 -12
  4. data/vim-tags.gemspec +3 -2
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24862170a8fd6195f07f07160c5c810336e859a5297712dac58b515cca323c60
4
- data.tar.gz: aab67522bb493fa0308d01b715030a0b66c3663471d121db9e54d4aeefb3c22c
3
+ metadata.gz: 4bc33aff0be21dfcf28ac60662708d2c0a7605bd3afe07d111006058ea3414f2
4
+ data.tar.gz: 8402bf3eaa4791579010a70cb5ced680114a0b32d3f36535fbfde52189eeec10
5
5
  SHA512:
6
- metadata.gz: '0890772903f0e49d8037c62c024742fb7b8c6a218e86b26c5f708c13a5fdecfccb428ddb4b04ec80a40043579d430d65026385505557ddc9b70d74f3626a5e61'
7
- data.tar.gz: 224d233cd91b633bc94967523665da3a2c4e8cfabd28b671c75f7064c914ad2b988e5b4fc67c09a7e9e3cc14a9f690209a326f7773523cb78a0d86bcc1c08c3b
6
+ metadata.gz: e4421652fb5563fe9ea28742d5db907477379f52be922b0fb040a7b128b1e808adbeb657743ca6cc0102b9c11b73e96ded702c7dcb1a90b7d4dade8f54d7e68d
7
+ data.tar.gz: f04f668af0c693c8c6d4e4aebd0acf88e65c6921d1349d98a871689cb0476ca96f090cf7feaa511b10592121423e9f234122975ae935310164a6a9ceaa109c08
data/plugin/vim-tags.vim CHANGED
@@ -1,19 +1,24 @@
1
1
  function! LoadRubyTags()
2
- if exists("g:vim_tags_loaded")
3
- return
4
- endif
2
+ let l:load_ruby_tags_dir = finddir('.git/..', expand('%:p:h').';')
5
3
 
6
- let s:load_ruby_tags_fp = finddir('.git/..', expand('%:p:h').';') . '/.bundle/.tag_files'
4
+ if !empty(l:load_ruby_tags_dir)
5
+ let l:load_ruby_tags_gem_tags_path = l:load_ruby_tags_dir . '/.bundle/.gem_tag_files'
7
6
 
8
- if !filereadable(s:load_ruby_tags_fp)
9
- let s:install_response = system('bundler plugin install vim-tags')
10
- let s:command_response = system('bundler vim-tags')
11
- endif
7
+ if !filereadable(l:load_ruby_tags_gem_tags_path)
8
+ let l:install_response = system('bundler plugin install vim-tags')
9
+ let l:command_response = system('bundler vim-tags')
10
+ endif
12
11
 
13
- let s:comma_tags = system("cat " . s:load_ruby_tags_fp . " | paste -sd ',' -")
14
- let g:vim_tags_loaded = 1
12
+ let g:gem_files = json_decode(readfile(l:load_ruby_tags_gem_tags_path))
13
+ let l:gem_comma_tags = join(values(g:gem_files), "/tags,") . '/tags'
14
+ let l:ruby_comma_tags = join(readfile(l:load_ruby_tags_dir . '/.bundle/.ruby_tag_files'), "/tags,") . '/tags'
15
15
 
16
- let &l:tags = &tags . ',' . s:comma_tags
16
+ setlocal includeexpr=get(g:gem_files,v:fname,v:fname)
17
+ setlocal suffixesadd=/
18
+ cnoremap <buffer><expr> <Plug><cfile> get(g:gem_files,expand("<cfile>"),"\022\006")
19
+
20
+ let &l:tags = &tags . ',' . l:gem_comma_tags . ',' . l:ruby_comma_tags
21
+ endif
17
22
  endfunction
18
23
 
19
24
  autocmd FileType ruby :call LoadRubyTags()
data/plugins.rb CHANGED
@@ -1,33 +1,64 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler"
4
+ require "json"
4
5
 
5
6
  class VimTagsCommand < Bundler::Plugin::API
6
7
  command "vim-tags"
7
8
 
8
9
  def exec(*)
9
- cache_file = File.join(Bundler.app_config_path, ".tag_files")
10
+ write_gem_file
11
+ write_ruby_file
12
+ end
10
13
 
11
- puts "\nWriting tag cache to #{cache_file}"
14
+ private
12
15
 
13
- File.open(cache_file, "w") do |f|
14
- f.truncate(0)
16
+ def write_gem_file
17
+ write_to_file(
18
+ File.join(Bundler.app_config_path, ".gem_tag_files"),
19
+ "\nWriting gem file tag cache",
20
+ { tags: gem_tags, paths: gem_paths }
21
+ )
22
+ end
23
+
24
+ def write_ruby_file
25
+ write_to_file(
26
+ File.join(Bundler.app_config_path, ".ruby_tag_files"),
27
+ "Writing ruby tag cache to",
28
+ { tags: ruby_tags, paths: $: }
29
+ )
30
+ end
31
+
32
+ def ruby_tags
33
+ $:.select { |path| File.exist?(File.join(path, "tags")) }
34
+ end
35
+
36
+ def gem_tags
37
+ gem_specs.filter_map do |spec|
38
+ tag_path = File.join(spec.full_gem_path, "tags")
15
39
 
16
- f.write (gem_paths + ruby_paths).uniq.join("\n")
40
+ next unless File.exist?(tag_path)
41
+
42
+ tag_path
17
43
  end
18
44
  end
19
45
 
20
46
  def gem_paths
21
- Bundler.load.specs.filter_map do |spec|
22
- next if spec.name == "bundler" ||
23
- !File.exist?(File.join(spec.full_gem_path, "tags"))
47
+ gem_specs.to_h { |spec| [spec.name, spec.full_gem_path] }
48
+ end
24
49
 
25
- spec.full_gem_path
26
- end
50
+ def gem_specs
51
+ @gem_specs ||= Bundler.load.specs
27
52
  end
28
53
 
29
- def ruby_paths
30
- $:.select { |path| File.exist?(File.join(path, "tags")) }
54
+ def write_to_file(file_path, description, payload)
55
+ puts "#{description} to #{cache_file}"
56
+
57
+ File.open(file_path, "w") do |f|
58
+ f.truncate(0)
59
+
60
+ f.write payload.to_json
61
+ end
31
62
  end
32
63
  end
33
64
 
data/vim-tags.gemspec CHANGED
@@ -2,11 +2,12 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "vim-tags"
5
- spec.version = "0.2.0"
5
+ spec.version = "0.3.0"
6
6
  spec.authors = ["Nick Pezza"]
7
7
  spec.email = ["pezza@hey.com"]
8
8
 
9
- spec.summary = "Generate cache file of all paths to tags files of dependencies"
9
+ spec.summary =
10
+ "Generate cache file of all paths to tags files of dependencies"
10
11
  spec.license = "MIT"
11
12
  spec.required_ruby_version = ">= 2.7.0"
12
13
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vim-tags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Pezza