Skip to content

[VS] Code Search: preview for X# results, the preview no longer takes the focus - #2171

Merged
RobertvanderHulst merged 2 commits into
X-Sharp:devfrom
hpetriffer:feature/code-search-preview
Nov 11, 2026
Merged

RobertvanderHulst merged 2 commits into
X-Sharp:devfrom
hpetriffer:feature/code-search-preview

Conversation

@hpetriffer

Copy link
Copy Markdown
Contributor

Summary

Two changes for the Code Search window (Ctrl+T) of VS 2022 17.6+ and VS 2026.

1. The preview no longer takes the focus (bug fix)

When the file of the selected result was already open in an editor, the focus jumped from the search box into the preview editor a moment after the window opened. The next keys typed for the search then changed the code.

  • Cause: XSharpDropDownClient.InitCaret calls SendExplicitFocus() on every new view of a file whose drop-down client already has an active view. The preview editor of the Code Search is such a view.
  • Fix: addTextView skips that step for views with the role SEARCH_RESULT_PREVIEW. All other views behave as before.
  • This also happened before this PR with the file (f:) and text (x:) results of VS itself, which preview .prg files in the same editor.

2. Preview for X# results

The X# source (XSharpSearchItemsSourceProvider) returned no preview panels, so the lower half of the window said "There is nothing to preview at the moment". It now returns a panel that shows the file at the declaration, in the editor of the search window, as C# does.

  • CodeEditorModel is created by reflection. Microsoft.VisualStudio.Search.dll is built against the Microsoft.VisualStudio.Threading of its own Visual Studio (17.14 here), newer than the one of our SDK package (17.10), and the compiler refuses the AsyncLazy<TextDocumentLocation> parameter with CS1705.
  • The location carries no project GUID (Guid.Empty), as the file search of VS does: a file may be in several projects.
  • The preview is editable, like the C# one.

Test plan

  • ProjectPackage2022 builds (Debug)
  • VS 2022 17.14, experimental instance, CpsTestBed.sln: select a method name in an open .prg, Ctrl+T, keep typing. The focus stays in the search box and the preview shows the declaration. Before the fix the typed text went into the preview editor.
  • VS 2026 (not tested; the preview API has the same signatures there)

🤖 Generated with Claude Code

hpetriffer and others added 2 commits November 11, 2026 17:12
DropDownClient.InitCaret sends the focus to every new view of a file that
is already open in an editor. The preview editor of the Code Search
(Ctrl+T) is such a view, so the keys typed for the search changed the
code. Views with the role SEARCH_RESULT_PREVIEW are left alone now.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The X# source of the Code Search returns a preview panel: the file in
the editor of the search window, at the declaration, as C# has it.

CodeEditorModel is created by reflection: Microsoft.VisualStudio.Search
is built against the Microsoft.VisualStudio.Threading of its own Visual
Studio, newer than the one of the SDK package (CS1705 on AsyncLazy).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@RobertvanderHulst
RobertvanderHulst merged commit e92d1cb into X-Sharp:dev Nov 11, 2026
1 check passed
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