Skip to content

Add Move to Schema command for database project files - #22705

Draft
Sai Avishkar Sreerama (ssreerama) wants to merge 5 commits into
mainfrom
sai/Aug_addMoveToSchema_fromMenu
Draft

Add Move to Schema command for database project files#22705
Sai Avishkar Sreerama (ssreerama) wants to merge 5 commits into
mainfrom
sai/Aug_addMoveToSchema_fromMenu

Conversation

@ssreerama

@ssreerama Sai Avishkar Sreerama (ssreerama) commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

This PR:

  • Add a SQL Database Projects file context-menu entry for Move to Schema.
  • Forward database project file paths to the MSSQL Move to Schema provider.
  • Resolve the target SQL object position in the provider for file-based entry points and calling the existing Move Schema logic
  • Added unit coverage.
image Sql_file_moveToSchema_opiton

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a “Move to Schema…” context-menu command for SQL Database Projects object files, delegating the action to the existing MSSQL Move to Schema refactor flow by passing a file path and resolving an appropriate cursor position in the MSSQL provider.

Changes:

  • Contribute and register sqlDatabaseProjects.moveToSchema and surface it in the Database Projects tree context menu.
  • Forward SQL object script file paths from sql-database-projects to the MSSQL mssql.moveToSchema command.
  • Extend the MSSQL Move-to-Schema provider to accept a file path entry point and add unit coverage.

Reviewed changes

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

Show a summary per file
File Description
localization/xliff/sql-database-projects.xlf Adds localized string entry for “Move to Schema…”.
extensions/sql-database-projects/src/controllers/projectController.ts Adds handler that validates a tree node and forwards the file path to mssql.moveToSchema.
extensions/sql-database-projects/src/controllers/mainController.ts Registers the new sqlDatabaseProjects.moveToSchema command.
extensions/sql-database-projects/src/common/constants.ts Adds constant for the forwarded MSSQL command ID (mssql.moveToSchema).
extensions/sql-database-projects/package.nls.json Adds display name string for the new command.
extensions/sql-database-projects/package.json Contributes the new command and adds it to the tree item context menu.
extensions/mssql/test/unit/sqlSymbolRenameProvider.test.ts Adds unit test for file-path entry point resolving position.
extensions/mssql/src/languageservice/sqlMoveToSchemaProvider.ts Accepts path-based invocation and adds local SQL token parsing to determine the symbol position.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread extensions/mssql/src/languageservice/sqlMoveToSchemaProvider.ts
Comment thread extensions/mssql/src/languageservice/sqlMoveToSchemaProvider.ts
Comment thread extensions/sql-database-projects/package.json
@github-actions

Copy link
Copy Markdown

PR Changes

Category Target Branch PR Branch Difference
vscode-mssql VSIX 80659 KB 80588 KB ⚪ -71 KB ( 0% )
sql-database-projects VSIX 2899 KB 2900 KB ⚪ 1 KB ( 0% )
data-workspace VSIX 202 KB 202 KB ⚪ 0 KB ( 0% )
keymap VSIX 7 KB 7 KB ⚪ 0 KB ( 0% )

@codecov-commenter

Codecov Comments Bot (codecov-commenter) commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.17647% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.76%. Comparing base (0e270aa) to head (59b0fb1).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
...sql/src/languageservice/sqlMoveToSchemaProvider.ts 88.80% 14 Missing ⚠️
...atabase-projects/src/controllers/mainController.ts 87.50% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main   #22705       +/-   ##
===========================================
- Coverage   88.74%   77.76%   -10.99%     
===========================================
  Files         340      423       +83     
  Lines      119800   135008    +15208     
  Branches      552     8497     +7945     
===========================================
- Hits       106317   104987     -1330     
- Misses      13483    30021    +16538     
Flag Coverage Δ
data-workspace 78.34% <ø> (ø)
mssql 76.07% <88.80%> (-13.80%) ⬇️
sqlproj 97.27% <97.77%> (+17.91%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ions/sql-database-projects/src/common/constants.ts 100.00% <100.00%> (+18.80%) ⬆️
...base-projects/src/controllers/projectController.ts 99.31% <100.00%> (+34.39%) ⬆️
...atabase-projects/src/controllers/mainController.ts 85.26% <87.50%> (+2.46%) ⬆️
...sql/src/languageservice/sqlMoveToSchemaProvider.ts 91.14% <88.80%> (-8.86%) ⬇️

... and 342 files with indirect coverage changes

🚀 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.

Copilot AI review requested due to automatic review settings August 11, 2026 20:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

Suppressed comments (2)

extensions/mssql/src/languageservice/sqlMoveToSchemaProvider.ts:216

  • For the file-path entry point, showing loc.noMovableSymbolAtCursor is misleading because the user didn’t invoke the action from a cursor position. Consider introducing a dedicated localized message for the file-based flow (e.g. "No object that can be moved to another schema was found in this file.") and using it here.
            const position = this.findMoveToSchemaSymbolPosition(document);
            if (!position) {
                void vscode.window.showInformationMessage(loc.noMovableSymbolAtCursor);
                return;
            }

extensions/mssql/test/unit/sqlSymbolRenameProvider.test.ts:72

  • The stubbed TextDocument.getText(range) implementation returns an incorrect substring when the range spans multiple lines (lineText.slice(0, range.end.character) ignores the start position and all full lines). This can make tests pass/fail for the wrong reasons if any code under test requests multi-line text.
            return lineText.slice(0, range.end.character);

await this.applyMove(document, position, selected.label, schemas);
}

//#region Tree Entry Local Parsing (replaceable)

@ssreerama Sai Avishkar Sreerama (ssreerama) Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the whole region is replaceable if STS can give the sql object name from the parser, which script Dom already have. But, needed STS changes which can be done in another release cycle not at the ask mode time.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is just to provide a quality-of-life improvement, correct? Might be better just to hold this fix back from this release so that we can do it correctly (using STS/ScriptDom)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Had a chat with Drew and this can be moved to other cycle as is not very urgent one.

have moved the issue to next cycle, updating the PR to draft (will close it and open a new one if required)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

Suppressed comments (3)

extensions/mssql/src/languageservice/sqlMoveToSchemaProvider.ts:109

  • The command handler now silently no-ops when invoked without a position (or with no args). Since this command is contributed publicly and can be invoked from the command palette / other extensions, it should fall back to the active editor selection (when available) rather than returning undefined with no feedback.
                    typeof documentOrPath === "string"
                        ? provider.runMoveToSchemaFromFilePath(documentOrPath)
                        : position
                          ? provider.runMoveToSchema(documentOrPath, position)
                          : undefined,

extensions/mssql/test/unit/sqlSymbolRenameProvider.test.ts:73

  • makeMoveDocument.getText(range) returns an incorrect substring when range spans multiple lines (lineText.slice(0, range.end.character) ignores the start line/character). This can make tests pass with an unrealistic document stub and hide bugs in range handling.
            return lineText.slice(0, range.end.character);
        }),

extensions/sql-database-projects/src/controllers/projectController.ts:2376

  • This error telemetry uses TelemetryActions.move, which is already used for file/folder moves in the project tree (see moveFile below). Reusing the same action for “Move to Schema” will conflate unrelated scenarios and make telemetry harder to interpret. Consider adding a dedicated telemetry action (e.g. moveToSchema) and emitting an action event on invocation (similar to configureCodeAnalysisSettings).
            void vscode.window.showErrorMessage(utils.getErrorMessage(err));
            TelemetryReporter.sendErrorEvent(
                TelemetryViews.ProjectController,
                TelemetryActions.move,
                err,
            );

Copilot AI review requested due to automatic review settings August 11, 2026 20:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

Suppressed comments (3)

extensions/mssql/src/languageservice/sqlMoveToSchemaProvider.ts:216

  • runMoveToSchemaFromFilePath shows noMovableSymbolAtCursor, which is phrased specifically for a cursor-based invocation. When invoked from the Database Projects tree there is no cursor, so this message is misleading.
            const document = await vscode.workspace.openTextDocument(vscode.Uri.file(filePath));
            const position = this.findMoveToSchemaSymbolPosition(document);
            if (!position) {
                void vscode.window.showInformationMessage(loc.noMovableSymbolAtCursor);
                return;

extensions/mssql/src/languageservice/sqlMoveToSchemaProvider.ts:266

  • findMoveToSchemaSymbolPosition returns undefined immediately when it finds a CREATE/ALTER + object type but the next token is missing. Returning inside the loop prevents scanning later statements in the file (e.g., if the first match is incomplete or parsing didn't line up with tokens).
            const firstNameToken = tokens[objectTypeIndex + 1];
            if (!firstNameToken) {
                return undefined;
            }

extensions/mssql/test/unit/sqlSymbolRenameProvider.test.ts:68

  • The TextDocument.getText(range) stub returns an incorrect substring when the range spans multiple lines (lineText.slice(0, range.end.character)). Even if current tests mostly use single-line ranges, this makes the helper fragile and can cause misleading failures if additional tests start requesting multi-line ranges.
        getText: sandbox.stub().callsFake((range?: vscode.Range) => {
            if (!range) return lineText;
            if (range.start.line === range.end.line) {
                return (lines[range.start.line] ?? "").slice(
                    range.start.character,

* Tokenizes SQL text into identifiers and separators while skipping whitespace, comments,
* and string literals so statement detection ignores non-executable text.
*/
private tokenizeMoveToSchemaSql(text: string): MoveToSchemaSqlToken[] {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't see any unit tests that cover this method. Please add several, especially since we're (temporarily) relying on a complicated REGEX.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right, Added the test coverage for the regex method and also created a task for the scriptDom replacement and added as a todo comment in the code.

Copilot AI review requested due to automatic review settings August 11, 2026 21:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

@ssreerama
Sai Avishkar Sreerama (ssreerama) marked this pull request as draft August 11, 2026 21:23
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.

[Feature Request]: Add "Move to Schema…" to the object context menu in the Database Projects tree

5 participants