From 06a6e8c7ea5d39d0186953ff88374870cd2f0480 Mon Sep 17 00:00:00 2001 From: XeroOl Date: Wed, 7 Sep 2022 21:19:36 -0500 Subject: [PATCH] Remove error response when hovering over nothing --- README.md | 2 +- src/fennel-ls/handlers.fnl | 4 +++- src/fennel-ls/language.fnl | 3 ++- src/fennel-ls/searcher.fnl | 2 +- src/fennel-ls/state.fnl | 4 +--- test/hover-test.fnl | 13 ++++++++++++- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 45ca013..1665748 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Features / To Do List / Things I would enjoy patches for: - [ ] from macros (only on first form in a list) - [ ] from specials (only on first form in a list) - [X] "dot completion" for table fields - - [ ] dot completion is aware of a string's fields + - [ ] dot completion is aware of a stdlib - [ ] from anywhere else that I'm forgetting right now - [ ] actually compliant rules about lexical scope (only see things declared before, not after) - [ ] show docs/icons on each suggestion diff --git a/src/fennel-ls/handlers.fnl b/src/fennel-ls/handlers.fnl index 2585ab1..a0ddd10 100644 --- a/src/fennel-ls/handlers.fnl +++ b/src/fennel-ls/handlers.fnl @@ -89,7 +89,8 @@ Every time the client sends a message, it gets handled by a function in the corr (match-try (language.find-symbol file.ast byte) symbol (language.search-main self file symbol {}) result {:contents {:kind "markdown" - :value (formatter.hover-format result)}}))) + :value (formatter.hover-format result)}} + (catch _ nil)))) (λ collect-scope [scope typ callback ?target] (let [result (or ?target [])] @@ -150,6 +151,7 @@ Every time the client sends a message, it gets handled by a function in the corr (send (message.diagnostics file))) (λ notifications.textDocument/didClose [self send {:textDocument {: uri}}] + ;; TODO reload from disk if we didn't get a didSave (local file (state.get-by-uri self uri)) (set file.open? false)) diff --git a/src/fennel-ls/language.fnl b/src/fennel-ls/language.fnl index 71746e4..912ddfb 100644 --- a/src/fennel-ls/language.fnl +++ b/src/fennel-ls/language.fnl @@ -57,7 +57,8 @@ the data provided by compiler.fnl." [-require- mod] (let [newfile (state.get-by-module self mod) newitem (. newfile.ast (length newfile.ast))] - (search self newfile newitem stack opts)) + (if newfile + (search self newfile newitem stack opts))) ; A . form indexes into item 1 with the other items [-dot- & split] (search self file (. split 1) diff --git a/src/fennel-ls/searcher.fnl b/src/fennel-ls/searcher.fnl index f02fed9..d71d729 100644 --- a/src/fennel-ls/searcher.fnl +++ b/src/fennel-ls/searcher.fnl @@ -40,7 +40,7 @@ I suspect this file is going to be gone after a bit of refactoring." (table.concat result ";"))) (λ lookup [{: root-uri} mod] - (match (or (fennel.searchModule mod (add-workspaces-to-path luapath [root-uri])) + (match (or ;; TODO support lua ;; (fennel.searchModule mod (add-workspaces-to-path luapath [root-uri])) (fennel.searchModule mod (add-workspaces-to-path fennelpath [root-uri]))) modname (utils.path->uri modname) nil nil)) diff --git a/src/fennel-ls/state.fnl b/src/fennel-ls/state.fnl index 67e1065..76323a0 100644 --- a/src/fennel-ls/state.fnl +++ b/src/fennel-ls/state.fnl @@ -42,9 +42,7 @@ object." uri (do (tset self.modules module uri) - (get-by-uri self uri)) - nil - (error (.. "cannot find module " module))))) + (get-by-uri self uri))))) (λ set-uri-contents [self uri text] (match (. self.files uri) diff --git a/test/hover-test.fnl b/test/hover-test.fnl index 231beb2..f938243 100644 --- a/test/hover-test.fnl +++ b/test/hover-test.fnl @@ -44,4 +44,15 @@ (check "hover.fnl" 12 9 "```fnl\nnil\n```")) (it "hovers over λ function" - (check "hover.fnl" 18 6 "```fnl\n(fn lambda-fn [arg1 arg2] ...)\n```\ndocstring"))) + (check "hover.fnl" 18 6 "```fnl\n(fn lambda-fn [arg1 arg2] ...)\n```\ndocstring")) + + (it "hovers over literally the very first character" + (local state (doto [] setup-server)) + (let [message (dispatch.handle* state + (message.create-request 2 "textDocument/hover" + {:position {:character 0 :line 0} + :textDocument {:uri (.. ROOT-URI "/hover.fnl")}}))] + (is-matching + message + [{:jsonrpc "2.0" :id 2}] + ""))))