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

voice command #25

Merged
merged 7 commits into from
Oct 12, 2024
Merged

voice command #25

merged 7 commits into from
Oct 12, 2024

Conversation

tsukimizake
Copy link
Contributor

@tsukimizake tsukimizake commented Oct 12, 2024

  • AiderVoiceが欲しかったので追加しました
  • biomeのlineWidthを120にしました
  • sendPromptWithInput -> sendPromptにリネームしました
  • AddFileのバッファ準備処理をbuffer.prepareAiderBufferとして分割してvoiceでも使っています

Summary by CodeRabbit

  • New Features

    • Introduced a new command for voice input in the Aider plugin.
    • Enhanced buffer handling with the addition of a new prepareAiderBuffer function.
  • Improvements

    • Improved code readability and maintainability through streamlined function signatures and simplified logic in command handling.
  • Bug Fixes

    • Corrected prompt handling across various commands for consistency.

Copy link
Contributor

coderabbitai bot commented Oct 12, 2024

Walkthrough

The pull request introduces several changes across multiple files, primarily focusing on enhancing the biome.jsonc configuration and restructuring functions within the denops/aider module. A new property for line width is added to the configuration file, while function signatures and return statements in bufferOperation.ts are simplified for better readability. Additionally, a new function, prepareAiderBuffer, is introduced to streamline buffer handling, and command handling in main.ts is updated to incorporate this new function along with the addition of a voice command.

Changes

File Change Summary
biome.jsonc Added property "lineWidth": 120 under the "formatter" section.
denops/aider/bufferOperation.ts - Updated method signatures for several functions for clarity.
- Added new function prepareAiderBuffer.
- Simplified return statements and removed unnecessary parentheses.
denops/aider/main.ts - Added import for prepareAiderBuffer.
- Reformatted ImplType and Opts for readability.
- Updated command handling to use sendPrompt and introduced new command voice.

Possibly related PRs

Suggested reviewers

  • nekowasabi

Poem

🐇 In the land of code where bunnies hop,
New lines of width make formatting stop!
Buffers now open with a swift little cheer,
Voice commands added, let’s all lend an ear!
Hopping through changes, so tidy and neat,
Code's now a garden, a wonderful treat! 🌼


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>, please review it.
    • Generate unit testing code for this file.
    • 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 generate unit testing code 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 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 generate unit testing code.
    • @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.

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 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
Owner

@nekowasabi nekowasabi left a comment

Choose a reason for hiding this comment

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

( ;´ワ `;)つLGTM☆

(余談)
コードフォーマットがなかなか安定しない感

@nekowasabi nekowasabi merged commit 6511d87 into nekowasabi:main Oct 12, 2024
1 check was pending
Copy link
Contributor

@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: 2

🧹 Outside diff range and nitpick comments (4)
denops/aider/bufferOperation.ts (1)

72-81: New function to centralize Aider buffer preparation

The new prepareAiderBuffer function centralizes the logic for preparing the Aider buffer, which is a good improvement for code organization and reusability. However, there's an unnecessary console.log statement that should be removed.

Consider removing the console.log statement on line 78:

-    console.log("Run Command again.");
denops/aider/main.ts (3)

Line range hint 26-42: Ensure consistent language for code comments

The code includes comments in both English and Japanese. For consistency and maintainability, consider using a single language for all code comments throughout the codebase. This will make it easier for all contributors to understand and maintain the code.


Line range hint 190-199: Add error handling for 'git' command execution in 'openIgnore' command

The openIgnore command assumes that Git is available and that the current directory is within a Git repository. If Git is not installed or the command fails (e.g., not in a Git repository), the code may throw an unhandled exception.

Consider adding error handling to manage cases where git rev-parse --show-toplevel fails, and provide a user-friendly message or fallback behavior.

Apply this diff to add error handling:

 const gitRoot = (await fn.system(denops, "git rev-parse --show-toplevel")).trim();
+if (!gitRoot) {
+  console.error("Not a git repository or Git not available.");
+  return;
+}

Line range hint 201-212: Use 'path.relative' to compute the relative path and handle potential errors

In the addIgnoreCurrentFile command, calculating relativePath using currentFile.replace(gitRoot, "") may not always produce the correct relative path, especially if currentFile is not a subpath of gitRoot or if the paths share common prefixes.

Consider using path.relative from Deno's standard library to accurately compute the relative path between gitRoot and currentFile. Additionally, add error handling in case Git is not available or the command fails.

Apply this diff to use path.relative and add error handling:

+import { relative } from "https://deno.land/std/path/mod.ts";

 const gitRoot = (await fn.system(denops, "git rev-parse --show-toplevel")).trim();
+if (!gitRoot) {
+  console.error("Not a git repository or Git not available.");
+  return;
+}

-const relativePath = currentFile.replace(gitRoot, "");
+const relativePath = relative(gitRoot, currentFile);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 19d5ce1 and 506af5b.

📒 Files selected for processing (3)
  • biome.jsonc (1 hunks)
  • denops/aider/bufferOperation.ts (19 hunks)
  • denops/aider/main.ts (12 hunks)
🧰 Additional context used
🔇 Additional comments (10)
denops/aider/bufferOperation.ts (8)

23-23: Improved readability with concise return statement

The function has been simplified by using a single-line return statement with a ternary operator. This change improves readability while maintaining the same functionality.


46-46: Improved consistency in function signature

The function signature has been updated to be on a single line, improving consistency with other function declarations in the file. The functionality remains unchanged.


83-83: Improved consistency in function signature

The function signature has been updated to be on a single line, improving consistency with other function declarations in the file. The functionality remains unchanged.


104-105: Improved function signature and simplified return statement

The function signature has been updated to be consistent with other functions in the file. The return statement has been simplified by removing the unnecessary explicit return of undefined.

Also applies to: 114-114


Line range hint 124-153: Enhanced floating window functionality with new keymaps

The function has been updated to include new keymap settings for the floating window. These changes improve user interaction by providing:

  1. A way to close the window with the 'q' key.
  2. A method to hide the visual select floating window with 'Q'.
  3. The ability to send a prompt with the enter key.

These additions enhance the usability of the floating window.


166-166: Improved consistency in function signatures

The function signatures for handleBackupPrompt and handleNoBackupPrompt have been updated to be on single lines, improving consistency with other function declarations in the file. The functionality of both functions remains unchanged.

Also applies to: 182-183


203-204: Improved consistency in function signature

The function signature for hideVisualSelectFloatingWindow has been updated to be on a single line, improving consistency with other function declarations in the file. The functionality remains unchanged.


Line range hint 1-366: Overall assessment: Improved code consistency and functionality

The changes in this file have significantly improved the consistency of function signatures and introduced new functionality, particularly in the floating window handling. The new prepareAiderBuffer function centralizes buffer preparation logic, which is a good improvement for code organization.

A minor suggestion was made to remove a console.log statement in the new function. Otherwise, all changes are approved and contribute positively to the codebase.

denops/aider/main.ts (2)

91-91: Refactored buffer preparation into 'prepareAiderBuffer'

Replacing direct buffer initialization with a call to prepareAiderBuffer improves code modularity and reusability by encapsulating the buffer setup logic.


215-220: Verify the use of 'fn.feedkeys' to enter insert mode

In the voice command, the use of await fn.feedkeys(denops, "a"); to enter insert mode may have unintended side effects or may not be reliable in all contexts.

Consider verifying whether this is the best approach to programmatically enter insert mode. It might be preferable to use a more controlled method, such as await denops.cmd('startinsert'), to ensure consistent behavior without interfering with the user's workflow.

Comment on lines +14 to +15
"indentStyle": "space",
"lineWidth": 120
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Lines exceed the configured line width of 120 characters.

The following lines in the codebase exceed the 120-character limit set in the formatter configuration:

  • denops/aider/main.ts:38
  • denops/aider/main.ts:58
  • denops/aider/main.ts:76
  • denops/aider/utils.ts:14
  • tests/testRunner.ts:17

Please refactor these lines to comply with the new line width setting.

🔗 Analysis chain

LGTM! Consider verifying the impact on the codebase.

The addition of "lineWidth": 120 to the formatter configuration aligns with the PR objectives and is a common standard in many codebases. This change will allow for more content per line while still maintaining readability.

To ensure this change doesn't negatively impact the existing codebase, consider running the following script to check the current line lengths in your JavaScript and TypeScript files:

This script will help you identify any potential formatting issues that may arise from this change.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check current line lengths in JS/TS files

# Find all JS and TS files, excluding node_modules
files=$(fd -e js -e ts --exclude node_modules)

# Check for lines longer than 120 characters
echo "Lines longer than 120 characters:"
for file in $files; do
  awk 'length($0) > 120 {print FILENAME ":" NR ":" $0}' "$file"
done

# Show distribution of line lengths
echo -e "\nDistribution of line lengths:"
for file in $files; do
  awk '{print length($0)}' "$file"
done | sort -n | uniq -c | sort -n

Length of output: 4436

Comment on lines +234 to 235
commands.map((command) => [command.methodName, command.impl as (args: unknown) => Promise<void>]),
);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid unnecessary type assertions in dispatcher mapping

In the dispatcher mapping, the type assertion as (args: unknown) => Promise<void> may mask potential type errors.

Consider refining the types to avoid using type assertions, ensuring type safety and better maintainability.

Apply this diff to adjust types:

 denops.dispatcher = Object.fromEntries(
-  commands.map((command) => [command.methodName, command.impl as (args: unknown) => Promise<void>]),
+  commands.map((command) => [command.methodName, command.impl]),
 );
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
commands.map((command) => [command.methodName, command.impl as (args: unknown) => Promise<void>]),
);
commands.map((command) => [command.methodName, command.impl]),
);

@@ -103,7 +103,7 @@ export async function main(denops: Denops): Promise<void> {

const currentFile = await getCurrentFilePath(denops);
const prompt = `/${prefix} ${currentFile}`;
await buffer.sendPromptWithInput(denops, prompt);
Copy link
Owner

Choose a reason for hiding this comment

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

@tsukimizake
過去の遺産(コマンドラインからプロンプトを入力していたころの名残)が残ったままだったの気になっていましたが、対応ありがとうございます。 🙇

Copy link
Contributor Author

Choose a reason for hiding this comment

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

わかる

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