ripper-tags 0.7.0 → 0.8.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.
- checksums.yaml +5 -5
- data/lib/ripper-tags.rb +36 -12
- data/lib/ripper-tags/default_formatter.rb +12 -5
- data/lib/ripper-tags/emacs_append_formatter.rb +43 -0
- data/lib/ripper-tags/emacs_formatter.rb +11 -11
- data/lib/ripper-tags/parser.rb +11 -3
- data/lib/ripper-tags/vim_append_formatter.rb +35 -0
- data/lib/ripper-tags/vim_formatter.rb +16 -4
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: af186884f47d60d67bc23e0bc85ceee5109a89c6bd60cb92024003803e11f87f
|
4
|
+
data.tar.gz: 6dbdd9ad152c076acb592533704df108ba38c582f75287e396fc57e439a2c525
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44316dc2bf8a70f9b00a9da621533f41b63b83ad91da0cfa768db558c920d222cdf7656e4454099a4e29ca4cb0ff82086f613eb491160f697d52d1174d4f142d
|
7
|
+
data.tar.gz: e209fcd4873a3a98bf69d03d0205506ad9ed4615e0fa4017476fe54e3b66df7aa2548b41dc7bc63b83e3ce2b2863f36150c6f97985a739db0a767c6d82c6372f
|
data/lib/ripper-tags.rb
CHANGED
@@ -5,19 +5,23 @@ require 'ripper-tags/parser'
|
|
5
5
|
require 'ripper-tags/data_reader'
|
6
6
|
require 'ripper-tags/default_formatter'
|
7
7
|
require 'ripper-tags/emacs_formatter'
|
8
|
+
require 'ripper-tags/emacs_append_formatter'
|
8
9
|
require 'ripper-tags/vim_formatter'
|
10
|
+
require 'ripper-tags/vim_append_formatter'
|
9
11
|
require 'ripper-tags/json_formatter'
|
10
12
|
|
11
13
|
module RipperTags
|
12
|
-
def self.version() "0.
|
14
|
+
def self.version() "0.8.0" end
|
13
15
|
|
14
16
|
FatalError = Class.new(RuntimeError)
|
15
17
|
|
16
18
|
def self.default_options
|
17
19
|
OpenStruct.new \
|
18
20
|
:format => nil,
|
21
|
+
:formatter => nil,
|
19
22
|
:extra_flags => Set.new,
|
20
23
|
:tag_file_name => nil,
|
24
|
+
:tag_file_append => false,
|
21
25
|
:tag_relative => nil,
|
22
26
|
:debug => false,
|
23
27
|
:verbose_debug => false,
|
@@ -87,8 +91,11 @@ module RipperTags
|
|
87
91
|
'"-" outputs to standard output') do |fname|
|
88
92
|
options.tag_file_name = fname
|
89
93
|
end
|
90
|
-
opts.on("--
|
91
|
-
options.
|
94
|
+
opts.on("-a", "--append[=yes|no]", "Append tags to existing file") do |value|
|
95
|
+
options.tag_file_append = value != "no"
|
96
|
+
end
|
97
|
+
opts.on("--tag-relative[=yes|no|always|never]", "Make file paths relative to the directory of the tag file") do |value|
|
98
|
+
options.tag_relative = value || true
|
92
99
|
end
|
93
100
|
opts.on("-L", "--input-file=FILE", "File to read paths to process trom (use `-` for stdin)") do |file|
|
94
101
|
options.input_file = file
|
@@ -103,7 +110,7 @@ module RipperTags
|
|
103
110
|
options.exclude << pattern
|
104
111
|
end
|
105
112
|
end
|
106
|
-
opts.on("--excmd=number", "
|
113
|
+
opts.on("--excmd=(number|pattern|mixed|combined)", "Type of EX command to find tags in vim with (default: pattern)") do |excmd|
|
107
114
|
options.excmd = excmd
|
108
115
|
end
|
109
116
|
opts.on("-n", "Equivalent to --excmd=number.") do
|
@@ -187,19 +194,36 @@ module RipperTags
|
|
187
194
|
options.format ||= File.basename(options.tag_file_name) == 'TAGS' ? 'emacs' : 'vim'
|
188
195
|
options.tag_relative = options.format == "emacs" if options.tag_relative.nil?
|
189
196
|
|
197
|
+
case options.tag_relative
|
198
|
+
when true, false, 'yes', 'no', 'always', 'never'
|
199
|
+
else
|
200
|
+
raise OptionParser::InvalidOption, 'unsupported value for --tag-relative: %p' % options.tag_relative
|
201
|
+
end
|
202
|
+
|
190
203
|
return run.call(options)
|
191
204
|
end
|
192
205
|
end
|
193
206
|
|
194
207
|
def self.formatter_for(options)
|
195
|
-
options.formatter
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
208
|
+
return options.formatter unless options.formatter.nil?
|
209
|
+
|
210
|
+
if options.tag_file_append
|
211
|
+
case options.format
|
212
|
+
when "vim" then RipperTags::VimAppendFormatter.new(RipperTags::VimFormatter.new(options))
|
213
|
+
when "emacs" then RipperTags::EmacsAppendFormatter.new(RipperTags::EmacsFormatter.new(options))
|
214
|
+
else
|
215
|
+
raise FatalError, "--append is only supported for vim/emacs; got #{options.format.inspect}"
|
216
|
+
end
|
217
|
+
else
|
218
|
+
case options.format
|
219
|
+
when "vim" then RipperTags::VimFormatter.new(options)
|
220
|
+
when "emacs" then RipperTags::EmacsFormatter.new(options)
|
221
|
+
when "json" then RipperTags::JSONFormatter.new(options)
|
222
|
+
when "custom" then RipperTags::DefaultFormatter.new(options)
|
223
|
+
else
|
224
|
+
raise FatalError, "unknown format: #{options.format.inspect}"
|
225
|
+
end
|
226
|
+
end
|
203
227
|
end
|
204
228
|
|
205
229
|
def self.run(options)
|
@@ -56,16 +56,23 @@ module RipperTags
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def tag_file_dir
|
59
|
-
@tag_file_dir ||=
|
59
|
+
@tag_file_dir ||= stdout? ?
|
60
|
+
Pathname.pwd :
|
61
|
+
Pathname.new(options.tag_file_name).dirname.expand_path
|
60
62
|
end
|
61
63
|
|
62
64
|
def relative_path(tag)
|
63
65
|
path = tag.fetch(:path)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
66
|
+
case options.tag_relative
|
67
|
+
when true, 'yes', 'always'
|
68
|
+
filepath = Pathname.new(path)
|
69
|
+
if options.tag_relative == 'always' || filepath.relative?
|
70
|
+
path = filepath.expand_path.relative_path_from(tag_file_dir).to_s
|
71
|
+
end
|
72
|
+
when 'never'
|
73
|
+
path = File.expand_path(path)
|
68
74
|
end
|
75
|
+
path
|
69
76
|
end
|
70
77
|
|
71
78
|
def constant?(tag)
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
module RipperTags
|
4
|
+
class EmacsAppendFormatter
|
5
|
+
# Wraps an EmacsFormatter
|
6
|
+
def initialize(fmt)
|
7
|
+
raise 'append is only possible to a file' if fmt.stdout?
|
8
|
+
@formatter = fmt
|
9
|
+
end
|
10
|
+
|
11
|
+
def with_output
|
12
|
+
old_sections = parse_tag_file
|
13
|
+
@seen_filenames = Set.new
|
14
|
+
|
15
|
+
@formatter.with_output do |out|
|
16
|
+
yield out
|
17
|
+
@formatter.flush_file_section(out)
|
18
|
+
|
19
|
+
old_sections.each do |filename, data|
|
20
|
+
next if @seen_filenames.include?(filename)
|
21
|
+
@formatter.write_section(filename, data, out)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def write(tag, out)
|
27
|
+
@formatter.write(tag, out)
|
28
|
+
@seen_filenames << @formatter.relative_path(tag)
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse_tag_file
|
32
|
+
section_map = {}
|
33
|
+
File.open(@formatter.options.tag_file_name) do |old_file|
|
34
|
+
while line = old_file.read(2)
|
35
|
+
raise 'expected "\f\n", got %p' % line unless "\x0C\n" == line
|
36
|
+
filename, length = old_file.gets.chomp.split(',')
|
37
|
+
section_map[filename] = old_file.read(length.to_i)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
section_map
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -11,12 +11,6 @@ module RipperTags
|
|
11
11
|
# new source file is encountered or when `with_output` block finishes. This
|
12
12
|
# assumes that incoming tags are ordered by source file.
|
13
13
|
class EmacsFormatter < DefaultFormatter
|
14
|
-
def initialize(*)
|
15
|
-
super
|
16
|
-
@current_file = nil
|
17
|
-
@section_io = nil
|
18
|
-
end
|
19
|
-
|
20
14
|
def supported_flags() ['q'] end
|
21
15
|
|
22
16
|
def include_qualified_names?
|
@@ -25,6 +19,9 @@ module RipperTags
|
|
25
19
|
end
|
26
20
|
|
27
21
|
def with_output
|
22
|
+
@current_file = nil
|
23
|
+
@section_io = nil
|
24
|
+
|
28
25
|
super do |io|
|
29
26
|
begin
|
30
27
|
yield io
|
@@ -43,21 +40,24 @@ module RipperTags
|
|
43
40
|
end
|
44
41
|
end
|
45
42
|
|
43
|
+
def write_section(filename, data, io)
|
44
|
+
io.write format_section_header(filename, data)
|
45
|
+
io.write data
|
46
|
+
end
|
47
|
+
|
46
48
|
def start_file_section(filename, io)
|
47
49
|
if filename != @current_file
|
48
50
|
flush_file_section(io)
|
49
51
|
@current_file = filename
|
50
52
|
@section_io = StringIO.new
|
51
|
-
else
|
52
|
-
@section_io
|
53
53
|
end
|
54
|
+
@section_io
|
54
55
|
end
|
55
56
|
|
56
57
|
def flush_file_section(out)
|
57
58
|
if @section_io
|
58
|
-
|
59
|
-
|
60
|
-
out.write data
|
59
|
+
write_section(@current_file, @section_io.string, out)
|
60
|
+
@section_io = nil
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
data/lib/ripper-tags/parser.rb
CHANGED
@@ -36,7 +36,13 @@ class Parser < Ripper
|
|
36
36
|
[:defs, receiver && receiver[0], *method]
|
37
37
|
end
|
38
38
|
def on_alias(lhs, rhs)
|
39
|
-
|
39
|
+
if lhs && rhs
|
40
|
+
name, other = lhs[0], rhs[0]
|
41
|
+
name = name[0] if Array === name
|
42
|
+
other = other[0] if Array === other
|
43
|
+
line = rhs[1]
|
44
|
+
[:alias, name, other, line]
|
45
|
+
end
|
40
46
|
end
|
41
47
|
def on_assign(lhs, rhs)
|
42
48
|
return if lhs.nil?
|
@@ -169,9 +175,11 @@ class Parser < Ripper
|
|
169
175
|
name, line = call[1]
|
170
176
|
case name
|
171
177
|
when "alias_method"
|
172
|
-
|
178
|
+
if args[1] && String === args[1][0] && args[2] && String === args[2][0]
|
179
|
+
[:alias, args[1][0], args[2][0], line]
|
180
|
+
end
|
173
181
|
when "define_method"
|
174
|
-
[:def, args[1][0], line]
|
182
|
+
[:def, args[1][0], line] if String === args[1][0]
|
175
183
|
when "public_class_method", "private_class_method", "protected_class_method", "private", "public", "protected"
|
176
184
|
access = name.sub("_class_method", "")
|
177
185
|
klass = name == access ? nil : 'self'
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
module RipperTags
|
4
|
+
class VimAppendFormatter
|
5
|
+
# Wraps a VimFormatter
|
6
|
+
def initialize(fmt)
|
7
|
+
raise 'append is only possible to a file' if fmt.stdout?
|
8
|
+
@formatter = fmt
|
9
|
+
end
|
10
|
+
|
11
|
+
def with_output
|
12
|
+
orig_lines = File.readlines(@formatter.options.tag_file_name)
|
13
|
+
@seen_filenames = Set.new
|
14
|
+
|
15
|
+
@formatter.with_output do |out|
|
16
|
+
yield out
|
17
|
+
|
18
|
+
orig_lines.each do |line|
|
19
|
+
f1, f2, = line.split("\t", 3)
|
20
|
+
# skip repeating header entries
|
21
|
+
next if f1 == '!_TAG_FILE_FORMAT' || f1 == '!_TAG_FILE_SORTED'
|
22
|
+
# skip old tags for newly processed files
|
23
|
+
next if f1.index('!_TAG_') != 0 && @seen_filenames.include?(f2)
|
24
|
+
# preserve other tags from original file
|
25
|
+
@formatter.write_line(line)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def write(tag, out)
|
31
|
+
@formatter.write(tag, out)
|
32
|
+
@seen_filenames << @formatter.relative_path(tag)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -30,21 +30,33 @@ module RipperTags
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def write(tag, out)
|
33
|
-
|
33
|
+
write_line(format(tag))
|
34
34
|
if include_qualified_names? && tag[:full_name] != tag[:name] && constant?(tag)
|
35
|
-
|
35
|
+
write_line(format(tag, :full_name))
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
def write_line(line)
|
40
|
+
@queued_write << line
|
41
|
+
end
|
42
|
+
|
39
43
|
def display_constant(const)
|
40
44
|
const.to_s.gsub('::', '.')
|
41
45
|
end
|
42
46
|
|
43
47
|
def display_excmd_info(tag)
|
44
|
-
|
48
|
+
case options.excmd
|
49
|
+
when 'n', 'number'
|
45
50
|
"%d;\"" % tag.fetch(:line)
|
46
|
-
|
51
|
+
when nil, 'p', 'pattern', 'm', 'mixed'
|
47
52
|
"/^%s$/;\"" % tag.fetch(:pattern).to_s.gsub('\\','\\\\\\\\').gsub('/','\\/')
|
53
|
+
when 'c', 'combined'
|
54
|
+
"%d;/^%s$/;\"" % [
|
55
|
+
tag.fetch(:line) - 1,
|
56
|
+
tag.fetch(:pattern).to_s.gsub('\\','\\\\\\\\').gsub('/','\\/')
|
57
|
+
]
|
58
|
+
else
|
59
|
+
raise 'invalid excmd value: %p', options.excmd
|
48
60
|
end
|
49
61
|
end
|
50
62
|
|
metadata
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ripper-tags
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
+
- Mislav Marohnić
|
7
8
|
- Aman Gupta
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2019-11-26 00:00:00.000000000 Z
|
12
13
|
dependencies: []
|
13
14
|
description: fast, accurate ctags generator for ruby source code using Ripper
|
14
15
|
email:
|
16
|
+
- mislav.marohnic@gmail.com
|
15
17
|
- aman@tmm1.net
|
16
18
|
executables:
|
17
19
|
- ripper-tags
|
@@ -24,11 +26,13 @@ files:
|
|
24
26
|
- lib/ripper-tags.rb
|
25
27
|
- lib/ripper-tags/data_reader.rb
|
26
28
|
- lib/ripper-tags/default_formatter.rb
|
29
|
+
- lib/ripper-tags/emacs_append_formatter.rb
|
27
30
|
- lib/ripper-tags/emacs_formatter.rb
|
28
31
|
- lib/ripper-tags/json_formatter.rb
|
29
32
|
- lib/ripper-tags/parser.rb
|
33
|
+
- lib/ripper-tags/vim_append_formatter.rb
|
30
34
|
- lib/ripper-tags/vim_formatter.rb
|
31
|
-
homepage:
|
35
|
+
homepage: https://github.com/tmm1/ripper-tags
|
32
36
|
licenses:
|
33
37
|
- MIT
|
34
38
|
metadata: {}
|
@@ -47,8 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
51
|
- !ruby/object:Gem::Version
|
48
52
|
version: '0'
|
49
53
|
requirements: []
|
50
|
-
|
51
|
-
rubygems_version: 2.5.2
|
54
|
+
rubygems_version: 3.0.3
|
52
55
|
signing_key:
|
53
56
|
specification_version: 4
|
54
57
|
summary: ctags generator for ruby code
|