Skip to content

Update rcodetools and hide warning during code completion #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Commands/Completion: Ruby (rcodetools).tmCommand
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
<string>#!/usr/bin/env ruby -w
<string>#!/usr/bin/env ruby

require "#{ENV["TM_SUPPORT_PATH"]}/lib/exit_codes"
require "#{ENV["TM_SUPPORT_PATH"]}/lib/ui"
Expand Down
46 changes: 46 additions & 0 deletions Support/vendor/rcodetools-old/CHANGES
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
rcodetools history
==================
User-visible changes since 0.5.0
--------------------------------
* "test-driven completion" (TDC) support for Emacs and vim (see README.TDC)
* --test (-t), --filename options for rct-complete and rct-doc, allowing to
specify the test to be run for 100% accurate completion/documentation in the
corresponding implementation
* ruby-toggle-file: finds the test file corresponding to a given
implementation and vice versa
* rct-fork, rct-fork-client: allow to eliminate the overhead due to library
loading (esp. useful for Rails)
* rbtest: executes unit tests in a single Ruby script
* --fork, --rbtest, --detect-rbtest supported by several commands
* xmpfilter's --spec now autodetects the RSpec version and generates
specifications with the appropriate syntax

User-visible changes since 0.4.1
--------------------------------
* --dev: adds project directories to $:
* --completion-class-info: list completion candidates and class info
* display completion candidates with description, both in emacs
and vim (using the menu+preview window).

User-visible changes since 0.4.0
--------------------------------
* rct-meth-args: implemented -I
* many bug fixes

xmpfilter was integrated into rcodetools as of 0.4.0.

xmpfilter history
=================
User-visible changes since 0.3.1 (2006-10-17)
* implemented --debug
* --[no]-warnings
* --cd working_dir
* --rails
* --no-poetry
* more intelligent assertions: try to find which local variables hold the
values compared against in assertions/expectations
* editor-independent completion (-C, --completion-emacs, --completion-vim)
* quick method/class reference with -D (--refe, --ri*)

User-visible changes since 0.3.0 (2006-10-16)
* xmpfilter.rb --spec works on win32 too
98 changes: 98 additions & 0 deletions Support/vendor/rcodetools-old/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@

rcodetools http://eigenclass.org/hiki.rb?rcodetools
Copyright (c) 2005-2007 Mauricio Fernandez <[email protected]> http://eigenclass.org
Copyright (c) 2006-2007 rubikitch <[email protected]> http://www.rubyist.net/~rubikitch/
Use and distribution subject to the terms of the Ruby license.

= Overview
rcodetools is a collection of Ruby code manipulation tools.
It includes xmpfilter and editor-independent Ruby development helper tools,
as well as emacs and vim interfaces.

Currently, rcodetools comprises:
* xmpfilter: Automagic Test::Unit assertions/RSpec expectations and code annotations
* rct-complete: Accurate method/class/constant etc. completions
* rct-doc: Document browsing and code navigator
* rct-meth-args: Precise method info (meta-prog. aware) and TAGS generation
* rct-fork: Pre-load heavy library(Rails etc) and speed up rct-complete/rct-doc (server)
* rct-fork-client: Run Ruby programs from state the rct-fork server has
* ruby-toggle-file: Toggle implementation file and test file
* rbtest: Embedded Test::Unit for small scripts

See also README.xmpfilter.

Originally rct-complete and rct-doc were subcommands of xmpfilter.
Actually they use xmpfilter's code heavily.
But the relationship between xmpfilter (annotation) and completion/doc is not
intuitive, so I (rubikitch) split it into separate executables.

= Usage
xmpfilter, rct-complete and rct-doc take its input from stdin and write to
stdout. They can run in several modes; see
xmpfilter -h
rct-complete -h
rct-doc -h
rct-meth-args -h
rct-fork -h
rct-fork-client -h
ruby-toggle-file -h
rbtest -h
README.emacs and README.vim describe how to use rcodetools from your editor.

= Accurate Completion Internal and Caveat
rct-complete and rct-doc use xmpfilter engine, ie they get runtime information by executing code.
In Ruby (dynamic languages), type of any expressions except literals cannot be known without actually executing code.
Moreover Ruby has open classes and singleton methods.
Rcodetools asks `ruby' run-time informations, so we can get very accurate informations.
Completion and document browsing are essentially identical operations,
they both need the object value in question.
Therefore we discuss completion.

rct-complete does:
(1) replaces target line with completion magic
(it calculates methods the target object has).
(2) executes modified script.
(3) once the control reaches completion magic, modified script exits.
(4) outputs in specified format. (list candidates, EmacsLisp...)

But this methodology has two big drawbacks, side-effects and inability to get any informations of uncovered code!

An extreme side-effect example:
File.unlink a_file
File. <-

If you call rct-complete, it removes a_file (sends a mail, accesses DB ...).
So you must be careful to use, especially at TOPLEVEL.
I (rubikitch) often experiment at TOPLEVEL with rcodetools, I NEVER use irb(sh) since rcodetools!

An uncovered code example:
def foo
1. <-
end

If the code does not call foo, we cannot do any completions.

Useless eh? But we already have a way to elude the drawbacks, test scripts (unit tests)!
Test scripts are self-enclosed and expected to be executed, so side-effects are not problem.
Moreover tests call methods we write.
Because Ruby's Test::Unit has an ability to test only one test method, we can do lightning-fast completion.
Let's call it Test-Driven Completion (TDC).

To support TDC, rct-complete has -t option.
With -t, it concatenate modified script and test/unit code.
If the control does not reach target line, test/unit code calls the line.

How do we select test script and test method?
The editor selects recently selected buffer of test script as test script of TDC,
because the test-infected tend to go and return between test script and implementation script.
It considers files matching /test.*\.rb/ as test script.
It selects test method at the cursor position.

TDC adds roles of test scripts.
Enjoy TDC magic!

See also README.TDC.


= License
rcodetools is licensed under the same terms as Ruby.
54 changes: 54 additions & 0 deletions Support/vendor/rcodetools-old/README.emacs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

rcodetools.el allows you to run rcodetools on a buffer.

To eval the sexp, type C-e C-x C-e; `end-of-line' and `eval-last-sexp'.

installation
============

If you use RI document feature, you must install ri-emacs first.
http://rubyforge.org/projects/ri-emacs/

If you feel RI and ri-emacs.rb startup is SLOW, you want to install FastRI.
FastRI offers ri-emacs compatible layer, so you can use it with ri-ruby.el.
http://eigenclass.org/hiki.rb?fastri

Copy <tt>rcodetools.el</tt> to the appropriate directory, which is in load-path.
Then require it.
(require 'rcodetools)

If you use icicles copy <tt>icicles-rcodetools.el</tt> too.
Then require it.
(require 'icicles-rcodetools)
It provides wonderful `help on candidate' feature, RI document on each candidate during completion.
I'm addicted to icicles!
http://www.emacswiki.org/cgi-bin/wiki/Icicles

xmpfilter on buffer
===================

# [EVAL IT] (describe-function 'xmp)

If you want to add => marks, call comment-dwim twice.

# [EVAL IT] (describe-function 'comment-dwim)

method/class/constant completion
================================

# [EVAL IT] (describe-function 'rct-complete-symbol)

If you use icicles-rcodetools, you can browse RI document for selected candidate
by typing C-M-RET. It is wonderful icicles feature!!

show RI document / jump to the definition
=========================================

# [EVAL IT] (describe-function 'rct-ri)

By default rct-ri asks for a TAGS file, which is generated by tag generator like rtags.
If there is a TAGS file, this command jumps to the definition of current method.
If use do not use this feature, evaluate:
(setq rct-find-tag-if-available nil)

# [EVAL IT] (describe-variable 'rct-find-tag-if-available)
13 changes: 13 additions & 0 deletions Support/vendor/rcodetools-old/README.method_analysis
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

method_analyzer.rb can be used to gather precise information about the exact
methods called in your code, allowing you to explore it better with rct-doc
(see README.emacs and README.vim for more information). This requires high
code coverage, since it can only record such data when the code is executed.

rct-meth-args can be used to generate fairly complete TAGS files. It operates
by loading the specified files and tracking method definitions; therefore, it
is meta-programming aware, unlike other implementations.

You can use them conveniently by adding the code shown in
Rakefile.method_analysis to your Rakefile.

111 changes: 111 additions & 0 deletions Support/vendor/rcodetools-old/README.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@

Copy rcodetools.vim to your plugin directory (typically $HOME/.vim/plugin) in
order to enable accurate code completion, quick RI execution and exact tag
jumping.

Switching between implementation and test files
===============================================
The <localleader>t binding (by default \t) will call ruby-toggle-file to
switch from test to implementation and vice versa. Moreover, when you switch
from the test to the implementation, rcodetools will remember which test
you were editing (based on the cursor position), and call it as needed for
advanced code completion or precise RI documentation, as documented below.

The actual binding can be changed in your .vimrc as follows:
let g:RCT_toggle_binding="<C-X><C-t>" " use ^X^T to go test <=> implementation

Code completion
===============
rcodetools.vim redefines user-defined completion for Ruby programs, so you can
use the intelligent, 100%-accurate completion with <C-X><C-U> in insert mode.
Note that this runs the code to obtain the exact candidate list.

If you've set completeopt to menu,preview then rcodetools.vim can display
information about the completion candidates. The menu will show the synopsis
as given in the RI documentation, and the preview window will contain the full
RI documentation.

This functionality relies on fri for quick lookups. It can be enabled by setting

let g:rct_completion_use_fri = 1 " 0 by default (disabled)

in your .vimrc (don't forget to run fastri-server too).
Obtaining the documentation for many candidates can be slow, so you can set
the threshold above which additional documentation will not be shown with

" 20 by default, about a couple secs max wait on a normal machine
let g:rct_completion_info_max_len = 20

Quick RI documentation and exact tag jumping
============================================
When you're editing a Ruby file, <C-]> will jump to the definition of the
chosen element if found in the TAGS file; otherwise, it will call RI and show
the documentation in a new window.
You can specify the RI executable to use by adding something like
let g:RCT_ri_cmd = "ri -T -f plain "
to your .vimrc. (rcodetools.vim also honors b:RCT_RI_cmd and w:RCT_RI_cmd if set).
By default, "fri -f plain " will be used. fri (FastRI) is an improved RI
documentation browser, which features more intelligent search modes, gem
integration, vastly better performance... You can find it at
http://eigenclass.org/hiki.rb?fastri and it's also available in gem format
gem install fastri

If you want to call RI for the word the cursor is on (instead of jumping to
the definition if found), you can use this binding:
<LocalLeader>r (\r by default if you haven't changed your localleader)
You can specify another binding in your .vimrc as follows:
let g:RCT_ri_binding="<C-X><C-R>" " use ^X^R to call vim on current word

Using xmpfilter
===============
xmpfilter takes code from stdin and outputs to stdout so you can filter
your code with ! as usual.

If you use xmpfilter often, you might want to use mappings like the
following, which allow you to:
* add annotations
* expand assertions
* insert/remove # => markers



" plain annotations
map <silent> <F10> !xmpfilter -a<cr>
nmap <silent> <F10> V<F10>
imap <silent> <F10> <ESC><F10>a

" Test::Unit assertions; use -s to generate RSpec expectations instead
map <silent> <S-F10> !xmpfilter -u<cr>
nmap <silent> <S-F10> V<S-F10>
imap <silent> <S-F10> <ESC><S-F10>a

" Annotate the full buffer
" I actually prefer ggVG to %; it's a sort of poor man's visual bell
nmap <silent> <F11> mzggVG!xmpfilter -a<cr>'z
imap <silent> <F11> <ESC><F11>

" assertions
nmap <silent> <S-F11> mzggVG!xmpfilter -u<cr>'z
imap <silent> <S-F11> <ESC><S-F11>a

" Add # => markers
vmap <silent> <F12> !xmpfilter -m<cr>
nmap <silent> <F12> V<F12>
imap <silent> <F12> <ESC><F12>a

" Remove # => markers
vmap <silent> <S-F12> ms:call RemoveRubyEval()<CR>
nmap <silent> <S-F12> V<S-F12>
imap <silent> <S-F12> <ESC><S-F12>a


function! RemoveRubyEval() range
let begv = a:firstline
let endv = a:lastline
normal Hmt
set lz
execute ":" . begv . "," . endv . 's/\s*# \(=>\|!!\).*$//e'
normal 'tzt`s
set nolz
redraw
endfunction
Loading