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

hotfix for Hy 1.0a1 #2

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.org
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
* Jedhy

/Last Hy version verified working for: Hy 0.16.0/
/Last Hy version verified working for: Hy 1.0a1/

~jedhy~ provides autocompletion, documentation introspection and formatting, and
other tools useful to IDEs for [[https://github.com/hylang/hy][Hy]], a lisp embedded in Python.
Expand Down
6 changes: 3 additions & 3 deletions jedhy/api.hy
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
;; * API

(defclass API [object]
(defn --init-- [self &optional globals- locals- macros-]
(defn __init__ [self [globals- None] [locals- None] [macros- None]]
(self.set-namespace globals- locals- macros-)

(setv self.-cached-prefix None))

(defn set-namespace [self &optional globals- locals- macros-]
(defn set-namespace [self [globals- None] [locals- None] [macros- None]]
"Rebuild namespace for possibly given `globals-`, `locals-`, and `macros-`.

Typically, the values passed are:
globals- -> (globals)
locals- -> (locals)
macros- -> --macros--"
macros- -> __macros__"
(setv self.namespace (Namespace globals- locals- macros-)))

(defn complete [self prefix-str]
Expand Down
26 changes: 13 additions & 13 deletions jedhy/inspection.hy
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
;; * Parameters

(defclass Parameter [object]
(defn --init-- [self symbol &optional default]
(defn __init__ [self symbol [default None]]
(setv self.symbol (unmangle symbol))
(setv self.default default))

(defn --str-- [self]
(defn __str__ [self]
(if (none? self.default)
self.symbol
(.format "[{} {}]" self.symbol self.default))))

;; * Signature

(defclass Signature [object]
(defn --init-- [self func]
(defn __init__ [self func]
(try (setv argspec (inspect.getfullargspec func))
(except [e TypeError]
(raise (TypeError "Unsupported callable for hy Signature."))))
Expand All @@ -39,7 +39,7 @@
argspec)))

#@(staticmethod
(defn -parametrize [symbols &optional defaults]
(defn -parametrize [symbols [defaults None]]
"Construct many Parameter for `symbols` with possibly defaults."
(when symbols
(tuple (map Parameter
Expand Down Expand Up @@ -122,7 +122,7 @@
[self.varkw "#**"]
[self.kwargs "&kwonly"]]))

(defn --str-- [self]
(defn __str__ [self]
(reduce self.-acc-lispy-repr self.-arg-opener-pairs (str))))

;; * Docstring conversion
Expand Down Expand Up @@ -206,24 +206,24 @@
;; ** Internal

(defclass Inspect [object]
(defn --init-- [self obj]
(defn __init__ [self obj]
(setv self.obj obj))

#@(property
(defn -docs-first-line [self]
(or (and self.obj.--doc--
(-> self.obj.--doc-- (.splitlines) first))
(or (and self.obj.__doc__
(-> self.obj.__doc__ (.splitlines) first))
"")))

#@(property
(defn -docs-rest-lines [self]
(or (and self.obj.--doc--
(->> self.obj.--doc-- (.splitlines) rest (.join "\n")))
(or (and self.obj.__doc__
(->> self.obj.__doc__ (.splitlines) rest (.join "\n")))
"")))

#@(property
(defn -args-docs-delim [self]
(or (and self.obj.--doc--
(or (and self.obj.__doc__
" - ")
"")))

Expand All @@ -250,7 +250,7 @@

#@(property
(defn obj-name [self]
(unmangle self.obj.--name--)))
(unmangle self.obj.__name__)))

#@(property
(defn lambda? [self]
Expand All @@ -265,7 +265,7 @@
#@(property
(defn method-wrapper? [self]
"Is object of type 'method-wrapper'?"
(instance? (type print.--str--) self.obj)))
(isinstance self.obj (type print.__str__))))

#@(property
(defn compile-table? [self]
Expand Down
42 changes: 34 additions & 8 deletions jedhy/macros.hy
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
(require [hy.extra.anaphoric [*]])

(import functools
itertools
[toolz.curried :as tz]

[hy.lex [unmangle
Expand All @@ -18,32 +19,57 @@

;; * Tag Macros

(deftag t [form]
(defmacro "#t" [form]
"Cast evaluated form to a tuple. Useful via eg. #t(-> x f1 f2 ...)."
`(tuple ~form))

(deftag $ [form]
(defmacro "#$" [form]
"Partially apply a form eg. (#$(map inc) [1 2 3])."
`(functools.partial ~@form))

(deftag f [form]
(defmacro "#f" [form]
"Flipped #$."
`(tz.flip ~@form))

;; * Misc

(defn -allkeys [d &kwonly [parents (,)]]
(defn -allkeys [d * [parents (,)]]
"In-order tuples of keys of nested, variable-length dict."
(if (isinstance d (, list tuple))
[]
#t(->> d
(tz.keymap (fn [k] (+ parents (, k))))
dict.items
(*map (fn [k v]
(if (isinstance v dict)
(-allkeys v :parents k)
[k])))
(itertools.starmap
(fn [k v]
(if (isinstance v dict)
(-allkeys v :parents k)
[k])))
tz.concat)))

(defn drop [count coll]
"Drop `count` elements from `coll` and yield back the rest."
(islice coll count None))

(defn first [coll]
"Return first item from `coll`."
(next (iter coll) None))

(defn last [coll]
"Return last item from `coll`."
(get (tuple coll) -1))

(defn allkeys [d]
(->> d -allkeys (map last) tuple))

(defn juxt [f #* fs]
"Return a function applying each `fs` to args, collecting results in a list."
(setv fs (+ (, f) fs))
(fn [#* args #** kwargs]
(lfor f fs (f #* args #** kwargs))))

(setv chain itertools.chain
islice itertools.islice
reduce functools.reduce
remove itertools.filterfalse
repeat itertools.repeat)
34 changes: 17 additions & 17 deletions jedhy/models.hy
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
hy
hy.compiler
hy.macros
[hy.compiler [-special-form-compilers :as -compile-table]]
[hy.compiler [_special_form_compilers :as -compile-table]]

;; Below imports populate --macros-- for Namespace
;; Below imports populate __macros__ for Namespace
[hy.core.language [*]]
[hy.core.macros [*]])

Expand All @@ -26,11 +26,11 @@
;; * Namespace

(defclass Namespace [object]
(defn --init-- [self &optional globals- locals- macros-]
(defn __init__ [self [globals- None] [locals- None] [macros- None]]
;; Components
(setv self.globals (or globals- (globals)))
(setv self.locals (or locals- (locals)))
(setv self.macros (tz.keymap unmangle (or macros- --macros--)))
(setv self.macros (tz.keymap unmangle (or macros- __macros__)))
(setv self.compile-table (self.-collect-compile-table))
(setv self.shadows (self.-collect-shadows))

Expand All @@ -40,9 +40,9 @@
#@(staticmethod
(defn -to-names [key]
"Function for converting keys (strs, functions, modules...) to names."
(unmangle (if (instance? str key)
(unmangle (if (string? key)
key
key.--name--))))
key.__name__))))

(defn -collect-compile-table [self]
"Collect compile table as dict."
Expand Down Expand Up @@ -83,22 +83,22 @@
;; * Candidate

(defclass Candidate [object]
(defn --init-- [self symbol &optional namespace]
(defn __init__ [self symbol [namespace None]]
(setv self.symbol (unmangle symbol))
(setv self.mangled (mangle symbol))
(setv self.namespace (or namespace (Namespace))))

(defn --str-- [self]
(defn __str__ [self]
self.symbol)

(defn --repr-- [self]
(defn __repr__ [self]
(.format "Candidate<(symbol={}>)" self.symbol))

(defn --eq-- [self other]
(when (instance? Candidate other)
(defn __eq__ [self other]
(when (isinstance other Candidate)
(= self.symbol other.symbol)))

(defn --bool-- [self]
(defn __bool__ [self]
(bool self.symbol))

(defn compiler? [self]
Expand Down Expand Up @@ -158,7 +158,7 @@
"shadowed"]

[obj?
(self.-translate-class obj.--class--.--name--)]
(self.-translate-class obj.__class__.__name__)]

[(.compiler? self)
"compiler"]
Expand All @@ -173,7 +173,7 @@
(defclass Prefix [object]
"A completion candidate."

(defn --init-- [self prefix &optional namespace]
(defn __init__ [self prefix [namespace None]]
(setv self.prefix prefix)
(setv self.namespace (or namespace (Namespace)))

Expand All @@ -182,7 +182,7 @@

(setv self.completions (tuple)))

(defn --repr-- [self]
(defn __repr__ [self]
(.format "Prefix<(prefix={})>" self.prefix))

#@(staticmethod
Expand Down Expand Up @@ -217,9 +217,9 @@
(+ (str self.candidate) "." completion)
completion))

(defn complete [self &optional cached-prefix]
(defn complete [self [cached-prefix None]]
"Get candidates for a given Prefix."
;; Short circuit the case: "1+nonsense.real-attr" eg. "foo.--prin"
;; Short circuit the case: "1+nonsense.real-attr" eg. "foo.__prin"
(when (and self.has-attr? ; The and ordering here matters for speed
(not self.obj?))
(setv self.completions (tuple))
Expand Down