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 candidates for cider-find-resource #1062

Closed
expez opened this issue Apr 3, 2015 · 10 comments
Closed

Completion candidates for cider-find-resource #1062

expez opened this issue Apr 3, 2015 · 10 comments

Comments

@expez
Copy link
Member

expez commented Apr 3, 2015

If #1060 is tackled and #1059 is tackled we should also update cider-find-resource to give a completing read of all available resources, with thing-at-point providing a default for the jump.

@bbatsov
Copy link
Member

bbatsov commented Apr 4, 2015

Yeah, that'd be great. We'll need middleware support for this.

@bbatsov
Copy link
Member

bbatsov commented Apr 19, 2015

@alexander-yakushev maybe it makes sense to have some completion for resource names in compliment as well. Those can be triggered only in certain functions (e.g. resource).

@alexander-yakushev
Copy link
Member

Why not. There can be a source for that, that will work in resource function, and can be also called independently by cider-find-resource. It's fairly easy to write that source for someone who knows about that resource stuff, but I can do it too if you give me some leads.

@alexander-yakushev
Copy link
Member

@expez Do you know how to get a list of available resources?

@expez
Copy link
Member Author

expez commented Apr 20, 2015

@alexander-yakushev I just started using clojure.java.classpath in refactor-nrepl yesterday to list stuff on classpath. If you don't want to pull in another dep the relevant code is only a few lines which can be inlined easily.

In general it's not possible to get a complete listing of everything on the classpath, you can only get resources by name or traverse it yourself (which might be real slow if there's a ton of stuff on cp).

After obtaining the content on classpath the simplest thing to do is:

  1. Filter out all jars
  2. Descend into every directory listed on classpath and recursively find files.

This should give you everything you want, but also quite a bit of stuff nobody cares about in this context (e.g. the source files for the project and I think target/classes).

To narrow the field further I think you have to consult project.clj or boot.clj in order to find out what the actual resources are.

@alexander-yakushev
Copy link
Member

@expez Thank you, I will try it out.

@alexander-yakushev
Copy link
Member

OK, done and done in 0.2.2-SNAPSHOT. Resource completion works only in the appropriate context that looks like (resource "__prefix__"). Resource function can have any namespace qualifier like clojure.java.io/resource, jio/resource etc.

There is also compliment.sources.resources/resources-by-prefix that unconditionally returns a list of matching resources given a prefix. This should be used in the middleware for cider-find-resource.

I wrote tests, but I can't test the client side, AC does't want to complete from a string, even though I did (setq ac-disable-faces nil). Someone with company-mode test please.

@expez
Copy link
Member Author

expez commented Apr 20, 2015

Hot damn, that was quick! I can't see the code in the compliment repo, though.

@alexander-yakushev
Copy link
Member

Pushed.

Also, @bbatsov and me decided in alexander-yakushev/compliment#24 to complete only resources that belong to the current project. Otherwise, classpath contains a lot of stuff even after you filter out classes and source files. Java jars themselves have plenty of images and other resources.

If you have better ideas how to include more resources but omit the cruft, please share.

@alexander-yakushev
Copy link
Member

And sorry, I forgot to require the source, so it probably is not initialized. I redeployed 0.2.2-SNAPSHOT, please delete the old one and retry.

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

3 participants