From 69fcd63fad917517272a0f5cc841c17090e2fe9d Mon Sep 17 00:00:00 2001 From: XeroOl Date: Tue, 30 Aug 2022 22:30:39 -0500 Subject: [PATCH] goto definition understands (let) --- README.md | 9 +++++---- src/fennel-ls/language.fnl | 4 ++++ test/goto-definition-test.fnl | 5 ++++- test/test-project/goto-definition.fnl | 2 ++ 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0af689d..a6a94ee 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/fennel-ls/language.fnl b/src/fennel-ls/language.fnl index b7f71f2..61ece67 100644 --- a/src/fennel-ls/language.fnl +++ b/src/fennel-ls/language.fnl @@ -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 diff --git a/test/goto-definition-test.fnl b/test/goto-definition-test.fnl index 4f2e7a1..c8b89cf 100644 --- a/test/goto-definition-test.fnl +++ b/test/goto-definition-test.fnl @@ -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 diff --git a/test/test-project/goto-definition.fnl b/test/test-project/goto-definition.fnl index 019568d..5078808 100644 --- a/test/test-project/goto-definition.fnl +++ b/test/test-project/goto-definition.fnl @@ -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})))