Skip to content

Conversation

@Victor1890
Copy link
Contributor

This pull request introduces SQL formatting capabilities to the Monaco editor by integrating the sql-formatter library and adding formatting providers. The main changes focus on improving the SQL editing experience by enabling automatic formatting for both entire documents and selected ranges, and refactoring formatting logic into a dedicated hook for better code organization.

SQL Formatting Integration:

  • Added sql-formatter as a dependency to package.json to enable SQL formatting features.
  • Implemented the useSqlFormattingProviders hook in ui/src/lib/monaco/sql-formatting.ts to register document and range formatting providers for SQL in Monaco, using sensible defaults and error handling.
  • Exported the new formatting hook from ui/src/lib/monaco/index.ts for use in other components.

Editor Component Enhancements:

  • Integrated the formatting providers into the editor by using useSqlFormattingProviders in ui/src/components/editor.tsx, keeping the component lean and maintainable. [1] [2]
  • Enabled automatic formatting on paste in the Monaco editor configuration for a smoother user experience.
image

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds SQL formatting capabilities to the Monaco editor by integrating the sql-formatter library. The implementation creates a reusable hook that registers document and range formatting providers, enabling users to format their SQL code both for entire documents and selected ranges with proper error handling.

Key Changes:

  • Added sql-formatter library as a dependency for SQL formatting functionality
  • Created useSqlFormattingProviders hook to encapsulate formatting provider registration logic
  • Enabled formatOnPaste option in the Monaco editor for improved user experience

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.

File Description
ui/package.json Added sql-formatter dependency to enable SQL formatting features
ui/src/lib/monaco/sql-formatting.ts Implemented reusable hook for registering document and range formatting providers with error handling
ui/src/lib/monaco/index.ts Exported the new formatting hook for use in components
ui/src/components/editor.tsx Integrated formatting providers using the new hook and enabled format-on-paste

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"lucide-react": "^0.533.0",
"monaco-editor": "^0.52.2",
"monaco-sql-languages": "^0.15.1",
"sql-formatter": "15.4.6",
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

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

The sql-formatter version is missing the caret (^) prefix that is used consistently for all other dependencies in this file. This could lead to stricter version locking than intended. Consider using "^15.4.6" to allow minor and patch updates while preventing breaking major version changes.

Suggested change
"sql-formatter": "15.4.6",
"sql-formatter": "^15.4.6",

Copilot uses AI. Check for mistakes.
@@ -0,0 +1 @@
export { useSqlFormattingProviders } from "./sql-formatting" No newline at end of file
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

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

Missing semicolon at the end of the export statement. The codebase consistently uses semicolons (see ui/src/lib/utils.ts and ui/src/components/editor.tsx), so this should have one as well for consistency.

Suggested change
export { useSqlFormattingProviders } from "./sql-formatting"
export { useSqlFormattingProviders } from "./sql-formatting";

Copilot uses AI. Check for mistakes.
disposablesRef.current.forEach((d) => d.dispose());
disposablesRef.current = [];
};
}, [monaco, languageId, getOptions]);
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

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

Including getOptions in the dependency array will cause the formatting providers to be re-registered whenever a new function reference is passed, even if the function's behavior is identical. Since getOptions is an optional callback function, it's likely to be recreated on every render unless the caller memoizes it. Consider either: (1) removing getOptions from the dependency array with an ESLint disable comment explaining it's intentionally stable, or (2) documenting that callers should use useCallback to memoize getOptions.

Copilot uses AI. Check for mistakes.
@frectonz
Copy link
Owner

frectonz commented Nov 30, 2025

Thank you. I will handle the AI reviews.

@frectonz frectonz merged commit b4ad15e into frectonz:main Nov 30, 2025
12 of 13 checks passed
@Victor1890 Victor1890 deleted the feature/sql-query-formatting branch November 30, 2025 14:21
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