FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
MIEngine/src/SSHDebugPS/VsOutputWindowWrapper.cs at main · microsoft/MIEngine · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
microsoft
/
MIEngine
Public
Notifications
You must be signed in to change notification settings
Fork
233
Star
858
Code
Issues
151
Pull requests
12
Actions
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
MIEngine
/
src
/
SSHDebugPS
/
VsOutputWindowWrapper.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
138 lines (122 loc) · 5.03 KB
Breadcrumbs
MIEngine
/
src
/
SSHDebugPS
/
VsOutputWindowWrapper.cs
Copy path
File metadata and controls
138 lines (122 loc) · 5.03 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
Diagnostics
;
using
System
.
Threading
;
using
Microsoft
.
VisualStudio
;
using
Microsoft
.
VisualStudio
.
Shell
;
using
Microsoft
.
VisualStudio
.
Shell
.
Interop
;
namespace
Microsoft
.
SSHDebugPS
{
internal
static
class
VsOutputWindowWrapper
{
private
static
Lazy
<
IVsOutputWindow
>
outputWindowLazy
=
new
Lazy
<
IVsOutputWindow
>
(
(
)
=>
{
IVsOutputWindow
outputWindow
=
null
;
try
{
ThreadHelper
.
ThrowIfNotOnUIThread
(
)
;
outputWindow
=
Package
.
GetGlobalService
(
typeof
(
SVsOutputWindow
)
)
as
IVsOutputWindow
;
}
catch
(
Exception
)
{
Debug
.
Fail
(
"Could not get OutputWindow service."
)
;
}
return
outputWindow
;
}
,
LazyThreadSafetyMode
.
PublicationOnly
)
;
private
static
Lazy
<
IVsUIShell
>
shellLazy
=
new
Lazy
<
IVsUIShell
>
(
(
)
=>
{
IVsUIShell
shell
=
null
;
try
{
ThreadHelper
.
ThrowIfNotOnUIThread
(
)
;
shell
=
Package
.
GetGlobalService
(
typeof
(
SVsUIShell
)
)
as
IVsUIShell
;
}
catch
(
Exception
)
{
Debug
.
Fail
(
"Could not get VSShell service."
)
;
}
return
shell
;
// Use "PublicationOnly", because the implementation of GetService does its own locking
}
,
LazyThreadSafetyMode
.
PublicationOnly
)
;
private
class
PaneInfo
{
public
PaneInfo
(
Guid
paneId
)
{
this
.
paneId
=
paneId
;
this
.
Shown
=
false
;
}
internal
Guid
paneId
;
internal
bool
Shown
{
get
;
set
;
}
}
private
const
string
DefaultOutputPane
=
"Debug"
;
private
static
Dictionary
<
string
,
PaneInfo
>
panes
=
new
Dictionary
<
string
,
PaneInfo
>
(
)
{
// The 'Debug' pane exists by default
{
DefaultOutputPane
,
new
PaneInfo
(
VSConstants
.
GUID_OutWindowDebugPane
)
}
}
;
/// <summary>
/// Writes text directly to the VS Output window.
/// </summary>
public
static
void
Write
(
string
message
,
string
pane
=
DefaultOutputPane
)
{
ThreadHelper
.
JoinableTaskFactory
.
RunAsync
(
async
delegate
{
await
ThreadHelper
.
JoinableTaskFactory
.
SwitchToMainThreadAsync
(
)
;
try
{
// Get the Output window
IVsOutputWindow
outputWindow
=
outputWindowLazy
.
Value
;
if
(
outputWindow
==
null
)
{
return
;
}
// Get the pane guid
PaneInfo
paneInfo
;
if
(
!
panes
.
TryGetValue
(
pane
,
out
paneInfo
)
)
{
// Pane didn't exist, create it
paneInfo
=
new
PaneInfo
(
Guid
.
NewGuid
(
)
)
;
panes
.
Add
(
pane
,
paneInfo
)
;
}
// Get the pane
IVsOutputWindowPane
outputPane
;
if
(
outputWindow
.
GetPane
(
ref
paneInfo
.
paneId
,
out
outputPane
)
!=
VSConstants
.
S_OK
)
{
// Failed to get the pane - might need to create it first
outputWindow
.
CreatePane
(
ref
paneInfo
.
paneId
,
pane
,
fInitVisible
:
1
,
fClearWithSolution
:
1
)
;
outputWindow
.
GetPane
(
ref
paneInfo
.
paneId
,
out
outputPane
)
;
}
// The first time we output text to a pane, ensure it's visible
if
(
!
paneInfo
.
Shown
)
{
paneInfo
.
Shown
=
true
;
// Switch to the pane of the Output window
outputPane
.
Activate
(
)
;
// Show the output window
IVsUIShell
shell
=
shellLazy
.
Value
;
if
(
shell
!=
null
)
{
object
inputVariant
=
null
;
shell
.
PostExecCommand
(
VSConstants
.
GUID_VSStandardCommandSet97
,
(
uint
)
VSConstants
.
VSStd97CmdID
.
OutputWindow
,
0
,
ref
inputVariant
)
;
}
}
// Output the text
outputPane
.
OutputStringThreadSafe
(
message
)
;
}
catch
(
Exception
)
{
Debug
.
Fail
(
"Failed to write to output pane."
)
;
}
}
)
.
FileAndForget
(
"VS/Diagnostics/Debugger/SSHDebugPS/VsOutputWindowWrapper/Write"
)
;
}
/// <summary>
/// Writes text directly to the VS Output window, appending a newline.
/// </summary>
public
static
void
WriteLine
(
string
message
,
string
pane
=
DefaultOutputPane
)
{
Write
(
string
.
Concat
(
message
,
Environment
.
NewLine
)
,
pane
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL