Skip to content

Shorten Peek Definition tab names - #2807

Merged
Aasim Khan (aasimkhan30) merged 3 commits into
mainfrom
aasim/fix/peek-definition-tab-names
Sep 2, 2026
Merged

Shorten Peek Definition tab names#2807
Aasim Khan (aasimkhan30) merged 3 commits into
mainfrom
aasim/fix/peek-definition-tab-names

Conversation

@aasimkhan30

@aasimkhan30 Aasim Khan (aasimkhan30) commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Description

Shortens Peek Definition tab names by replacing the GUID suffix with stable object-based file names. Repeated requests for the same object reuse the existing tab, while collisions receive a numeric suffix such as _2.

The change preserves parallel safety with per-file write locks, avoids rewriting unchanged scripts, keeps the resolved database in the internal collision identity without adding it to unqualified tab names, and sanitizes invalid or Windows-reserved file names.

Fixes microsoft/vscode-mssql#22785

Code Changes Checklist

  • New or updated unit tests added
  • All existing tests pass (dotnet test)
  • Code follows contributing guidelines
  • Logging/telemetry updated if relevant
  • No protocol or behavioral regressions

Reviewers: Please read our reviewer guidelines

Peek Definition wrote each generated script to a file named
"<db>.<schema>.<object>_<32 hex GUID>.sql", and VS Code labels a tab with the
file name, so a handful of open definitions filled the tab strip with
unreadable titles. The GUID also meant every request produced a new file, so
asking for the same definition twice opened a second tab for it.

Name the file after the object instead. A given object keeps one file for the
life of the process, so a repeated request refreshes the tab already open. Two
different objects that want the same name, which happens when one qualified
name resolves against two connections, are separated by a numeric suffix.

The GUID was also doing real work: it was added to make these APIs parallel
safe, since definition requests run concurrently and would otherwise write the
same path at once. That is now handled directly, by taking a per-file lock
around the write and by reading the lines from the generated script rather
than back off disk. A write is skipped entirely when the file already holds
the same script, so an editor with the definition open is left alone.

Object identity is compared case sensitively, because a case sensitive
collation can hold both "Foo" and "foo" and giving them one file would show
the wrong definition for one of them. Characters that are legal in a quoted
identifier but not in a file name are replaced, which the GUID never guarded
against.

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

This PR updates Peek Definition script file naming to remove the per-request GUID suffix so VS Code editor tab titles remain short and repeated requests reuse the same tab/file within a process, while preserving parallel-safety via per-file write locking and stable per-object name assignment.

Changes:

  • Replace GUID-suffixed Peek Definition filenames with stable, object-derived names (and numeric suffixes to avoid collisions).
  • Add in-process synchronization and “skip write if unchanged” behavior when writing definition files under parallel request handling.
  • Add new unit tests covering name assignment, sanitization, and concurrent naming/writing behavior.

Reviewed changes

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

File Description
test/Microsoft.SqlTools.ServiceLayer.UnitTests/LanguageServer/PeekDefinitionTests.cs Updates existing test to assert stable names for the same object.
test/Microsoft.SqlTools.ServiceLayer.UnitTests/LanguageServer/PeekDefinitionFileNameTests.cs Adds comprehensive tests for filename assignment, sanitization, and concurrent behavior.
src/Microsoft.SqlTools.LanguageService/Scripting/ScripterCore.cs Implements new naming API, per-file locking, and avoids disk read-back for line scanning.
src/Microsoft.SqlTools.LanguageService/Scripting/PeekDefinitionFileNames.cs New helper for stable per-identity naming, collision suffixing, and invalid-character sanitization.

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

Comment thread src/Microsoft.SqlTools.LanguageService/Scripting/ScripterCore.cs Outdated
Copilot AI review requested due to automatic review settings September 2, 2026 06:28

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.

🟢 Approval recommended

The functional change is well-covered by new unit tests and appears correct; only a minor misleading comment should be adjusted.

Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment on lines +308 to +309
// A missing object produces no script. Treat that the same as the empty file written
// by the previous implementation so the caller can return an empty location list.
Copilot AI review requested due to automatic review settings September 2, 2026 06:38

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.

🔵 Needs a closer look

The new filename sanitization can still produce Windows-invalid names (trailing spaces/periods), which can prevent script files from being created.

Review details

Suppressed comments (2)

Previously missed (1) — in code that hasn't changed since the last review.

src/Microsoft.SqlTools.LanguageService/Scripting/PeekDefinitionFileNames.cs:136

  • SanitizeBaseName only replaces Path.GetInvalidFileNameChars() and checks reserved device names, but it can still return names that are invalid on Windows because file names cannot end with a space or period (e.g., object name "CON." or "name "). This can still happen even after prefixing reserved names, resulting in a file that cannot be created on Windows.

src/Microsoft.SqlTools.LanguageService/Scripting/ScripterCore.cs:310

  • The new comment says an object with no script is treated so the caller can return an empty location list, but this method actually sets error state and returns null in that case. The comment should match the actual behavior (or the behavior should be updated to return an empty array if that’s intended).
            // A missing object produces no script. Treat that the same as the empty file written
            // by the previous implementation so the caller can return an empty location list.
            string script = operation.ScriptText ?? string.Empty;
  • Files reviewed: 4/4 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@aasimkhan30
Aasim Khan (aasimkhan30) merged commit 2cdf450 into main Sep 2, 2026
7 checks passed
@aasimkhan30
Aasim Khan (aasimkhan30) deleted the aasim/fix/peek-definition-tab-names branch September 2, 2026 22:45
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]: Shorten tab name after opening object definition with CTRL

3 participants