rcodetools 0.5.0.0 → 0.7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/CHANGES +14 -0
  2. data/README +63 -0
  3. data/README.TDC +158 -0
  4. data/README.ja +84 -0
  5. data/README.vim +11 -0
  6. data/Rakefile +15 -2
  7. data/THANKS +5 -0
  8. data/bin/rct-complete +4 -2
  9. data/bin/rct-doc +4 -2
  10. data/bin/rct-meth-args +1 -1
  11. data/bin/xmpfilter +7 -1
  12. data/icicles-rcodetools.el +2 -1
  13. data/lib/rcodetools/completion.rb +36 -18
  14. data/lib/rcodetools/doc.rb +3 -0
  15. data/lib/rcodetools/fork.rb +222 -0
  16. data/lib/rcodetools/fork_config.rb +26 -0
  17. data/lib/rcodetools/options.rb +34 -1
  18. data/lib/rcodetools/xmpfilter.rb +106 -18
  19. data/lib/rcodetools/xmptestunitfilter.rb +116 -55
  20. data/lib/ruby_toggle_file.rb +99 -0
  21. data/rcodetools.el +64 -9
  22. data/rcodetools.vim +41 -6
  23. data/test/data/completion_class_info-input.rb +1 -0
  24. data/test/data/completion_class_info-output.rb +10 -0
  25. data/test/data/completion_class_info_no_candidates-input.rb +1 -0
  26. data/test/data/completion_class_info_no_candidates-output.rb +1 -0
  27. data/test/data/completion_detect_rbtest-input.rb +7 -0
  28. data/test/data/completion_detect_rbtest-output.rb +2 -0
  29. data/test/data/completion_detect_rbtest2-input.rb +1 -0
  30. data/test/data/completion_detect_rbtest2-output.rb +2 -0
  31. data/test/data/completion_in_method-input.rb +3 -0
  32. data/test/data/completion_in_method-output.rb +1 -0
  33. data/test/data/completion_in_method-test.rb +6 -0
  34. data/test/data/completion_rbtest-input.rb +7 -0
  35. data/test/data/completion_rbtest-output.rb +2 -0
  36. data/test/data/doc_detect_rbtest-input.rb +1 -0
  37. data/test/data/doc_detect_rbtest-output.rb +1 -0
  38. data/test/data/doc_detect_rbtest2-input.rb +7 -0
  39. data/test/data/doc_detect_rbtest2-output.rb +1 -0
  40. data/test/data/doc_rbtest-input.rb +7 -0
  41. data/test/data/doc_rbtest-output.rb +1 -0
  42. data/test/data/rspec-input.rb +9 -9
  43. data/test/data/rspec-output.rb +21 -21
  44. data/test/data/rspec_poetry-input.rb +9 -9
  45. data/test/data/rspec_poetry-output.rb +21 -21
  46. data/test/data/sample_test_script.rb +9 -0
  47. data/test/data/unit_test_detect_rbtest-input.rb +50 -0
  48. data/test/data/unit_test_detect_rbtest-output.rb +52 -0
  49. data/test/data/unit_test_detect_rbtest2-input.rb +6 -0
  50. data/test/data/unit_test_detect_rbtest2-output.rb +6 -0
  51. data/test/data/unit_test_rbtest-input.rb +6 -0
  52. data/test/data/unit_test_rbtest-output.rb +6 -0
  53. data/test/test_completion.rb +37 -3
  54. data/test/test_doc.rb +2 -0
  55. data/test/test_functional.rb +75 -14
  56. data/test/test_options.rb +1 -0
  57. data/test/test_ruby_toggle_file.rb +125 -0
  58. data/test/test_run.rb +7 -3
  59. data/test/test_xmpfilter.rb +132 -5
  60. data/test/test_xmptestunitfilter.rb +1 -0
  61. metadata +76 -43
data/CHANGES CHANGED
@@ -1,5 +1,19 @@
1
1
  rcodetools history
2
2
  ==================
3
+ User-visible changes since 0.5.0
4
+ --------------------------------
5
+ * "test-driven completion" (TDC) support for Emacs and vim (see README.TDC)
6
+ * --test (-t), --filename options for rct-complete and rct-doc, allowing to
7
+ specify the test to be run for 100% accurate completion/documentation in the
8
+ corresponding implementation
9
+ * ruby-toggle-file: finds the test file corresponding to a given
10
+ implementation and vice versa
11
+ * rct-fork, rct-fork-client: allow to eliminate the overhead due to library
12
+ loading (esp. useful for Rails)
13
+ * rbtest: executes unit tests in a single Ruby script
14
+ * --fork, --rbtest, --detect-rbtest supported by several commands
15
+ * xmpfilter's --spec now autodetects the RSpec version and generates
16
+ specifications with the appropriate syntax
3
17
 
4
18
  User-visible changes since 0.4.1
5
19
  --------------------------------
data/README CHANGED
@@ -14,6 +14,10 @@ Currently, rcodetools comprises:
14
14
  * rct-complete: Accurate method/class/constant etc. completions
15
15
  * rct-doc: Document browsing and code navigator
16
16
  * rct-meth-args: Precise method info (meta-prog. aware) and TAGS generation
17
+ * rct-fork: Pre-load heavy library(Rails etc) and speed up rct-complete/rct-doc (server)
18
+ * rct-fork-client: Run Ruby programs from state the rct-fork server has
19
+ * ruby-toggle-file: Toggle implementation file and test file
20
+ * rbtest: Embedded Test::Unit for small scripts
17
21
 
18
22
  See also README.xmpfilter.
19
23
 
@@ -29,7 +33,66 @@ stdout. They can run in several modes; see
29
33
  rct-complete -h
30
34
  rct-doc -h
31
35
  rct-meth-args -h
36
+ rct-fork -h
37
+ rct-fork-client -h
38
+ ruby-toggle-file -h
39
+ rbtest -h
32
40
  README.emacs and README.vim describe how to use rcodetools from your editor.
33
41
 
42
+ = Accurate Completion Internal and Caveat
43
+ rct-complete and rct-doc use xmpfilter engine, ie they get runtime information by executing code.
44
+ In Ruby (dynamic languages), type of any expressions except literals cannot be known without actually executing code.
45
+ Moreover Ruby has open classes and singleton methods.
46
+ Rcodetools asks `ruby' run-time informations, so we can get very accurate informations.
47
+ Completion and document browsing are essentially identical operations,
48
+ they both need the object value in question.
49
+ Therefore we discuss completion.
50
+
51
+ rct-complete does:
52
+ (1) replaces target line with completion magic
53
+ (it calculates methods the target object has).
54
+ (2) executes modified script.
55
+ (3) once the control reaches completion magic, modified script exits.
56
+ (4) outputs in specified format. (list candidates, EmacsLisp...)
57
+
58
+ But this methodology has two big drawbacks, side-effects and inability to get any informations of uncovered code!
59
+
60
+ An extreme side-effect example:
61
+ File.unlink a_file
62
+ File. <-
63
+
64
+ If you call rct-complete, it removes a_file (sends a mail, accesses DB ...).
65
+ So you must be careful to use, especially at TOPLEVEL.
66
+ I (rubikitch) often experiment at TOPLEVEL with rcodetools, I NEVER use irb(sh) since rcodetools!
67
+
68
+ An uncovered code example:
69
+ def foo
70
+ 1. <-
71
+ end
72
+
73
+ If the code does not call foo, we cannot do any completions.
74
+
75
+ Useless eh? But we already have a way to elude the drawbacks, test scripts (unit tests)!
76
+ Test scripts are self-enclosed and expected to be executed, so side-effects are not problem.
77
+ Moreover tests call methods we write.
78
+ Because Ruby's Test::Unit has an ability to test only one test method, we can do lightning-fast completion.
79
+ Let's call it Test-Driven Completion (TDC).
80
+
81
+ To support TDC, rct-complete has -t option.
82
+ With -t, it concatenate modified script and test/unit code.
83
+ If the control does not reach target line, test/unit code calls the line.
84
+
85
+ How do we select test script and test method?
86
+ The editor selects recently selected buffer of test script as test script of TDC,
87
+ because the test-infected tend to go and return between test script and implementation script.
88
+ It considers files matching /test.*\.rb/ as test script.
89
+ It selects test method at the cursor position.
90
+
91
+ TDC adds roles of test scripts.
92
+ Enjoy TDC magic!
93
+
94
+ See also README.TDC.
95
+
96
+
34
97
  = License
35
98
  rcodetools is licensed under the same terms as Ruby.
@@ -0,0 +1,158 @@
1
+
2
+ = Overview
3
+
4
+ Ruby is very dynamic language, therefore it is impossible to do
5
+ accurate completion without executing script. While executing script
6
+ from start to cursor point is often dangerous, executing unit test
7
+ script covering current point is SAFE. I call this methodology
8
+ `Test-Driven Completion' (TDC).
9
+
10
+ As I have already stated in README, browsing documentation of method
11
+ (rct-doc) is almost identical operation to completion. This
12
+ discussion is applicable to rct-doc.
13
+
14
+ = Why TDD Is Needed
15
+
16
+ In the following code snippet:
17
+
18
+ File.unlink a_file
19
+ File. <-
20
+
21
+ If you complete after `File.', rct-complete actually deletes a_file.
22
+ Normally it is unpleasant.
23
+ In real-life development, side-effect is inevitable.
24
+
25
+ In the foo method which are not called:
26
+
27
+ def foo
28
+ 1. <-
29
+ end
30
+
31
+ If the code does not call foo, rct-complete cannot do any completions.
32
+ Before TDC, if you want to do completion in methods, you have to write
33
+ method call and remove it after completion. Too useless!!
34
+
35
+ = Messianic Unit Test Script
36
+
37
+ Recently Test-Driven Development (TDD) is widespread. Many developers
38
+ write unit tests. Fortunately Ruby's unit tester, Test::Unit, is
39
+ sophisticated enough to test one test method. Unit tests are
40
+ self-enclosed: they must tear down resources, so executing unit tests
41
+ are SAFE. TDC uses unit test to do completion.
42
+
43
+ = TDC Methodology
44
+
45
+ (1) Switch to unit test script.
46
+ (2) Write a test for target method.
47
+ (3) Switch to implementation script.
48
+ (4) You can write target method WITH COMPLETION!
49
+ (5) Back to (1)
50
+
51
+ TDC methodology is almost identical to TDD. TDC is very easy for TDDers.
52
+
53
+ = TDC With Example
54
+
55
+ For simplicity, suppose that you are unfamiliar with Time class and
56
+ you want to write a method to format date string.
57
+
58
+ The directory structure and file contents is following:
59
+
60
+ /tmp/mylib0/
61
+ /tmp/mylib0/lib/
62
+ mylib0.rb
63
+ /tmp/mylib0/test/
64
+ test_mylib0.rb
65
+
66
+ List: mylib0.rb
67
+ # contrived example of long-runtime method
68
+ def mysleep(x)
69
+ sleep x
70
+ end
71
+
72
+ def mytime(tm)
73
+
74
+ end
75
+
76
+
77
+ List: test_mylib0.rb
78
+ require 'test/unit'
79
+ require 'mylib0'
80
+ class TestMylib0 < Test::Unit::TestCase
81
+ def test_0_mysleep
82
+ s = Time.now
83
+ mysleep 3.0
84
+ e = Time.now
85
+ assert_in_delta 3.0, e-s, 0.01
86
+ end
87
+
88
+ def test_1_mytime
89
+
90
+ end
91
+ end
92
+
93
+ These sample files are in demo/ directory.
94
+
95
+
96
+ == Switch to unit test script.
97
+
98
+ TDC starts with writing unit test as TDD does.
99
+ Open test_mylib0.rb.
100
+
101
+ == Write a test for target method.
102
+
103
+ Suppose that you want to write mytime method and test_1_mytime test
104
+ method, and that you want to experiment Time class first (before
105
+ forming an assertion).
106
+
107
+ In TDC, you do not have to write an assertion first: just write only a
108
+ method call. If you are familiar with Time class, you are free to
109
+ write an assertion, of course.
110
+
111
+ def test_1_mytime
112
+ mytime(Time.now)
113
+ end
114
+
115
+ At this time, the cursor position is in test_1_mytime test method.
116
+
117
+ == Switch to implementation script.
118
+
119
+ Open mylib0.rb with the `ruby-toggle-file' script. For example, in Emacs use
120
+ the `ruby-toggle-buffer' command, and in vim the <localleader>t (by default
121
+ \t) binding. Since in TDD/TDC you often switch between the test and the
122
+ implementation, it is much handier than typing the filename manually.
123
+
124
+ The rct-complete uses latest-selected test script as TDC test script
125
+ and test method at cursor position as TDC test method. In this case,
126
+ test_mylib0.rb is TDC test script and test_1_mytime is TDC test
127
+ method. If the cursor position of test_mylib0.rb is at the top,
128
+ rct-complete executes whole test methods in test_mylib0.rb. Therefore
129
+ latency of completion is longer.
130
+
131
+ == You can write target method WITH COMPLETION!
132
+
133
+ Fill mytime method.
134
+
135
+ def mytime(tm)
136
+ tm.
137
+ end
138
+
139
+ Do completion after `tm.'. Here! Your editor is listing methods `tm'
140
+ accepts!! If your editor has help-on-candidate mechanism (eg. Emacs +
141
+ Icicles), you would see documentation of each listed method.
142
+
143
+ Then you find `Time#strftime' method. Type `str' and do completion.
144
+
145
+ def mytime(tm)
146
+ tm.strftime
147
+ end
148
+
149
+ Usage is... use `rct-doc' (in Emacs, `rct-ri') after `strftime'.
150
+
151
+ After you are familiar with Time class, switch to test script and write assertions.
152
+
153
+ = When Modifying Another Method
154
+
155
+ If you want to modify already-written method, setting cursor position
156
+ of corresponding test script to corresponding test method is better.
157
+ It tells rct-complete new test script and test method, so you can do
158
+ completion in the new method.
@@ -0,0 +1,84 @@
1
+
2
+ rcodetools http://eigenclass.org/hiki.rb?rcodetools
3
+ Copyright (c) 2005-2007 Mauricio Fernandez <mfp@acm.org> http://eigenclass.org
4
+ Copyright (c) 2006-2007 rubikitch <rubikitch@ruby-lang.org> http://www.rubyist.net/~rubikitch/
5
+ Use and distribution subject to the terms of the Ruby license.
6
+
7
+ = ����
8
+ rcodetools �� Ruby �Υ����ɤ򰷤��ġ��뷲�Ǥ���
9
+ rcodetools �ˤ� xmpfilter �ȥ��ǥ����˰�¸���ʤ���ȯ�ٱ�ġ��뤬�ޤޤ�Ƥ��ޤ���
10
+ Emacs �� Vim �Υ��󥿡��ե��������Ѱդ��Ƥ��ޤ���
11
+
12
+ * xmpfilter: Test::Unit assert* / RSpec should* ��ư����������������
13
+ * rct-complete: �����٥᥽�å�̾�����饹̾�����̾���䴰
14
+ * rct-doc: �ɥ�����Ȼ��ȡ������ɥʥӥ�������
15
+ * rct-meth-args: �����٥᥽�åɾ���ꥹ�ȡ�TAGS �ե��������
16
+ * rct-fork: Rails ���Ť��饤�֥���ͽ������ɤ����䴰���®������ʥ����С�
17
+ * rct-fork-client: rct-fork �����Ф��ݻ�������֤��� Ruby ������ץȤ�¹Ԥ���
18
+ * ruby-toggle-file: �ƥ��ȥ�����ץȤȼ���������ץȤ��ڤ괹����
19
+ * rbtest: �����ϥ�����ץȤΤ���������� Test::Unit
20
+
21
+
22
+ = �Ȥ���
23
+
24
+ == ����������
25
+ �����ͤ�ɽ���������Ԥ� # => ��ä��ޤ���
26
+
27
+ a, b = "foo", "baz"
28
+ a + b # =>
29
+ a.size # =>
30
+
31
+ xmpfilter ���̤��Ȳ��Τ褦�˼����ͤ�ɽ�����Ƥ���ޤ���
32
+
33
+ a, b = "foo", "baz"
34
+ a + b # => "foobaz"
35
+ a.size # => 3
36
+
37
+
38
+ == Test::Unit assert ʸ����
39
+
40
+ ���ǤˤǤ������äƤ���ץ������Υƥ��ȥ�����ץȤ�񤯤Τ����ݤǤ��͡�
41
+
42
+ def test_insertion
43
+ @o.insert "bar"
44
+ @o.insert "baz"
45
+ @o.size # =>
46
+ @o.last # =>
47
+ @o.first # =>
48
+ @o.complex_computation # =>
49
+ @o.last(2) # =>
50
+ end
51
+
52
+ xmpfilter��-u ���ץ����ˤ���֤�ڸ����Ƥ���ޤ���
53
+
54
+ def test_insertion
55
+ @o.insert "bar"
56
+ @o.insert "baz"
57
+ assert_equal(2, @o.size)
58
+ assert_equal("baz", @o.last)
59
+ assert_equal("bar", @o.first)
60
+ assert_in_delta(3.14159265358979, @o.complex_computation, 0.0001)
61
+ assert_equal(["baz", "bar"], @o.last(2))
62
+ end
63
+
64
+ RSpec �ˤĤ��Ƥ�Ʊ�ͤΤ��Ȥ��Ǥ��ޤ�����-s ���ץ�����
65
+
66
+ == �䴰���ɥ�����Ȼ���
67
+
68
+ ư��ˤ�륹���꡼�󥷥�åȤ򸫤Ƥ���������
69
+
70
+ http://eigenclass.org/hiki.rb?rcodetools-screenshots
71
+
72
+ == �ܤ����Ȥ���
73
+ -h ���ץ�����Ĥ���Ȼ��Ѳ�ǽ�ʥ��ץ����ɽ������ޤ���
74
+
75
+ xmpfilter -h
76
+ rct-complete -h
77
+ rct-doc -h
78
+ rct-meth-args -h
79
+ rct-fork -h
80
+ rct-fork-client -h
81
+ ruby-toggle-file -h
82
+ rbtest -h
83
+
84
+ README.emacs �� README.vim �˥��ǥ�����ǤλȤ������ܤ����񤤤Ƥ���ޤ���
data/README.vim CHANGED
@@ -3,6 +3,17 @@ Copy rcodetools.vim to your plugin directory (typically $HOME/.vim/plugin) in
3
3
  order to enable accurate code completion, quick RI execution and exact tag
4
4
  jumping.
5
5
 
6
+ Switching between implementation and test files
7
+ ===============================================
8
+ The <localleader>t binding (by default \t) will call ruby-toggle-file to
9
+ switch from test to implementation and vice versa. Moreover, when you switch
10
+ from the test to the implementation, rcodetools will remember which test
11
+ you were editing (based on the cursor position), and call it as needed for
12
+ advanced code completion or precise RI documentation, as documented below.
13
+
14
+ The actual binding can be changed in your .vimrc as follows:
15
+ let g:RCT_toggle_binding="<C-X><C-t>" " use ^X^T to go test <=> implementation
16
+
6
17
  Code completion
7
18
  ===============
8
19
  rcodetools.vim redefines user-defined completion for Ruby programs, so you can
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ PKG_REVISION = ".0"
4
4
  $:.unshift "lib" if File.directory? "lib"
5
5
  require 'rcodetools/xmpfilter'
6
6
  require 'rake/testtask'
7
-
7
+ include Rcodetools
8
8
  RCT_VERSION = XMPFilter::VERSION
9
9
 
10
10
  desc "Run the unit tests in pure-Ruby mode ."
@@ -40,7 +40,20 @@ end
40
40
  # DO NOT EDIT!! EDITABLE
41
41
  [ ["test/data/rspec_poetry-input.rb", "test/data/rspec-input.rb"],
42
42
  ["test/data/unit_test_poetry-input.rb", "test/data/unit_test-input.rb"],
43
- ["test/data/completion_emacs-input.rb", "test/data/completion-input.rb"]
43
+ ["test/data/completion_emacs-input.rb", "test/data/completion-input.rb"],
44
+ ["test/data/unit_test_detect_rbtest-input.rb", "test/data/unit_test-input.rb"],
45
+ ["test/data/unit_test_detect_rbtest-output.rb", "test/data/unit_test-output.rb"],
46
+ ["test/data/unit_test_detect_rbtest2-input.rb", "test/data/unit_test_rbtest-input.rb"],
47
+ ["test/data/unit_test_detect_rbtest2-output.rb", "test/data/unit_test_rbtest-output.rb"],
48
+ ["test/data/completion_detect_rbtest-input.rb", "test/data/completion_rbtest-input.rb"],
49
+ ["test/data/completion_detect_rbtest-output.rb", "test/data/completion_rbtest-output.rb"],
50
+ ["test/data/completion_detect_rbtest2-input.rb", "test/data/completion-input.rb"],
51
+ ["test/data/completion_detect_rbtest2-output.rb", "test/data/completion-output.rb"],
52
+ ["test/data/doc_detect_rbtest-input.rb", "test/data/doc-input.rb"],
53
+ ["test/data/doc_detect_rbtest-output.rb", "test/data/doc-output.rb"],
54
+ ["test/data/doc_detect_rbtest2-input.rb", "test/data/doc_rbtest-input.rb"],
55
+ ["test/data/doc_detect_rbtest2-output.rb", "test/data/doc_rbtest-output.rb"],
56
+
44
57
  ].each do |outfile, infile|
45
58
  basetestfiles << outfile
46
59
  file(outfile => infile, &copy)
data/THANKS CHANGED
@@ -4,3 +4,8 @@ rubikitch
4
4
  * expanded xmp3.rb (a previous version of xmpfilter.rb) to support RSpec expectations
5
5
  * wrote the elisp magic to use xmpfilter.rb with emacs
6
6
  * made the 100% accurate, editor-independent completion system
7
+ [rubikitch took xmpfilter and turned it into the much more powerful
8
+ rcodetools, so there are way too many things to list them here :)]
9
+
10
+ Adagios
11
+ * found & fixed problem with rcodetools.vim plugin on win32
@@ -1,8 +1,9 @@
1
- #! /home/batsman/usr//bin/ruby
1
+ #! /home/batsman/usr/bin/ruby
2
2
  require 'rcodetools/xmpfilter'
3
3
  require 'rcodetools/completion'
4
4
  require 'rcodetools/options'
5
5
 
6
+ include Rcodetools
6
7
  options = DEFAULT_OPTIONS
7
8
  klass = XMPCompletionFilter
8
9
 
@@ -32,9 +33,10 @@ end
32
33
 
33
34
  set_extra_opts options
34
35
  opts.parse!(ARGV)
36
+ check_opts options
35
37
 
36
38
  targetcode = ARGF.read
37
39
  Dir.chdir options[:wd] if options[:wd]
38
-
40
+ XMPFilter.detect_rbtest(targetcode, options)
39
41
  # Do the job. dispatched by klass.
40
42
  puts klass.run(targetcode, options)
@@ -1,8 +1,9 @@
1
- #! /home/batsman/usr//bin/ruby
1
+ #! /home/batsman/usr/bin/ruby
2
2
  require 'rcodetools/xmpfilter'
3
3
  require 'rcodetools/doc'
4
4
  require 'rcodetools/options'
5
5
 
6
+ include Rcodetools
6
7
  options = DEFAULT_OPTIONS
7
8
  klass = XMPDocFilter
8
9
 
@@ -42,9 +43,10 @@ end
42
43
 
43
44
  set_extra_opts options
44
45
  opts.parse!(ARGV)
46
+ check_opts options
45
47
 
46
48
  targetcode = ARGF.read
47
49
  Dir.chdir options[:wd] if options[:wd]
48
-
50
+ XMPFilter.detect_rbtest(targetcode, options)
49
51
  # Do the job. dispatched by klass.
50
52
  puts klass.run(targetcode, options)
@@ -1,4 +1,4 @@
1
- #! /home/batsman/usr//bin/ruby
1
+ #! /home/batsman/usr/bin/ruby
2
2
  # Copyright (c)
3
3
  # 2006-2007 Mauricio Fernandez <mfp@acm.org> http://eigenclass.org
4
4
  # 2006-2007 rubikitch <rubikitch@ruby-lang.org> http://www.rubyist.net/~rubikitch/