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

Add finding docs functionality from ClojureDocs #64

Merged
merged 2 commits into from Jul 20, 2019

Conversation

liquidz
Copy link
Member

@liquidz liquidz commented Jul 10, 2019

PR for clojure-emacs/cider#2663
Introduce finding docs functionality from not Grimoire but ClojureDocs

  • The commits are consistent with our contribution guidelines
  • You've added tests to cover your change(s)
  • All tests are passing
  • The new code is not generating reflection warnings

@@ -0,0 +1,35 @@
(ns orchard.clojuredocs
"Find docs from ClojureDocs and retrieve the result as a map."
{:author "Masashi Iizuka"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add to the metadata that the namespace was added in version 0.5.

(defn- map-from-key [f coll]
(reduce #(assoc %1 (f %2) %2) {} coll))

(defn update-documents-cache!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can just name this update-cache!, as it's clear from the namespace which cache we are referring to.

(reset! cache))
true))

(defn find-document
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can't come up with a better name here, as the word document implies something else. Perhaps find-doc (for documentation). Can't think of a great name, but names are important.

@bbatsov
Copy link
Member

bbatsov commented Jul 17, 2019

Apart from my small remarks the changes look good to me. I just wonder if now we should replace the usage of the see-also.edn with this and weather to integrate more of this data (e.g. notes and examples) into the info as well. //cc @arichiardi @SevereOverfl0w @dpsutton

@SevereOverfl0w
Copy link
Collaborator

It would be nice to carry this along with the info as well, given this is cached it's probably going to have a reasonable performance. We are loading the full 2.8M string into memory with the slurp, so that might be something to consider changing, but I haven't looked deeply at the memory meter and considered whether we care.

@liquidz
Copy link
Member Author

liquidz commented Jul 17, 2019

@bbatsov Thank you for your reviewing!
I fixed them.

@arichiardi
Copy link
Contributor

The patch looks good to me apart from the slurp of the whole thing which we could maybe do lazily ad hoc if we had a different data format (one file per ClojureDocs entry?). Could be an optimization for later.

On another note we should potentially merge this to https://github.com/cljs/api for ClojureScript support.


Return nil if there is no matching document."
{:added "0.5.0"}
[export-edn-file ns-name var-name]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One final remark - I think here edn-file should be an optional param, as we know the default location of the file after it's downloaded and specifying it explicitly all the time seems redundant to me.

A EDN format file is expected to the `export-edn-file` argument.
(e.g. https://clojuredocs-edn.netlify.com/export.edn)"
{:added "0.5.0"}
[export-edn-file]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should make this param optional and load the cache straight from the default url.

@bbatsov
Copy link
Member

bbatsov commented Jul 17, 2019

@liquidz After reading the code once more I thought of something else - it'd be nice if we were saving the export file locally, so it could be loaded directly on future invocations of Orchard. We can add some load-cache function which checks if the file is locally available (and it's not older than a week) and this function can call update-cache! then. I think that'd be a more user-friendly experience in general.

@liquidz
Copy link
Member Author

liquidz commented Jul 17, 2019

@bbatsov I thought to do that on the editor plugin side.
But because it adds extra work, I agree to save the exported file locally on orchard side.

How about to save the file in $XDG_CACHE_HOME/orchard/clojuredocs/export.edn ?
cf. https://standards.freedesktop.org/basedir-spec/latest/

@bbatsov
Copy link
Member

bbatsov commented Jul 17, 2019

Yeah, that sounds good to me.

@SevereOverfl0w
Copy link
Collaborator

https://github.com/soc/directories-jvm even if not used, should have it's methods ported, in order to properly support windows & mac properly.

@liquidz
Copy link
Member Author

liquidz commented Jul 17, 2019

@SevereOverfl0w Thanks!
I'll port some of them!

@liquidz liquidz force-pushed the feature/clojuredocs branch 2 times, most recently from 01edbb5 to 571f9bd Compare July 19, 2019 16:55
@liquidz
Copy link
Member Author

liquidz commented Jul 19, 2019

@bbatsov @SevereOverfl0w Fixed!

I tested orchard.directory/cache-dir for Windows on AppVeyor.
https://ci.appveyor.com/project/liquidz/windows-test/builds/26108911
Tested codes (same as orchard.directory/cache-dir) are here:
https://github.com/liquidz/windows-test/blob/master/src/windows_test/directory.clj

@@ -0,0 +1,67 @@
(ns orchard.directory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this namespace should be named in some more generic way (provided we want to keep there os-related functionality). Maybe orchard.os or orchard.platform? Not sure how this is typically named.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like orchard.os shorter!

@@ -3,8 +3,19 @@
[clojure.java.io :as io]
[clojure.string :as str]))

(def os-name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can put the os-* in the new namespace as well. We'll just keep the existing functions here for compatibility and deprecate them.

:added "0.5.0"}
(:require [clojure.java.io :as io]
[clojure.string :as str]
[orchard.misc :as u])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think misc is a better alias than u. :-) The weird aliases in the codebase today are due to the fact that this namespace was named util in cider-nrepl (if I recall correctly that is).

@liquidz
Copy link
Member Author

liquidz commented Jul 20, 2019

@bbatsov Thank you for your reviewing! I fixed them!

@bbatsov bbatsov merged commit e664c92 into clojure-emacs:master Jul 20, 2019
@bbatsov
Copy link
Member

bbatsov commented Jul 20, 2019

Great work! I'll cut a new beta now, so you can update cider-nrepl accordingly.

@bbatsov
Copy link
Member

bbatsov commented Jul 20, 2019

Hmm, seems I pushed beta-9 from my other PC without doing git push and now I don't have access to the other computer. Guess we'll mess up a bit the git history now, but whatever.

@bbatsov
Copy link
Member

bbatsov commented Jul 20, 2019

0.5.0-beta10 is out!

@liquidz
Copy link
Member Author

liquidz commented Jul 20, 2019

Thanks! I'll create a PR to cider-nrepl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants