rcodetools 0.5.0.0 → 0.7.0.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 (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
@@ -4,15 +4,20 @@
4
4
  ;;;
5
5
  ;;; Use and distribution subject to the terms of the Ruby license.
6
6
 
7
- (defvar xmpfilter-command-name "ruby -S xmpfilter --dev"
7
+ (defvar xmpfilter-command-name "ruby -S xmpfilter --dev --detect-rbtest"
8
8
  "The xmpfilter command name.")
9
- (defvar rct-doc-command-name "ruby -S rct-doc --dev"
9
+ (defvar rct-doc-command-name "ruby -S rct-doc --dev --fork --detect-rbtest"
10
10
  "The rct-doc command name.")
11
- (defvar rct-complete-command-name "ruby -S rct-complete --dev"
11
+ (defvar rct-complete-command-name "ruby -S rct-complete --dev --fork --detect-rbtest"
12
12
  "The rct-complete command name.")
13
+ (defvar ruby-toggle-file-command-name "ruby -S ruby-toggle-file"
14
+ "The ruby-toggle-file command name.")
13
15
  (defvar rct-option-history nil) ;internal
14
16
  (defvar rct-option-local nil) ;internal
15
17
  (make-variable-buffer-local 'rct-option-local)
18
+ (defvar rct-debug nil
19
+ "If non-nil, output debug message into *Messages*.")
20
+ ;; (setq rct-debug t)
16
21
 
17
22
  (defadvice comment-dwim (around rct-hack activate)
18
23
  "If comment-dwim is successively called, add => mark."
@@ -55,7 +60,7 @@
55
60
  See also `rct-interactive'. "
56
61
  (interactive (rct-interactive))
57
62
  (rct-save-position
58
- (lambda () (shell-command-on-region (point-min) (point-max) (xmpfilter-command option) t t))))
63
+ (lambda () (shell-command-on-region (point-min) (point-max) (xmpfilter-command option) t t " *rct-error*"))))
59
64
 
60
65
  (defun xmpfilter-command (&optional option)
61
66
  "The xmpfilter command line, DWIM."
@@ -76,6 +81,8 @@ See also `rct-interactive'. "
76
81
  (defvar rct-complete-symbol-function 'rct-complete-symbol--normal
77
82
  "Function to use rct-complete-symbol.")
78
83
  ;; (setq rct-complete-symbol-function 'rct-complete-symbol--icicles)
84
+ (defvar rct-use-test-script t
85
+ "Whether rct-complete/rct-doc use test scripts.")
79
86
 
80
87
  (defun rct-complete-symbol (&optional option)
81
88
  "Perform ruby method and class completion on the text around point.
@@ -113,20 +120,60 @@ See also `rct-interactive'."
113
120
 
114
121
  ;; (define-key ruby-mode-map "\M-\C-i" 'rct-complete-symbol)
115
122
 
123
+ (defun rct-debuglog (logmsg)
124
+ "if `rct-debug' is non-nil, output LOGMSG into *Messages*. Returns LOGMSG."
125
+ (if rct-debug
126
+ (message "%s" logmsg))
127
+ logmsg)
128
+
116
129
  (defun rct-exec-and-eval (command opt)
117
130
  "Execute rct-complete/rct-doc and evaluate the output."
118
131
  (let ((eval-buffer (get-buffer-create " *rct-eval*")))
119
132
  ;; copy to temporary buffer to do completion at non-EOL.
120
133
  (shell-command-on-region
121
134
  (point-min) (point-max)
122
- (format "%s %s %s --line=%d --column=%d"
123
- command opt (or rct-option-local "")
124
- (rct-current-line) (current-column))
125
- eval-buffer)
135
+ (rct-debuglog (format "%s %s %s --line=%d --column=%d %s"
136
+ command opt (or rct-option-local "")
137
+ (rct-current-line) (current-column)
138
+ (if rct-use-test-script (rct-test-script-option-string) "")))
139
+ eval-buffer nil " *rct-error*")
126
140
  (message "")
127
141
  (eval (with-current-buffer eval-buffer
128
142
  (goto-char 1)
129
- (read (current-buffer))))))
143
+ (unwind-protect
144
+ (read (current-buffer))
145
+ (unless rct-debug (kill-buffer eval-buffer)))))))
146
+
147
+ (defun rct-test-script-option-string ()
148
+ (if (null buffer-file-name)
149
+ ""
150
+ (let ((test-buf (rct-find-test-script-buffer))
151
+ (bfn buffer-file-name)
152
+ t-opt test-filename)
153
+ (if test-buf
154
+ ;; pass test script's filename and lineno
155
+ (with-current-buffer test-buf
156
+ (setq t-opt (format "%s@%s" buffer-file-name (rct-current-line)))
157
+ (format "-t %s --filename=%s" t-opt bfn))
158
+ ""))))
159
+
160
+ (require 'cl)
161
+
162
+ (defun rct-find-test-script-buffer (&optional buffer-list)
163
+ "Find the latest used Ruby test script buffer."
164
+ (setq buffer-list (or buffer-list (buffer-list)))
165
+ (dolist (buf buffer-list)
166
+ (with-current-buffer buf
167
+ (if (and buffer-file-name (string-match "test.*\.rb$" buffer-file-name))
168
+ (return buf)))))
169
+
170
+ ;; (defun rct-find-test-method (buffer)
171
+ ;; "Find test method on point on BUFFER."
172
+ ;; (with-current-buffer buffer
173
+ ;; (save-excursion
174
+ ;; (forward-line 1)
175
+ ;; (if (re-search-backward "^ *def *\\(test_[A-Za-z0-9?!_]+\\)" nil t)
176
+ ;; (match-string 1)))))
130
177
 
131
178
  (defun rct-try-completion ()
132
179
  "Evaluate the output of rct-complete."
@@ -159,4 +206,12 @@ See also `rct-interactive'. "
159
206
  (error
160
207
  (ri fullname)))))
161
208
 
209
+ ;;;;
210
+ (defun ruby-toggle-buffer ()
211
+ "Open a related file to the current buffer. test<=>impl."
212
+ (interactive)
213
+ (find-file (shell-command-to-string
214
+ (format "%s %s" ruby-toggle-file-command-name buffer-file-name))))
215
+
216
+
162
217
  (provide 'rcodetools)
@@ -46,19 +46,36 @@ endfunction
46
46
 
47
47
 
48
48
  "{{{ RCT_completion function
49
+
50
+ let s:last_test_file = ""
51
+ let s:last_test_lineno = 0
52
+
49
53
  let s:rct_completion_col = 0
50
54
  let s:rct_tmpfile = ""
51
55
 
56
+ function! <SID>RCT_command_with_test_options(cmd)
57
+ if s:last_test_file != ""
58
+ return a:cmd .
59
+ \ "-" . "-filename='" . expand("%:p") . "' " .
60
+ \ "-t '" . s:last_test_file . "@" . s:last_test_lineno . "' "
61
+ endif
62
+ return a:cmd
63
+ endfunction
64
+
52
65
  function! <SID>RCT_completion(findstart, base)
53
66
  if a:findstart
54
67
  let s:rct_completion_col = col('.') - 1
55
- let s:rct_tmpfile = "tmp-rcodetools" . strftime("Y-%m-%d-%T.rb")
68
+ let s:rct_tmpfile = "tmp-rcodetools" . strftime("Y-%m-%d-%H-%M-%S.rb")
56
69
  silent exec ":w " . s:rct_tmpfile
57
70
  return strridx(getline('.'), '.', col('.')) + 1
58
71
  else
59
72
  let line = line('.')
60
73
  let column = s:rct_completion_col
61
- let command = "rct-complete --completion-class-info --line=" . line . " --column=" . column . " " . s:rct_tmpfile
74
+
75
+ let command = "rct-complete --completion-class-info --dev --fork --line=" .
76
+ \ line . " --column=" . column . " "
77
+ let command = <SID>RCT_command_with_test_options(command) . s:rct_tmpfile
78
+
62
79
  let data = split(system(command), '\n')
63
80
 
64
81
  for dline in data
@@ -116,23 +133,41 @@ function! RCT_find_tag_or_ri(fullname)
116
133
  endfunction
117
134
 
118
135
  function! <SID>RCT_smart_ri()
119
- let tmpfile = "tmp-rcodetools" . strftime("Y-%m-%d-%T.rb")
136
+ let tmpfile = "tmp-rcodetools" . strftime("Y-%m-%d-%H-%M-%S.rb")
120
137
  silent exec ":w " . tmpfile
121
138
 
122
139
  let line = line('.')
123
140
  let column = col('.') - 1
124
- let command = "rct-doc --ri-vim --line=" . line . " --column=" . column . " " . tmpfile
141
+ let command = "rct-doc --ri-vim --line=" . line . " --column=" . column . " "
142
+ let command = <SID>RCT_command_with_test_options(command) . tmpfile
125
143
  "let term = matchstr(system(command), "\\v[^\n]+")
126
144
  exec system(command)
127
145
  call delete(tmpfile)
128
146
  "call RCT_find_tag_or_ri(term)
129
147
  endfunction
130
148
 
149
+ function! <SID>RCT_ruby_toggle()
150
+ let curr_file = expand("%:p")
151
+ let cmd = "ruby -S ruby-toggle-file " . curr_file
152
+ if match(curr_file, '\v_test|test_') != -1
153
+ let s:last_test_file = curr_file
154
+ let s:last_test_lineno = line(".")
155
+ endif
156
+ let dest = system(cmd)
157
+ silent exec ":w"
158
+ exec ("edit " . dest)
159
+ silent! normal g;
160
+ endfunction
161
+
131
162
  "{{{ bindings and au
132
163
 
133
- execute "au Filetype ruby setlocal completefunc=" . s:sid . "RCT_completion"
164
+ if v:version >= 700
165
+ execute "au Filetype ruby setlocal completefunc=" . s:sid . "RCT_completion"
166
+ endif
134
167
  execute 'au Filetype ruby nmap <buffer><silent> <C-]> :exec "call ' .
135
168
  \ 'RCT_find_tag_or_ri(''" . expand("<cword>") . "'')"<cr>'
136
- execute 'au Filetype ruby nmap <buffer><silent>' . s:GetOption("RCT_ri_binding", "<LocalLeader>r") .
169
+ execute 'au Filetype ruby nmap <buffer><silent>' . s:GetOption("RCT_ri_binding", "<LocalLeader>r") .
137
170
  \ ' :call ' . s:sid . 'RCT_smart_ri()<cr>'
171
+ execute 'au Filetype ruby nmap <buffer><silent>' . s:GetOption("RCT_toggle_binding", "<LocalLeader>t") .
172
+ \ ' :call ' . s:sid . 'RCT_ruby_toggle()<cr>'
138
173
  let &cpo = s:save_cpo
@@ -0,0 +1 @@
1
+ Array.new(3).s
@@ -0,0 +1,10 @@
1
+ select Array#select
2
+ send Object#send
3
+ shift Array#shift
4
+ singleton_methods Object#singleton_methods
5
+ size Array#size
6
+ slice Array#slice
7
+ slice! Array#slice!
8
+ sort Array#sort
9
+ sort! Array#sort!
10
+ sort_by Enumerable#sort_by
@@ -0,0 +1 @@
1
+ Array.new(3).nonexisten
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ =begin test_bar
3
+ assert_equal "BAR", bar("bar")
4
+ =end
5
+ def bar(s)
6
+ s.upca
7
+ end
@@ -0,0 +1,2 @@
1
+ upcase
2
+ upcase!
@@ -0,0 +1 @@
1
+ Array.new(3).uni
@@ -0,0 +1,3 @@
1
+ def fooz
2
+ [].lengt
3
+ end
@@ -0,0 +1,6 @@
1
+ require 'test/unit'
2
+ class TestFooz < Test::Unit::TestCase
3
+ def test_fooz
4
+ assert_equal(0, fooz)
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ =begin test_bar
3
+ assert_equal "BAR", bar("bar")
4
+ =end
5
+ def bar(s)
6
+ s.upca
7
+ end
@@ -0,0 +1,2 @@
1
+ upcase
2
+ upcase!
@@ -0,0 +1 @@
1
+ [].length
@@ -0,0 +1 @@
1
+ Array#length
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ =begin test_bar
3
+ assert_equal "BAR", bar("bar")
4
+ =end
5
+ def bar(s)
6
+ s.upcase
7
+ end
@@ -0,0 +1 @@
1
+ String#upcase
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ =begin test_bar
3
+ assert_equal "BAR", bar("bar")
4
+ =end
5
+ def bar(s)
6
+ s.upcase
7
+ end
@@ -0,0 +1 @@
1
+ String#upcase
@@ -11,36 +11,36 @@ class X
11
11
  end
12
12
 
13
13
 
14
- context "Testing xmpfilter's expectation expansion" do
15
- setup do
14
+ describe "xmpfilter's expectation expansion" do
15
+ before do
16
16
  @o = X.new
17
17
  end
18
18
 
19
- specify "Should expand should_equal expectations" do
19
+ it "should expand should == expectations" do
20
20
  @o.foo(true) # =>
21
21
  @o.foo(true).a # =>
22
22
  @o.foo(false) # =>
23
23
  end
24
24
 
25
- specify "Should expand should_raise expectations" do
25
+ it "should expand should raise_error expectations" do
26
26
  @o.bar # =>
27
27
  end
28
28
 
29
- specify "Should expand should_be_nil expectations" do
29
+ it "should expand should be_nil expectations" do
30
30
  @o.baz # =>
31
31
  end
32
32
 
33
- specify "Should expand correct expectations for complex values" do
33
+ it "should expand correct expectations for complex values" do
34
34
  @o.babar # =>
35
35
  end
36
36
 
37
- specify "Should expand should_be_close expectations" do
37
+ it "should expand should be_close expectations" do
38
38
  @o.fubar(10) # =>
39
39
  end
40
40
  end
41
41
 
42
- context "Testing binding" do
43
- specify "Should expand should_equal expectations" do
42
+ describe "xmpfilter's automagic binding detection" do
43
+ it "should expand should == expectations" do
44
44
  a = b = c = 1
45
45
  d = a
46
46
  d # =>
@@ -11,42 +11,42 @@ class X
11
11
  end
12
12
 
13
13
 
14
- context "Testing xmpfilter's expectation expansion" do
15
- setup do
14
+ describe "xmpfilter's expectation expansion" do
15
+ before do
16
16
  @o = X.new
17
17
  end
18
18
 
19
- specify "Should expand should_equal expectations" do
20
- (@o.foo(true)).should_be_a_kind_of X::Y
21
- (@o.foo(true).inspect).should_equal "#<struct X::Y a=2>"
22
- (@o.foo(true).a).should_equal 2
23
- (@o.foo(false)).should_equal 2
19
+ it "should expand should == expectations" do
20
+ (@o.foo(true)).should be_a_kind_of(X::Y)
21
+ (@o.foo(true).inspect).should == ("#<struct X::Y a=2>")
22
+ (@o.foo(true).a).should == (2)
23
+ (@o.foo(false)).should == (2)
24
24
  end
25
25
 
26
- specify "Should expand should_raise expectations" do
27
- lambda{@o.bar}.should_raise RuntimeError
26
+ it "should expand should raise_error expectations" do
27
+ lambda{@o.bar}.should raise_error(RuntimeError)
28
28
  end
29
29
 
30
- specify "Should expand should_be_nil expectations" do
31
- (@o.baz).should_be_nil
30
+ it "should expand should be_nil expectations" do
31
+ (@o.baz).should be_nil
32
32
  end
33
33
 
34
- specify "Should expand correct expectations for complex values" do
35
- (@o.babar).should_equal [1, 2]
34
+ it "should expand correct expectations for complex values" do
35
+ (@o.babar).should == ([1, 2])
36
36
  end
37
37
 
38
- specify "Should expand should_be_close expectations" do
39
- (@o.fubar(10)).should_be_close 101.0, 0.0001
38
+ it "should expand should be_close expectations" do
39
+ (@o.fubar(10)).should be_close(101.0, 0.0001)
40
40
  end
41
41
  end
42
42
 
43
- context "Testing binding" do
44
- specify "Should expand should_equal expectations" do
43
+ describe "xmpfilter's automagic binding detection" do
44
+ it "should expand should == expectations" do
45
45
  a = b = c = 1
46
46
  d = a
47
- (d).should_equal a
48
- (d).should_equal b
49
- (d).should_equal c
50
- (d).should_equal 1
47
+ (d).should == (a)
48
+ (d).should == (b)
49
+ (d).should == (c)
50
+ (d).should == (1)
51
51
  end
52
52
  end
@@ -11,36 +11,36 @@ class X
11
11
  end
12
12
 
13
13
 
14
- context "Testing xmpfilter's expectation expansion" do
15
- setup do
14
+ describe "xmpfilter's expectation expansion" do
15
+ before do
16
16
  @o = X.new
17
17
  end
18
18
 
19
- specify "Should expand should_equal expectations" do
19
+ it "should expand should == expectations" do
20
20
  @o.foo(true) # =>
21
21
  @o.foo(true).a # =>
22
22
  @o.foo(false) # =>
23
23
  end
24
24
 
25
- specify "Should expand should_raise expectations" do
25
+ it "should expand should raise_error expectations" do
26
26
  @o.bar # =>
27
27
  end
28
28
 
29
- specify "Should expand should_be_nil expectations" do
29
+ it "should expand should be_nil expectations" do
30
30
  @o.baz # =>
31
31
  end
32
32
 
33
- specify "Should expand correct expectations for complex values" do
33
+ it "should expand correct expectations for complex values" do
34
34
  @o.babar # =>
35
35
  end
36
36
 
37
- specify "Should expand should_be_close expectations" do
37
+ it "should expand should be_close expectations" do
38
38
  @o.fubar(10) # =>
39
39
  end
40
40
  end
41
41
 
42
- context "Testing binding" do
43
- specify "Should expand should_equal expectations" do
42
+ describe "xmpfilter's automagic binding detection" do
43
+ it "should expand should == expectations" do
44
44
  a = b = c = 1
45
45
  d = a
46
46
  d # =>