feat: replace WebView2+xterm.js with native Microsoft.Terminal.Wpf#8
Open
feat: replace WebView2+xterm.js with native Microsoft.Terminal.Wpf#8
Conversation
Use VS's built-in terminal rendering control (same as Windows Terminal). Eliminates Chromium dependency, ~80MB memory reduction, instant startup, native DirectWrite rendering, VS theme integration. - Implement ITerminalConnection in TerminalToolWindowControl - Add TerminalThemer for VS dark/light theme colors - Remove WebView2, xterm.js, addon-fit, addon-webgl - Reference VS-deployed Microsoft.Terminal.Wpf.dll (Private=false) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Owner
Author
|
Hey @bommerts, thank you again for the initial prototype. I tried to move to the native terminal support that we have in VS, and it worked. I need more testing of course, but it could be great. |
- Replace WebView2+xterm.js terminal with VS's built-in Microsoft.Terminal.Wpf - Use VsInstallRoot HintPath for CI-compatible assembly resolution - Add AppDomain.AssemblyResolve handler for runtime DLL loading - Add TerminalThemer for VS dark/light theme integration - Remove WebView2 NuGet, xterm.js resources, and related code - Update docs, changelog, and squad files for new terminal stack Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace WebView2+xterm.js with native Microsoft.Terminal.Wpf
Summary
Replace the Chromium-based terminal renderer (WebView2 + xterm.js) with VS's built-in native terminal control (
Microsoft.Terminal.Wpf) — the same DirectWrite rendering engine used by Windows Terminal and VS's own integrated terminal.Motivation
The embedded terminal (added in PR #7) used WebView2 to host xterm.js. While functional, this carried significant overhead:
SetTheme()How it works
Microsoft.Terminal.Wpf.dllships with every Visual Studio installation atCommonExtensions\Microsoft\Terminal\. Our extension references it at build time and resolves it at runtime via anAssemblyResolvehandler that locates the DLL from the VS install directory.The new
TerminalToolWindowControlimplementsITerminalConnection— a 4-member interface:WriteInput(string data)— user keystroke → ConPTYTerminalOutputevent — ConPTY output → native rendererResize(uint rows, uint columns)— dimensions changedClose()— cleanupThe ConPTY layer (
TerminalProcess,TerminalSessionService) is completely unchanged — same I/O pipeline, just a different consumer.Changes
New files
TerminalThemer.cs(79 lines) — VS theme →TerminalThemewith dark/light ANSI palettes (COLORREF/BGR format), auto-switches onVSColorTheme.ThemeChangedTerminalToolWindowControl.cs— rewritten asITerminalConnectionimplementation (183 lines, down from 209)Removed files
Resources/Terminal/terminal.html— WebView2 host pageResources/Terminal/terminal-app.js— xterm.js bridge, resize, I/OResources/Terminal/lib/xterm.js— xterm.js coreResources/Terminal/lib/xterm.css— xterm.js stylesResources/Terminal/lib/addon-fit.js— FitAddonResources/Terminal/lib/addon-webgl.js— WebglAddonModified files
CopilotCliIde.csproj— removed WebView2 NuGet + Terminal resources, added Terminal.Wpf assembly referenceCopilotCliIdePackage.cs— added staticAssemblyResolvehandler forMicrosoft.Terminal.WpfDirectory.Packages.props— removedMicrosoft.Web.WebView2package versionTerminalToolWindow.cs— simplified (removed WebView2-specificPreProcessMessage)TerminalSessionService.cs— removed stale commentpackage-lock.json— cleaned ghost xterm referencesDocumentation updated
.github/copilot-instructions.md— architecture now references Microsoft.Terminal.WpfREADME.md— terminal stack updatedCHANGELOG.md— migration documented under [Unreleased]Unchanged (ConPTY layer)
TerminalProcess.cs— ConPTY process managementTerminalSessionService.cs— session lifecycleConPty.cs— P/Invoke bindingsStats
Net removal of 322 lines — simpler codebase with better rendering.
Testing
ToolWindowBackgroundColorKeyNotes
Microsoft.Terminal.Wpf.dllis not bundled in the VSIX — it resolves from the VS install directory at runtime. This avoids redistribution concerns and ensures version compatibility with the host VS.AssemblyResolvehandler in the package's static constructor findsdevenv.exe's directory viaProcess.GetCurrentProcess().MainModule.FileName, then looks for the DLL atCommonExtensions\Microsoft\Terminal\.ITerminalConnection.Resizemay be called from a non-UI thread by the native control. The session start (which needsGetWorkspaceFolder()on the UI thread) is marshaled viaDispatcher.BeginInvoke.