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

👍 Remove Worker from the system (POC) #291

Closed
wants to merge 2 commits into from
Closed

Conversation

lambdalisue
Copy link
Member

@lambdalisue lambdalisue commented Nov 26, 2023

TBW

Summary by CodeRabbit

  • Refactor

    • Updated the batch function across various classes for improved type handling.
    • Reorganized internal class structure to utilize a new Service instance, enhancing the plugin's architecture.
    • Streamlined the Service class by integrating DenopsImpl and simplifying method calls.
  • Chores

    • Removed unused Session type and associated properties to clean up the codebase.
    • Deprecated the dispose method in the Service class.

@lambdalisue lambdalisue marked this pull request as draft November 26, 2023 09:20
Copy link

coderabbitai bot commented Nov 26, 2023

Walkthrough

The changes across various TypeScript files in the codebase reflect a significant refactoring effort. The Host interface and its implementations in Neovim and Vim classes have been updated to enforce stricter parameter types for the batch method. The DenopsImpl class has undergone a structural overhaul, replacing the Session with a new Service instance, which has also been reworked to remove its reliance on Worker and instead use direct method calls on DenopsImpl.

Changes

File Path Change Summary
.../@denops-private/host/base.ts
.../@denops-private/host/nvim.ts
.../@denops-private/host/vim.ts
Updated batch method signature to accept an array of tuples with stricter typing.
.../@denops-private/impl.ts Removed Session type, introduced Service instance, and reorganized internal structure.
.../@denops-private/service.ts Replaced Worker with DenopsImpl, removed trace parameter, and updated method calls.

🐇✨
In the realm of code, where the rabbits hop,
Refactoring's done; the old patterns drop.
With tuples aligned, and services anew,
The den of Denops shines bright and true. 🌟🎉


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6c7ebef and 7114d5d.
Files selected for processing (5)
  • denops/@denops-private/host/base.ts (1 hunks)
  • denops/@denops-private/host/nvim.ts (1 hunks)
  • denops/@denops-private/host/vim.ts (1 hunks)
  • denops/@denops-private/impl.ts (2 hunks)
  • denops/@denops-private/service.ts (6 hunks)
Additional comments: 10
denops/@denops-private/host/base.ts (1)
  • 18-23:
    The return type of the batch method is [unknown[], string], which suggests it returns a single tuple. Verify if this is the intended behavior or if it should return an array of tuples, each corresponding to the result of a batch call.
denops/@denops-private/host/nvim.ts (1)
  • 63-67:
    The changes to the batch method are consistent with the pull request summary and follow TypeScript best practices. The use of a rest parameter with tuple types ensures type safety and immutability of the input arguments. The method correctly maps the calls to the expected format for 'nvim_call_atomic' and handles errors appropriately.
denops/@denops-private/host/vim.ts (1)
  • 39-43:
    The change to the batch method signature to use a rest parameter of type (readonly [string, ...unknown[]])[] is consistent with the goal of enforcing immutability. Ensure that all calls to this method throughout the codebase are updated to pass immutable arrays.
denops/@denops-private/impl.ts (3)
  • 5-16:
    Verify if the dispatcher property should be public or if it was intended to be private or protected.

  • 35-44:
    The changes to the batch method correctly handle the new tuple type arguments and maintain consistent error handling.

  • 51-68:
    The dispatch method is correctly updated to interact with the Service instance and is appropriately marked as async.

denops/@denops-private/service.ts (4)
  • 26-30:
    The _trace parameter is not used in the register method. If this is intentional and reserved for future use, consider documenting its purpose to avoid confusion.

  • 45-45:
    The error handling for already registered plugins is clear and informative.

  • 115-120:
    The error handling in the dispatch method is consistent with the requirements of Vim/Neovim, which do not handle JavaScript Error instances.

  • 126-128:
    The dispose method is currently a no-op. If this method is not intended to be implemented in the future, consider removing it to reduce confusion. If it is part of the Disposable interface or reserved for future use, document its current state and intended purpose.

Comment on lines +48 to 88
const denops = new DenopsImpl(name, meta, this);
// Import module with fragment so that reload works properly
// https://github.com/vim-denops/denops.vim/issues/227
const suffix = `#${performance.now()}`;
const scriptUrl = resolveScriptUrl(script);
worker.postMessage({ scriptUrl: `${scriptUrl}${suffix}`, meta, trace });
const session = buildServiceSession(
name,
meta,
readableStreamFromWorker(worker),
writableStreamFromWorker(worker),
this,
trace,
);
import(`${scriptUrl}${suffix}`).then(async (mod) => {
try {
await denops.cmd(
`doautocmd <nomodeline> User DenopsSystemPluginPre:${name}`,
)
.catch((e) =>
console.warn(
`Failed to emit DenopsSystemPluginPre:${name}: ${e}`,
)
);
await mod.main(denops);
await denops.cmd(
`doautocmd <nomodeline> User DenopsSystemPluginPost:${name}`,
)
.catch((e) =>
console.warn(
`Failed to emit DenopsSystemPluginPost:${name}: ${e}`,
)
);
} catch (e) {
console.error(e);
await denops.cmd(
`doautocmd <nomodeline> User DenopsSystemPluginFail:${name}`,
)
.catch((e) =>
console.warn(
`Failed to emit DenopsSystemPluginFail:${name}: ${e}`,
)
);
}
});
this.#plugins.set(name, {
script,
worker,
session,
client: new Client(session, { errorDeserializer }),
denops,
});
}
Copy link

Choose a reason for hiding this comment

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

Consider improving error handling within the dynamic import. Logging to the console may not be sufficient for production environments. It might be beneficial to implement a more robust error reporting mechanism or to rethrow the error after logging.

@lambdalisue
Copy link
Member Author

See #293

@lambdalisue lambdalisue deleted the remove-worker branch November 26, 2023 20:19
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