rcodetools 0.4.0.0 → 0.4.1.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.
- data/CHANGES +5 -0
- data/README +1 -0
- data/Rakefile +8 -1
- data/Rakefile.method_analysis +1 -1
- data/bin/rct-meth-args +22 -11
- data/icicles-rcodetools.el +1 -1
- data/lib/rcodetools/completion.rb +20 -14
- data/lib/rcodetools/doc.rb +4 -0
- data/lib/rcodetools/xmpfilter.rb +4 -3
- data/rcodetools.el +2 -2
- data/test/data/completion_emacs_icicles-input.rb +1 -1
- data/test/data/completion_emacs_icicles-output.rb +3 -3
- data/test/test_completion.rb +28 -0
- data/test/test_doc.rb +19 -0
- metadata +2 -2
data/CHANGES
CHANGED
data/README
CHANGED
data/Rakefile
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
|
2
2
|
PKG_REVISION = ".0"
|
3
|
-
RCT_VERSION = "0.4.0"
|
4
3
|
|
5
4
|
$:.unshift "lib" if File.directory? "lib"
|
5
|
+
require 'rcodetools/xmpfilter'
|
6
6
|
require 'rake/testtask'
|
7
7
|
|
8
|
+
RCT_VERSION = XMPFilter::VERSION
|
9
|
+
|
8
10
|
desc "Run the unit tests in pure-Ruby mode ."
|
9
11
|
Rake::TestTask.new(:test) do |t|
|
10
12
|
t.libs << "ext/rcovrt"
|
@@ -120,4 +122,9 @@ rescue LoadError
|
|
120
122
|
# RubyGems not installed
|
121
123
|
end
|
122
124
|
|
125
|
+
desc "install by setup.rb"
|
126
|
+
task :install do
|
127
|
+
sh "sudo ruby setup.rb install"
|
128
|
+
end
|
129
|
+
|
123
130
|
# vim: set sw=2 ft=ruby:
|
data/Rakefile.method_analysis
CHANGED
data/bin/rct-meth-args
CHANGED
@@ -9,22 +9,24 @@
|
|
9
9
|
$VERBOSE = nil
|
10
10
|
$__method_args_off = true
|
11
11
|
|
12
|
-
if ARGV.empty?
|
12
|
+
if ARGV.empty? or ARGV.include? '-h' or ARGV.include? '--help'
|
13
13
|
puts <<EOF
|
14
|
-
rct-meth-args [-i] [-m] [-c] [-n] <file> [<file> ...]
|
14
|
+
rct-meth-args [-Idirectory] [-i] [-m] [-c] [-n] <file> [<file> ...]
|
15
15
|
|
16
|
-
-
|
17
|
-
-m omit instance methods defined in modules
|
18
|
-
-c omit class methods
|
16
|
+
-Idirectory specify $LOAD_PATH directory (same as ruby)
|
19
17
|
|
20
|
-
-
|
21
|
-
-
|
18
|
+
-i omit instance methods defined in classes
|
19
|
+
-m omit instance methods defined in modules
|
20
|
+
-c omit class methods
|
21
|
+
|
22
|
+
-n print the filename and line number with output lines
|
23
|
+
-t generate TAGS output
|
22
24
|
|
23
25
|
The given files will be #require()d in order.
|
24
26
|
Examples:
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
rct-meth-args complex
|
28
|
+
rct-meth-args thread
|
29
|
+
rct-meth-args -c rubygems
|
28
30
|
EOF
|
29
31
|
exit
|
30
32
|
end
|
@@ -246,13 +248,22 @@ new_args = []
|
|
246
248
|
omissions = {}
|
247
249
|
$__with_location = false
|
248
250
|
$__printer = Printer.new
|
251
|
+
i_opt_p = false
|
249
252
|
|
250
253
|
ARGV.each do |arg|
|
251
254
|
case arg
|
252
255
|
when "-n"; $__with_location = true
|
253
256
|
when "-t"; $__printer = TagsPrinter.new; $__with_location = true
|
257
|
+
when /-I(.+)$/; $:.unshift $1
|
258
|
+
when "-I"; i_opt_p = true
|
254
259
|
when /-./; omissions[$&] = true
|
255
|
-
else
|
260
|
+
else
|
261
|
+
if i_opt_p
|
262
|
+
$:.unshift arg
|
263
|
+
i_opt_p = false
|
264
|
+
else
|
265
|
+
new_args << arg
|
266
|
+
end
|
256
267
|
end
|
257
268
|
end
|
258
269
|
|
data/icicles-rcodetools.el
CHANGED
@@ -190,38 +190,44 @@ class XMPCompletionFilter < XMPFilter
|
|
190
190
|
@prefix = expr
|
191
191
|
case expr
|
192
192
|
when /^\$\w+$/ # global variable
|
193
|
-
__prepare_line 'global_variables'
|
193
|
+
__prepare_line 'nil', 'global_variables'
|
194
194
|
when /^@@\w+$/ # class variable
|
195
|
-
__prepare_line 'Module === self ? class_variables : self.class.class_variables'
|
195
|
+
__prepare_line 'nil', 'Module === self ? class_variables : self.class.class_variables'
|
196
196
|
when /^@\w+$/ # instance variable
|
197
|
-
__prepare_line 'instance_variables'
|
198
|
-
when /^([A-Z].*)::(
|
197
|
+
__prepare_line 'nil', 'instance_variables'
|
198
|
+
when /^([A-Z].*)::([^.]*)$/ # nested constants / class methods
|
199
199
|
@prefix = $2
|
200
|
-
__prepare_line "#$1.constants | #$1.methods(true)"
|
200
|
+
__prepare_line $1, "#$1.constants | #$1.methods(true)"
|
201
201
|
when /^[A-Z]\w*$/ # normal constants
|
202
|
-
__prepare_line 'Module.constants'
|
203
|
-
when
|
202
|
+
__prepare_line 'nil', 'Module.constants'
|
203
|
+
when /^(.*::.+)\.(.+)$/ # toplevel class methods
|
204
204
|
@prefix = $2
|
205
|
-
__prepare_line
|
205
|
+
__prepare_line $1, "#$1.methods"
|
206
|
+
when /^(::.+)::(.*)$/ # toplevel nested constants
|
207
|
+
@prefix = $2
|
208
|
+
__prepare_line $1, "#$1.constants | #$1.methods"
|
206
209
|
when /^::(.*)/ # toplevel constant
|
207
210
|
@prefix = $1
|
208
|
-
__prepare_line 'Object.constants'
|
211
|
+
__prepare_line 'nil', 'Object.constants'
|
209
212
|
when /^(:[^:.]*)$/ # symbol
|
210
|
-
__prepare_line 'Symbol.all_symbols.map{|s| ":" + s.id2name}'
|
213
|
+
__prepare_line 'nil', 'Symbol.all_symbols.map{|s| ":" + s.id2name}'
|
211
214
|
when /\.([^.]*)$/ # method call
|
212
215
|
@prefix = $1
|
213
|
-
|
216
|
+
recv = Regexp.last_match.pre_match
|
217
|
+
__prepare_line recv, "(#{recv}).methods(true)"
|
214
218
|
else # bare words
|
215
|
-
__prepare_line "methods | private_methods | local_variables | self.class.constants"
|
219
|
+
__prepare_line 'self', "methods | private_methods | local_variables | self.class.constants"
|
216
220
|
end
|
217
221
|
end
|
218
222
|
|
219
|
-
def __prepare_line(all_completion_expr)
|
223
|
+
def __prepare_line(recv, all_completion_expr)
|
220
224
|
v = "#{VAR}"
|
221
225
|
idx = 1
|
222
226
|
oneline_ize(<<EOC)
|
223
227
|
#{v} = (#{all_completion_expr}).grep(/^#{Regexp.quote(@prefix)}/)
|
224
|
-
|
228
|
+
#{v}2 = (#{recv})
|
229
|
+
#{v}2 = Module === #{v}2 ? #{v}2 : #{v}2.class
|
230
|
+
$stderr.puts("#{MARKER}[#{idx}] => " + #{v}2.to_s + " " + #{v}.join(" ")) || #{v}
|
225
231
|
exit
|
226
232
|
EOC
|
227
233
|
end
|
data/lib/rcodetools/doc.rb
CHANGED
@@ -72,6 +72,10 @@ $stderr.print("#{MARKER}[#{idx}] => " + #{v}.class.to_s + " ")
|
|
72
72
|
if #{ancestor_class}
|
73
73
|
$stderr.puts(#{ancestor_class}.to_s + #{flag} + '#{meth}')
|
74
74
|
else
|
75
|
+
if '#{meth}' == 'new' and #{v}.private_method_defined?(:initialize)
|
76
|
+
$stderr.puts(#{v}.to_s + #{flag} + '#{meth}'); exit
|
77
|
+
end
|
78
|
+
|
75
79
|
[Kernel, Module, Class].each do |k|
|
76
80
|
if (k.instance_methods(false) + k.private_instance_methods(false)).include? '#{meth}'
|
77
81
|
$stderr.printf("%s#%s\\n", k, '#{meth}'); exit
|
data/lib/rcodetools/xmpfilter.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# Use and distribution subject to the terms of the Ruby license.
|
5
5
|
|
6
6
|
class XMPFilter
|
7
|
-
VERSION = "0.4.
|
7
|
+
VERSION = "0.4.1"
|
8
8
|
|
9
9
|
MARKER = "!XMP#{Time.new.to_i}_#{Process.pid}_#{rand(1000000)}!"
|
10
10
|
XMP_RE = Regexp.new("^" + Regexp.escape(MARKER) + '\[([0-9]+)\] (=>|~>|==>) (.*)')
|
@@ -110,8 +110,9 @@ end || #{v}
|
|
110
110
|
def execute_tmpfile(code)
|
111
111
|
stdin, stdout, stderr = (1..3).map do |i|
|
112
112
|
fname = "xmpfilter.tmpfile_#{Process.pid}-#{i}.rb"
|
113
|
-
|
114
|
-
File.
|
113
|
+
f = File.open(fname, "w+")
|
114
|
+
at_exit { f.close unless f.closed?; File.unlink fname }
|
115
|
+
f
|
115
116
|
end
|
116
117
|
stdin.puts code
|
117
118
|
stdin.close
|
data/rcodetools.el
CHANGED
@@ -77,11 +77,11 @@ See also `rct-interactive'. "
|
|
77
77
|
"Function to use rct-complete-symbol.")
|
78
78
|
;; (setq rct-complete-symbol-function 'rct-complete-symbol--icicles)
|
79
79
|
|
80
|
-
(defun rct-complete-symbol ()
|
80
|
+
(defun rct-complete-symbol (&optional option)
|
81
81
|
"Perform ruby method and class completion on the text around point.
|
82
82
|
This command only calls a function according to `rct-complete-symbol-function'.
|
83
83
|
See also `rct-interactive', `rct-complete-symbol--normal', and `rct-complete-symbol--icicles'."
|
84
|
-
(interactive)
|
84
|
+
(interactive (rct-interactive))
|
85
85
|
(call-interactively rct-complete-symbol-function))
|
86
86
|
|
87
87
|
(defun rct-complete-symbol--normal (&optional option)
|
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
1.div
|
data/test/test_completion.rb
CHANGED
@@ -116,6 +116,11 @@ EOC
|
|
116
116
|
assert_equal(["popen"], doit('::File::pop',1))
|
117
117
|
|
118
118
|
assert_equal(["popen"], doit('File.pop',1))
|
119
|
+
assert_equal(["popen"], doit('::File.pop',1))
|
120
|
+
|
121
|
+
assert_equal(["new"], doit('::File::Stat.ne',1))
|
122
|
+
assert_equal(["new"], doit('File::Stat.ne',1))
|
123
|
+
|
119
124
|
end
|
120
125
|
|
121
126
|
|
@@ -464,4 +469,27 @@ EOC
|
|
464
469
|
def XXtest_oneline
|
465
470
|
assert_equal(["aaa"], doit('aaa=1; aa', 1))
|
466
471
|
end
|
472
|
+
|
473
|
+
################################################################
|
474
|
+
|
475
|
+
def get_class(code, lineno, column=nil, options={})
|
476
|
+
xmp = XMPCompletionFilter.new options
|
477
|
+
klass, = xmp.runtime_data_with_class(code, lineno, column).sort
|
478
|
+
klass
|
479
|
+
end
|
480
|
+
|
481
|
+
def test_class__Class
|
482
|
+
assert_equal("File", get_class("File::n", 1))
|
483
|
+
assert_equal("File", get_class("File.n", 1))
|
484
|
+
assert_equal("File::Stat", get_class("File::Stat::n", 1))
|
485
|
+
assert_equal("File::Stat", get_class("File::Stat.n", 1))
|
486
|
+
|
487
|
+
assert_equal("FileTest", get_class("FileTest.exis", 1))
|
488
|
+
assert_equal("FileTest", get_class("FileTest::exis", 1))
|
489
|
+
end
|
490
|
+
|
491
|
+
def test_class__NotClass
|
492
|
+
assert_equal("Fixnum", get_class("1.ch", 1))
|
493
|
+
assert_equal("String", get_class("'a'.siz", 1))
|
494
|
+
end
|
467
495
|
end
|
data/test/test_doc.rb
CHANGED
@@ -39,6 +39,25 @@ $hoge.popen
|
|
39
39
|
EOC
|
40
40
|
end
|
41
41
|
|
42
|
+
# not File::Stat.methods(false).include? 'new'
|
43
|
+
def test_class_method__File_Stat_new
|
44
|
+
assert_equal("File::Stat.new", doit("File::Stat.new", 1))
|
45
|
+
assert_equal("File::Stat.new", doit("File::Stat::new", 1))
|
46
|
+
|
47
|
+
assert_equal("File::Stat.new", doit("::File::Stat.new", 1))
|
48
|
+
assert_equal("File::Stat.new", doit("::File::Stat::new", 1))
|
49
|
+
end
|
50
|
+
|
51
|
+
# IO.methods(false).include? 'new'
|
52
|
+
def test_class_method__IO_new
|
53
|
+
assert_equal("IO.new", doit("IO.new", 1))
|
54
|
+
assert_equal("IO.new", doit("IO::new", 1))
|
55
|
+
|
56
|
+
assert_equal("IO.new", doit("::IO.new", 1))
|
57
|
+
assert_equal("IO.new", doit("::IO::new", 1))
|
58
|
+
end
|
59
|
+
|
60
|
+
|
42
61
|
def test_constant__File
|
43
62
|
assert_equal("File", doit("File", 1))
|
44
63
|
assert_equal("File", doit("::File", 1))
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rcodetools
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.4.
|
7
|
-
date:
|
6
|
+
version: 0.4.1.0
|
7
|
+
date: 2007-01-13 00:00:00 +01:00
|
8
8
|
summary: rcodetools is a collection of Ruby code manipulation tools
|
9
9
|
require_paths:
|
10
10
|
- lib
|