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 Completion #466

Open
LordMZTE opened this issue Feb 23, 2023 · 16 comments
Open

Common Lisp Completion #466

LordMZTE opened this issue Feb 23, 2023 · 16 comments

Comments

@LordMZTE
Copy link

It'd be awesome to get Conjure to provide completion for Common Lisp. I've looked far and wide, and couldn't find any suitable language server or other completion provider that's easy to integrate into nvim-cmp. Considering that Conjure otherwise makes for an amazing development environment, it'd be great to expand it further.

@glyh
Copy link

glyh commented Apr 3, 2023

I'm not sure about this. In my perspective, conjure is designed as an evaluation environment, rather than a completion source.

Also does that require common lisp codes in this project?

What's preventing you from writing a common lisp language server? That feels more modular than just integrate the feature you request for in this project.

@Olical
Copy link
Owner

Olical commented Jul 5, 2023

I'm very strongly leaning towards "just use LSP" for anything like this these days. The tooling outside and inside of Neovim has come along so far. LSP + DAP cover 90% of what everyone needs beautifully, Conjure should narrow it's focus down onto running your program and executing chunks of code, allowing you to merge the concept of editor and REPL. I'm going to close this in favour of recommending LSP for now, feel free to reopen or comment with opinions against this!

@Olical Olical closed this as completed Jul 5, 2023
@LordMZTE
Copy link
Author

LordMZTE commented Jul 6, 2023

This isn't an option, mainly since I've not found an LSP that works, but also because there is not really a way to do an LSP in the traditional sense in Common Lisp. The whole language environment is so dynamic that static analysis like what an LSP would typically do is impossible. The only way an LSP in CL could possibly work is if it were running under the same runtime as the REPL server Conjure is connected to. However, such an LSP does not exist.

Considering that this would then mean having 2 connections between the CL runtime and Neovim (1 for Conjure, 1 for this hypothetical LSP) whereas the SWANK API Conjure uses already provides LSP-like APIs for completion and such (I believe?), this solution makes little to no sense.

@Olical
Copy link
Owner

Olical commented Jul 6, 2023

Ah interesting, I didn't realise static analysis was kinda not valid in the CL space, I've never looked into it too closely and have very surface level knowledge. Thanks for explaining! I'll reopen and keep it in the backlog of things to enhance if there's no LSP with autocomplete for CL, I just thought it'd be similar to Clojure or something where yes there's REPL state, but it should almost perfectly reflect the static analysis anyway.

@Olical Olical reopened this Jul 6, 2023
@glyh
Copy link

glyh commented Jul 6, 2023

Well then the codebase should be shifted to another project that implement LSP based on Sly/Swank or whatever. BTW, Olical says he will likely to redesign this plugin (reference here ). I guess by then people can implement whatever they want in a separate plugin rather than keep throwing everything together.

@russtoku
Copy link
Contributor

russtoku commented Jul 8, 2023

Alternatives to LSP:

  • nvim-cmp-vlime is an nvim-cmp completion source for Common Lisp via Vlime (see List of sources). Downside: duplicated REPLs and more set-up.
  • Another project to build an nvim-cmp completion source plugin that would use the Conjure Common Lisp client's connection to a Common Lisp REPL running the Swank LISP code. Downside: a bit convoluted but, hopefully, less work than building an LSP server.

Having said that, if the future direction of Conjure stil includes completions as a client feature, then it would be reasonable to add the functionality to the Common Lisp client.

Of course, someone needs to implement the completion functionality whether the "mode" is LSP, nvim-cmp source, or client feature.

@Olical
Copy link
Owner

Olical commented Jul 8, 2023 via email

@Olical
Copy link
Owner

Olical commented Jul 8, 2023 via email

@russtoku
Copy link
Contributor

Looking at the Slimv plugin, it appears that these should ask Swank (running in the Common Lisp REPL) for completions:

  • Simple completions
'(swank:simple-completions "symbol" "package")'
  • Fuzzy completions
'(swank:fuzzy-completions "symbol" "package" :limit 2000 :time-limit-in-msec 2000)'

Slimv uses a Python provider to talk to Swank.
https://github.com/kovisoft/slimv

@russtoku
Copy link
Contributor

@LordMZTE, how do you have your Common Lisp set up with Swank? I haven't used Comon Lisp before and was going to try set up Conjure to talk to sbcl.

@russtoku
Copy link
Contributor

Oops! I just saw that there is a dev/common-lisp/README.adoc file. I'll read that.

@glyh
Copy link

glyh commented Jul 14, 2023

@LordMZTE
Copy link
Author

@LordMZTE, how do you have your Common Lisp set up with Swank? I haven't used Comon Lisp before and was going to try set up Conjure to talk to sbcl.

I use cl-repl as a command-line REPL. I've set up a custom command to start swank, so I just have to open cl-repl and type %swank to start a swank server. For the custom command, see my config.

@russtoku
Copy link
Contributor

russtoku commented Jul 14, 2023

Thanks @glyh and @LordMZTE !

I opened the dev/common-lisp/sandbox.lisp file and evaluated the forms there to verify that Swank is working.

Then I tried evaluating some forms that I thought might coax Swank into replying with some suggested words for completions. The simple-completions appear to work.

(swank:simple-completions "get" "")                                                             
; (("get" "get-decoded-time" "get-dispatch-macro-character"                                     
;   "get-internal-real-time" "get-internal-run-time" "get-macro-character"                      
;   "get-output-stream-string" "get-properties" "get-setf-expansion"                            
;   "get-universal-time" "getf" "gethash")                                                      
;  "get")

(swank:simple-completions "flo" "")                                                             
; (("float" "float-digits" "float-precision" "float-radix" "float-sign"                         
;   "floating-point-inexact" "floating-point-invalid-operation"                                 
;   "floating-point-overflow" "floating-point-underflow" "floatp" "floor")                      
;  "flo")

But fuzzy-completions doesn't work because there's no package loaded for it.

(swank:fuzzy-completions "flo" "" :limit 2000 :time-limit-in-msec 2000)                         
; The function SWANK:FUZZY-COMPLETIONS is undefined.

This should provide some starting point to flesh out a completions function in the Common Lisp client (fnl/conjure/client/common-lisp/swank.fnl). At least a simple one as mentioned in the Client features - Wiki.

@russtoku
Copy link
Contributor

@LordMZTE and @glyh, please try my PR and see if it helps.

@Olical
Copy link
Owner

Olical commented Jul 28, 2023

This is now merged into develop, thank you so much @russtoku 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants