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

Common Lisp/ros/swank not behaving as expected #561

Closed
kflak opened this issue Feb 29, 2024 · 15 comments
Closed

Common Lisp/ros/swank not behaving as expected #561

kflak opened this issue Feb 29, 2024 · 15 comments
Labels
bug Something isn't working client-commonlisp

Comments

@kflak
Copy link

kflak commented Feb 29, 2024

Hi,

Don't know quite how to formulate this, as I'm new to the CL ecosystem, but I am able to run this code within a ros repl with no issue:

(ql:quickload :cl-collider)
(in-package :sc-user)
(named-readtables:in-readtable :sc)

(setf *s* (make-external-server "localhost" :port 48800))
(server-boot *s*)

(defvar *synth*)
(setf *synth* (play(sin-osc.ar [320 321] 0 0.2)))

However, when running it in nvim/conjure with

❯ ros run --eval '(ql:quickload :swank)' --eval '(swank:create-server :dont-close t)'

I get this:

; 127.0.0.1:4005 (connected)
; with-protoent
; --------------------------------------------------------------------------------
; eval (root-form): (ql:quickload :cl-collider)
; To load "cl-collider":
;   Load 1 ASDF system:
;     cl-collider
; ; Loading "cl-collider"
; 
; 
(:CL-COLLIDER)
; --------------------------------------------------------------------------------
; eval (root-form): (in-package :sc-user)
#<PACKAGE "SC-USER">
; --------------------------------------------------------------------------------
; eval (root-form): (named-readtables:in-readtable :sc)
#<NAMED-READTABLE :SC {1005AB0633}>
; --------------------------------------------------------------------------------
; eval (root-form): (setf *s* (make-external-server "localhost...
; The function COMMON-LISP-USER::MAKE-EXTERNAL-SERVER is undefined.
; --------------------------------------------------------------------------------
; eval (root-form): (server-boot *s*)
; The variable *S* is unbound.
; --------------------------------------------------------------------------------
; eval (root-form): (defvar *synth*)
*SYNTH*
; --------------------------------------------------------------------------------
; eval (root-form): (setf *synth* (play(sin-osc.ar [320 321] 0...
; The function COMMON-LISP-USER::SIN-OSC.AR is undefined.

Running on arch linux with ros-installed sbcl:

❮ ros config  
sbcl.version=2.4.2
setup.time=3918183544
sbcl-bin.version=2.4.1
default.lisp=sbcl

Not sure if it's got to do with cl-collider only, or if it's a general issue... Any help much appreciated!

@Olical Olical added bug Something isn't working client-commonlisp labels Mar 1, 2024
@Olical
Copy link
Owner

Olical commented Mar 1, 2024

Hey sorry about the bug, it's because Conjure is swapping the package to "common-lisp-user" on each eval because it's looking for a defpackage form and not finding it. It's related to #557

I'm just trying to add a fix now that is a best effort contextual eval that should support multiple defpackage / in-package forms in a file. Conjure's context system was designed with Clojure in mind with one ns form at the top and you generally keep the link of file-namespace name. It looks like in CL people swap the package a lot in some files, so I haven't accounted for that yet.

I'm not a CL user so it's a bit unfamiliar to me, but I'll add a best effort fix for this to develop now.

@kflak
Copy link
Author

kflak commented Mar 1, 2024

Great, thanks! I'm also brand new to the whole world of CL, so it's all a bit confusing :-)

@Olical
Copy link
Owner

Olical commented Mar 1, 2024

Pushed a change to develop that I think addresses this? We now search up through the lines from your cursor position for the nearest in-package or defpackage then try to assume that package name with the eval you're doing. So it should support multiple regions in your files where you swap between packages for different calls.

I think that's useful for CL? But I'm really not sure! Let me know if that works for you. I can call the functions you listed in your example now but I do run into some other kind of errors, I think because I don't have whatever dependencies it needs installed.

@kflak
Copy link
Author

kflak commented Mar 1, 2024

Wow, that seems to work! Thanks a lot.

A couple of initial tests:

(in-package :sc-user)
(named-readtables:in-readtable :sc)

(setf *s* (make-external-server "localhost" :port 48800))
(server-boot *s*)

(defvar *synth*)

(setf *synth* (play(sin-osc.ar [320 321] 0 0.2))) ;; evaluating root form here...
(free *synth*) ;; ... also evaluates this.

(server-quit *s*) ;; evaluating root form on this also evaluates the previous two forms.

Not sure if this is expected behavior....

@Olical
Copy link
Owner

Olical commented Mar 1, 2024 via email

@kflak
Copy link
Author

kflak commented Mar 1, 2024

Yup, using treesitter. I did notice, however, that the highlighting is off in a way that suggests something is not quite right here...:
2024-03-01_17:49:49

@Olical
Copy link
Owner

Olical commented Mar 1, 2024

Good spot! That's 100% related, the highlighting and Conjure's view of your code tree are interlinked in tree sitter. So if what you're seeing is wrong, Conjure is seeing the same when it queries the tree. You might have to update your tree sitter parsers, I've had to do that between Neovim versions before otherwise I saw similar problems.

@kflak
Copy link
Author

kflak commented Mar 1, 2024

OK, so treesitter is to blame here, I think :-) Tried updating it, but seems it hasn't seen an update for 4 months, so there may be some breaking changes in the treesitter since then. When I disable treesitter for commonlisp the evaluation works as expected. If I have a bit more time I'll open an issue over at cl-treesitter!

@kflak
Copy link
Author

kflak commented Mar 1, 2024

Ah, figured out where treesitter stumbles: it doesn't like the square brackets in this expression:

(setf *synth* (play(sin-osc.ar [320 321] 0 0.2))) ;; evaluating root form here...

When I change those to regular parentheses it all works fine.

@russtoku
Copy link
Contributor

russtoku commented Mar 2, 2024

@Olical commented:

I'm just trying to add a fix now that is a best effort contextual eval that should support multiple defpackage / in-package forms in a file. Conjure's context system was designed with Clojure in mind with one ns form at the top and you generally keep the link of file-namespace name. It looks like in CL people swap the package a lot in some files, so I haven't accounted for that yet.

I think that it should be the nearest preceeding in-package form from the form or item being evaluated. I've put a comment regarding this on the discussion #557.

But I will try the fix added to the develop branch to see how things works so far.

@russtoku
Copy link
Contributor

russtoku commented Mar 2, 2024

I tried the fix added to the develop branch (20df0e0) and it seems to work.

@Olical
Copy link
Owner

Olical commented Mar 2, 2024 via email

@russtoku
Copy link
Contributor

russtoku commented Mar 2, 2024

No, just in-package should be OK.

@Olical
Copy link
Owner

Olical commented Mar 11, 2024

So are we happy with this now? I'm going to merge anyway and get it in more hands, I think it's solid theoretically from what I understand of CL now. Thanks for doing research, sharing it and testing this @russtoku ❤️

@Olical
Copy link
Owner

Olical commented Mar 22, 2024

Closing this issue because I think we did it! Please re-open if you run into issues!

@Olical Olical closed this as completed Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working client-commonlisp
Projects
None yet
Development

No branches or pull requests

3 participants