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

refactor(thread): refactor hasCapability call with a better readable way #3732

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

Sma1lboy
Copy link
Collaborator

@Sma1lboy Sma1lboy commented Jan 20, 2025

Update

LIST_CAPABILITY has been deprecated and will no longer be used.

Description

In the new version, we will no longer use hasCapability individually to check exposed APIs. Instead, we will obtain them during the communication establishment between two threads. Here we provide 1 protocol change and 2 inner thread methods.

Protocol Change

  • EXPOSE_LIST
    Added a mechanism to exchange exposed APIs. When data is received, it will be automatically saved to cache.

Convention: Once two threads establish a connection, the exposed APIs will not be modified during this period.

Inner Thread Methods

  • requestMethods: Only receive their APIs

Clarification: 'A' represents Outside (the IDE/client), while 'B' represents Inside (the server).

In our scenario, A is always created first, followed by B. This ensures B can successfully send messages to A. However, if A arrives too early, B might not receive the message signal. Furthermore, we only need A's Exposed APIs on the B side (server side). Currently, we only use requestMethods in createThreadFromInsideIframe.

By the way, we could also use exposed methods to check server's exposed APIs?

I have added numerous logs for now, which will be cleaned up after review.

Demo

Screenshot from log
image

Also the way we call in server side

      // proxy.has way
      if ('refresh' in server) {
        console.log('refresh in server')
      }
      // base on a server side trap method
      // no promise anymore, get answer instantally
      console.log('support v2?:', server?.supports['onApplyInEditorV2'])

@Sma1lboy Sma1lboy force-pushed the refactor-hasCapability-with-proxy-has branch from 6edd0dd to 9d8fbbe Compare January 21, 2025 08:28
@Sma1lboy Sma1lboy force-pushed the refactor-hasCapability-with-proxy-has branch from 7a4f2a3 to 02e80a6 Compare January 21, 2025 09:12
@Sma1lboy Sma1lboy requested a review from icycodes January 21, 2025 09:14
@Sma1lboy Sma1lboy force-pushed the refactor-hasCapability-with-proxy-has branch from 49668c6 to 9e2fc10 Compare January 22, 2025 20:21
…essary conditional block

refactor(chat-page): simplify capability checks by consolidating server support evaluations

refactor(chat-webview): remove redundant logging during initialization
@Sma1lboy Sma1lboy force-pushed the refactor-hasCapability-with-proxy-has branch from ec3200d to 524913d Compare January 22, 2025 20:35
@Sma1lboy Sma1lboy marked this pull request as ready for review January 22, 2025 20:42
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.

1 participant