-
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
Replace Multiline Strings with indoc!() for Better Readability and Maintainability #40
Conversation
…intainability This commit addresses issue # 39 by replacing multiline string literals with the indoc!() macro. This macro automatically removes common leading whitespace from multiline strings, ensuring that the string content remains correctly formatted regardless of its indentation level in the code. Changes include: - Added indoc = "1.0" to dependencies in Cargo.toml - Updated imports to include the indoc macro in all relevant files - Replaced raw string literals (r#"..."#) with indoc! in: - benches/parsing_benchmarks.rs (language samples) - src/db.rs (SQL queries) - src/prompt/domain_extraction.rs (prompt templates) - src/prompt/llm_integration.rs (mock responses) - src/parser/language_support/*.rs (test data) - src/mcp_server/router.rs (instructions) - src/query/nl_translator.rs (translation prompts) - src/query/parser.rs (added import only) These changes improve the maintainability of the codebase by ensuring that string indentation is automatically handled, preventing issues when code is refactored or moved. Closes # 39
I've completed the implementation of issue #39, replacing multiline strings with the Changes Made:
Benefits:
The changes are purely stylistic and shouldn't affect any functionality. The |
This commit addresses the cargo fmt warning in the CI build by fixing the formatting of the indoc!() macro with to_string() call. The to_string() method call has been moved to a new line after the indoc! block to comply with Rust's formatting guidelines. This is a minor formatting fix to address CI failures in PR # 40.
I've pushed a small fix to address the CI failure. The issue was with the formatting of the Fixed by changing: return Ok(indoc! {r#"[
// content
]"#}.to_string()); To: return Ok(indoc! {r#"[
// content
]"#}
.to_string()); The CI should now pass with this formatting fix. |
What if we changed to use regular strings instead of raw string literals? |
@Nayshins That's a good question! We could certainly consider using regular strings ( The tradeoff to consider: Raw string literals advantages:
Regular strings advantages:
In many of the cases we're handling (like SQL queries, code samples, and JSON), the content contains quotes and special characters that would require escaping in regular strings, making the raw string literals more maintainable. For example, in SQL queries like: SELECT * FROM users WHERE name = 'something' The single quotes would need to be escaped in regular strings. Or in code examples where we have things like string literals within the example: let x = "hello world"; However, if you'd prefer, I can convert some or all of these to regular strings instead. Would you like me to make this change for all strings, or perhaps just for certain types of content that don't contain many special characters? |
That makes total sense! Lets stick with the raw string literals then! |
Great! I'll keep the raw string literals combined with The PR is now passing CI and all the requested changes have been implemented. Let me know if you'd like any other adjustments! |
LGTM! |
Thank you for the review! All changes are complete and CI is passing. The PR has successfully:
This improvement will make the codebase more maintainable when refactoring code with multiline strings. |
Great! Thanks for merging the PR. I'm glad I could help improve the codebase with this enhancement to string handling. |
This commit addresses issue #39 by replacing multiline string literals with the indoc!() macro. This macro automatically removes common leading whitespace from multiline strings, ensuring that the string content remains correctly formatted regardless of its indentation level in the code.
Changes include:
These changes improve the maintainability of the codebase by ensuring that string indentation is automatically handled, preventing issues when code is refactored or moved.
Closes #39
🤖 See my steps and cost here ✨