Describe the bug
After connecting to the nrepl, I tried to simply eval the following expression:
By placing the cursor on the first parentesis and always got Not Found, I spent a few hours trying to debug but could not find the root cause, nevertheless I think the problem is with interop between lua and clojure, and the function get_code is not return the list.
This are the files I modified in my debug session:
diff --git a/lua/elin/sexpr.lua b/lua/elin/sexpr.lua
index 7c4203f..505314f 100644
--- a/lua/elin/sexpr.lua
+++ b/lua/elin/sexpr.lua
@@ -5,6 +5,7 @@ local get_node_from_cursor_position = function(cursor_row, cursor_col)
end
local function get_code(node)
+ vim.fn.writefile(node, 'elin.log', 'a')
local node_type = node:type()
local start_row, start_col, end_row, end_col = node:range()
local node_text = vim.api.nvim_buf_get_lines(0, start_row, end_row + 1, false)
@@ -14,7 +15,8 @@ local function get_code(node)
and string.sub(node_text[end_row - start_row + 1], 1, end_col - start_col)
or string.sub(node_text[end_row - start_row + 1], 1, end_col)
- return { code = table.concat(node_text, "\n"); lnum = start_row + 1; col = start_col + 1 }
+ return { code = "(+ 1 1)"; lnum = start_row + 1; col = start_col + 1 }
+
end
local function find_list_lit(node)
@@ -41,7 +43,12 @@ end
local get_list = function(cursor_row, cursor_col)
local node = get_node_from_cursor_position(cursor_row, cursor_col)
local list_node = node and find_list_lit(node) or nil
- return list_node and get_code(list_node) or nil
+ local result = list_node and get_code(list_node) or nil
+
+
+ vim.fn.writefile(node, 'elin.log', 'a')
+
+ return { code = "(+ 1 1)"; lnum = cursor_row + 1; col = cursor_col + 1 }
end
local get_expr = function(cursor_row, cursor_col)
diff --git a/src/elin/component/server/impl/sexpr.clj b/src/elin/component/server/impl/sexpr.clj
index 7124942..72be923 100644
--- a/src/elin/component/server/impl/sexpr.clj
+++ b/src/elin/component/server/impl/sexpr.clj
@@ -28,9 +28,11 @@
([host lnum col]
(get-list-sexpr!* host "" lnum col))
([host path lnum col]
+ (spit "debug.log" (str "get-list-sexpr!* Getting list at line: " lnum ", column: " col ",path: " path "\n") :append true)
(async/go
(e/-> (e.c.s.function/request! host "elin#internal#sexpr#get_list" [path lnum col])
- (async/<!)
+ (async/<!!)
+ #((spit "debug.log" (str "get-list-sexpr!* Response: " %) :append true) %)
(update-keys keyword)))))
(m/=> get-single-sexpr!* [:function
diff --git a/src/elin/function/evaluate.clj b/src/elin/function/evaluate.clj
index c2e0071..5e48623 100644
--- a/src/elin/function/evaluate.clj
+++ b/src/elin/function/evaluate.clj
@@ -66,8 +66,9 @@
([elin]
(evaluate-current-list elin {}))
([{:as elin :component/keys [nrepl]} options]
- (e/let [{:as base-params :keys [cursor-line cursor-column]} (get-base-params elin)
- {:keys [code lnum col]} (e.f.sexpr/get-list elin cursor-line cursor-column)]
+ (e/let [{:as base-params :keys [cursor-line cursor-column file]} (get-base-params elin)
+ _ (spit "debug.log" (str "DEBUG evaluate-current-list - base-params: " base-params "\n") :append true)
+ {:keys [code lnum col]} (e.f.sexpr/get-list elin file cursor-line cursor-column)]
(->> (merge options
base-params
{:line lnum :column col})
diff --git a/src/elin/function/sexpr.clj b/src/elin/function/sexpr.clj
index e72505f..1b32dcf 100644
--- a/src/elin/function/sexpr.clj
+++ b/src/elin/function/sexpr.clj
@@ -12,6 +12,7 @@
(m/=> validate-code-and-position [:=> [:cat e.s.host/?CodeAndPosition] (e.schema/error-or e.s.host/?CodeAndPosition)])
(defn- validate-code-and-position
[{:as code-and-position :keys [code]}]
+ (spit "debug.log" (str "Validating code and position: " code-and-position "\n") :append true)
(if (seq code)
code-and-position
(e/not-found)))
@@ -32,10 +33,14 @@
[:-> e.s.handler/?Elin string? int? int? (e.schema/error-or e.s.host/?CodeAndPosition)]])
(defn get-list
([{:component/keys [host]} lnum col]
+ (spit "debug.log" (str "get-list Getting list at line: " lnum ", column: " col "\n") :append true)
(e/-> (async/<!! (e.p.host/get-list-sexpr! host lnum col))
+ #((spit "debug.log" (str "get-list Result: " %) :append true) %)
(validate-code-and-position)))
([{:component/keys [host]} path lnum col]
+ (spit "debug.log" (str "get-list Getting list at line: " lnum ", column: " col ", path: " path "\n") :append true)
(e/-> (async/<!! (e.p.host/get-list-sexpr! host path lnum col))
+ #((spit "debug.log" (str "get-list Result: " %) :append true) %)
(validate-code-and-position))))
(m/=> get-expr [:function
And this are some of the logs I got:
DEBUG evaluate-current-list - base-params: {:cursor-line 2, :cursor-column 2, :line 2, :column 2, :file "/Users/juan/tools/get-api-status/core.clj"}
get-list Getting list at line: 2, column: 2, path: /Users/juan/tools/get-api-status/core.clj
get-list-sexpr!* Getting list at line: 2, column: 2,path: /Users/juan/tools/get-api-status/core.clj
Validating code and position: {:lnum 0, :col 0, :code ""}
Expected behavior
It is supposed to return => 2
Environemnt (please complete the following information):
- Editor: Neovim
- Editor version: v0.11.3
- Babashka version: v1.12.207
PS: Regular :ElinEval (+ 1 2) works as intended
nvim-config
Describe the bug
After connecting to the nrepl, I tried to simply eval the following expression:
By placing the cursor on the first parentesis and always got Not Found, I spent a few hours trying to debug but could not find the root cause, nevertheless I think the problem is with interop between lua and clojure, and the function
get_codeis not return the list.This are the files I modified in my debug session:
And this are some of the logs I got:
Expected behavior
It is supposed to return => 2
Environemnt (please complete the following information):
PS: Regular :ElinEval (+ 1 2) works as intended
nvim-config