Skip to content

Add close function to popup module #286

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 1 commit into from
Jun 22, 2025
Merged

Add close function to popup module #286

merged 1 commit into from
Jun 22, 2025

Conversation

lambdalisue
Copy link
Member

@lambdalisue lambdalisue commented Jun 22, 2025

Summary by CodeRabbit

  • New Features

    • Added a standalone function to close popup windows by their ID, compatible with both Vim and Neovim.
  • Tests

    • Introduced a new test to verify that popup windows can be closed using the standalone close function.

Copy link

coderabbitai bot commented Jun 22, 2025

Walkthrough

A new asynchronous close function was introduced in the popup module to close popup windows using their window ID, supporting both Vim and Neovim. Corresponding tests were added to verify this standalone close functionality, ensuring that popups can be closed independently of the object returned by the open function.

Changes

File(s) Change Summary
popup/mod.ts Added an exported async close function to close popup windows by ID, compatible with Vim/Neovim.
popup/mod_test.ts Added a test step to validate closing a popup window using the new standalone close function.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Suite
    participant Popup as popup/mod.ts
    participant Denops as Denops Host

    Test->>Popup: open(denops, options)
    Popup->>Denops: Create popup window
    Denops-->>Popup: Return winid
    Popup-->>Test: Return winid

    Test->>Popup: close(denops, winid)
    Popup->>Denops: Determine host (Vim/Neovim)
    Popup->>Denops: Call appropriate close function
    Denops-->>Popup: Popup closed
    Popup->>Denops: Redraw UI
Loading

Poem

In the land where popups bloom and fade,
A new close function has been made.
With Vim or Neovim, it knows what to do,
Closing windows by ID, swift as dew.
Now tested and true, it hops with pride—
A rabbit’s code, with joy inside!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 253bde0 and f26e0f7.

📒 Files selected for processing (2)
  • popup/mod.ts (1 hunks)
  • popup/mod_test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • popup/mod_test.ts
  • popup/mod.ts
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: test (windows-latest, 1.x, v9.1.0448, v0.10.0)
  • GitHub Check: test (macos-latest, 1.45.0, v9.1.0448, v0.10.0)
  • GitHub Check: test (ubuntu-latest, 1.45.0, v9.1.0448, v0.10.0)
  • GitHub Check: test (ubuntu-latest, 1.x, v9.1.0448, v0.10.0)
  • GitHub Check: test (macos-latest, 1.x, v9.1.0448, v0.10.0)
  • GitHub Check: test (windows-latest, 1.45.0, v9.1.0448, v0.10.0)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
popup/mod.ts (1)

178-189: Consider adding a noRedraw option for consistency.

The standalone close function always calls denops.redraw(), while the instance method's close() respects the noRedraw option from the original open() call. This inconsistency could lead to unexpected behavior when users want to batch multiple operations without triggering redraws.

Consider adding an optional parameter or making the redraw behavior consistent with other functions in the module.

/**
- * Close popup window
+ * Close popup window by window ID in Vim/Neovim compatible way.
+ *
+ * ```typescript
+ * import type { Entrypoint } from "jsr:@denops/std";
+ * import * as popup from "jsr:@denops/std/popup";
+ *
+ * export const main: Entrypoint = async (denops) => {
+ *   // Open a popup window
+ *   const popupWindow = await popup.open(denops, {
+ *     relative: "editor",
+ *     width: 20,
+ *     height: 20,
+ *     row: 1,
+ *     col: 1,
+ *   });
+ *
+ *   // Close using the standalone close function
+ *   await popup.close(denops, popupWindow.winid);
+ * }
+ * ```
+ *
+ * Note that this function does NOT work in `batch.collect()`.
 */
export async function close(
  denops: Denops,
  winid: number,
+  options: { noRedraw?: boolean } = {},
): Promise<void> {
  const close = denops.meta.host === "vim" ? closePopupVim : closePopupNvim;
  await close(denops, winid);
-  await denops.redraw();
+  if (!options.noRedraw) {
+    await denops.redraw();
+  }
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4a275c5 and bae3c6a.

📒 Files selected for processing (2)
  • popup/mod.ts (1 hunks)
  • popup/mod_test.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: test (ubuntu-latest, 1.45.0, v9.1.0448, v0.10.0)
  • GitHub Check: test (ubuntu-latest, 1.x, v9.1.0448, v0.10.0)
  • GitHub Check: test (macos-latest, 1.x, v9.1.0448, v0.10.0)
  • GitHub Check: test (macos-latest, 1.45.0, v9.1.0448, v0.10.0)
  • GitHub Check: test (windows-latest, 1.x, v9.1.0448, v0.10.0)
  • GitHub Check: test (windows-latest, 1.45.0, v9.1.0448, v0.10.0)
🔇 Additional comments (1)
popup/mod_test.ts (1)

109-130: Well-structured test for the new close function.

The test properly verifies the standalone close functionality by:

  • Opening a popup window and confirming its type
  • Using the new popup.close() function with the window ID
  • Verifying the popup is properly closed afterward

The test follows the existing patterns in the file and provides good coverage for the new functionality.

Copy link

codecov bot commented Jun 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.84%. Comparing base (4a275c5) to head (f26e0f7).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #286      +/-   ##
==========================================
+ Coverage   85.80%   85.84%   +0.03%     
==========================================
  Files          65       65              
  Lines        3459     3468       +9     
  Branches      301      302       +1     
==========================================
+ Hits         2968     2977       +9     
  Misses        489      489              
  Partials        2        2              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lambdalisue lambdalisue merged commit d87b762 into main Jun 22, 2025
10 checks passed
@lambdalisue lambdalisue deleted the imp-popup branch June 22, 2025 17:01
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