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

<localleader>ee, <localleader>E evaluate the whole file #547

Open
jminh opened this issue Dec 17, 2023 · 9 comments
Open

<localleader>ee, <localleader>E evaluate the whole file #547

jminh opened this issue Dec 17, 2023 · 9 comments
Labels
bug Something isn't working

Comments

@jminh
Copy link

jminh commented Dec 17, 2023

(1) <localleader>ee is used to evaluate the current form
(2) <localleader>E is used to evaluate the current selection

But they seems to evaluate the whole file as well. Is this an expected behavior?

Take following file for example, we can print the vaule of a and b after using
<localleader>ee or <localleader>E to evaluate example_input.

$ cat src/hello.clj
(ns hello
  (:gen-class))

(def example_input "199
200
208
210
200
207
240
269
260
263")

(def a 1)
(def b 2)

Here is the full setup of the small example.

$ cat deps.edn
{:deps {org.clojure/clojure {:mvn/version "1.10.1"}}
   :paths ["src" "resources"]
    :aliases {:test {:extra-paths ["test"]}}} ;; <- test alias
    
$ cat src/hello.clj
(ns hello
  (:gen-class))

(def example_input "199
200
208
210
200
207
240
269
260
263")

(def a 1)
(def b 2)

To reproduce the issue, you can create deps.edn and src/hello.clj and then on a
terminal run:

clj -Sdeps '{:deps {nrepl/nrepl {:mvn/version "1.0.0"} cider/cider-nrepl {:mvn/version "0.42.1"}}}' \
    --main nrepl.cmdline \
    --middleware '["cider.nrepl/cider-middleware"]' \
    --interactive

On a second terminal, start nvim as below:

nvim src/hello.clj

We'll see messages like:

; localhost:34235 (connected): .nrepl-port

Use <localleader>ee to evaluate example_input, we'll see

; eval (current-form): (def example_input "199 200 208 210 200 20...

Or use <localleader>E to evalute example_input, we'll see

; eval (selection): (def example_input "199 200 208 210 200 20...
#'hello/example_input

Then we can print out the value of a and b.

@Olical
Copy link
Owner

Olical commented Dec 17, 2023

Not something I'm seeing and definitely not expected. Could you try running :TSInstall clojure or :TSUpdate for me and see if that helps?

@Olical
Copy link
Owner

Olical commented Dec 17, 2023

That's assuming you're using TreeSitter which I highly recommend. If not, what does your syntax highlighting situation look like? Do you have any?

@jminh
Copy link
Author

jminh commented Dec 18, 2023

Could you try running :TSInstall clojure or :TSUpdate for me and see if that helps?

Below is the ouput of running :TSUpdate .

E492: Not an editor command: TSUpdate

If not, what does your syntax highlighting situation look like? Do you have any?

I do have syntax highlight for clojure file but I am not sure what information
you are looking for.

But it reminds me one recent change I made in ~/.config/nvim/init.vim is using
nvim default colorscheme since nvim 0.10.0 comes with a new default colorscheme.
So I changed it to my original colorscheme setting as below.

  # Before the change
  colorscheme default
  
  # After the change (my orignal colorscheme setting)
  set termguicolors
  let g:equinusocio_material_style = 'darker'
  colorscheme equinusocio_material

With such change there is no such "<localleader>ee, <localleader>E evaluate the
whole file" issue .

I have no idea why such simple change can fix the issue and after that I cannot
reproduce the issue when I switch back the default colorscheme.

@Olical
Copy link
Owner

Olical commented Dec 23, 2023

Cool so we've confirmed you're not using TreeSitter, might be worth setting it up, I think it's vastly superior to the default system in Neovim and it allows Conjure to do some more tricks for you.

My hunch is that this new Neovim scheme is tagging the words with different highlight groups that Conjure doesn't expect for some reason. In the default mode, it's looking for certain highlight groups to work out if you're inside a string or not (for example), with tree sitter we can query the tree to see what kind of nodes your cursor is in.

I'll have to reproduce this myself with this new theme and see what the issue is, will get back to you when I've got some evidence.

@Olical
Copy link
Owner

Olical commented Dec 23, 2023

Ah Neovim 0.10 isn't out yet! I see, will get a copy of it somehow and reproduce the issue hopefully.

@Olical
Copy link
Owner

Olical commented Dec 23, 2023

Hm, I'm using 0.10 with the new default colorscheme and tree sitter disabled but it all works fine for me 🤔 I can't reproduce the issue, maybe it's because I loaded the buffer with another scheme / tree sitter which polluted some shared mutable state. I'll try to open Neovim fresh with these settings and this version.

@Olical
Copy link
Owner

Olical commented Dec 23, 2023

Still can't reproduce the issue on NVIM v0.10.0-dev-1938+g242261d4e with Clojure's tree sitter module uninstalled, the theme set to default. Everything works as expected for me,

What is the issue you're actually seeing? Because after re-reading your initial comment I don't see any problems there in your example. You're evaluating the (def example_input ...) form which is working and returning the var. Are you saying that when you do that you'd expect to see the example_input get defined but instead the entire file is being evaluated?

And if the entire file is evaluated then you should be seeing the result of (def b 2) after each evaluation since it's the last form in the file.

I think I'm misunderstanding something here, I'd like to help, I just need a little more of a "what you're seeing" and "what you expect to see" I think? Thanks!

@Olical Olical added the bug Something isn't working label Dec 23, 2023
@jminh
Copy link
Author

jminh commented Dec 26, 2023

Cool so we've confirmed you're not using TreeSitter, might be worth setting it up, I think it's vastly superior to the default system in Neovim and it allows Conjure to do some more tricks for you.

I have a side question. Would you elaborate a bit what's additional benefit if I
use tree sitter for a Lisp dialect language?

Note: (1) IIRC last time I check out this plugin there is no tree sitter support
and it still supported clojure. (2) README only says for non Lisp languages
enabling tree sitter is required if we want to use form based evaluation
mappings(ex: <prefix>ee). But there is no mention about the additional feature
tree sitter can provide for a Lisp language.

What is the issue you're actually seeing? Because after re-reading your initial comment I don't see any problems there in your example. You're evaluating the (def example_input ...) form which is working and returning the var. Are you saying that when you do that you'd expect to see the example_input get defined but instead the entire file is being evaluated?

Yes, the entire file is being evaluated as well. If there is anything not clear
in the reproduce steps please let me know.

@Olical
Copy link
Owner

Olical commented Dec 30, 2023

This is a good summary of the benefits of tree sitter https://thevaluable.dev/tree-sitter-neovim-overview/

For Conjure specifically you get accuracy in some cases (allowing you to evaluate things like Clojure deref, set and short function syntax correctly) AND performance on slower machines because Conjure doesn't have to hunt character to character looking for matching parenthesis. You also get features such as the comment block eval which treats (comment ...) forms like a (do ...) so you can evaluate comments containing developer tools easily.

And then there's the more obvious one of being able to evaluate Python / Lua etc as if it was a lisp.

I've found my syntax highlighting is far deeper and more meaningful with TS and I don't run into issues where something is highlighted incorrectly because my regex line limit is set too low.

I wouldn't be surprised if it one day completely replaced the regex engine as the default system in Neovim, only using regex as a fallback for some languages.

I'd consider it the first class highlighting / parsing system for Conjure, it's fantastic as a plugin author to have access to an AST instead of a string of characters with an archaic regex based tagging system as my only source of semantic information. I treat the regex support as a fallback these days, so still supported, but just the essentials.

I haven't attempted to reproduce your actual issue just yet, I've been staying with my family for a week or so and haven't found the time. I'll try to do it soon though! Would be great to know if anyone else has this issue too. And do you see the issue with ANY other theme, or just the new Neovim one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants