Skip to content

Conversation

vspinu
Copy link
Contributor

@vspinu vspinu commented Oct 11, 2018

Implement "friendly" sessions - sessions linked to dependent projects. Fix #2446, close #2464 and re-fix #2408 in a more elegant way.

The best way I could find to implement this is by searching through the classpath for the buffer file path. I have no estimation of how fast this is and whether it could cause performance issues. Remains to be seen. I am caching the classpath on the first use and haven't seen any issues in my experiments.

Regarding #2464, I will add at some point an option to sesman for picking first available session in non-linked contexts, but let's first see if this is really necessary for the CIDER's use case.


Before submitting the PR make sure the following things have been done (and denote this
by checking the relevant checkboxes):

  • The commits are consistent with our contribution guidelines
  • You've added tests (if possible) to cover your change(s)
  • All tests are passing (make test)
  • All code passes the linter (make lint) which is based on [elisp-lint]
  • You've updated the changelog (if adding/changing user-visible functionality)
  • You've updated the user manual (if adding/changing user-visible functionality)

@arrdem
Copy link
Contributor

arrdem commented Oct 11, 2018

Nice! Note that there may be some unfortunate intricacies with (non)absolute paths in the classpath here, and buffers whose file names aren't absolute. Spoken as someone who uses a lot of symlinks ;)

@vspinu
Copy link
Contributor Author

vspinu commented Oct 11, 2018

(non)absolute paths in the classpath here

Is this the case? I don't see simlinks in my classpaths.

I am afraid running file-truename on every entry in the class path might be a considerable performance hit, even if it's done once.

buffers whose file names aren't absolut

This is taken care of.

(or (null host)
(equal host (plist-get ses-params :host))))))
(sesman-linked-sessions 'CIDER '(project)))))
(sesman-current-sessions 'CIDER '(project)))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, shouldn't this be just sesman-sessions or something? Both linked and current seem misleading to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already sesman-sessions which returns ALL sessions for a system. linked and current have slightly different semantics. Linked should be very clear given that linking is such a central concept in sesman; "current" conveys a general idea of "active" sessions in the current context. It basically means linked + friendly sessions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I get this, but I feel that sesman-sessions should just return all sessions by default and narrow this down depending on optional params passed to it. Seems to me we've used relevant instead of current in CIDER, but I generally feel that in the present of the params it's pretty clear what sessions we're talking about without adding more functions to the API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree in general and in case of sesman-sessions this might actually work better. There is also sesman-links and sesman-current-links. Plus sesman-current-session which is the (car (sesman-current-sessions)). Let me see if I could simplify the api without making too many tradeoffs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave it a bit of thought and I am afraid the sesman-current-sessions and sesman-current-links will have to stay. The reason for the "current" instead of "relevant" is because those are sessions active in the current context and the sesman-current-session is the most relevant session for the current context. The latter is also how CIDER calls its most relevant repl. The reason for not subsuming sesman-current-session into sesman-sessions is because I would need to subsume sesman-current-links (which is a bit trickier) and the CIDER code would have to look like (sesman-sessions 'CIDER '(linked friendly) 'sort) which is rather annoying as all readers will have to learn about all those internals, while sesman-current-sessions is kinda self-explanatory.

It makes sense to subsume sesman-friendly-sessions and sesman-linked-sessions though. Those are somewhat internal. Looking into that right now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, fine by me.

(file-len (length file)))
(seq-find (lambda (path)
(when (>= file-len (length path))
(string= path (substring file 0 (length path)))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you just simplify all of this using string-prefix-p or something along those lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha. I didn't know about string-prefix-p. Will do.

- <kbd>C-c C-s p</kbd> `sesman-link-with-project`
- <kbd>C-c C-s u</kbd> `sesman-unlink`

## Friendly Sessions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like much the friendly term, but I'm not sure what'd be better here. Did you entertain any other names for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought of "external" after similar concept in project.el but I don't like it much. I think "friendly" is pretty suggestive and generic. There might be other notions of "friendliness" than dependency. If you have other ideas I am all ears.

@bbatsov
Copy link
Member

bbatsov commented Oct 12, 2018

Implement "friendly" sessions - sessions linked to dependent projects

And jars I guess.

@vspinu
Copy link
Contributor Author

vspinu commented Oct 12, 2018

And jars I guess.

Yes.

@vspinu vspinu force-pushed the friendly-sessions branch from f082a17 to 783943d Compare October 13, 2018 14:36
@vspinu
Copy link
Contributor Author

vspinu commented Oct 13, 2018

Done!

@bbatsov bbatsov merged commit bc1d909 into clojure-emacs:master Oct 13, 2018
@bbatsov
Copy link
Member

bbatsov commented Oct 13, 2018

Thanks!

@vspinu vspinu deleted the friendly-sessions branch October 15, 2018 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants