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

Denops v6 #302

Merged
merged 39 commits into from
Feb 3, 2024
Merged

Denops v6 #302

merged 39 commits into from
Feb 3, 2024

Conversation

lambdalisue
Copy link
Member

@lambdalisue lambdalisue commented Jan 1, 2024

For Users

Changes seen by users using the Denops plugin are mostly limited to updates of supported versions, with no significant changes other than that.

Updates of Supported Versions

In Denops v6, the following versions are supported:

Name Version
Deno 1.38.5 or later
Vim 9.0.2189 or later
Neovim 0.9.4 or later

Approximately 50% Reduction in Memory Usage

The memory usage of the Denops server has been reduced by approximately half compared to v5. For more details, refer to Memory (RSS) usage difference between denops v5 and v6.

Improved Communication Speed with Vim/Neovim

Communication speed with Vim/Neovim has been enhanced, especially noticeable in Neovim, where under specific conditions, you can issue about 1.8 times more commands compared to v5. For detailed results, see Communication performance difference between denops v5 and v6.


Reduced Impact on Initialization Time Due to the Number of Plugins

The issue of increasing initialization time as the number of plugins dependent on Denops grows has been resolved. However, users who do not utilize a large number (around 100) of Denops plugins will not perceive a significant difference. For detailed results, refer to Startup performance difference between v5 and v6.

For Denops Plugin Developers

Plugins are no longer isolated by Worker threads

Until v5, each plugin was processed in a dedicated Worker thread, but from v6 onwards, processing is done in a Worker thread per Vim/Neovim instance. Be cautious if your code uses global variables, and consider using the denops.context (Record<PropertyKey, unknown>) provided for each plugin instead.

Results of console.log() always returned to Vim/Neovim

Until v5, the output location of console.log() differed between Local server and Shared server, but now it is always displayed on the Vim/Neovim side in both cases.

Tip

console.log() is intended for temporary use during development. If you want to display messages to users as part of the plugin's functionality, continue to use denops.cmd("echo ...") or the echo function in denops_std.

For Denops Developers

denops_core has been separated into a separate repository

The type information of Denops, which was managed in the denops/@denops directory until v5, has been separated into a separate repository called deno-denops-core. With this change, the version update policy of "no releases other than updates under the denops/@denops directory" has been abolished, and version updates will follow semantic versioning.

Lower-level test utilities included, separate from denops_test

A module named denops/@denops-private/testutil has been added to directly test the Host used in the internal implementation of Denops. As a result, the parts that were tested using denops_test have been removed, and testing is now self-contained in denops.vim.

Summary by CodeRabbit

  • New Features

    • Introduced a new logging function to improve information display.
    • Added new test utilities to enhance plugin development and testing.
    • Implemented a new worker-based communication approach for better performance.
  • Enhancements

    • Upgraded support for Deno, Vim, and Neovim to their latest versions.
    • Improved error serialization and deserialization for robust error handling.
    • Refined the communication protocol between services and hosts (Vim/Neovim).
  • Bug Fixes

    • Fixed issues with autocmd event handling by removing outdated events.
    • Resolved version check discrepancies in the Vim plugin.
  • Refactor

    • Streamlined tasks and commands in workflow and configuration files.
    • Overhauled internal class structures and method calls for clarity and efficiency.
  • Documentation

    • Updated README.md with current versioning information and streamlined content.
  • Chores

    • Cleaned up obsolete functionality and updated import statements for consistency.
  • Tests

    • Added comprehensive tests for new and existing functionalities to ensure stability.

@lambdalisue lambdalisue marked this pull request as draft January 1, 2024 20:49
Copy link

coderabbitai bot commented Jan 1, 2024

Warning

Rate Limit Exceeded

@lambdalisue has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 14 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 5a16d82 and d68e8fc.

Walkthrough

The project underwent a significant update, primarily focused on improving compatibility with newer versions of Deno, Vim, and Neovim. Changes include updating version constants, refining testing workflows, and enhancing error handling. Autoload functions and internal logic were refactored for efficiency, and the plugin system was restructured to better manage communication and task execution. All updates aim to streamline the development process and ensure smoother integration with the updated software versions.

Changes

File Path Change Summary
.github/workflows/test.yml, README.md, deno.jsonc, plugin/denops.vim Updated Deno, Vim, and Neovim versions; modified test commands and coverage reporting; removed outdated versioning section.
autoload/denops.vim, autoload/health/denops.vim Replaced request function with notify; updated version constants; removed autocmd event-related functionality.
autoload/denops/_internal/... Added new logging and test functions; updated echo function behavior.
denops/@denops-private/... (various files) Refactored class structures, methods, and imports; introduced new types and tests; updated error handling; added worker-based communication logic.
denops/@denops-private/testdata/..., denops/@denops-private/testutil/... Added test data and utilities for plugin validation and testing configurations.

"In the burrow of code, we dig and we tweak, 🐇
With a hop and a jump, new versions we seek.
Through the fields of syntax, our updates now roam,
Bringing bits and bytes back to their digital home."

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Base automatically changed from fix-denops-ready to main January 2, 2024 11:31
lambdalisue added a commit to vim-denops/deno-denops-test that referenced this pull request Jan 2, 2024
Copy link

codecov bot commented Jan 2, 2024

Codecov Report

Attention: 42 lines in your changes are missing coverage. Please review.

Comparison is base (16d4bbc) 96.47% compared to head (d68e8fc) 89.66%.

Files Patch % Lines
denops/@denops-private/host/vim.ts 77.77% 12 Missing ⚠️
denops/@denops-private/service.ts 88.00% 12 Missing ⚠️
denops/@denops-private/testutil/conf.ts 79.41% 7 Missing ⚠️
denops/@denops-private/testutil/with.ts 93.97% 5 Missing ⚠️
denops/@denops-private/host/nvim.ts 95.94% 3 Missing ⚠️
denops/@denops-private/version.ts 66.66% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #302      +/-   ##
==========================================
- Coverage   96.47%   89.66%   -6.82%     
==========================================
  Files           3        9       +6     
  Lines          85      648     +563     
  Branches        6       61      +55     
==========================================
+ Hits           82      581     +499     
- Misses          3       67      +64     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Shougo
Copy link
Contributor

Shougo commented Jan 3, 2024

I have tested it in Windows environment.
The initialization time is longer than previous version.
It tooks time 5000ms+.

@lambdalisue lambdalisue force-pushed the v6-pre branch 12 times, most recently from 1357251 to 8dc5e89 Compare January 9, 2024 20:38
@lambdalisue lambdalisue changed the title TBW: v6 pre Denops v6 Jan 15, 2024
@lambdalisue lambdalisue marked this pull request as ready for review January 19, 2024 19:52
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: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 83f167b and 8dc5e89.
Files selected for processing (31)
  • .github/workflows/test.yml (2 hunks)
  • README.md (2 hunks)
  • autoload/denops.vim (1 hunks)
  • autoload/denops/_internal/echo.vim (2 hunks)
  • autoload/denops/_internal/test.vim (1 hunks)
  • autoload/denops/plugin.vim (1 hunks)
  • autoload/health/denops.vim (1 hunks)
  • deno.jsonc (1 hunks)
  • denops/@denops-private/cli.ts (1 hunks)
  • denops/@denops-private/denops.ts (2 hunks)
  • denops/@denops-private/denops_test.ts (1 hunks)
  • denops/@denops-private/error.ts (1 hunks)
  • denops/@denops-private/error_test.ts (1 hunks)
  • denops/@denops-private/host.ts (1 hunks)
  • denops/@denops-private/host/nvim.ts (4 hunks)
  • denops/@denops-private/host/nvim_test.ts (1 hunks)
  • denops/@denops-private/host/vim.ts (4 hunks)
  • denops/@denops-private/host/vim_test.ts (1 hunks)
  • denops/@denops-private/host_test.ts (1 hunks)
  • denops/@denops-private/service.ts (2 hunks)
  • denops/@denops-private/service_test.ts (1 hunks)
  • denops/@denops-private/testdata/dummy_invalid_plugin.ts (1 hunks)
  • denops/@denops-private/testdata/dummy_valid_plugin.ts (1 hunks)
  • denops/@denops-private/testutil/cli.ts (1 hunks)
  • denops/@denops-private/testutil/conf.ts (1 hunks)
  • denops/@denops-private/testutil/conf_test.ts (1 hunks)
  • denops/@denops-private/testutil/with.ts (1 hunks)
  • denops/@denops-private/util.ts (1 hunks)
  • denops/@denops-private/version.ts (1 hunks)
  • denops/@denops-private/worker.ts (1 hunks)
  • plugin/denops.vim (2 hunks)
Files skipped from review due to trivial changes (1)
  • autoload/health/denops.vim
Additional comments: 77
denops/@denops-private/testdata/dummy_invalid_plugin.ts (1)
  • 1-5: The code change introduces a dummy plugin that throws an error when executed. This is likely used for testing error handling within the Denops framework.
denops/@denops-private/testdata/dummy_valid_plugin.ts (1)
  • 1-10: The code change introduces a valid dummy plugin for testing purposes. It defines a dispatcher with a test function that echoes a message, ensuring the plugin's basic functionality can be verified.
denops/@denops-private/util.ts (2)
  • 1-2: Updated import versions for Meta, is, and Predicate to ensure compatibility with the latest module versions.
  • 1-1: Ensure that the updated version of denops_core (v6.0.5) is compatible with the rest of the codebase and that no breaking changes affect the functionality.
deno.jsonc (1)
  • 4-8: The tasks in deno.jsonc have been updated to reflect changes in the Deno CLI options and to introduce a new task for test coverage. Ensure that the removal of the --unstable flag does not affect any features that were previously relying on it.
denops/@denops-private/testutil/cli.ts (1)
  • 1-22: The main function in cli.ts has been refactored to use a new ADDR_ENV_NAME constant and to handle connections to the Denops server. Ensure that the environment variable is correctly set and used across the codebase.
denops/@denops-private/error.ts (1)
  • 1-7: The import of the unknownutil module has been updated to version v3.13.0, and new functions from the errorutil module have been introduced. Ensure that these changes are compatible with the existing error handling logic.
denops/@denops-private/version.ts (1)
  • 9-23: The getVersionOr function has been updated to return a SemVer object or a fallback value asynchronously. Ensure that the error handling and command execution logic are correctly implemented to accommodate this change.
autoload/denops/_internal/test.vim (1)
  • 1-17: The code introduces functions for testing purposes that wrap the denops#_internal#rpc#nvim#notify and denops#_internal#rpc#nvim#request functions for Neovim and their Vim counterparts. Ensure that these functions are used correctly in the test environment and do not interfere with the production code.
autoload/denops/_internal/echo.vim (2)
  • 8-10: Added a new function denops#_internal#echo#log for logging purposes. Ensure that this function is used consistently across the codebase for logging messages.
  • 20-20: Modified the denops#_internal#echo#info function to call s:echomsg('Title', a:000) instead of s:echomsg('None', a:000). Verify that this change is reflected in the user interface where informational messages are displayed.
plugin/denops.vim (1)
  • 6-8: The version check requirements for Vim and Neovim have been updated. Ensure that these new version requirements are communicated to users and that they do not cause issues for users on older versions who may not be able to update.
autoload/denops.vim (1)
  • 19-25: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-22]

The denops#request_async function has been modified to use denops#_internal#server#chan#notify instead of denops#_internal#server#chan#request. This change affects the control flow and likely the handling of responses. Ensure that all asynchronous requests are still handled correctly after this change.

denops/@denops-private/testutil/conf.ts (1)
  • 1-45: The getConfig function has been updated to handle environment variables and default values for the Denops path and Vim/Neovim executables. Ensure that these changes do not affect the expected behavior of the test environment.
denops/@denops-private/cli.ts (1)
  • 1-72: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-92]

The cli.ts file has been refactored to use version ranges for imports and to handle connections with a worker-based approach. Ensure that the worker script URL is correctly resolved and that the worker-based connection handling is robust and error-free.

denops/@denops-private/denops.ts (1)
  • 1-57: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-98]

Significant modifications have been made to the DenopsImpl class, including changes to the import statements, the structure of classes, and the way methods are called. New type definitions for Host and Service have been introduced. Ensure that these changes are consistent with the overall architecture and design principles of the Denops framework.

denops/@denops-private/testutil/conf_test.ts (1)
  • 1-76: The tests for the removeTrailingSep function have been updated to handle different operating systems. Ensure that these tests cover all edge cases and that the function behaves correctly on all supported platforms.
denops/@denops-private/error_test.ts (1)
  • 1-77: Tests for the errorSerializer and errorDeserializer functions have been added. Ensure that these tests adequately cover the serialization and deserialization logic and that any edge cases are handled correctly.
.github/workflows/test.yml (2)
  • 56-60: The Deno and Vim versions have been updated in the GitHub Actions workflow. Ensure that these version updates do not introduce any compatibility issues with the testing environment.
  • 91-91: The test command has been updated to deno task test:coverage. Verify that the coverage task is configured correctly and that it generates accurate coverage reports.
denops/@denops-private/host.ts (1)
  • 1-97: The Host interface and related types and functions have been defined or updated. Ensure that these changes are consistent with the expected behavior of the host in the Denops framework and that they do not introduce any breaking changes.
denops/@denops-private/worker.ts (1)
  • 1-93: The worker.ts file has been updated to handle the initialization and termination of the Denops service within a worker context. Ensure that the worker is correctly terminated to avoid resource leaks and that error handling is robust.
denops/@denops-private/testutil/with.ts (1)
  • 1-102: The withVim and withNeovim functions have been updated to handle test environments for Vim and Neovim. Ensure that these functions correctly set up and tear down the test environment without leaving any processes or resources hanging.
denops/@denops-private/denops_test.ts (1)
  • 1-106: Tests for the DenopsImpl class have been added, covering various methods such as redraw, call, batch, cmd, eval, and dispatch. Ensure that these tests are comprehensive and that they accurately reflect the behavior of the DenopsImpl class.
denops/@denops-private/host_test.ts (1)
  • 1-126: Tests for the invoke function in host.ts have been added. Ensure that these tests cover all scenarios, including valid and invalid arguments, and that they correctly assert the behavior of the invoke function.
denops/@denops-private/host/vim.ts (8)
  • 1-7: Imports from unknownutil and vim_channel_command modules have been updated. Ensure that the updated versions are compatible with the rest of the codebase.
  • 21-21: The onMessage handler for this.#session is correctly handling both success and error cases when dispatching messages. However, ensure that the error logging is comprehensive and that it doesn't leak any sensitive information.
  • 47-53: The error message in the call method provides a clear indication of the potential issue with 'denops.vim' not being in 'runtimepath'. This is good for debugging purposes.
  • 63-80: The batch method has similar error handling to the call method, which is consistent and maintains readability.
  • 83-85: The notify method is implemented correctly to send notifications without waiting for a response.
  • 87-90: The init method correctly binds the Service instance to the host. Ensure that the Service instance is always initialized before calling init.
  • 105-114: The #dispatch method is private and correctly throws an error for unexpected messages. Ensure that the error message is clear and actionable.
  • 122-134: The utility functions isCallReturn, isBatchReturn, isVoidMessage, and isInvokeMessage are using type guards from unknownutil to ensure the correctness of the message formats.
denops/@denops-private/host/nvim.ts (8)
  • 1-8: Imports from unknownutil and messagepack_rpc modules have been updated. Ensure that the updated versions are compatible with the rest of the codebase.
  • 27-36: The dispatcher method invoke is correctly checking for the presence of #service before attempting to call invoke. This prevents potential runtime errors.
  • 38-39: The nvim_error_event handler logs errors to the console. Ensure that the error logging is comprehensive and that it doesn't leak any sensitive information.
  • 59-72: The call method has been refactored to handle errors and formatting differently. Ensure that the error handling is consistent with the rest of the codebase and that the error messages are clear.
  • 77-90: The batch method has been refactored similarly to the call method. Ensure that the error handling is consistent and that the error messages provide enough information for debugging.
  • 95-97: The notify method is implemented correctly to send notifications without waiting for a response.
  • 99-120: The init method correctly sets the client information and binds the Service instance to the host. Ensure that the Service instance is always initialized before calling init.
  • 136-151: The utility functions isNvimErrorObject and isNvimCallAtomicReturn are using type guards from unknownutil to ensure the correctness of the message formats.
README.md (2)
  • 6-8: The badges in the README have been updated to reflect the new supported versions of Deno, Vim, and Neovim. Ensure that these versions are indeed supported and that the links point to the correct versions.
  • 6-8: The section on versioning has been removed from the README. Ensure that this information is either outdated or relocated to a more appropriate place in the documentation.
denops/@denops-private/service.ts (11)
  • 1-8: Imports have been updated to use specific versions, which is good for ensuring compatibility and preventing issues with future changes to dependencies.
  • 14-17: The Service class now uses private fields and methods, which is a good practice for encapsulation and maintainability.
  • 26-44: The load method has been refactored to return a promise. Ensure that all calls to this method properly handle the promise, either with await or with .then() and .catch().
  • 49-61: The reload method now returns a promise. Ensure that all calls to this method properly handle the promise, and that the reloading logic is correctly implemented.
  • 64-69: The #dispatch method is private and correctly throws an error for unloaded plugins. Ensure that the error message is clear and actionable.
  • 74-76: The dispatch method correctly wraps the private #dispatch call in a try-catch block to convert errors to a Vim-friendly format.
  • 80-104: The dispatchAsync method correctly handles both success and failure cases when dispatching messages asynchronously. Ensure that the error handling is comprehensive and that it doesn't leak any sensitive information.
  • 109-111: The dispose method no longer returns a promise, which is consistent with the Disposable interface. Ensure that all usages of dispose do not expect a promise.
  • 114-140: The new Plugin class handles plugin loading and calling. Ensure that the plugin lifecycle is correctly managed and that errors during plugin loading are handled appropriately.
  • 143-148: The emit function correctly emits autocmd events. Ensure that the event names are consistent and that they are used correctly throughout the codebase.
  • 158-166: The utility functions resolveScriptUrl and toVimError are unchanged and should continue to work as expected.
denops/@denops-private/host/vim_test.ts (2)
  • 1-17: Imports for testing utilities have been updated. Ensure that the updated versions are compatible with the test cases and that they provide the necessary functionality for testing.
  • 18-154: The test cases for the Vim class cover various scenarios, including error handling and message dispatching. Ensure that the tests are comprehensive and that they cover all new changes to the Vim class.
denops/@denops-private/host/nvim_test.ts (2)
  • 1-17: Imports for testing utilities have been updated. Ensure that the updated versions are compatible with the test cases and that they provide the necessary functionality for testing.
  • 18-167: The test cases for the Neovim class cover various scenarios, including error handling and message dispatching. Ensure that the tests are comprehensive and that they cover all new changes to the Neovim class.
autoload/denops/plugin.vim (1)
  • 168-173: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1-1]

The autocmd events DenopsSystemPluginWorkerPre and DenopsSystemPluginWorkerPost have been removed. Ensure that this change is intentional and that it does not affect the plugin initialization flow.

denops/@denops-private/service_test.ts (18)
  • 17-20: The use of new URL with import.meta.url is correct for referencing test data files in a Deno project.
  • 22-28: The meta object is correctly structured to represent metadata for the test environment.
  • 29-33: The host object uses unimplemented() for methods that are not relevant to the test, which is a good use of the errorutil library to explicitly mark unimplemented functionality.
  • 36-41: The test case correctly asserts that an error is thrown when trying to load a plugin without a bound host.
  • 44-58: The test case for dispatchAsync() properly handles the rejection when no host is bound, aligning with the expected behavior.
  • 62-62: Binding the host to the service is necessary before proceeding with further tests that require a host. This is done correctly.
  • 64-92: The test case for load() correctly stubs the host.call method and asserts that the autocmd events are emitted as expected.
  • 95-118: The test case for loading a plugin that fails to initialize properly checks that the DenopsSystemPluginFail autocmd event is emitted, which is a good practice for error handling in plugin systems.
  • 122-140: The test case for loading an already loaded plugin correctly asserts that no additional calls are made and logs the appropriate message.
  • 143-171: The reload() test case is similar to the load() test case and correctly checks for the autocmd events during the plugin reload process.
  • 174-191: The test case for reload() when the plugin is not loaded yet correctly asserts that no calls are made and the expected log message is output.
  • 195-209: The test case for dispatch() correctly asserts that the plugin API is called as expected.
  • 212-220: The test case for dispatch() when the plugin is not loaded yet correctly rejects and matches the expected error message.
  • 223-247: The test case for dispatch() when the API call fails correctly rejects and matches the expected error message.
  • 251-280: The test case for dispatchAsync() when the API call succeeds correctly asserts that the success callback is called.
  • 284-320: The test case for dispatchAsync() when the API call fails correctly asserts that the failure callback is called.
  • 324-368: The test case for dispatchAsync() when the success callback fails correctly asserts that the error is logged.
  • 372-413: The test case for dispatchAsync() when the failure callback itself fails correctly asserts that the error is logged.

denops/@denops-private/host/vim.ts Show resolved Hide resolved
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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8dc5e89 and 3ab6a62.
Files selected for processing (1)
  • README.md (4 hunks)
Additional comments: 14
README.md (14)
  • 4-4: The subtitle change is more concise and clear.
  • 6-8: Updated version badges reflect the new minimum supported versions for Deno, Vim, and Neovim.
  • 21-30: Introduction of pronunciation and links to related technologies is a good addition for clarity and resourcefulness.
  • 34-35: The instruction to install the latest Deno is clear and directs users to the official manual.
  • 38-40: The check for deno command's executability from Vim/Neovim is a practical step for troubleshooting.
  • 47-52: Providing an alternative method to specify the Deno executable path is helpful for users with non-standard setups.
  • 54-59: Instructions for installing denops.vim using a plugin manager are straightforward.
  • 61-71: The addition of a test plugin installation and verification step is a good practice to ensure correct setup.
  • 85-118: The explanation of the shared server concept and setup instructions are clear and could improve user experience.
  • 120-132: The Windows-specific advice regarding antivirus software and Deno's cache directory is a valuable tip for troubleshooting performance issues.
  • 78-137: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [134-152]

The support policy section is informative and sets clear expectations for version support.

  • 153-170: The section for plugin developers provides useful resources and community support options.
  • 174-182: Acknowledging the inspiration from coc.nvim and providing links to the community and related technologies is a nice touch.
  • 190-192: The licensing section is standard and clear.

@Shougo
Copy link
Contributor

Shougo commented Jan 21, 2024

It works for me.

The latest Vim version is 9.1 thus we should support the latest version
of Vim 9.0.
vim-win32-installer provides 9.0.2189 as the latest Vim 9.0 so we
decided to support that version.
The most recent version of Neovim is 0.9.5, so we provide support
for version 0.9.4 and newer. Please note that while we mention
supporting the two most recent minor versions of Neovim, the
software has not reached version 1.0. Therefore, we consider the
patch version to be equivalent to the minor version for the
purpose of support.
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: 32

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 16d4bbc and 5a16d82.
Files selected for processing (31)
  • .github/workflows/test.yml (2 hunks)
  • README.md (3 hunks)
  • autoload/denops.vim (1 hunks)
  • autoload/denops/_internal/echo.vim (2 hunks)
  • autoload/denops/_internal/test.vim (1 hunks)
  • autoload/denops/plugin.vim (1 hunks)
  • autoload/health/denops.vim (1 hunks)
  • deno.jsonc (1 hunks)
  • denops/@denops-private/cli.ts (1 hunks)
  • denops/@denops-private/denops.ts (2 hunks)
  • denops/@denops-private/denops_test.ts (1 hunks)
  • denops/@denops-private/error.ts (1 hunks)
  • denops/@denops-private/error_test.ts (1 hunks)
  • denops/@denops-private/host.ts (1 hunks)
  • denops/@denops-private/host/nvim.ts (4 hunks)
  • denops/@denops-private/host/nvim_test.ts (1 hunks)
  • denops/@denops-private/host/vim.ts (4 hunks)
  • denops/@denops-private/host/vim_test.ts (1 hunks)
  • denops/@denops-private/host_test.ts (1 hunks)
  • denops/@denops-private/service.ts (2 hunks)
  • denops/@denops-private/service_test.ts (1 hunks)
  • denops/@denops-private/testdata/dummy_invalid_plugin.ts (1 hunks)
  • denops/@denops-private/testdata/dummy_valid_plugin.ts (1 hunks)
  • denops/@denops-private/testutil/cli.ts (1 hunks)
  • denops/@denops-private/testutil/conf.ts (1 hunks)
  • denops/@denops-private/testutil/conf_test.ts (1 hunks)
  • denops/@denops-private/testutil/with.ts (1 hunks)
  • denops/@denops-private/util.ts (1 hunks)
  • denops/@denops-private/version.ts (1 hunks)
  • denops/@denops-private/worker.ts (1 hunks)
  • plugin/denops.vim (2 hunks)
Files skipped from review due to trivial changes (2)
  • autoload/denops/plugin.vim
  • autoload/health/denops.vim
Additional comments: 31
autoload/denops/_internal/test.vim (1)
  • 1-17: No issues found.
autoload/denops/_internal/echo.vim (2)
  • 8-10: No issues found.
  • 20-20: No issues found.
plugin/denops.vim (1)
  • 6-8: No issues found.
autoload/denops.vim (1)
  • 22-22: No issues found.
.github/workflows/test.yml (3)
  • 56-60: No issues found.
  • 91-91: No issues found.
  • 98-98: No issues found.
denops/@denops-private/host/vim.ts (2)
  • 1-8: Update the dependency versions to unknownutil and vim_channel_command to ensure compatibility with the new versions.
  • 105-114: Ensure proper error handling and validation for the #dispatch method to prevent unexpected runtime errors.
Verification successful

The provided shell script output confirms that the #dispatch method in denops/@denops-private/host/vim.ts includes error handling through the use of throw new Error for different scenarios:

  1. When no service is registered in the host, it throws an error stating, "No service is registered in the host."
  2. It also handles unexpected JSON channel messages by throwing an error with the message content for debugging purposes.

These checks ensure that the method has proper error handling mechanisms to prevent unexpected runtime errors related to service invocation and message processing. Therefore, the review comment regarding ensuring proper error handling and validation for the #dispatch method to prevent unexpected runtime errors has been addressed in the code.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify proper error handling in #dispatch method
grep -C3 "throw new Error" denops/@denops-private/host/vim.ts

Length of output: 1348

denops/@denops-private/host/nvim.ts (2)
  • 1-5: Update the dependency versions to unknownutil and ensure compatibility with the new versions.
  • 136-145: Ensure proper error handling and validation for the nvim_error_event message to prevent unexpected runtime errors.
Verification successful

The provided shell script output shows that there is explicit error handling for nvim_error_event messages within the denops/@denops-private/host/nvim.ts file. The error handling mechanism logs the error to the console using console.error, which is a basic form of error reporting. This indicates that there is a mechanism in place to handle and report errors related to nvim_error_event.

Given this context, it appears that the original review comment concerning ensuring proper error handling and validation for the nvim_error_event message to prevent unexpected runtime errors has been addressed to some extent by logging the error. However, the depth of error handling (beyond logging) and whether it fully prevents unexpected runtime errors cannot be fully assessed without a deeper understanding of the overall error handling strategy and implementation details within the application.

Based on the information available, it seems appropriate to conclude that the review comment has been addressed in terms of identifying and logging errors related to nvim_error_event. Further analysis on the effectiveness of this error handling strategy in preventing runtime errors would require a more comprehensive review of the application's error handling mechanisms.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify proper error handling for nvim_error_event message
grep -C3 "console.error" denops/@denops-private/host/nvim.ts

Length of output: 484

denops/@denops-private/service.ts (6)
  • 1-8: Ensure all new imports are used effectively and check for any unnecessary imports after refactoring.
  • 14-23: The introduction of the Service class with a constructor accepting Meta is a good practice for dependency injection.
  • 80-90: Ensure dispatchAsync method properly handles errors and uses callbacks correctly to avoid unhandled promises.
  • 109-111: Validate disposal logic in dispose method to ensure all resources are cleaned up properly.
  • 114-140: Review the Plugin class for proper error handling and lifecycle management of plugins.
  • 161-166: Check the implementation of toVimError to ensure it correctly formats errors for Vim/Neovim.
denops/@denops-private/host/vim_test.ts (2)
  • 1-17: Ensure all new imports are used effectively and check for any unnecessary imports after refactoring.
  • 18-154: Review the test cases for Vim class to ensure they cover all new functionality and error handling paths.
denops/@denops-private/host/nvim_test.ts (2)
  • 1-17: Ensure all new imports are used effectively and check for any unnecessary imports after refactoring.
  • 18-168: Review the test cases for Neovim class to ensure they cover all new functionality and error handling paths.
README.md (6)
  • 6-8: Update the badges for Deno, Vim, and Neovim to reflect the new supported versions.
  • 85-120: The introduction of the shared server feature to improve plugin startup time is well-documented and provides clear instructions for setup.
  • 124-133: The guidance for Windows users regarding antivirus software and Deno's cache directory is helpful and well-explained.
  • 135-151: Ensure the support policy section is updated to reflect the current policy and supported versions.
  • 156-173: Review the section for plugin developers to ensure it provides clear guidance and useful resources.
  • 177-195: Ensure the miscellaneous section, including developer acknowledgments and license information, is accurate and up-to-date.
denops/@denops-private/service_test.ts (3)
  • 1-16: Ensure all new imports are used effectively and check for any unnecessary imports after refactoring.
  • 17-21: Verify the test data files dummy_valid_plugin.ts and dummy_invalid_plugin.ts are correctly implemented for testing.
Verification successful

The provided script outputs show the contents of both dummy_valid_plugin.ts and dummy_invalid_plugin.ts files, which are intended for testing within the denops framework.

  • dummy_valid_plugin.ts defines an async main function that sets up a dispatcher with a test method and executes a couple of commands using denops.cmd. This implementation seems correctly designed to simulate a valid Denops plugin, demonstrating how it interacts with the Denops framework by registering a dispatcher and executing commands.

  • dummy_invalid_plugin.ts defines a main function that immediately throws an error. This is a straightforward way to simulate a plugin that fails upon execution, which is useful for testing error handling within the Denops framework.

Based on the provided context and the contents of these files, it appears that both test data files are implemented in a manner that aligns with their intended purpose: dummy_valid_plugin.ts to simulate a correctly functioning plugin and dummy_invalid_plugin.ts to simulate a plugin that fails. This suggests that the verification process for the implementation of these test data files is successful.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the implementation of test data files
cat denops/@denops-private/testdata/dummy_valid_plugin.ts
cat denops/@denops-private/testdata/dummy_invalid_plugin.ts

Length of output: 627

* 22-416: Review the test cases for `Service` class to ensure they cover all new functionality, error handling paths, and plugin lifecycle management.


export class Vim implements Host {
#session: Session;
#client: Client;
#invoker?: Invoker;
#service?: Service;
Copy link

Choose a reason for hiding this comment

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

Ensure that all usages of #service are checked for undefined before accessing its methods to prevent runtime errors.

-  #service?: Service;
+  #service: Service | undefined;

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
#service?: Service;
#service: Service | undefined;

Comment on lines +47 to +52
if (result === "ERROR") {
// Not sure why but Vim just returns "ERROR" when 'denops.vim' is not in 'runtimepath'.
// This makes debugging nightmare so we throw an error with better message here.
throw new Error(
`Vim just returns "ERROR" for 'denops#api#vim#call()'. Check if 'denops.vim' exist in 'runtimepath' properly`,
);
Copy link

Choose a reason for hiding this comment

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

The error message for call method when result is "ERROR" could be more specific to help with debugging.

-        `Vim just returns "ERROR" for 'denops#api#vim#call()'. Check if 'denops.vim' exist in 'runtimepath' properly`,
+        `Vim returned "ERROR" for 'denops#api#vim#call()'. Ensure 'denops.vim' is correctly included in 'runtimepath'.`,

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if (result === "ERROR") {
// Not sure why but Vim just returns "ERROR" when 'denops.vim' is not in 'runtimepath'.
// This makes debugging nightmare so we throw an error with better message here.
throw new Error(
`Vim just returns "ERROR" for 'denops#api#vim#call()'. Check if 'denops.vim' exist in 'runtimepath' properly`,
);
if (result === "ERROR") {
// Not sure why but Vim just returns "ERROR" when 'denops.vim' is not in 'runtimepath'.
// This makes debugging nightmare so we throw an error with better message here.
throw new Error(
`Vim returned "ERROR" for 'denops#api#vim#call()'. Ensure 'denops.vim' is correctly included in 'runtimepath'.`,
);

Comment on lines +65 to +70
if (result === "ERROR") {
// Not sure why but Vim just returns "ERROR" when 'denops.vim' is not in 'runtimepath'.
// This makes debugging nightmare so we throw an error with better message here.
throw new Error(
`Vim just returns "ERROR" for 'denops#api#vim#batch()'. Check if 'denops.vim' exist in 'runtimepath' properly`,
);
Copy link

Choose a reason for hiding this comment

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

Similar to the previous comment, refine the error message for clarity in the batch method.

-        `Vim just returns "ERROR" for 'denops#api#vim#batch()'. Check if 'denops.vim' exist in 'runtimepath' properly`,
+        `Vim returned "ERROR" for 'denops#api#vim#batch()'. Ensure 'denops.vim' is correctly included in 'runtimepath'.`,

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if (result === "ERROR") {
// Not sure why but Vim just returns "ERROR" when 'denops.vim' is not in 'runtimepath'.
// This makes debugging nightmare so we throw an error with better message here.
throw new Error(
`Vim just returns "ERROR" for 'denops#api#vim#batch()'. Check if 'denops.vim' exist in 'runtimepath' properly`,
);
if (result === "ERROR") {
// Not sure why but Vim just returns "ERROR" when 'denops.vim' is not in 'runtimepath'.
// This makes debugging nightmare so we throw an error with better message here.
throw new Error(
`Vim returned "ERROR" for 'denops#api#vim#batch()'. Ensure 'denops.vim' is correctly included in 'runtimepath'.`,
);

@@ -0,0 +1,5 @@
import type { Denops } from "https://deno.land/x/denops_core@v6.0.5/mod.ts";
Copy link

Choose a reason for hiding this comment

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

Missing module version specification in the import statement.

- import type { Denops } from "https://deno.land/x/denops_core@v6.0.5/mod.ts";
+ import type { Denops } from "https://deno.land/x/denops_core/mod.ts";

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
import type { Denops } from "https://deno.land/x/denops_core@v6.0.5/mod.ts";
import type { Denops } from "https://deno.land/x/denops_core/mod.ts";

@@ -0,0 +1,10 @@
import type { Denops } from "https://deno.land/x/denops_core@v6.0.5/mod.ts";
Copy link

Choose a reason for hiding this comment

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

Missing module version specification in the import statement.

- import type { Denops } from "https://deno.land/x/denops_core@v6.0.5/mod.ts";
+ import type { Denops } from "https://deno.land/x/denops_core/mod.ts";

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
import type { Denops } from "https://deno.land/x/denops_core@v6.0.5/mod.ts";
import type { Denops } from "https://deno.land/x/denops_core/mod.ts";

Comment on lines +1 to +6
import type { Meta } from "https://deno.land/x/denops_core@v6.0.5/mod.ts";
import {
assertSpyCall,
stub,
} from "https://deno.land/std@0.211.0/testing/mock.ts";
import { DenopsImpl, Host, Service } from "./denops.ts";
Copy link

Choose a reason for hiding this comment

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

Missing module version specification in the import statement.

- import type { Meta } from "https://deno.land/x/denops_core@v6.0.5/mod.ts";
- import {
-   assertSpyCall,
-   stub,
- } from "https://deno.land/std@0.211.0/testing/mock.ts";
- import { DenopsImpl, Host, Service } from "./denops.ts";
+ import type { Meta } from "https://deno.land/x/denops_core/mod.ts";
+ import {
+   assertSpyCall,
+   stub,
+ } from "https://deno.land/std/testing/mock.ts";
+ import { DenopsImpl, Host, Service } from "./denops.ts"; // Ensure all imports specify a version

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
import type { Meta } from "https://deno.land/x/denops_core@v6.0.5/mod.ts";
import {
assertSpyCall,
stub,
} from "https://deno.land/std@0.211.0/testing/mock.ts";
import { DenopsImpl, Host, Service } from "./denops.ts";
import type { Meta } from "https://deno.land/x/denops_core/mod.ts";
import {
assertSpyCall,
stub,
} from "https://deno.land/std/testing/mock.ts";
import { DenopsImpl, Host, Service } from "./denops.ts"; // Ensure all imports specify a version

Comment on lines +1 to +10
import { assertThrows } from "https://deno.land/std@0.211.0/assert/mod.ts";
import {
assertSpyCall,
assertSpyCalls,
stub,
} from "https://deno.land/std@0.211.0/testing/mock.ts";
import { AssertError } from "https://deno.land/x/unknownutil@v3.13.0/mod.ts";
import { invoke, Service } from "./host.ts";
import { unimplemented } from "https://deno.land/x/errorutil@v0.1.1/mod.ts";

Copy link

Choose a reason for hiding this comment

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

Missing module version specification in the import statement.

- import { assertThrows } from "https://deno.land/std@0.211.0/assert/mod.ts";
- import {
-   assertSpyCall,
-   assertSpyCalls,
-   stub,
- } from "https://deno.land/std@0.211.0/testing/mock.ts";
- import { AssertError } from "https://deno.land/x/unknownutil@v3.13.0/mod.ts";
- import { invoke, Service } from "./host.ts";
- import { unimplemented } from "https://deno.land/x/errorutil@v0.1.1/mod.ts";
+ import { assertThrows } from "https://deno.land/std/assert/mod.ts";
+ import {
+   assertSpyCall,
+   assertSpyCalls,
+   stub,
+ } from "https://deno.land/std/testing/mock.ts";
+ import { AssertError } from "https://deno.land/x/unknownutil/mod.ts";
+ import { invoke, Service } from "./host.ts";
+ import { unimplemented } from "https://deno.land/x/errorutil/mod.ts"; // Ensure all imports specify a version

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
import { assertThrows } from "https://deno.land/std@0.211.0/assert/mod.ts";
import {
assertSpyCall,
assertSpyCalls,
stub,
} from "https://deno.land/std@0.211.0/testing/mock.ts";
import { AssertError } from "https://deno.land/x/unknownutil@v3.13.0/mod.ts";
import { invoke, Service } from "./host.ts";
import { unimplemented } from "https://deno.land/x/errorutil@v0.1.1/mod.ts";
import { assertThrows } from "https://deno.land/std/assert/mod.ts";
import {
assertSpyCall,
assertSpyCalls,
stub,
} from "https://deno.land/std/testing/mock.ts";
import { AssertError } from "https://deno.land/x/unknownutil/mod.ts";
import { invoke, Service } from "./host.ts";
import { unimplemented } from "https://deno.land/x/errorutil/mod.ts";

Comment on lines +64 to +69
async #dispatch(name: string, fn: string, args: unknown[]): Promise<unknown> {
const plugin = this.#plugins.get(name);
if (!plugin) {
throw new Error(`No plugin '${name}' is loaded`);
}
return await plugin.call(fn, ...args);
Copy link

Choose a reason for hiding this comment

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

Validate plugin existence before attempting to call its methods in #dispatch to prevent runtime errors.

+  if (!this.#plugins.has(name)) {
+    throw new Error(`Plugin '${name}' not found`);
+  }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
async #dispatch(name: string, fn: string, args: unknown[]): Promise<unknown> {
const plugin = this.#plugins.get(name);
if (!plugin) {
throw new Error(`No plugin '${name}' is loaded`);
}
return await plugin.call(fn, ...args);
async #dispatch(name: string, fn: string, args: unknown[]): Promise<unknown> {
if (!this.#plugins.has(name)) {
throw new Error(`Plugin '${name}' not found`);
}
const plugin = this.#plugins.get(name);
if (!plugin) {
throw new Error(`No plugin '${name}' is loaded`);
}
return await plugin.call(fn, ...args);

Comment on lines +74 to +76
return await this.#dispatch(name, fn, args);
} catch (e) {
// NOTE:
// Vim/Neovim does not handle JavaScript Error instance thus use string instead
throw `${e.stack ?? e.toString()}`;
throw toVimError(e);
Copy link

Choose a reason for hiding this comment

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

Improve error handling in dispatch method by catching and re-throwing errors with more context.

-      throw toVimError(e);
+      throw new Error(`Error dispatching to plugin '${name}': ${toVimError(e)}`);

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
return await this.#dispatch(name, fn, args);
} catch (e) {
// NOTE:
// Vim/Neovim does not handle JavaScript Error instance thus use string instead
throw `${e.stack ?? e.toString()}`;
throw toVimError(e);
return await this.#dispatch(name, fn, args);
} catch (e) {
throw new Error(`Error dispatching to plugin '${name}': ${toVimError(e)}`);

Comment on lines +143 to +148
async function emit(denops: Denops, name: string): Promise<void> {
try {
await denops.cmd(`doautocmd <nomodeline> User ${name}`);
} catch (e) {
console.error(`Failed to emit ${name}: ${e}`);
}
Copy link

Choose a reason for hiding this comment

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

Ensure emit function properly handles errors and does not suppress them silently.

-    console.error(`Failed to emit ${name}: ${e}`);
+    throw new Error(`Failed to emit event '${name}': ${e}`);

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
async function emit(denops: Denops, name: string): Promise<void> {
try {
await denops.cmd(`doautocmd <nomodeline> User ${name}`);
} catch (e) {
console.error(`Failed to emit ${name}: ${e}`);
}
async function emit(denops: Denops, name: string): Promise<void> {
try {
await denops.cmd(`doautocmd <nomodeline> User ${name}`);
} catch (e) {
throw new Error(`Failed to emit event '${name}': ${e}`);
}

@lambdalisue lambdalisue merged commit 4124f6a into main Feb 3, 2024
7 of 9 checks passed
@lambdalisue lambdalisue deleted the v6-pre branch February 3, 2024 07:38
kg8m added a commit to kg8m/vim-detect-indent that referenced this pull request Feb 27, 2024
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.

2 participants