Help needed - Code completion

3 replies

Fri, 2011-10-21, 14:49

Aishwarya Singhal

Joined: 2011-09-09,

Hi

I am working on writing an IDE for Scala and need some help. I would
like to implement coding assistance so that I could present a list of
options when a user presses a period (".") or a space (" "). e.g. if
projects is a List, as soon as user types "projects." or "projects ",
I would like to show all methods of scala.List that he could use
(regular IDE stuff). I know that scala.tools.nsc.interactive package
provides this capability, but I am unable to figure out how to do it.
Besides, it seems that the interactive package would use REPL and
would be slow for this purpose. Is that a fair assumption, and if yes,
are there any alternatives?

Also, is there a way I could get a call reference tree for a literal/
method (where all is the method referred to in a code base) ?

On Fri, Oct 21, 2011 at 3:49 PM, Aishwarya Singhal wrote:
> Hi
>
> I am working on writing an IDE for Scala and need some help. I would
> like to implement coding assistance so that I could present a list of
> options when a user presses a period (".") or a space (" "). e.g. if
> projects is a List, as soon as user types "projects." or "projects ",
> I would like to show all methods of scala.List that he could use
> (regular IDE stuff). I know that scala.tools.nsc.interactive package
> provides this capability, but I am unable to figure out how to do it.

Have a look at CompilerControl, and at the tests in Scala trunk to get
an idea how to invoke those methods. They are in
test/files/presentation.

You can also have a look at the Eclipse IDE code, netbeans and ensime.
They all use the presentation compiler. It should be fairly easy to
find the source code yourself.

> Besides, it seems that the interactive package would use REPL and
> would be slow for this purpose. Is that a fair assumption, and if yes,
> are there any alternatives?

I don't think the REPL uses the presentation compiler.

>
> Also, is there a way I could get a call reference tree for a literal/
> method (where all is the method referred to in a code base) ?

I assume you mean 'find references'. Such functionality needs to be
coded by you. You can use lower-level services from the presentation
compiler to implement it (such as retrieving a parsed-and-typed AST
for a given source file). Given that type checking is time-consuming,
you should maintain an index per workspace (or project), and use it to
restrict the amount of type checking you need to do for a given search
term. For instance, if you look for all method references to 'foo',
use the index to find the set of files that mention 'foo', and then
typecheck only those (for locating the exact position of the
reference).

I'll also ask the obvious question: why don't you contribute to one of
the existing IDEs for Scala?

> I'll also ask the obvious question: why don't you contribute to one of
> the existing IDEs for Scala?

Sure, but my intent is to have something that's really light and non-
intrusive. Most of the existing ones I have come across are existing
IDEs for Java that are now offering Scala support. Nothing wrong with
it, but it just means that the IDE does a lot more than you would need
for scala coding. I am just avoiding building on top of something
that's already heavy. I could be totally mistaken and I may realise so
down the line, but I do want to give it a try :-)

On Oct 21, 7:53 pm, iulian dragos wrote:
> On Fri, Oct 21, 2011 at 3:49 PM, Aishwarya Singhal wrote:
> > Hi
>
> > I am working on writing an IDE for Scala and need some help. I would
> > like to implement coding assistance so that I could present a list of
> > options when a user presses a period (".") or a space (" "). e.g. if
> > projects is a List, as soon as user types "projects." or "projects ",
> > I would like to show all methods of scala.List that he could use
> > (regular IDE stuff). I know that scala.tools.nsc.interactive package
> > provides this capability, but I am unable to figure out how to do it.
>
> Have a look at CompilerControl, and at the tests in Scala trunk to get
> an idea how to invoke those methods. They are in
> test/files/presentation.
>
> You can also have a look at the Eclipse IDE code, netbeans and ensime.
> They all use the presentation compiler. It should be fairly easy to
> find the source code yourself.
>
> > Besides, it seems that the interactive package would use REPL and
> > would be slow for this purpose. Is that a fair assumption, and if yes,
> > are there any alternatives?
>
> I don't think the REPL uses the presentation compiler.
>
>
>
> > Also, is there a way I could get a call reference tree for a literal/
> > method (where all is the method referred to in a code base) ?
>
> I assume you mean 'find references'. Such functionality needs to be
> coded by you. You can use lower-level services from the presentation
> compiler to implement it (such as retrieving a parsed-and-typed AST
> for a given source file). Given that type checking is time-consuming,
> you should maintain an index per workspace (or project), and use it to
> restrict the amount of type checking you need to do for a given search
> term. For instance, if you look for all method references to 'foo',
> use the index to find the set of files that mention 'foo', and then
> typecheck only those (for locating the exact position of the
> reference).
>
> I'll also ask the obvious question: why don't you contribute to one of
> the existing IDEs for Scala?
>
> cheers,
> iulian
>
>
>
> > Thanks and Best regards
> > Aishwarya
>
> --
> « Je déteste la montagne, ça cache le paysage »
> Alphonse Allais