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

Add addon client and server base classes #2501

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

st0012
Copy link
Member

@st0012 st0012 commented Aug 28, 2024

Motivation

The client/server architecture of ruby-lsp-rails to a large degree can be adopted by many other addons too. For example, other web frameworks, like Hanami, can also use it to provide runtime information. And if we extract the base client/server implementation into ruby-lsp, it'll make such applications easier to implement.

Also, through such extraction we can standardize things like:

  • Logging interface (to VS Code's Output tab)
  • Communications between the client and server
  • Server's lifecycle management

And that will make ruby-lsp-rails easier to maintain and understand as well.

Draft PR from ruby-lsp-rails: Shopify/ruby-lsp-rails#439

Implementation

  • Add RubyLsp::Addon::ProcessClient|ProcessServer classes. To use them, addons should require ruby_lsp/addon/process_client in the client file and ruby_lsp/addon/process_server in the server file.
  • I added process prefix with the hope to indicate that they're only needed when the addon needs to interact with another process.

Automated Tests

I added a new test/addon/process_client_server_test.rb with a fake addon to test the client and server end-to-end.

Manual Tests

@st0012 st0012 added enhancement New feature or request addons Tasks related to Ruby LSP addons server This pull request should be included in the server gem's release notes labels Aug 28, 2024
@st0012 st0012 force-pushed the add-on-client-server-framework branch 2 times, most recently from 36ea722 to d997d70 Compare September 2, 2024 17:36
@st0012 st0012 marked this pull request as ready for review September 2, 2024 17:37
@st0012 st0012 requested a review from a team as a code owner September 2, 2024 17:37
@st0012 st0012 force-pushed the add-on-client-server-framework branch 2 times, most recently from 145b51d to dcb2257 Compare September 2, 2024 18:17
@st0012 st0012 self-assigned this Sep 2, 2024
This commit introduces two new classes to enhance the addon framework:

1. ProcessClient: Manages communication with addon servers, handling
   initialization, message sending/receiving, and shutdown.

2. ProcessServer: Provides a base class for addon servers to handle
   requests and responses.

These classes facilitate better separation of concerns and provide a
structured approach for addons to communicate with the Ruby LSP server.
@st0012 st0012 force-pushed the add-on-client-server-framework branch from dcb2257 to d578615 Compare September 2, 2024 21:17
# typed: strict
# frozen_string_literal: true

require "sorbet-runtime"
Copy link
Contributor

Choose a reason for hiding this comment

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

We had some issues in the past when requiring sorbet-runtime within the Rails side. I can't recall the exact cause, but we might need to be wary of that or do some extra checking.

@running = false
{ result: {} }
else
VOID
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't need the VOID stuff any more now that Shopify/ruby-lsp-rails#453 is merged.

@st0012
Copy link
Member Author

st0012 commented Nov 4, 2024

FYI, I'll update this after Tapioca LSP is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addons Tasks related to Ruby LSP addons enhancement New feature or request server This pull request should be included in the server gem's release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants