[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Auto-completion editor/IDE

Eli Tucker

10/26/2004 11:49:00 PM

Does anyone have any info on an IDE or editor that supports
auto-completion for Ruby?

So far I've been using Scite which came with the One-Click Windows Ruby
installer, but have not figured out how to turn on auto-completion (or
to be more specific, how to create the needed api file).

I just downloaded RDE, but the auto-completion seems half baked. For
example, if I type the following:

a = [4,2,3]
b = a.

a pop-up is shown just like you would expect where I can select a
method of Array. But then if I continue along to here:

a = [4,2,3]
b = a.sort
b.

.... no pop-up is shown -- it doesn't know that b is an Array.

Perhaps there isn't yet an IDE or editor for Ruby with auto-completion
features like those seen in Microsoft Visual Studio, Jet Brains IDEA,
or Eclipse? If not, I would be interested in hearing what other
developers are using to create ruby code.

Thanks in advance,
- Eli

16 Answers

timsuth

10/27/2004 1:21:00 AM

0

In article <1098834541.819479.278620@f14g2000cwb.googlegroups.com>, Eli Tucker
wrote:
>Does anyone have any info on an IDE or editor that supports
>auto-completion for Ruby?
>
>So far I've been using Scite which came with the One-Click Windows Ruby
>installer, but have not figured out how to turn on auto-completion (or
>to be more specific, how to create the needed api file).
>
>I just downloaded RDE, but the auto-completion seems half baked. For
>example, if I type the following:
>
>a = [4,2,3]
>b = a.
>
>a pop-up is shown just like you would expect where I can select a
>method of Array. But then if I continue along to here:
>
>a = [4,2,3]
>b = a.sort
>b.
>
>... no pop-up is shown -- it doesn't know that b is an Array.
>
>Perhaps there isn't yet an IDE or editor for Ruby with auto-completion
>features like those seen in Microsoft Visual Studio, Jet Brains IDEA,
>or Eclipse? If not, I would be interested in hearing what other
>developers are using to create ruby code.

I don't think there is one. It's a difficult problem because Ruby is such a
dynamic language (e.g. `method_missing'). (In fact, it's impossible to do a
perfect job automatically.)

I've been thinking a little about what would be needed to achieve at least
an "approximate" auto-completion.

Rdoc (inline documentation tool) gives us a list of classes and the methods they
implement. It allows for documenting methods/classes that it fails to find
automatically. I believe that any auto-completion system should use rdoc
data - if a method has been nicely documented you get auto-completion, and
otherwise you don't.

The missing component is the "type" a method returns. e.g. in your example,
that Array#sort returns an Array.

It's true that the methods an object responds to generally corresponds to
the instance methods of its class. So ignore the cases when this isn't true.

Also, methods can be redefined at runtime, e.g. Array#sort could be modified
to return a `MagicArray' having different methods. At least in these cases
the methods supported by the new return type should be approximately the
same as the old. (To preserve duck typing.) Ignore this problem.

Then add a tag to the rdoc markup for specifying return type(s) (as names of
classes). Methods defined in C extensions would need these to be specified
manually.

We can then do type inference on methods defined in Ruby to determine the
likely return types. We'll need some tricks for when many different types
can be returned, e.g. "def identity(x); x; end". Incorrect/incomplete
results can be fixed via the rdoc tag.

A big problem with this type guessing system is that when it gets a method
type wrong, the error will "bubble up" through the rest of the code, i.e.
any other method whose return value is from that method can be wrong too.
(Whereas if rdoc gets the methods of a class wrong, the error is localised.)

There are also some problems when the possible return "types" don't
correspond to any documented classes. e.g.
def method
class << Object.new
def hello
puts('hello'
end
end
end

Maybe we can live with these being wrong.


In a few weeks I may have time to experiment with these ideas. Whether
they're good probably depends whether confusion resulting from incorrect
inference causes more problems than it solves. (i.e. cure worse than the
complaint.)

timsuth

10/27/2004 3:52:00 AM

0

In article <slrncnttvj.tfp.timsuth@europa.zone>, Tim Sutherland wrote:
[...]
>There are also some problems when the possible return "types" don't
>correspond to any documented classes. e.g.
> def method
> class << Object.new
> def hello
> puts('hello'
> end
> end
> end
>
>Maybe we can live with these being wrong.
[...]

I meant:

def method
o = Object.new
class << o
def hello
puts('hello')
end
end
o
end

Francis Hwang

10/27/2004 4:15:00 AM

0

Patrick put it pretty well when we were hanging out talkin' Ruby night:
He said "The same features that make Ruby fun for humans to write makes
it hard for computers to read." All the extra typing you do for, say,
Java, makes it a lot easier to write things like auto-completion,
refactoring tools, etc.

At any rate, one thing I'd look at is 'irb/completion', which does
auto-completion in irb. I haven't looked at the internals, but I use it
all the time and it would be probably be a good place to start.

F.

On Oct 26, 2004, at 9:24 PM, Tim Sutherland wrote:

> In article <1098834541.819479.278620@f14g2000cwb.googlegroups.com>,
> Eli Tucker
> wrote:
>> Does anyone have any info on an IDE or editor that supports
>> auto-completion for Ruby?
>>
>> So far I've been using Scite which came with the One-Click Windows
>> Ruby
>> installer, but have not figured out how to turn on auto-completion (or
>> to be more specific, how to create the needed api file).
>>
>> I just downloaded RDE, but the auto-completion seems half baked. For
>> example, if I type the following:
>>
>> a = [4,2,3]
>> b = a.
>>
>> a pop-up is shown just like you would expect where I can select a
>> method of Array. But then if I continue along to here:
>>
>> a = [4,2,3]
>> b = a.sort
>> b.
>>
>> ... no pop-up is shown -- it doesn't know that b is an Array.
>>
>> Perhaps there isn't yet an IDE or editor for Ruby with auto-completion
>> features like those seen in Microsoft Visual Studio, Jet Brains IDEA,
>> or Eclipse? If not, I would be interested in hearing what other
>> developers are using to create ruby code.
>
> I don't think there is one. It's a difficult problem because Ruby is
> such a
> dynamic language (e.g. `method_missing'). (In fact, it's impossible to
> do a
> perfect job automatically.)
>
> I've been thinking a little about what would be needed to achieve at
> least
> an "approximate" auto-completion.
>
> Rdoc (inline documentation tool) gives us a list of classes and the
> methods they
> implement. It allows for documenting methods/classes that it fails to
> find
> automatically. I believe that any auto-completion system should use
> rdoc
> data - if a method has been nicely documented you get auto-completion,
> and
> otherwise you don't.
>
> The missing component is the "type" a method returns. e.g. in your
> example,
> that Array#sort returns an Array.
>
> It's true that the methods an object responds to generally corresponds
> to
> the instance methods of its class. So ignore the cases when this isn't
> true.
>
> Also, methods can be redefined at runtime, e.g. Array#sort could be
> modified
> to return a `MagicArray' having different methods. At least in these
> cases
> the methods supported by the new return type should be approximately
> the
> same as the old. (To preserve duck typing.) Ignore this problem.
>
> Then add a tag to the rdoc markup for specifying return type(s) (as
> names of
> classes). Methods defined in C extensions would need these to be
> specified
> manually.
>
> We can then do type inference on methods defined in Ruby to determine
> the
> likely return types. We'll need some tricks for when many different
> types
> can be returned, e.g. "def identity(x); x; end". Incorrect/incomplete
> results can be fixed via the rdoc tag.
>
> A big problem with this type guessing system is that when it gets a
> method
> type wrong, the error will "bubble up" through the rest of the code,
> i.e.
> any other method whose return value is from that method can be wrong
> too.
> (Whereas if rdoc gets the methods of a class wrong, the error is
> localised.)
>
> There are also some problems when the possible return "types" don't
> correspond to any documented classes. e.g.
> def method
> class << Object.new
> def hello
> puts('hello'
> end
> end
> end
>
> Maybe we can live with these being wrong.
>
>
> In a few weeks I may have time to experiment with these ideas. Whether
> they're good probably depends whether confusion resulting from
> incorrect
> inference causes more problems than it solves. (i.e. cure worse than
> the
> complaint.)
>



timsuth

10/27/2004 8:36:00 AM

0

In article <7D594374-27CF-11D9-8F01-000A95DBF456@fhwang.net>, Francis Hwang
wrote:
>Patrick put it pretty well when we were hanging out talkin' Ruby night:
>He said "The same features that make Ruby fun for humans to write makes
>it hard for computers to read." All the extra typing you do for, say,
>Java, makes it a lot easier to write things like auto-completion,
>refactoring tools, etc.

Very true.

>At any rate, one thing I'd look at is 'irb/completion', which does
>auto-completion in irb. I haven't looked at the internals, but I use it
>all the time and it would be probably be a good place to start.

irb/completion basically just uses `foo.methods'. irb is doing completion at
runtime. In an editor you really want compile-time completion.

gabriele renzi

10/27/2004 11:22:00 AM

0

Tim Sutherland ha scritto:


> irb/completion basically just uses `foo.methods'. irb is doing completion at
> runtime. In an editor you really want compile-time completion.

you don't necessarily need to have the two separated, just think of the
smalltalk environments.
A friend of mine points out often how cool the SLIME system for lisp
(based on emacs) is, and it is basically an ide talking to a live
environment (think of bridging irb and freeride or whatever)

Eivind Eklund

10/27/2004 11:50:00 AM

0

On Wed, 27 Oct 2004 08:54:03 +0900, Eli Tucker <eli-news@nerdmonkey.com> wrote:
> Perhaps there isn't yet an IDE or editor for Ruby with auto-completion
> features like those seen in Microsoft Visual Studio, Jet Brains IDEA,
> or Eclipse?

Tim Sutherland had a nice description of the problems in this, and the
approaches necessary to make it more or less work (and I think it
could work quite nicely for most day to day work, but there will be
breakdowns).

> If not, I would be interested in hearing what other developers are using to
> create ruby code.

I use vim, including use of its text based completion (Ctrl-N). This
completes the rest of the word/identifier I'm typing, and saves me
from getting typos in long identifiers (plus the typing, but that's
IMO less important.)

Eivind.
--
Hazzle free packages for Ruby?
RPA is available from http://www.rubyar...


Alexey Verkhovsky

10/27/2004 5:52:00 PM

0

On Wed, 2004-10-27 at 14:24, gabriele renzi wrote:
> Tim Sutherland ha scritto:
>
>
> > irb/completion basically just uses `foo.methods'. irb is doing completion at
> > runtime. In an editor you really want compile-time completion.

Some people were writing about continuous unit testing (where a test
runner senses file changes, runs test suite automatically and reports
problems, if any.

Maybe the way to make Ruby development environment more aware about the
code is somewhere along these lines?

Alex



Eli Tucker

10/27/2004 6:14:00 PM

0

Thanks for the thoughtful replies.

Eivind, I'm curious how vim knows what to complete with. Where does it
get the data?

Tim, thanks for rundown of the issues. I must admit that I didn't think
the impact of the dynamic nature of Ruby causing these problems.

Gabriele, I actually thought of this. Could there be some way in which
the IDE could be executing the program in memory, but not really
executing it -- just enough so that it can call whatever.methods? I'm
too new to the Ruby world to know if this type of things is possible.
- Eli

Bill Atkins

10/27/2004 6:30:00 PM

0

If it's anything like Emacs, it probably just looks for matching
symbols in the rest of the file. I could be wrong, though.

Bill

On Thu, 28 Oct 2004 03:19:01 +0900, Eli Tucker <eli-news@nerdmonkey.com> wrote:
> Eivind, I'm curious how vim knows what to complete with. Where does it
> get the data?


Eivind Eklund

10/27/2004 7:08:00 PM

0

On Thu, 28 Oct 2004 03:19:01 +0900, Eli Tucker <eli-news@nerdmonkey.com> wrote:
> Thanks for the thoughtful replies.
>
> Eivind, I'm curious how vim knows what to complete with. Where does it
> get the data?

vim looks in the loaded buffers, with priority rules that usually gets
things right (at least for me - but I'm used to them).

It isn't perfect but it is very useful.

Eivind.
--
Hazzle free packages for Ruby?
RPA is available from http://www.rubyar...