Autocomplete from Java libraries in classpath?


#1

Hi guys,

I know there are a few Autocomplete packages, but from what I have seen, none of them provide you with autocomplete suggestions for methods that come from imported libraries or classes…

I have gotten used to Eclipse and similar IDEs whose autocomplete suggestions are practically infallible, giving you options from other packages (if classes and methods are public etc) and other libraries added to the project’s classpath…

Anything like that out there for Atom, by any chance?

Cheers


#2

Just found this other similar topic, though for Javascript:


#3

i don’t think that anyone have a solution for this ,
just move to another editors like brackets its much more better than atom when it coms to this .


#4

I would be surprised if it wasn’t possible for a package to look for dependencies like this.
Atom experts to the rescue!


#5

Are you sure brackets supports Java completion? Do you know how they do it?


#6

i was talking about javascript (about my post)


#7

I’m pretty sure it’ll be possible, but IDE-like features requires a lot of work and in general that work cannot be shared with other languages (except for really abstract features and uis), afaik the only language I know that is really editor friendly is Haxe as it’s the compiler itself that provides autocompletion and code insight, I wish more languages would take the same approach as haxe did.

As @MohamedAmine mention, Brackets has a great JS/CSS support when it comes to autocompletion. But it seems that it lacks support for many languages and is really intended to be a web development tool, so I wouldn’t expect it to provides this kind of autocompletion for anything beyond web technologies except with a third party extensions (which is pretty much the situation Atom is in).


#8

all of those open-source editors are not perfect by a way or another ,
the best choice now is paid IDE’s like phpstorm and komodo that is the conclusion .


#9

Maybe I’m a bit naive here, but I thought the whole point of the “hackable editor” was that you can make it do pretty much whatever you want, coding skills provided.

Now, I know there are limitation based on the technologies used and available API etc. But I don’t see anything fundamentally impossible in this case.

I could image it would be similar to a lint-type package, which, instead of just using its in-built references, also traverses the folder structure, provided that it follows a certain Java project structure (e.g. using package declarations or a configurable project config file etc).

I’m not up to the task, unfortunately, but I don’t see any real hindrance for a package like this.

Edit:
Also @MohamedAmine, what’s with the fatalism? We’re still in early stages, this is still a beta product, give it some time :wink:


#10

Of course it’s possible, but it’s a massive undertaking. I doubt anyone will spend hundreds of hours (if not thousands) implementing this, when there are existing IDEs that do a better job.

If you want a Java specific IDE experience, use Eclipse, IntelliJ, NetBeans, or some such. Unless you want to learn and take this on yourself, because I sincerely doubt anyone else will.


#11

It’s a shame. I didn’t think it would be such a large piece of work, but of course I never got far beyond the ascii-art package :wink:, so I really have no authority in this matter.

I’m happy to continue to use Eclipse for my Java purposes. I was just hoping this could be a relatively easy package for someone who knows how to work, say, the tree view and the project manager. It seems to me with those two you’d be off to a good start.

Here’s my (as I said, naive) expectation of how this might go down (e.g. in a Java file):

  1. Use a key-up event listener, similar to packages like autocomplete-plus to watch what’s being typed
  2. Wait for a dot ("."), then:
    1. Retrieve the word before the dot and assume it’s a class/object
    2. Check for so-named classes within the current folder structure (use package declaration at the top of this .java file), which have a public modifier and retrieve a list of all their methods and fields etc. (lots of damn regex, I’m sure)
    3. Create a tooltip window nicely placed under the current cursor position, listing those items.
    4. Let the user navigate through the list and select the right item to insert after the dot.
    5. Auto-import that class into this .java file.

That then can be nicely decorated and made real user-friendly.

Am I so far off here? The trickiest part I would imagine is getting the regular expressions right, but there must be something like that out there in google land, no?


#12

Well, for a good implementation, you need to determine accessibility level of each symbol. E.g. private methods should not be returned when outside the class that defines it. Same goes for local variables and what not. This is a non-trivial piece of work.

Your best bet to get close if want to stick to Atom, is to use Ctags. It supports Java, and Atom supports Ctags.


#13

Well, if the name before the dot is a class name, then sure … that would be reasonably easy. But if it is an instance variable, then you have to keep track of every symbol in the current file (or any symbol reachable by the current file) and what type it is. Then you can do your backtracking. Oh and you have to make it recursive for those instances where someone decides they want to make a method chain train …

Essentially, it gets ugly fast and moves beyond the ability of regular expressions to handle on their own. What is needed is a parser, one designed for each and every language that you want to support in your IDE. Preferably, one that allows you to easily update the AST on the fly rather than regenerate it from scratch like compilers and interpreters do.

I would love to see this kind of ability added to Atom in the future … don’t get me wrong. But it is going to require a lot of up-front work and it will require constant maintenance as the languages they support evolve.


#14

This is where the Haxe approach seems the right one to me. Why having a compiler if every editor have to re-implement the very logic the compiler already handle, and as @leedohm said, every times the language changes, the tools have to changes as well. Making the compiler a tool that both evaluates/validates/compiles your code and provides information for tools to use seems so logical when you think about it that I don’t understand why it didn’t became a rule of thumb of recent languages (yes I’m talking to you go, rust, etc.).

And it’s even worse when the language doesn’t have a proper compiler, statically typed languages will always have better autocompletion support than dynamic languages as they don’t need to actually run to provides information on a given variable/function. They know what you can expect on a given variable as you had to declare its type somewhere before. They can tell you what parameters a function expect. They can tell you what you can’t do. Dynamic languages are what they are, a magical tool for whoever wants to go fast without the burden of doing rocket science when what you need is just a playground to test ideas.

As @thomasjo said, it’s possible to have smart completion in Atom, but the risk is that you’ll have great support for language X that language Y won’t have (think of javascript with tern vs coffeescript). And I don’t see how Atom, being hackable, can provides a better answer to this problem when other editors failed as well to do it.

Talking about java, every time I had to work with it, the IDE I used at that time was requesting that I create a project, referencing the dependencies I used, and even if I had ant tasks or other custom build the IDE setup was mandatory if I wanted to have proper completion/validation (how many times do I had to figure why I had missing dependencies raised in the IDE where my ant tasks just worked).

The parsing part is just the tip of the iceberg. You can parse any file, it won’t tell you where to find class X and what are the methods available for type Y. Unless you had declared all that stuff beforehand. And java is probably not the worse language when it comes to declarative stuff (one of the reason I moved to languages like ruby, python or coffeescript, write less, read more).

My hope is that at some point compilers/transpilers/interpreters will all implements basic API to tell what you can expect to access at any given position in a file, but until that day, our brain, knowledge and intuition will do a better job than any tool.

In the end programming is just that, a game we play with our brain, trying to figure every path, every edge case, whether the computer understand it or not. Tools can help us, but they won’t be able to write beautiful/meaningful code by themselves unless we had figured it ourselves.


#15

Well, the problems are a bit more clear to me now. It always seems so straight forward when you’re used to an IDE doing shit for you when you need it.Like driving cars for decades without ever learning about how an Otto motor works.

Well who knows. Maybe someone enthusiastic, with lots of time on their hands, will take on the job anyway.

Thanks for your feedback, @leedohm, @thomasjo.
@abe I had never heard of Haxe, but that sounds like a very convenient design for a compiler. I’ll check that out sometime.


#16

I think the main problem is that it’s not so easy to find the class you’re looking for:

List x = new List();
x._

Underscore indicates the position of the cursor. Now you have to figure out that x is a List object, and then you need to figure out which methods do List objects provide. (They provide not only their own methods, but also methods inherited from other classes.)

Also, x could be a parameter to a method:

public void foo(List x) {
    x._
}

#17

i know that atom is new editor , maybe i expected much more than atom can do
with out essential features for essential languages like javascript i don’t think that atom will be capable of facing other editors & IDE’s
any way I will keep watching atom and hoping one day he will be my major editor :wink:


#18

I have a little ideal resolve this, I create new issue for my atom-ctags package

Add completion support for libraries by direct read it’s tagfile
https://github.com/yongkangchen/atom-ctags/issues/9


#19

atom-ctags now support setting extra tag files.