quinnj / Sublime-IJulia

An IJulia Frontend for Sublime Text 3
90 stars 16 forks source link

Allow for IJulia auto-completion #38

Open cbecker opened 10 years ago

cbecker commented 10 years ago

(Apologies if this is already implemented but I just cannot find the way to trigger it) Is it possible to have auto-completion working within Sublime-IJulia, like plain IJulia or julia repl? This is extremely useful in many cases when debugging or trying to find functions/symbols. More specifically, I mean for example to type

str + <equivalent to tab> and get

julia> str
strchr      stringmime  string      strides     stride      strftime    strerror    strwidth    strip       strptime

I know there is base function auto-completion from sublime, but I wonder if something can be done to support the 'intrinsic' auto-completion of IJulia.

quinnj commented 10 years ago

Definitely possible, I just don't have time to really get around to it. To me, doing a quick parsing of the standard library was fairly painless and didn't involve any dealing with the kernel, plus the fact that you get the auto-completion in julia source files instead of just the console (though now that I think about it, there's not really a reason you couldn't set it up to work in julia source as well).

cbecker commented 10 years ago

Thanks. I managed to get it to work, after reading the ipython docs. Before filing a pull request, a question: Kernel.queue is the command queue, so I guess that we need to add another queue for auto-completion requests, does this make sense? Right now I can call self.complete(code), in the same way as one does to execute code with self.execute(code).

cbecker commented 10 years ago

Also, I wonder how to keep track of auto-completion, especially when in the middle of a command, for example if the cursor is in the middle of the code written in the sublime window, so that if the user accepts the completion, it should be updated properly.

This would require keeping track of the input and updating it properly, and also some what to know where the cursor is at when the auto-complete command is called.

quinnj commented 10 years ago

I'd have to look at your code to help further, so a PR may be best at this point. How are you planning on displaying the auto-completion list? Are you using a similar facility to Sublime's own autocompletion?

cbecker commented 10 years ago

I am not sure how to display the auto-completion list. For now it could be just showing the possible completions, returned by IJulia.

You can check my test here https://github.com/cbecker/Sublime-IJulia/tree/autocompletiontest Basically it will display the auto-completion list when the string to be run contains str. See my comments at https://github.com/cbecker/Sublime-IJulia/commit/9bc99e9cee4221ff5663b4cece7b6b5e730cdb83

I am not sure how to merge everything together, seems like the best solution requires quite a bit of coding to integrate it properly in sublime

quinnj commented 10 years ago

Working on this now. @one-more-minute, how do you do auto-completion in LightTable? I notice in particular that you are able to do completions for packages. Is that all through the Base REPLCompletions machinery, or do you have your own magic you're using?

MikeInnes commented 10 years ago

Take a look at Jewel.jl's completions.jl, all the logic is in there. I've tried not to make it too Light Table specific, so you should be able to call allcompletions with the code and a cursor position, feed the resulting data back to Sublime and have it work without too much hassle. I'm happy to work with you if changes are needed, though – just let me know if you want any more info.

quinnj commented 10 years ago

I'm not sure I understand the inputs to allcompletions. Do I want to pass in the entire file text as code and the cursor position as cursor? Seems like that might be prohibitive for large files? Or am I missing something?

MikeInnes commented 10 years ago

That's right, the idea is to pick up on the right context. You can only determine what module the user is in by parsing the whole file.

allcompletions returns a regex for pulling out the current token alongside the relevant hints. That way the frontend can react to input on its own without having to update the hints on every keypress. It definitely could be more efficient, but in practice it works quite well already.

OTOH if you're not worried about supporting modules other than Main, you could always just pass a single line in, e.g.

Jewel.allcompletions("  Pkg.", LNR.cursor(1, 7))
quinnj commented 10 years ago

Ah, I see. So if I pass the whole file, then the module parsing is done in the completions.jl code?

MikeInnes commented 10 years ago

Currently this call actually does the parsing, but really allcompletions should call that itself, that's just an oversight on my part. (So in principle, yes.)

malmaud commented 9 years ago

Any activity on this?