-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add more insertAt options #69
Conversation
WalkthroughWalkthroughThe pull request introduces enhancements to the documentation and functionality of the SilverBullet AI plugin. Key changes include the restructuring of documentation to clarify the integration of Large Language Models (LLMs) and the addition of new utility functions for text manipulation. The Changes
Recent review detailsConfiguration used: CodeRabbit UI Files selected for processing (2)
Additional context usedPath-based instructions (2)
Additional comments not posted (6)
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 (3)
docs/Library/AICore/AIPrompt/AI Rewrite - Grammar.md (1)
15-24
: Refine the user instructions and make the assistant responses more engaging.Consider making the following improvements:
- Simplify the user instructions at line 24 to make them more concise. For example:
Rewrite the text, correcting grammar and improving clarity. Preserve meaning, facts and formatting. Return only the rewritten text.
- Make the assistant responses more engaging by adding personality. For example, at line 16:
**assistant**: Great! What's the title of the note you'd like me to help with?
docs/index.md (1)
34-34
: Consider making the backup warning more prominent.The warning about backing up notes before using the plug is important. Consider making it more prominent by:
- Moving it to the top of the document, perhaps right after the "Requirements" section.
- Using a more eye-catching formatting, like a colored box or a different font.
This will ensure users don't miss this critical piece of advice.
Tools
LanguageTool
[grammar] ~34-~34: The word “backup” is a noun. The verb is spelled with a space.
Context: ...I Core Library]] > Warning: Please backup your notes before using this plug. It i...(NOUN_VERB_CONFUSION)
src/editorUtils.ts (1)
86-126
: Optimize the function and remove debugging statements.The function correctly identifies and returns the paragraph containing the cursor position. However, consider the following improvements:
- Remove or comment out the console log statements used for debugging purposes.
- Optimize the function by avoiding the use of
slice
andjoin
methods inside the loops. Instead, you can keep track of the start and end line numbers and use them to extract the paragraph text outside the loops.Here's an optimized version of the function:
export function getParagraph(text: string, pos: number): { from: number; to: number; text: string; } { const lines = text.split("\n"); let currentPos = 0; let start = 0; let end = text.length; + let startLine = 0; + let endLine = lines.length - 1; for (let i = 0; i < lines.length; i++) { const lineLength = lines[i].length + 1; if (currentPos <= pos && pos < currentPos + lineLength) { - // Look backwards for the start of the paragraph - console.log("Looking backwards for the start of the paragraph"); for (let j = i; j >= 0; j--) { if (j === 0 || lines[j - 1].trim() === "") { - start = j === 0 ? 0 : lines.slice(0, j).join("\n").length + 1; + startLine = j; break; } } - // Look forwards for the end of the paragraph - console.log("Looking forwards for the end of the paragraph"); for (let k = i; k < lines.length; k++) { if (k === lines.length - 1 || lines[k + 1].trim() === "") { - end = lines.slice(0, k + 1).join("\n").length; + endLine = k; break; } } break; } currentPos += lineLength; } - console.log("Found paragraph", text.slice(start, end)); + start = startLine === 0 ? 0 : lines.slice(0, startLine).join("\n").length + 1; + end = lines.slice(0, endLine + 1).join("\n").length; return { from: start, to: end, text: text.slice(start, end), }; }
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (7)
- docs/Changelog.md (2 hunks)
- docs/Library/AICore/AIPrompt/AI Rewrite - Grammar.md (1 hunks)
- docs/Library/AICore/AIPrompt/AI Rewrite - Professional.md (1 hunks)
- docs/Templated Prompts.md (1 hunks)
- docs/index.md (1 hunks)
- src/editorUtils.ts (1 hunks)
- src/prompts.ts (5 hunks)
Additional context used
Path-based instructions (7)
docs/Library/AICore/AIPrompt/AI Rewrite - Grammar.md (1)
Pattern
**/*.md
: Review these markdown files. They are written for a markdown note taking tool called Silverbullet, and may contain extra syntax not typically found in markdown.Ensure any documentation makes sense and is good.
docs/Library/AICore/AIPrompt/AI Rewrite - Professional.md (1)
Pattern
**/*.md
: Review these markdown files. They are written for a markdown note taking tool called Silverbullet, and may contain extra syntax not typically found in markdown.Ensure any documentation makes sense and is good.
docs/index.md (1)
Pattern
**/*.md
: Review these markdown files. They are written for a markdown note taking tool called Silverbullet, and may contain extra syntax not typically found in markdown.Ensure any documentation makes sense and is good.
src/editorUtils.ts (1)
Pattern
**/*.ts
: Review these typescript files for best practices, readability, and DRY.docs/Templated Prompts.md (1)
Pattern
**/*.md
: Review these markdown files. They are written for a markdown note taking tool called Silverbullet, and may contain extra syntax not typically found in markdown.Ensure any documentation makes sense and is good.
docs/Changelog.md (1)
Pattern
**/*.md
: Review these markdown files. They are written for a markdown note taking tool called Silverbullet, and may contain extra syntax not typically found in markdown.Ensure any documentation makes sense and is good.
src/prompts.ts (1)
Pattern
**/*.ts
: Review these typescript files for best practices, readability, and DRY.
LanguageTool
docs/index.md
[grammar] ~34-~34: The word “backup” is a noun. The verb is spelled with a space.
Context: ...I Core Library]] > Warning: Please backup your notes before using this plug. It i...(NOUN_VERB_CONFUSION)
docs/Templated Prompts.md
[uncategorized] ~82-~82: Loose punctuation mark.
Context: ...tain child items. *selectedText
: Text the user has currently selected. *...(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~83-~83: Loose punctuation mark.
Context: ...tly selected. *currentParagraph
: Text of the current paragraph where the...(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~84-~84: Loose punctuation mark.
Context: ...r is located. *smartReplaceType
: Indicates the type of content being rep...(UNLIKELY_OPENING_PUNCTUATION)
[style] ~84-~84: To form a complete sentence, be sure to include a subject.
Context: ... when using the 'replace-smart' option. Can be 'selected-text', 'current-item', or ...(MISSING_IT_THERE)
[uncategorized] ~85-~85: Loose punctuation mark.
Context: ...t-paragraph'. *smartReplaceText
: The text that will be replaced when usi...(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~94-~94: Loose punctuation mark.
Context: .... The valid options are: *cursor
: Inserts at the current cursor position ...(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~108-~108: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...he selection. - If no text is selected but the cursor is within a list item or tas...(COMMA_COMPOUND_SENTENCE_2)
[style] ~109-~109: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... task, it replaces the entire item. - If neither of the above applies, it replac...(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
Markdownlint
docs/Templated Prompts.md
82-82: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
83-83: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
84-84: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
85-85: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
94-94: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
95-95: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
96-96: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
97-97: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
98-98: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
99-99: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
100-100: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
101-101: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
102-102: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
103-103: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
104-104: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
105-105: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
106-106: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
Biome
src/prompts.ts
[error] 281-281: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
[error] 290-290: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
[error] 306-306: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
[error] 320-320: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
Additional comments not posted (17)
docs/Library/AICore/AIPrompt/AI Rewrite - Grammar.md (1)
1-24
: The AI prompt template looks good overall!The file follows the expected structure for defining an AI prompt, with appropriate metadata and a clear description. The chat-based interaction flow is well-designed.
docs/Library/AICore/AIPrompt/AI Rewrite - Professional.md (1)
1-24
: Apply the same suggestions asAI Rewrite - Grammar.md
.This file has a very similar structure and content as the previously reviewed file. The same suggestions apply here:
- Simplify the user instructions at line 24 to make them more concise.
- Make the assistant responses more engaging by adding personality.
Refer to the previous review for examples.
docs/index.md (1)
1-34
: The documentation changes look great!The new sections provide valuable context and guidance for users:
- Explaining what LLMs are
- Clearly listing the requirements
- Mentioning the development status and encouraging user feedback
- Providing a getting started guide
The changes make the documentation more comprehensive and user-friendly. Great job!
Tools
LanguageTool
[grammar] ~34-~34: The word “backup” is a noun. The verb is spelled with a space.
Context: ...I Core Library]] > Warning: Please backup your notes before using this plug. It i...(NOUN_VERB_CONFUSION)
docs/Templated Prompts.md (4)
82-82
: LGTM!The addition of
selectedText
global metadata variable is approved. It provides useful context about the user's current selection to the templated prompts.Tools
LanguageTool
[uncategorized] ~82-~82: Loose punctuation mark.
Context: ...tain child items. *selectedText
: Text the user has currently selected. *...(UNLIKELY_OPENING_PUNCTUATION)
Markdownlint
82-82: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
83-83
: LGTM!The addition of
currentParagraph
global metadata variable is approved. It provides useful context about the current paragraph to the templated prompts.Tools
LanguageTool
[uncategorized] ~83-~83: Loose punctuation mark.
Context: ...tly selected. *currentParagraph
: Text of the current paragraph where the...(UNLIKELY_OPENING_PUNCTUATION)
Markdownlint
83-83: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
84-85
: LGTM!The addition of
smartReplaceType
andsmartReplaceText
global metadata variables is approved. They provide useful context about the content being replaced when using the 'replace-smart' option in templated prompts.Tools
LanguageTool
[uncategorized] ~84-~84: Loose punctuation mark.
Context: ...r is located. *smartReplaceType
: Indicates the type of content being rep...(UNLIKELY_OPENING_PUNCTUATION)
[style] ~84-~84: To form a complete sentence, be sure to include a subject.
Context: ... when using the 'replace-smart' option. Can be 'selected-text', 'current-item', or ...(MISSING_IT_THERE)
[uncategorized] ~85-~85: Loose punctuation mark.
Context: ...t-paragraph'. *smartReplaceText
: The text that will be replaced when usi...(UNLIKELY_OPENING_PUNCTUATION)
Markdownlint
84-84: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
85-85: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
92-110
: LGTM!The addition of new
insertAt
options for templated prompts is approved. These options provide more granular control over content insertion and replacement, significantly enhancing the functionality of templated prompts.Tools
LanguageTool
[uncategorized] ~94-~94: Loose punctuation mark.
Context: .... The valid options are: *cursor
: Inserts at the current cursor position ...(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~108-~108: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...he selection. - If no text is selected but the cursor is within a list item or tas...(COMMA_COMPOUND_SENTENCE_2)
[style] ~109-~109: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... task, it replaces the entire item. - If neither of the above applies, it replac...(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
Markdownlint
94-94: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
95-95: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
96-96: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
97-97: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
98-98: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
99-99: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
100-100: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
101-101: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
102-102: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
103-103: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
104-104: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
105-105: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
106-106: Expected: dash; Actual: asterisk
Unordered list style(MD004, ul-style)
docs/Changelog.md (1)
18-30
: LGTM!The changelog entry accurately documents the addition of new
insertAt
options for templated prompts and the addition of template prompts for rewriting text. The changes are well-described and provide a clear overview of the enhancements made to the templated prompts functionality.src/prompts.ts (9)
15-15
: LGTM!The code changes are approved.
120-122
: LGTM!The code changes are approved.
156-166
: LGTM!The code changes are approved.
168-172
: LGTM!The code changes are approved.
185-192
: LGTM!The code changes are approved.
194-227
: LGTM!The code changes are approved.
229-243
: LGTM!The code changes are approved.
245-254
: LGTM!The code changes are approved.
381-384
: LGTM!The code changes are approved.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
There was a problem hiding this 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
Outside diff range and nitpick comments (1)
src/prompts.ts (1)
280-338
: LGTM, but consider using optional chaining to simplify the code.The updated switch statement with cases for the new insertion types, such as
replace-selection
,replace-paragraph
, andreplace-smart
, significantly enhances the functionality of theinsertAiPromptFromTemplate
function. These additions provide more flexible text manipulation options based on user selection or cursor position, making the function more versatile and user-friendly.The
replace-smart
case, in particular, offers a more intelligent experience by prioritizing text replacement based on the availability of selected text, current item text, or current paragraph text.To further simplify the code and avoid potential errors, consider using optional chaining as suggested by the static analysis tool. For example, you can change the following lines:
-if (selectedText && selectedText.text) { +if (selectedText?.text) { -if (currentParagraph && currentParagraph.text) { +if (currentParagraph?.text) { -if (selectedText && selectedText.text) { +if (selectedText?.text) { -if (currentParagraph && currentParagraph.text) { +if (currentParagraph?.text) {Do you want me to apply these changes or open a GitHub issue to track this improvement?
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- docs/index.md (1 hunks)
- src/prompts.ts (5 hunks)
Additional context used
Path-based instructions (2)
docs/index.md (1)
Pattern
**/*.md
: Review these markdown files. They are written for a markdown note taking tool called Silverbullet, and may contain extra syntax not typically found in markdown.Ensure any documentation makes sense and is good.
src/prompts.ts (1)
Pattern
**/*.ts
: Review these typescript files for best practices, readability, and DRY.
Additional comments not posted (6)
docs/index.md (2)
5-7
: LGTM!The new section "What are LLMs?" provides a clear and concise explanation of Large Language Models, enhancing the reader's understanding of the technology behind the plugin.
9-33
: Great additions to the documentation!The new sections "Requirements", "Development Status", and "Getting Started" significantly improve the documentation's structure and user-friendliness:
- The "Requirements" section clearly outlines the necessary components for using the plugin, aiding users in setting up the tool effectively.
- The "Development Status" section encourages user engagement by inviting them to report issues and share feature ideas, fostering a community-driven approach to development.
- The "Getting Started" section provides a clear pathway for new users to begin using the plugin, enhancing the overall user experience.
These changes make the documentation more informative and accessible to users.
src/prompts.ts (4)
15-15
: LGTM!The new import statement for
getPageLength
,getParagraph
, andgetSelectedText
from./editorUtils.ts
is necessary to support the additional insertion types and improve the functionality of theinsertAiPromptFromTemplate
function.
156-172
: LGTM!The new local variables, such as
currentParagraph
,selectedText
,smartReplaceType
, andsmartReplaceText
, are necessary to store and manage data related to the new insertion types. These variables improve the function's ability to handle various text manipulation scenarios, making it more versatile and user-friendly.
185-192
: Great improvement in error handling!The enhanced error handling with try-catch blocks around critical operations, such as fetching the current page text, cursor position, current item, current paragraph, and selected text, significantly improves the robustness of the
insertAiPromptFromTemplate
function.By logging any issues encountered during these critical operations and communicating them to the user through notifications, the function can gracefully handle errors and provide a better user experience.
Also applies to: 226-227, 236-242, 252-254
381-384
: LGTM!The additional properties
selectedText
,currentParagraph
,smartReplaceType
, andsmartReplaceText
in theglobalMetadata
object provide more context for rendering templates and enriching chat messages. These changes support the new insertion types and improve the overall functionality of theinsertAiPromptFromTemplate
function by allowing for more flexible and context-aware text manipulation.
Related to #59
We can now replace selected text, current item/paragraph, and there's a "smart" option that tries to do what's best.
Summary by CodeRabbit
New Features
Documentation
Bug Fixes