Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3fb44a4

Browse files
cartermpKevinRansom
authored andcommitted
Remove dependency on FSharp.LanguageService from FSharp.ProjectSystem (dotnet#4385)
* Remove dependency on FSharp.LanguageService from FSharp.ProjectSystem* Fix bad merge
1 parent33159e8 commit3fb44a4

File tree

2 files changed

+232
-1
lines changed

2 files changed

+232
-1
lines changed
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
usingSystem;
4+
usingSystem.Runtime.InteropServices;
5+
usingSystem.Xml;
6+
usingSystem.Collections;
7+
usingSystem.Collections.Generic;
8+
usingSystem.Threading;
9+
usingSystem.IO;
10+
usingSystem.Text;
11+
usingSystem.Drawing;
12+
usingSystem.Windows.Forms;
13+
usingSystem.Diagnostics;
14+
usingMicrosoft.VisualStudio.Shell.Interop;
15+
usingMicrosoft.VisualStudio.OLE.Interop;
16+
usingMicrosoft.VisualStudio.TextManager.Interop;
17+
usingMicrosoft.VisualStudio.Threading;
18+
usingMicrosoft.VisualStudio.Shell;
19+
usingIOleServiceProvider=Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
20+
usingIServiceProvider=System.IServiceProvider;
21+
usingVsShell=Microsoft.VisualStudio.Shell.VsShellUtilities;
22+
usingSystem.Diagnostics.CodeAnalysis;
23+
24+
namespaceMicrosoft.VisualStudio.FSharp.LanguageService
25+
{
26+
internalstaticclassUIThread
27+
{
28+
staticSynchronizationContextctxt;
29+
staticboolisUnitTestingMode=false;
30+
#ifDEBUG
31+
staticStackTracecaptureStackTrace;// stack trace when ctxt was captured
32+
staticThreaduithread;
33+
#endif
34+
publicstaticSynchronizationContextTheSynchronizationContext
35+
{
36+
get
37+
{
38+
Debug.Assert(ctxt!=null,"Tried to get TheSynchronizationContext before it was captured");
39+
returnctxt;
40+
}
41+
}
42+
43+
publicstaticvoidInitUnitTestingMode()
44+
{
45+
Debug.Assert(ctxt==null,"Context has already been captured; too late to InitUnitTestingMode");
46+
isUnitTestingMode=true;
47+
}
48+
49+
[Conditional("DEBUG")]
50+
publicstaticvoidMustBeCalledFromUIThread()
51+
{
52+
#ifDEBUG
53+
Debug.Assert(uithread==System.Threading.Thread.CurrentThread||isUnitTestingMode,"This must be called from the GUI thread");
54+
#endif
55+
}
56+
publicstaticvoidCaptureSynchronizationContext()
57+
{
58+
if(isUnitTestingMode)return;
59+
#ifDEBUG
60+
uithread=System.Threading.Thread.CurrentThread;
61+
#endif
62+
63+
if(ctxt==null)
64+
{
65+
#ifDEBUG
66+
// This is a handy place to do this, since the product and all interesting unit tests
67+
// must go through this code path.
68+
AppDomain.CurrentDomain.UnhandledException+=newUnhandledExceptionEventHandler(delegate(objectsender,UnhandledExceptionEventArgsargs)
69+
{
70+
if(args.IsTerminating)
71+
{
72+
strings=String.Format("An unhandled exception is about to terminate the process. Exception info:\n{0}",args.ExceptionObject.ToString());
73+
Debug.Assert(false,s);
74+
}
75+
});
76+
captureStackTrace=newStackTrace(true);
77+
#endif
78+
ctxt=newWindowsFormsSynchronizationContext();
79+
}
80+
else
81+
{
82+
#ifDEBUG
83+
// Make sure we are always capturing the same thread.
84+
Debug.Assert(uithread==Thread.CurrentThread);
85+
#endif
86+
}
87+
}
88+
privatestaticreadonlyQueue<Action>ourUIQueue=newQueue<Action>();
89+
privatestaticboolourIsReentrancy;
90+
91+
// Runs the action on UI thread. Prevents from reentracy.
92+
publicstaticvoidRun(Actionaction)
93+
{
94+
if(isUnitTestingMode)
95+
{
96+
action();
97+
return;
98+
}
99+
Debug.Assert(ctxt!=null,"The SynchronizationContext must be captured before calling this method");
100+
#ifDEBUG
101+
StackTracestackTrace=newStackTrace(true);
102+
#endif
103+
ctxt.Post(delegate(objectignore)
104+
{
105+
UIThread.MustBeCalledFromUIThread();
106+
ourUIQueue.Enqueue(action);
107+
if(ourIsReentrancy)return;
108+
ourIsReentrancy=true;
109+
try
110+
{
111+
while(ourUIQueue.Count>0)
112+
{
113+
try
114+
{
115+
vara=ourUIQueue.Dequeue();
116+
a();
117+
}
118+
#ifDEBUG
119+
catch(Exceptione)
120+
{
121+
// swallow, random exceptions should not kill process
122+
Debug.Assert(false,string.Format("UIThread.Run caught and swallowed exception: {0}\n\noriginally invoked from stack:\n{1}",e.ToString(),stackTrace.ToString()));
123+
}
124+
#else
125+
catch(Exception){
126+
// swallow, random exceptions should not kill process
127+
}
128+
#endif
129+
130+
}
131+
}
132+
finally
133+
{
134+
ourIsReentrancy=false;
135+
}
136+
},null);
137+
138+
}
139+
140+
/// <summary>
141+
/// RunSync puts orignal exception stacktrace to Exception.Data by this key if action throws on UI thread
142+
/// </summary>
143+
/// WrappedStacktraceKey is a string to keep exception serializable.
144+
publicstaticreadonlystringWrappedStacktraceKey="$$Microsoft.VisualStudio.Package.UIThread.WrappedStacktraceKey$$";
145+
146+
publicstaticvoidRunSync(Actiona)
147+
{
148+
if(isUnitTestingMode)
149+
{
150+
a();
151+
return;
152+
}
153+
Exceptionexn=null;
154+
Debug.Assert(ctxt!=null,"The SynchronizationContext must be captured before calling this method");
155+
// Send on UI thread will execute immediately.
156+
ctxt.Send(ignore=>
157+
{
158+
try
159+
{
160+
UIThread.MustBeCalledFromUIThread();
161+
a();
162+
}
163+
catch(Exceptione)
164+
{
165+
exn=e;
166+
}
167+
},null
168+
);
169+
if(exn!=null)
170+
{
171+
// throw exception on calling thread, preserve stacktrace
172+
if(!exn.Data.Contains(WrappedStacktraceKey))exn.Data[WrappedStacktraceKey]=exn.StackTrace;
173+
throwexn;
174+
}
175+
}
176+
177+
/// <summary>
178+
/// Local JoinableTaskContext
179+
/// ensuring non-reentrancy.
180+
/// </summary>
181+
privatestaticJoinableTaskContextjtc=null;
182+
privatestaticJoinableTaskFactoryJTF
183+
{
184+
get
185+
{
186+
if(jtc==null)
187+
{
188+
JoinableTaskContextj=null;
189+
if(VsTaskLibraryHelper.ServiceInstance==null)
190+
{
191+
j=newJoinableTaskContext();
192+
}
193+
else
194+
{
195+
j=ThreadHelper.JoinableTaskContext;
196+
}
197+
Interlocked.CompareExchange(refjtc,j,null);
198+
}
199+
200+
returnjtc.Factory;
201+
}
202+
}
203+
204+
/// <summary>
205+
/// Performs a callback on the UI thread and blocks until it is done, using the VS mechanism for
206+
/// ensuring non-reentrancy.
207+
/// </summary>
208+
[SuppressMessage("Microsoft.Design","CA1031:DoNotCatchGeneralExceptionTypes")]
209+
internalstaticTDoOnUIThread<T>(Func<T>callback)
210+
{
211+
returnJTF.Run<T>(asyncdelegate
212+
{
213+
awaitJTF.SwitchToMainThreadAsync();
214+
returncallback();
215+
});
216+
}
217+
218+
/// <summary>
219+
/// Performs a callback on the UI thread and blocks until it is done, using the VS mechanism for
220+
/// ensuring non-reentrancy.
221+
/// </summary>
222+
[SuppressMessage("Microsoft.Design","CA1031:DoNotCatchGeneralExceptionTypes")]
223+
internalstaticvoidDoOnUIThread(Actioncallback)
224+
{
225+
JTF.Run(asyncdelegate
226+
{
227+
awaitJTF.SwitchToMainThreadAsync();
228+
callback();
229+
});
230+
}
231+
}
232+
}

‎vsintegration/src/FSharp.ProjectSystem.FSharp/ProjectSystem.fsproj‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
<ItemGroup>
4141
<ProjectReferenceInclude="$(FSharpSourcesRoot)\fsharp\FSharp.Core\FSharp.Core.fsproj" />
4242
<ProjectReferenceInclude="$(FSharpSourcesRoot)\fsharp\FSharp.Compiler.Private\FSharp.Compiler.Private.fsproj" />
43-
<ProjectReferenceInclude="..\FSharp.LanguageService\FSharp.LanguageService.fsproj" />
4443
<ProjectReferenceInclude="..\FSharp.VS.FSI\FSharp.VS.FSI.fsproj" />
4544
<ProjectReferenceInclude="..\FSharp.ProjectSystem.Base\Project\ProjectSystem.Base.csproj" />
4645
<ProjectReferenceInclude="..\FSharp.ProjectSystem.PropertyPages\FSharp.PropertiesPages.vbproj" />

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp