Skip to content
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

Completion with company-mode #5

Closed
chrisbarrett opened this issue Jun 3, 2014 · 36 comments
Closed

Completion with company-mode #5

chrisbarrett opened this issue Jun 3, 2014 · 36 comments

Comments

@chrisbarrett
Copy link
Collaborator

Find a way to get code-completion working with completion-at-point to enable auto-completion using company-mode.

@bbatsov
Copy link
Collaborator

bbatsov commented Jun 4, 2014

You'll need subprocess integration first. The completion part is trivial afterwards.

@ap4y
Copy link
Collaborator

ap4y commented Oct 14, 2014

Just wanted to mention that I was able to get completions from sourcekitd over xpc connection. It looks promising for code completion and proper syntax check.

@bbatsov
Copy link
Collaborator

bbatsov commented Oct 14, 2014

@chrisbarrett You should consider making @ap4y a project collaborator. His work so far has been outstanding!

@chrisbarrett
Copy link
Collaborator Author

Absolutely agreed. @ap4y, you have the power.

@ap4y
Copy link
Collaborator

ap4y commented Oct 14, 2014

Thanks guys, I'll do my best. :)

@Pitometsu
Copy link

Is it possible to use clang -code-completion-at or clang_codeCompleteAt() function for getting completions list? Is there any known way to get it?

@nathankot
Copy link
Contributor

I've been trying to achieve this using sourcekitten which acts as a sane interface to SourceKit.
My progress is here, I'll finish it / will be ready when jpsim/SourceKitten#71 makes it into a stable release

@ap4y
Copy link
Collaborator

ap4y commented Oct 1, 2015

looks interesting! Glad that sourcekitten added support for code completion

@terhechte
Copy link

I forked @nathankot's code and have a working version of Swift completion in Emacs now. You can try it out here:
https://github.com/terhechte/company-sourcekit

@nathankot
Copy link
Contributor

Nice! I'm gonna try it when I get home, I've been dabbling with mine but admittedly haven't gotten anywhere

Nathan Kot

On 12/11/2015, at 05:11, Benedikt Terhechte notifications@github.com wrote:

I forked @nathankot's code and have a working version of Swift completion in Emacs now. You can try it out here:
https://github.com/terhechte/company-sourcekit


Reply to this email directly or view it on GitHub.

@ap4y
Copy link
Collaborator

ap4y commented Nov 11, 2015

Looks good, like yasnippet integration. I have a question: does sourcekitten support something like clang compilation database or there is another way of defining args for the compiler?

@terhechte
Copy link

I played a bit around with it, and it still has a lot of rough edges. Initializers don't work too well, the return type isn't listed yet, and much more. However, I'm hopeful that most of that can be implemented easily.

@ap4y I may be wrong here, but sourcekitten uses the same XPC service (SourceKitD) as Xcode for code completion. However, Xcode has the service running in the background all the time, so I suppose that SourceKitD does internal caching. company-sourcekit currently runs sourcekitten for every completion call. It'd probably be better to keep the XPC service running. Technically that seems to be possible as sourcekitten also provides a framework which can be integrated in an app. Then, one would need to run a daemon that keeps the XPC running and emacs/company-sourcekit could connect to it and do completions. That's probably a lot more work though.

@ap4y
Copy link
Collaborator

ap4y commented Nov 11, 2015

Things might have changed, but when I played with sourcekit xpc you had to provide compilation args, maybe sourcekitten handles this internally. I think as a first cut non-daemon solution is good enough, but I like daemon idea a lot. I had a bit crazy (for OSX devs) idea of allowing remote calls for such daemon. I like emacs on linux (and tiling vms) a bit more, so I usually run linux VM on macbook or OSX VM on Linux machine, so being able to call some sort of remote api from Linux will help me a lot.

@terhechte
Copy link

Since I had to fix a bug in Sourcekitten in order to get this to work, I had a brief look at how it works, and those are the args that are send to the XPC for completion:

                "key.request": sourcekitd_uid_get_from_cstr("source.request.codecomplete"),
                "key.name": file,
                "key.sourcefile": file,
                "key.sourcetext": contents,
                "key.offset": offset,
                "key.compilerargs": (arguments.map { $0 as XPCRepresentable } as XPCArray)

Compilerargs look like this:
["-c", "F5341891-7247-401B-AEE6-EC4444DAE482.swift", "-sdk", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk"]

@ap4y
Copy link
Collaborator

ap4y commented Nov 11, 2015

Interesting, thanks for the info!

@nicklanasa
Copy link

I got this working too with company-sourcekit and it's glorious. Now for documentation and parameter completion. :D Great job.

@nathankot
Copy link
Contributor

@nicklanasa by parameter completion do you mean parameter placeholders? Because it should already work if you have yasnippet installed ;)

And you should get type annotations below the mode line, will look into getting some documentation that xcode normally displays available as well

company-sourcekit

@nicklanasa
Copy link

@nathankot I do have yasnippet installed but no parameter placeholders. How would I go about setting this up? or is there some fancy keyboard macro I'm missing?

@nicklanasa
Copy link

@nathankot I've cloned your fork of company-sourcekit and added it to my init.el but no haven't gotten it to work yet. :/

@nathankot
Copy link
Contributor

@nicklanasa yasnippet integration should work automatically by detecting whether or not you have yasnippet installed. To move between parameters you call yas-next-field-or-maybe-expand (or whichever key is bound to it)

Hmmm how did you add it to init.el? Try the following steps:

  • mkdir -p ~/.emacs.d/vendor
  • cd ~/.emacs.d/vendor
  • git clone https://github.com/nathankot/company-sourcekit.git
  • Add this to you init.el:
(add-to-list 'load-path "~/.emacs.d/vendor")
(require 'company-sourcekit)

@nathankot
Copy link
Contributor

@nicklanasa if you describe-variable and then company-sourcekit-use-yasnippet is it set to true? It might be switched off if company-sourcekit is loaded before yasnippet

@nicklanasa
Copy link

@nathankot Ok, so I got company-sourcekit to load and company-sourcekit-use-yasnippet is set to t. Company mode seems to be working show CGRect when I type something like CGR but I'm not getting any parameter placeholders.

Here's a screenshot and I've pushed my emacs config to my repo: https://github.com/nicklanasa/emacs/blob/master/init.el#L116

Thanks for your help so far!

screen shot 2015-11-13 at 10 04 10 pm

@nathankot
Copy link
Contributor

So right now company-sourcekit really only supports completion after typing
'.' I think the 'CGRect' completion you're getting is coming from another
backend. Can you try typing 'CGRect.' and see if anything shows up? Btw
have you built sourcekitten from master? There is a bug in the current
release that will prevent this from working.

nathankot/company-sourcekit#5 will also involve
getting completion to work for other prefixes

On Sat, Nov 14, 2015 at 4:06 PM, Nickolas Lanasa notifications@github.com
wrote:

@nathankot https://github.com/nathankot Ok, so I got company-sourcekit
to load and company-sourcekit-use-yasnippet is set to t. Company mode
seems to be working show CGRect when I type something like CGR but I'm
not getting any parameter placeholders.

Here's a screenshot and I've pushed my emacs config to my repo:
https://github.com/nicklanasa/emacs

Thanks for your help so far!

[image: screen shot 2015-11-13 at 10 04 10 pm]
https://cloud.githubusercontent.com/assets/787099/11161719/cb13fc92-8a52-11e5-9649-2d2c63915535.png


Reply to this email directly or view it on GitHub
#5 (comment)
.

@nicklanasa
Copy link

@nathankot Nothing shows up when I type CGRect. I installed sourcekitten via Homebrew, does Homebrew install it from the master branch?

@terhechte
Copy link

@nicklanasa try checking out master and building from source. I also first installed source kitten via homebrew, but that crashed with a Dylib error

@nicklanasa
Copy link

@terhechte Got it working when I build sourekitten from source on the master branch. Thanks everybody.

@nathankot
Copy link
Contributor

Hey guys just want to announce that @terhechte and I have spent a good amount of time getting emacs to do completion for swift and now it works!

Please try out company-sourcekit and let us know how it goes 😁

@stardiviner
Copy link

Is it possible to get completion on Linux?
I mean use Docker or virtualbox(vagrant) to get SourceKit etc.
Then complete in Linux?

@nicklanasa
Copy link

@nathankot Does it only work for Objective C Classes? Not seeing String show autocomplete suggestions just NSString

@nathankot
Copy link
Contributor

It should do (see screenshot). To debug you can M-x RET set-variable RET sourcekit-verbose RET t RET (before trying a completion) and check the *sourcekit-output* buffer for anything suspicious?

Note however that just like when using xcode there are situations where completion won't work if the file or project you're working on isn't compiling

screen shot 2015-12-06 at 11 47 59 pm

@terhechte
Copy link

@stardiviner The daemon (SourceKittenDaemon) just runs a webserver but currently requires OS X. If you run the SourceKittenDaemon on an OSX machine, you can connect to it from anywhere on your network (Linux, FreeBSD, etc) and get completions. So if OSX is your host, and Linux is your guest, you need to forward the webserver port from OSX into Linux, and then you could get completions. Similarly the other way around (OSX Guest, Linux Host).

Although right now, I believe, the SourceKittenDaemon webserver starts by default on "localhost" instead of "0.0.0.0", so I'm unsure whether it will be reachable from outside the machine, but that would be an easy fix.

@nicklanasa
Copy link

@nathankot That works but if I wanted to use String(format:...), I don't get completion for that only when using NSString. Also, any reason why it doesn't work with workspaces?

@nicklanasa
Copy link

Took a quick little video testing it and it returns the JSON but doesn't stop parsing it (it seems).
ezgif com-video-to-gif

@stardiviner
Copy link

@terhechte Thanks for your help.

@nathankot
Copy link
Contributor

@nicklanasa String(... isn't working for me either, seems like it is returning a never-ending amount of useless output.

We haven't gotten around to supporting workspaces yet. But since workspaces simply link multiple .xcodeproj's together, it should still work as long as you compile all the frameworks/dependencies in the workspace first (correct me if I'm wrong)

Let's continue this discussion @ nathankot/company-sourcekit#13 and nathankot/company-sourcekit#12

@taku0
Copy link
Member

taku0 commented Sep 18, 2016

Closing.

@taku0 taku0 closed this as completed Sep 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants