gem-ripper-tags 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +82 -0
- data/Rakefile +11 -0
- data/gem-ripper-tags.gemspec +19 -0
- data/lib/rubygems/commands/ripper_tags_command.rb +87 -0
- data/lib/rubygems_plugin.rb +8 -0
- metadata +88 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) Tim Pope
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
RubyGems Automatic Ctags Generator
|
2
|
+
==================================
|
3
|
+
|
4
|
+
If you do like Vim and Ctags like I or [Tim Pope][] do, you maybe appreciate
|
5
|
+
automatic generation of ctags for each installed gem. This small project is
|
6
|
+
based on Tim's [gem-ctags][], but the main difference is it does *not* use
|
7
|
+
[Exuberant Ctags][].
|
8
|
+
|
9
|
+
Upstream site is at: https://github.com/lzap/gem-ripper-tags
|
10
|
+
|
11
|
+
Usage
|
12
|
+
-----
|
13
|
+
|
14
|
+
Install the thing (only Ruby 1.9+):
|
15
|
+
|
16
|
+
gem install gem-ripper-tags
|
17
|
+
|
18
|
+
Then generate tags for all already installed gems:
|
19
|
+
|
20
|
+
gem ripper
|
21
|
+
|
22
|
+
Anytime you install a gem now, tags will be automatically created.
|
23
|
+
|
24
|
+
gem instal some_gem ...
|
25
|
+
|
26
|
+
If you're using RVM, I recommend extending your global gemset by adding
|
27
|
+
`gem-ripper-tags` to `~/.rvm/gemsets/global.gems`. Put it at the top so the
|
28
|
+
gems below it will be indexed.
|
29
|
+
|
30
|
+
Motivation
|
31
|
+
----------
|
32
|
+
|
33
|
+
Why would you care about not using ctags in the first place? Ctags is a great
|
34
|
+
project and it does support many (like 50) languages. But Ruby support is very
|
35
|
+
weak, the parser is not in good condition and it has not been changed 4 years
|
36
|
+
now.
|
37
|
+
|
38
|
+
* Ctags doesn't deal with: module A::B
|
39
|
+
* Ctags doesn't tag (at least some of) the operator methods like ==
|
40
|
+
* Ctags doesn't support qualified tags, -type=+
|
41
|
+
* Ctags doesn't output tags for constants or attributes.
|
42
|
+
|
43
|
+
Unfortunately all the others (I found 2) Ruby ctags generators are either
|
44
|
+
outdated (no Ruby 1.9+ support) or very slow. This project makes use of
|
45
|
+
[ripper-tags][] that leverages built-in Ruby parser API called Ripper. It is
|
46
|
+
fast and it works as expected.
|
47
|
+
|
48
|
+
Vim Tips
|
49
|
+
--------
|
50
|
+
|
51
|
+
To easily edit a gem with your current working directory set to the
|
52
|
+
gem's root, install [gem-browse][].
|
53
|
+
|
54
|
+
If you have [rake.vim][] installed (which, by the way, is a misleading
|
55
|
+
name), Vim will already know where to look for the tags file when
|
56
|
+
editing a gem.
|
57
|
+
|
58
|
+
If you have [bundler.vim][] installed, Vim will be aware of all tags
|
59
|
+
files from all gems in your bundle.
|
60
|
+
|
61
|
+
If you want to get crazy, add this to your vimrc to get Vim to search
|
62
|
+
all gems in your current RVM gemset (requires [pathogen.vim][]):
|
63
|
+
|
64
|
+
autocmd FileType ruby let &l:tags = pathogen#legacyjoin(pathogen#uniq(
|
65
|
+
\ pathogen#split(&tags) +
|
66
|
+
\ map(split($GEM_PATH,':'),'v:val."/gems/*/tags"')))
|
67
|
+
|
68
|
+
Tim Pope doesn't like to get crazy. ;-)
|
69
|
+
|
70
|
+
License
|
71
|
+
-------
|
72
|
+
|
73
|
+
Copyright (c) Tim Pope; Lukáš Zapletal. MIT License.
|
74
|
+
|
75
|
+
[Tim Pope]: http://tpo.pe/
|
76
|
+
[Exuberant Ctags]: http://ctags.sourceforge.net/
|
77
|
+
[gem-ctags]: https://github.com/tpope/gem-ctags
|
78
|
+
[gem-browse]: https://github.com/tpope/gem-browse
|
79
|
+
[bundler.vim]: https://github.com/tpope/vim-bundler
|
80
|
+
[pathogen.vim]: https://github.com/tpope/vim-pathogen
|
81
|
+
[rake.vim]: https://github.com/tpope/vim-rake
|
82
|
+
[ripper-tags]: https://github.com/tmm1/ripper-tags
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "gem-ripper-tags"
|
6
|
+
s.version = "1.0.0"
|
7
|
+
s.authors = ["Tim Pope", "Lukas Zapletal"]
|
8
|
+
s.email = ["code@tpop"+'e.net', "lzap+rpm@red"+'hat.com']
|
9
|
+
s.homepage = "https://github.com/lzap/gem-ripper-tags"
|
10
|
+
s.summary = %q{fast and accurate ctags generator on gem install}
|
11
|
+
|
12
|
+
s.files = `git ls-files`.split("\n")
|
13
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
|
17
|
+
s.add_dependency 'ripper-tags'
|
18
|
+
s.add_development_dependency 'rake'
|
19
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'rubygems/command'
|
2
|
+
require 'tag_ripper'
|
3
|
+
|
4
|
+
class Gem::Commands::RipperTagsCommand < Gem::Command
|
5
|
+
def initialize
|
6
|
+
super 'ripper', 'Generate ctags for gems with Ruby/Ripper parser'
|
7
|
+
end
|
8
|
+
|
9
|
+
def execute
|
10
|
+
if Gem::Specification.respond_to?(:each)
|
11
|
+
Gem::Specification
|
12
|
+
else
|
13
|
+
Gem.source_index.gems.values
|
14
|
+
end.each do |spec|
|
15
|
+
self.class.index(spec) do |message|
|
16
|
+
say message
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.ctags(paths)
|
22
|
+
# this bit is taken from ripper-tags/bin
|
23
|
+
all_tags = []
|
24
|
+
paths.each do |file|
|
25
|
+
begin
|
26
|
+
if File.directory?(file)
|
27
|
+
Dir.foreach(file){ |f| paths << File.expand_path(File.join(file, f)) if f !~ /^\.\.?/ }
|
28
|
+
next
|
29
|
+
else
|
30
|
+
next if file !~ /\.rb$/
|
31
|
+
data = File.read(file)
|
32
|
+
end
|
33
|
+
sexp = TagRipper.new(data, file).parse
|
34
|
+
v = TagRipper::Visitor.new(sexp, file, data)
|
35
|
+
all_tags += v.tags
|
36
|
+
rescue Exception => e
|
37
|
+
#STDERR.puts "Skipping invalid file #{file}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
File.open('tags', 'w') do |file|
|
42
|
+
file.puts <<-EOC
|
43
|
+
!_TAG_FILE_FORMAT\t2\t/extended format; --format=1 will not append ;" to lines/
|
44
|
+
!_TAG_FILE_SORTED\t1\t/0=unsorted, 1=sorted, 2=foldcase/
|
45
|
+
EOC
|
46
|
+
|
47
|
+
all_tags.sort_by!{ |t| t[:name] }
|
48
|
+
all_tags.each do |tag|
|
49
|
+
kwargs = ''
|
50
|
+
kwargs << "\tclass:#{tag[:class].gsub('::','.')}" if tag[:class]
|
51
|
+
kwargs << "\tinherits:#{tag[:inherits].gsub('::','.')}" if tag[:inherits]
|
52
|
+
|
53
|
+
kind = case tag[:kind]
|
54
|
+
when 'method' then 'f'
|
55
|
+
when 'singleton method' then 'F'
|
56
|
+
when 'constant' then 'C'
|
57
|
+
else tag[:kind].slice(0,1)
|
58
|
+
end
|
59
|
+
|
60
|
+
code = tag[:pattern].gsub('\\','\\\\\\\\').gsub('/','\\/')
|
61
|
+
file.puts "%s\t%s\t/^%s$/;\"\t%c%s" % [tag[:name], tag[:path], code, kind, kwargs]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.index(spec)
|
67
|
+
return unless File.directory?(spec.full_gem_path)
|
68
|
+
|
69
|
+
Dir.chdir(spec.full_gem_path) do
|
70
|
+
|
71
|
+
#if !(File.file?('tags') && File.read('tags', 1) == '!') && !File.directory?('tags')
|
72
|
+
if !File.directory?('tags')
|
73
|
+
yield "Generating ctags for #{spec.full_name}" if block_given?
|
74
|
+
ctags(spec.require_paths.select { |p| File.directory?(p) })
|
75
|
+
end
|
76
|
+
|
77
|
+
target = 'lib/bundler/cli.rb'
|
78
|
+
if File.writable?(target) && !File.read(target).include?('load_plugins')
|
79
|
+
yield "Injecting gem-ripper-tags into #{spec.full_name}" if block_given?
|
80
|
+
File.open(target, 'a') do |f|
|
81
|
+
f.write "\nGem.load_plugins rescue nil\n"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gem-ripper-tags
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tim Pope
|
9
|
+
- Lukas Zapletal
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-06-27 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: ripper-tags
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: rake
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
description:
|
48
|
+
email:
|
49
|
+
- code@tpope.net
|
50
|
+
- lzap+rpm@redhat.com
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- Gemfile
|
57
|
+
- MIT-LICENSE
|
58
|
+
- README.markdown
|
59
|
+
- Rakefile
|
60
|
+
- gem-ripper-tags.gemspec
|
61
|
+
- lib/rubygems/commands/ripper_tags_command.rb
|
62
|
+
- lib/rubygems_plugin.rb
|
63
|
+
homepage: https://github.com/lzap/gem-ripper-tags
|
64
|
+
licenses: []
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.8.23
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: fast and accurate ctags generator on gem install
|
87
|
+
test_files: []
|
88
|
+
has_rdoc:
|