goto definition understands (let)

This commit is contained in:
XeroOl 2022-08-30 22:30:39 -05:00
parent 2c47e61f2c
commit 69fcd63fad
No known key found for this signature in database
GPG Key ID: 9DD4B4B4DAED0322
4 changed files with 15 additions and 5 deletions

View File

@ -20,7 +20,7 @@ Features / To Do List / Things I would enjoy patches for:
- [X] table destructuring
- [X] multisyms
- [X] `.` special form (when called with constants)
- [ ] `do` special form
- [X] `do` and `let` special form
- [X] `require` and cross-module definition lookups
- [ ] goes to a.method on `(: a :method)` when triggered at `:method`
- [X] expanded macros (a little bit)
@ -33,15 +33,16 @@ Features / To Do List / Things I would enjoy patches for:
- [ ] mutation on aliased tables (difficult)
- [X] Reports compiler errors
- [ ] Reports linting issues
- [ ] Brainstorm more linting patterns (I spent a couple minutes brainstorming these ideas, other ideas are welcome of course)
- [ ] Unused locals
- [ ] Discarding results from pcall/xpcall/other functions.
- [ ] Discarding results from pcall/xpcall/other functions
- [ ] `unpack` or `values` into an operator special
- [ ] `do`/`values` with only one inner form
- [ ] redundant `do` as the last/only item in a form that accepts a "body"
- [ ] Dead code. (I'm not sure what sort of things cause dead code)
- [ ] `var` forms that could be `local`
- [ ] Dead code (I'm not sure what sort of things cause dead code)
- [ ] Unused fields (difficult)
- [ ] unification in a `match` pattern (difficult)
- [ ] Brainstorm more linting patterns (I spent a couple minutes brainstorming these ideas, other ideas are welcome of course)
- [ ] Completion Suggestions
- [X] from globals
- [ ] from current scope

View File

@ -12,6 +12,7 @@ the data provided by compiler.fnl."
(local -require- (sym :require))
(local -dot- (sym :.))
(local -do- (sym :do))
(local -let- (sym :let))
(var search nil) ;; all of the search functions are mutually recursive
@ -52,6 +53,9 @@ the data provided by compiler.fnl."
;; A do block returns the last form
[-do- & body]
(search self file (. body (length body)) stack)
[-let- _binding & body]
(search self file (. body (length body)) stack)))
(set search

View File

@ -66,7 +66,10 @@
(check :goto-definition.fnl 45 15 :goto-definition.fnl 40 7 40 13))
(it "works directly on a require/include (require XXX))"
(check :goto-definition.fnl 1 5 :bar.fnl 0 0 0 2)))
(check :goto-definition.fnl 1 5 :bar.fnl 0 0 0 2))
(it "goes to the last form of `do` and `let`"
(check :goto-definition.fnl 47 13 :goto-definition.fnl 47 30 47 52)))
;; TODO
;; (it "can go to a function in another file imported via destructuring assignment") ;; WORKS, just needs a test case

View File

@ -44,3 +44,5 @@
(local mixed [{:key [5 {:foo shallow}]}])
(local funny (. mixed 1 :key 2 :foo))
(print funny.field)
(local object (do (let [a 10] {:my-definition :here})))