Skip to content

feat(open): add 'open vscode' and 'open ssms', remove retired 'open ads'#688

Open
dlevy-msft-sql wants to merge 36 commits into
microsoft:mainfrom
dlevy-msft-sql:pr-685
Open

feat(open): add 'open vscode' and 'open ssms', remove retired 'open ads'#688
dlevy-msft-sql wants to merge 36 commits into
microsoft:mainfrom
dlevy-msft-sql:pr-685

Conversation

@dlevy-msft-sql
Copy link
Copy Markdown
Contributor

@dlevy-msft-sql dlevy-msft-sql commented Feb 1, 2026

Summary

Adds two new subcommands and removes one that no longer applies:

  • sqlcmd open vscode — writes a connection profile for the current context into VS Code's settings.json and launches VS Code on it via the vscode:// URL handler (which prompts to install the MSSQL extension on first use if needed).
  • sqlcmd open ssms — launches SSMS connected to the current context (Ssms.exe -S host,port -nosplash [-C] [-U user] with the password handed off via the clipboard).
  • sqlcmd open ads is removed: Azure Data Studio was retired in August 2025.

Password handling for VS Code

The VS Code profile includes the SQL password inline in settings.json rather than prompting the user for it. sqlcmd's containers are short-lived local development instances with throwaway credentials, and the goal of open vscode is one-shot, zero-prompt connect. The MSSQL extension migrates the password out of settings.json and into the OS credential store on first read, so the on-disk window is brief; we accept that trade-off in exchange for not requiring the user to paste a password they did not choose. This applies only to the local-container dev flow; users connecting to real servers should manage credentials through the extension directly.

Editor discovery (Windows)

  • VS Code: PATH (code / code-insiders) → Inno Setup uninstall registry → default install dirs. --build stable|insiders selects which build to launch; the connection profile is written to that build's settings.json so the profile and the launched build always match.
  • SSMS: vswhere -products Microsoft.VisualStudio.Product.Ssms, which finds SSMS 21+ on any drive. --version pins a major version; values below 21 are rejected (older SSMS releases are legacy-MSI and aren't registered with the VS Installer).

Why not ssms://?

An earlier revision used the ssms:// protocol handler. Its grammar only accepts s/a/u/d/h/q/dn and silently drops -C (trust server certificate) and -P. Local container connections need -C, so the URL path could not connect to a fresh local SQL container regardless of SSMS version. That commit was reverted; the argv launch path is what ships.

Testing

  • go build ./... on windows/linux/darwin
  • go test ./internal/tools/tool/... ./cmd/modern/root/open/...
  • New unit tests cover: vswhere arg construction and output parsing, SSMS install resolution, VS Code build selection, per-build settings.json routing.

Copy link
Copy Markdown

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 PR adds support for opening Visual Studio Code and SQL Server Management Studio (SSMS) to work with SQL Server connections managed by sqlcmd, addressing the deprecation of Azure Data Studio. The implementation uses clipboard-based password sharing since both tools use sandboxed credential storage.

Changes:

  • Adds sqlcmd open vscode command that creates connection profiles in VS Code settings and auto-installs the MSSQL extension
  • Adds sqlcmd open ssms command (Windows-only) that launches SSMS with pre-configured connection parameters
  • Implements cross-platform clipboard support for secure password sharing
  • Includes comprehensive tests and documentation updates

Reviewed changes

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

Show a summary per file
File Description
cmd/modern/root/open.go Updates open command to include VSCode and SSMS subcommands
cmd/modern/root/open/vscode.go Main VSCode command implementation with settings file manipulation
cmd/modern/root/open/vscode_*.go Platform-specific VSCode implementations
cmd/modern/root/open/ssms.go Main SSMS command implementation
cmd/modern/root/open/ssms_*.go Platform-specific SSMS implementations (Fatal on non-Windows)
cmd/modern/root/open/clipboard.go Helper function for clipboard-based password sharing
cmd/modern/root/open/*_test.go Comprehensive test coverage for new commands
internal/tools/tool/vscode*.go VSCode tool detection and configuration
internal/tools/tool/ssms*.go SSMS tool detection and configuration
internal/pal/clipboard*.go Cross-platform clipboard implementation using native APIs
internal/tools/tools.go Registers VSCode and SSMS tools
README.md Adds clear documentation with usage examples
.gitignore Adds /modern build artifact

Comment thread cmd/modern/root/open/vscode.go Outdated
Comment thread cmd/modern/root/open/ssms.go Outdated
Comment thread cmd/modern/root/open/vscode.go Outdated
Copy link
Copy Markdown

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

Copilot reviewed 30 out of 31 changed files in this pull request and generated 9 comments.

Comment thread cmd/modern/root/open/ssms_unix.go
Comment thread cmd/modern/root/open/vscode.go Outdated
Comment thread cmd/modern/root/open/ssms.go Outdated
Comment thread cmd/modern/root/open/ssms.go Outdated
Comment thread cmd/modern/root/open/vscode_test.go Outdated
Comment thread cmd/modern/root/open/ssms_test.go Outdated
Comment thread cmd/modern/root/open/ssms_darwin.go Outdated
Comment thread cmd/modern/root/open/vscode.go Outdated
Comment thread cmd/modern/root/open/vscode.go Outdated
Copy link
Copy Markdown

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

Copilot reviewed 30 out of 31 changed files in this pull request and generated 1 comment.

Comment thread cmd/modern/root/open/vscode.go Outdated
Copy link
Copy Markdown

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

Copilot reviewed 30 out of 31 changed files in this pull request and generated 1 comment.

Comment thread cmd/modern/root/open/vscode.go Outdated
Copy link
Copy Markdown

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

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

Comment thread cmd/modern/root/open/vscode.go Outdated
Comment thread internal/tools/tool/vscode_linux.go
Comment thread README.md Outdated
Copy link
Copy Markdown

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

Copilot reviewed 33 out of 34 changed files in this pull request and generated 1 comment.

Comment thread cmd/modern/root/open/ssms.go Outdated
Copy link
Copy Markdown

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

Copilot reviewed 33 out of 34 changed files in this pull request and generated 2 comments.

Comment thread cmd/modern/root/open/vscode.go Outdated
Comment thread cmd/modern/root/open/ssms.go Outdated
Copy link
Copy Markdown

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

Copilot reviewed 33 out of 34 changed files in this pull request and generated 4 comments.

Comment thread internal/tools/tool/tool.go Outdated
Comment thread cmd/modern/root/open.go Outdated
Comment thread cmd/modern/root/open/ssms.go Outdated
Comment thread cmd/modern/root/open/vscode.go Outdated
…ectory

exec.Cmd.Start on the .app directory fails with permission denied. Probe the PATH shim first, then fall back to <app>/Contents/Resources/app/bin/code at the standard install locations.
os/exec.Cmd elements are not shell-parsed, so strings.ReplaceAll of double quotes injected literal backslashes into the SSMS login dialog. Drop the escape and let SSMS see the username verbatim.
readSettings strips JSONC features so the standard json package can parse it, but writeSettings then round-trips through encoding/json and silently drops the user's comments. Detect the JSONC features on read, save the original to settings.json.sqlcmd-backup, and warn so the user can restore anything they care about.
RunWithOutput on tool.VSCode is a test-only stub with no callers since isMssqlExtensionInstalled started reading the extensions directory directly. Delete it. Remove tests that re-implement production logic inside the test file (buildServerArg, username ReplaceAll) or set config values and read them back, plus the clipboard test that t.Logf's its error and asserts nothing.
Previous commit 9c97b72 pointed searchLocations at <bundle>/Contents/Resources/app/bin/code, but tool_darwin.go's generateCommandLine launches via 'open -a <path> --args ...', which only accepts registered app names or .app bundle paths. With the changed location, open -a fails with 'Unable to find application'. file.Exists already accepts directories, so the original .app path was correct end-to-end. Restore it and keep the additional \C:\Users\DLevy/Applications probe.
… fire-and-forget it

tool.Run calls Process.Release immediately after Start, so the previous 'MSSQL extension installed successfully' message printed before the install had a chance to fail. Tell the user the install was requested and to watch VS Code for progress; only warn when the launch itself fails.
…ner leak

When os.OpenFile(os.DevNull) fails, the original code fell through with the bytes.Buffer pipes generateCommandLine attached, which makes exec.Cmd.Start spawn drainer goroutines that block on the GUI tool's stdout/stderr until it exits, defeating the Process.Release detach. Set Std{in,out,err} to nil in the fallback so the child inherits the parent's stdio with no extra goroutines.
The Windows assertion strings.Contains(stable, "Code") was structurally
always-true because the build name itself was "Code". Assert the full
AppData/Roaming/Code/User/settings.json tail on Windows, the
Library/Application Support/... tail on macOS, and the .config/... tail
on Linux so the test would actually catch a wrong configDir.
When VS Code follows the vscode://ms-mssql.mssql/connect URL and the
mssql extension is not installed, VS Code itself prompts the user to
install it. That UX is strictly better than the fire-and-forget
`code --install-extension` shell-out, which could not report success
or failure (tool.Run calls Process.Release immediately after Start).

Removes the --install-extension flag, the installExtension field, the
pre-launch isMssqlExtensionInstalled directory scan, and the related
example/messaging. The flag was added earlier in this PR and never
shipped, so this is not a user-visible breaking change.

Also regenerates the translations catalog to drop the corresponding
strings.
- README: rewrite vscode section; remove --install-extension flag step and clipboard step (URL handler now triggers extension install prompt)

- vscode_windows installText: replace --install-extension instructions with URL-handler note

- pal/clipboard_linux: use fmt.Errorf instead of localizer.Errorf (gotext scope excludes internal/pal)
…ion hint

RunWithOutput had no callers and could mislead on Start failures (exitCode 0 when ProcessState is nil). Remove the method and its interface entry. Update vscode_linux/vscode_darwin install text to match windows: extension installs on first use via the vscode:// URL handler, no --install-extension flag.
The rebase onto upstream/main resolved internal/translations/* using -X theirs, which took upstream's catalog.go. That catalog's placeholder bindings no longer match this branch's source strings, causing TestSqlCmdOutputAndError to emit 'Invalid variable identifier $!(UNKNOWNMSGHANDLER=0x61)' instead of the expected error. Restore internal/translations/ to the pre-rebase state from this branch so generated bindings match the source.
Comment thread cmd/modern/root/config/add-context.go Outdated
Comment thread cmd/modern/root/open/clipboard_test.go
Comment thread cmd/modern/root/open/ssms_unix.go
Comment thread cmd/modern/root/open/vscode.go Outdated
Comment thread cmd/modern/root.go
Comment thread internal/tools/tool/ssms_test.go Outdated
Comment thread internal/tools/tool/ssms_windows_test.go
Comment thread .gitignore Outdated
Copy link
Copy Markdown

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

Copilot reviewed 60 out of 72 changed files in this pull request and generated 4 comments.

Comment thread cmd/modern/root/open/vscode_test.go
Comment thread cmd/modern/root/open/vscode_test.go
Comment thread cmd/modern/root/open/vscode.go
Comment thread cmd/modern/root/open/vscode.go
The MSSQL extension expects the connection profile server field in 'host,port' grammar (matching .devcontainer/devcontainer.json), not the 'tcp:host,port' form sqlcmd/go-mssqldb uses. Prefixing with 'tcp:' prevented the extension from matching the saved profile when launched via the vscode://ms-mssql.mssql/connect URI. Drop the prefix in both createProfile and mssqlConnectURI.

Also fix TestVSCodeCreateProfile, which stored the password as plain text. config.GetCurrentContextInfo() runs the stored value through secret.Decode, so the test panicked once createProfile started reading the password. Encode with secret.Encode and set PasswordEncryption='none' to match.
Address PR microsoft#688 review feedback:

- Add 'sqlcmd open vscode' to root help example chain (was Windows-only via ssms).

- In 'sqlcmd config add-context' next-step hints, include 'Open in SQL Server Management Studio' only on Windows; always include 'Open in Visual Studio Code'.

- Match ssms Short text on Windows and non-Windows builds; both now say '(Windows only)' so users on macOS/Linux understand why 'sqlcmd open ssms --help' shows up alongside vscode.

- Remove /modern from .gitignore. No build path produces a 'modern' binary at the repo root; the rule was dead.
Add TestSSMSNotInstalledWhenSsmsExeMissing: when vswhere reports an install root but Common7\IDE\Ssms.exe is absent (corrupt install, or another VS product registered under the same productID), IsInstalled must return false. This was the only gap in ssms_windows_test.go alongside the existing Windows-only coverage in vswhere_windows_test.go (version range pinning, latest fallback, multi-line output, exec failure, missing vswhere.exe).

Delete the cross-platform ssms_test.go. Its sole assertion was that Name() returns 'ssms', which is set by a literal string in Init() and tests nothing about the SSMS discovery or launch behavior that actually matters.
dlevy-msft-sql added a commit to dlevy-msft-sql/go-sqlcmd that referenced this pull request May 29, 2026
Replace the strip-comments-then-marshal round trip (which silently lost
user comments and trailing commas, requiring a .sqlcmd-backup file
written alongside settings.json) with a hujson AST patch. We parse the
original document, build an RFC 6902 patch that adds or replaces only
the two keys we own (mssql.connections, mssql.connectionGroups), and
pack the modified AST. Comments, trailing commas, and unrelated user
settings round-trip untouched on replace operations.

Drops the multi-backup hazard raised in PR microsoft#688: the previous code
overwrote settings.json.sqlcmd-backup on every invocation, so a second
container creation lost the original. With comments preserved, no
backup file is created.

Full AST-level preservation across additions and per-connection
comments is tracked in microsoft#767.
@dlevy-msft-sql dlevy-msft-sql requested a review from Copilot May 29, 2026 18:23
Copy link
Copy Markdown

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

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

Comments suppressed due to low confidence (1)

internal/tools/tool/tool_test.go:107

  • TestRun starts an interactive shell (cmd.exe) with arbitrary args and tool.Run now detaches the process, so on Windows this can leave a stray cmd.exe running (and on non-Windows COMSPEC is typically unset). Make the test run an OS-appropriate command that exits immediately (e.g., cmd.exe /c exit 0 or /bin/sh -c true) so the test is deterministic and doesn’t spawn long-lived processes.

Replace the strip-comments-then-marshal round trip (which silently lost
user comments and trailing commas, requiring a .sqlcmd-backup file
written alongside settings.json) with a hujson AST patch. We parse the
original document, build an RFC 6902 patch that adds or replaces only
the two keys we own (mssql.connections, mssql.connectionGroups), and
pack the modified AST. Comments, trailing commas, and unrelated user
settings round-trip untouched on replace operations.

Drops the multi-backup hazard raised in PR microsoft#688: the previous code
overwrote settings.json.sqlcmd-backup on every invocation, so a second
container creation lost the original. With comments preserved, no
backup file is created.

Full AST-level preservation across additions and per-connection
comments is tracked in microsoft#767.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Size: S Small issue (less than one week effort) SSMS vscode-mssql-ext

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants