Skip to content

refactor: comint daemon to jsonrpc #165

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

Merged
merged 6 commits into from
Oct 31, 2022
Merged

Conversation

elken
Copy link
Contributor

@elken elken commented May 27, 2022

Change the hacky comint implementation to a more stable and robust
JSONRPC implementation.

A process is managed by emacs and commands are sent/recieved
asynchronously to that process.

Currently there still exists a couple of bugs I'm struggling to nail down
(mostly because I'm unfamiliar with the hash-table/dash combination):

  • On startup, sometimes it errors because it sends the two startup messages at
    once. This should easily be rectified with a listp check when parsing
  • Debugging emulators on linux fails, and I'm struggling to work out exactly
    why. I suspect something isn't being set correctly maybe in one of the
    listeners
    • However , debugging regular linux works fine and seems faster and more stable

Apologies for opening two PRs for the same thing, when I first tried getting
this working every request timed out so I looked into the tcp implementation.
This supersedes that now as it's much more simple.

Obseletes #164

@ericdallo
Copy link
Member

@elken sorry for the delay, could you fix conflicts and the CI ?

@elken
Copy link
Contributor Author

elken commented Aug 10, 2022

Apologies, I haven't used flutter in ages so these changes have been forgotten.

I will make time to resolve these this week

@elken
Copy link
Contributor Author

elken commented Aug 21, 2022

Apparently time makes fools of us all! 😅

I'm looking at this as we speak (will try and resolve the merge conflicts too)

@elken elken force-pushed the feat/jsonrpc branch 2 times, most recently from 218239f to 6717ab1 Compare August 21, 2022 16:14
@elken
Copy link
Contributor Author

elken commented Aug 21, 2022

@ericdallo I'm not familiar with eask but it seems to be complaining about missing packages and autoloads now (missing packages might be https://github.com/emacs-eask/eask/issues/11)

@elken elken force-pushed the feat/jsonrpc branch 3 times, most recently from 6f21aca to c5f8af6 Compare August 21, 2022 16:46
@elken
Copy link
Contributor Author

elken commented Aug 21, 2022

Well I can't replicate the CI errors...

Have tried with freshly built emacs 27 and it runs everything fine

@nidyaonur
Copy link

After seeing your last comment, I have reinstalled emacs freshly as well, and I am getting the same error. I can assist you in the process if you need someone for that. @elken

@elken
Copy link
Contributor Author

elken commented Aug 23, 2022

Sure! If you figure them out do let me know, I'll try and pick it up as I have spare time

@nidyaonur
Copy link

I misread the CI part 😅. If you could instruct me how to use your branch on my local machine, I can try it out. I am not really good at these:/

@elken
Copy link
Contributor Author

elken commented Aug 23, 2022

I misread the CI part 😅. If you could instruct me how to use your branch on my local machine, I can try it out. I am not really good at these:/

Well that's the thing, it works fine when I run it in isolation locally. Maybe see if act breaks

@ericdallo
Copy link
Member

@jcs090218 any thoughts about CI failing?

@elken
Copy link
Contributor Author

elken commented Aug 23, 2022

Cool this looks like it might resolve the CI errors.

This isn't ready to go in yet though, and I am starting to be annoyed enough to resolve this so I'll try and have the issues resolved this week ish

EDIT: Did a quick google of the windows snapshot failure, it's an emacs 29 function so best guess would be it's pinned to a commit that doesn't have it?

@jcs090218
Copy link
Member

There is an issue is from Emacs windows snapshot, see https://lists.gnu.org/archive/html/bug-gnu-emacs/2022-07/msg01656.html. We could do the following:

  1. ignore it, since it's a snapshot
  2. Add experimental flag, see example code in https://github.com/jcs-emacs/jcs-emacs/blob/master/.github/workflows/startup.yml#L26-L45. (this will turn the badge from red to green, but the icon in action tab will remain the same, red ❌)

@elken
Copy link
Contributor Author

elken commented Aug 24, 2022

There is an issue is from Emacs windows snapshot, see https://lists.gnu.org/archive/html/bug-gnu-emacs/2022-07/msg01656.html. We could do the following:

  1. ignore it, since it's a snapshot
  2. Add experimental flag, see example code in https://github.com/jcs-emacs/jcs-emacs/blob/master/.github/workflows/startup.yml#L26-L45. (this will turn the badge from red to green, but the icon in action tab will remain the same, red ❌)

I like the experimental version the most, me personally I don't consider Emacs 29 as anything as there's not even a branch cut. So I'd be fine ignoring it unless it's needed.

@jcs090218
Copy link
Member

Oh yes, please ignore 29. I have it there for my own use. Just look at the experimental part of the code.

@elken
Copy link
Contributor Author

elken commented Aug 24, 2022

Oh yes, please ignore 29. I have it there for my own use. Just look at the experimental part of the code.

I know what you were referring to, I was agreeing xD

I'll submit those in a different PR though

@ericdallo
Copy link
Member

@elken Looks good to me!
I'll give a little bit of more testing and then we can merge it

@elken
Copy link
Contributor Author

elken commented Aug 25, 2022

@elken Looks good to me! I'll give a little bit of more testing and then we can merge it

You sure? I was having issues with emulators starting up in a few cases.

It's your codebase so you are obviously much more knowledgable so if you're happy to merge it go for it, I just want to run through some usecases to make sure it works and resolves my issues proper! :D

Glad you're happy with it though, I was worried when I made it that I botched it lol

@ericdallo
Copy link
Member

ericdallo commented Aug 25, 2022

I meant the code review 😅 I still need to manually test it

@ericdallo
Copy link
Member

@elken any updates on this? it'd be really nice to have this fixed

@elken
Copy link
Contributor Author

elken commented Oct 18, 2022

@elken any updates on this? it'd be really nice to have this fixed

Posted an update on discord but for visibility; I'm leaving the company that uses flutter so my usage of it has gone way down, but I'm keen to try and pick it back up to wrap it up when I can.

EDIT: I have acquired much more free time now, so I will be looking into this this week

@Pacane
Copy link

Pacane commented Oct 19, 2022

I've tried running this branch with the latest master changes, and here's an error I get when opening a dart buffer, and also when I call lsp-dart-run in my flutter project.

LSP :: Guessed project root is ~/code/dart/test_mono_repo
LSP :: Connected to [dart_analysis_server:48364/starting].
Error processing message (wrong-type-argument stringp ("/Users/joel/.asdf/installs/flutter/3.3.4-stable/bin/flutter")).
make-process--with-editor-process-filter: Wrong type argument: stringp, ("/Users/joel/.asdf/installs/flutter/3.3.4-stable/bin/flutter")

The path of my flutter install is correct, written like this in my config.el file (actually here's the whole lsp-dart config block)

(use-package! lsp-dart
  :config
  (setq lsp-dart-sdk-dir (expand-file-name "~/.asdf/installs/flutter/3.3.4-stable/bin/cache/dart-sdk/")
        lsp-dart-flutter-sdk-dir (expand-file-name "~/.asdf/installs/flutter/3.3.4-stable/")
        lsp-dart-project-root-discovery-strategies '(closest-pubspec lsp-root)
        lsp-dart-flutter-widget-guides nil
        gc-cons-threshold (* 100 1024 1024)
        read-process-output-max (* 1024 1024))
  )

@elken
Copy link
Contributor Author

elken commented Oct 19, 2022

I've tried running this branch with the latest master changes, and here's an error I get when opening a dart buffer, and also when I call lsp-dart-run in my flutter project.

LSP :: Guessed project root is ~/code/dart/test_mono_repo
LSP :: Connected to [dart_analysis_server:48364/starting].
Error processing message (wrong-type-argument stringp ("/Users/joel/.asdf/installs/flutter/3.3.4-stable/bin/flutter")).
make-process--with-editor-process-filter: Wrong type argument: stringp, ("/Users/joel/.asdf/installs/flutter/3.3.4-stable/bin/flutter")

The path of my flutter install is correct, written like this in my config.el file (actually here's the whole lsp-dart config block)

(use-package! lsp-dart
  :config
  (setq lsp-dart-sdk-dir (expand-file-name "~/.asdf/installs/flutter/3.3.4-stable/bin/cache/dart-sdk/")
        lsp-dart-flutter-sdk-dir (expand-file-name "~/.asdf/installs/flutter/3.3.4-stable/")
        lsp-dart-project-root-discovery-strategies '(closest-pubspec lsp-root)
        lsp-dart-flutter-widget-guides nil
        gc-cons-threshold (* 100 1024 1024)
        read-process-output-max (* 1024 1024))
  )

A change was recently made to adjust how the dart executable is called, I have time to work on this PR again so I will look into it in the next couple of days

@Pacane
Copy link

Pacane commented Oct 19, 2022

Just a mention though, I've tried running a dart vm main file with lsp-dart-run and it works fine so far.

@Pacane
Copy link

Pacane commented Oct 28, 2022

Any update on this? I can provide details/help if needed. I could also provide a PR if somebody directed me to something to look at!

@elken
Copy link
Contributor Author

elken commented Oct 28, 2022

Thanks for this ping, I really do hate having a life sometimes 😅

This weekend I should be free so I'll try my very best to pick it up. I tried to pick this up the other day...

In terms of help, I've put the couple of issues I was getting in the initial PR message.

@ericdallo I know lsp-mode is starting to move everything over to plists, is this something I should add in here or is that something you'll look into later? Just remembered the last time I tried it when I had my macbook I was running the plist setup and kept hitting issues

@ericdallo
Copy link
Member

ericdallo commented Oct 29, 2022

@elken Feel free to do whatever it's easiest for you, I can migrate it later, there are some missing points on other places of lsp-dart that I still need to take a look
lsp-dart already has issues with lsp-use-plists, I intend to take a look at this soon

@elken
Copy link
Contributor Author

elken commented Oct 29, 2022

@elken Feel free to do whatever it's easiest for you, I can migrate it later, there are some missing points on other places of lsp-dart that I still need to take a look lsp-dart already has issues with lsp-use-plists, I intend to take a look at this soon

In that case I'll leave it then. Worth being aware of though, last I spoke to yyoncho about it it seemed that most of the other clients have implemented it so I imagine the switch will be soon ™️

@ericdallo
Copy link
Member

ericdallo commented Oct 29, 2022

Yep, it's the top lsp-dart priority to me ATM after this PR , I will try to take a look in the next days

elken added 6 commits October 30, 2022 09:52
Change the hacky comint implementation to a more stable and robust
JSONRPC implementation.

A process is managed by emacs and commands are sent/recieved
asynchronously to that process.

Obseletes emacs-lsp#164
Ensure this is pulled while we need it
Handle the fact that lsp-dart-flutter-command is now a list rather than
a fixed string
Upon loading, the daemon sends a couple of messages that jsonrpc tries
to treat as a single message
Only process the success callback when there's a result to apply
@elken
Copy link
Contributor Author

elken commented Oct 30, 2022

@ericdallo I can't apologise enough for this taking so long 😅

I've fixed both the issues I mentioned in the original message, so this should be fine to look over now. I appreciate that jsonrpc is a bit of a black box, so I'm happy to provide some accompanying documentation on how things work but as far as I can tell this should be good for testing at least.

I also don't have access to a macbook now, but I might be able to wrangle some people who do; but there's no reason that this shouldn't resolve the original issue that spawned this.

I also know it's a busy night for you, so without derailing this thread good luck!

Copy link
Member

@ericdallo ericdallo left a comment

Choose a reason for hiding this comment

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

Thank you very much for this @elken!
I reviewed and manually tested and works great, I will merge this and do only a few refactorings on master like removing the message, try to remove ht dep and improve some function's complexity, anyway glad to see this working!

@ericdallo ericdallo merged commit d50fc42 into emacs-lsp:master Oct 31, 2022
@elken
Copy link
Contributor Author

elken commented Oct 31, 2022

Thank you very much for this @elken! I reviewed and manually tested and works great, I will merge this and do only a few refactorings on master like removing the message, try to remove ht dep and improve some function's complexity, anyway glad to see this working!

Thanks! Glad it's working smoothly. I wrote that massive process filter function in a bit of a haze then convinced myself "ah it works for now" 🤣

@elken elken deleted the feat/jsonrpc branch October 31, 2022 07:15
@ericdallo
Copy link
Member

@elken no problem, I'm finishing the refactor on that function, it's not that better than before but it's using some lsp-mode functions for that instead.
The issue is that jsonrpc only accepts plists, and lsp-mode users could be using plists or hash-tables depending of the lsp-use-plists, not a big deal for now though, I should commit the changes soon

@elken
Copy link
Contributor Author

elken commented Oct 31, 2022

The issue is that jsonrpc only accepts plists, and lsp-mode users could be using plists or hash-tables depending of the lsp-use-plists, not a big deal for now though, I should commit the changes soon

Yeah, ideally both would have to be supported. Maybe create a frozen no-plists branch when lsp-mode pushes the change? There's probably not a clean way to handle this

@ericdallo
Copy link
Member

yeah for now I'll try to leave this complexity in a specific function or so

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

Successfully merging this pull request may close these issues.

5 participants