clojure-emacs / cider

The Clojure Interactive Development Environment that Rocks for Emacs
https://cider.mx
GNU General Public License v3.0
3.54k stars 646 forks source link

`sesman-use-friendly-sessions` not respected #3642

Closed FelipeCortez closed 5 months ago

FelipeCortez commented 5 months ago

Expected behavior

When setting up sesman-use-friendly-sessions to nil, use only explicitly linked sessions. Switching projects should make the modeline say cider[not connected] and evals shouldn't eval.

Actual behavior

Cider always picks up friendly sessions regardless of the value of sesman-use-friendly-sessions

Steps to reproduce the problem

Environment & Version information

;; CIDER 1.14.0-snapshot (package: 20240201.2038), nREPL 1.0.0
;; Clojure 1.11.1, Java 17.0.3

Emacs version

29.1

Operating system

macOS Sonoma 14.2.1

More details

the Cider docs say

When you evaluate some code from a dependency project and there are no explicit links in that project, the most recent friendly session is used to evaluate the code. Explicitly linked sessions have precedence over the friendly sessions.

You can disable friendly session inference by customizing sesman-use-friendly-sessions.

but can you really? I set this to nil after realizing that projects I didn't jack-into were picking up a REPL. then I noticed cider-current-repl calls cider-repls, and then sesman-current-session singular, which is

(defun sesman-current-session (system &optional cxt-types)
  ,,,
  (or (car (sesman--linked-sessions system 'sort cxt-types))
      (car (sesman--friendly-sessions system 'sort))))

sesman-current-sessions plural seems to respect use-friendly-sessions:

(defun sesman-current-sessions (system &optional cxt-types)
 ,,,
  (if sesman-use-friendly-sessions
      (delete-dups
       (append (sesman--linked-sessions system 'sort cxt-types)
               (sesman--friendly-sessions system 'sort)))
    (sesman--linked-sessions system 'sort cxt-types)))

originally posted in the Clojurians slack: https://clojurians.slack.com/archives/C0617A8PQ/p1713215082795399

vemv commented 5 months ago

Thanks!

Looks like you've found what seems quite clearly a bug in sesman-current-session (https://github.com/vspinu/sesman) - with an easy fix (observe the defcustom)

@vspinu do you agree?

vemv commented 5 months ago

(@FelipeCortez you should be able to redefine sesman-current-session in the meantime)

FelipeCortez commented 5 months ago

@vemv just did!

(defun my-sesman-current-session (system &optional cxt-types)
  (if sesman-use-friendly-sessions
      (or (car (sesman--linked-sessions system 'sort cxt-types))
          (car (sesman--friendly-sessions system 'sort)))
    (car (sesman--linked-sessions system 'sort cxt-types))))

(advice-add 'sesman-current-session :override #'my-sesman-current-session)

makes it work as expected.

bbatsov commented 5 months ago

I've commit access for Sesman, so if you file a PR there I can merge it.

FelipeCortez commented 5 months ago

@bbatsov thanks! here's the PR: https://github.com/vspinu/sesman/pull/28

FelipeCortez commented 5 months ago

updated sesman to the latest version with the fix and this seems to be working now. thanks for the assistance!