Skip to content

Commit 2bb4275

Browse files
committed
refactoring
1 parent 7bf52ee commit 2bb4275

File tree

4 files changed

+33
-26
lines changed

4 files changed

+33
-26
lines changed

ReSharper.FSharp/src/FSharp/FSharp.Common/FSharp.Common.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
<Compile Include="src\Shim\FileSystem\AssemblyInfoShim.fs" />
7070
<Compile Include="src\Shim\AssemblyReader\AssemblyReaderShim.fs" />
7171
<Compile Include="src\Shim\TypeProviders\TypeProvidersClient.fs" />
72-
<Compile Include="src\Shim\TypeProviders\ExtensionTypingProviderShim.fs" />
72+
<Compile Include="src\Shim\TypeProviders\TypeProvidersShim.fs" />
7373
<Compile Include="src\Shim\TypeProviders\ZoneMarker.fs" />
7474
<Compile Include="src\Checker\ScriptFcsProjectProvider.fs" />
7575
<Compile Include="src\Checker\FcsProjectBuilder.fs" />

ReSharper.FSharp/src/FSharp/FSharp.Common/src/Shim/TypeProviders/TypeProvidersClient.fs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ open System.Collections.Generic
66
open FSharp.Compiler.TypeProviders
77
open FSharp.Compiler.Text
88
open FSharp.Core.CompilerServices
9+
open JetBrains.Core
910
open JetBrains.Diagnostics
1011
open JetBrains.Lifetimes
1112
open JetBrains.ProjectModel
@@ -86,9 +87,10 @@ type ITypeProvidersClient =
8687
compilerToolsPath: string list *
8788
m: range -> ITypeProvider list
8889

90+
abstract member Scope: TypeProvidersHostingScope
8991
abstract member Context: TypeProvidersContext
9092
abstract member IsActive: bool
91-
abstract member Execute: (TypeProvidersConnection -> 'a) -> 'a
93+
abstract member RuntimeVersion: string
9294
abstract member Terminate: unit -> unit
9395
abstract member Dump: unit -> string
9496

@@ -121,6 +123,7 @@ type internal TypeProvidersClientBase(lifetimeDef: LifetimeDefinition, connectio
121123
member this.Lifetime = lifetime
122124
member this.DisposeTypeProviders(path: string) = disposeTypeProviders path
123125
abstract member CreateTypeProviders: RdTypeProvider[] * TypeProvidersContext * ResolutionEnvironment -> IProxyTypeProvider list
126+
abstract member Scope: TypeProvidersHostingScope
124127

125128
interface ITypeProvidersClient with
126129
member x.GetOrCreate(runTimeAssemblyFileName: string, designTimeAssemblyNameString: string,
@@ -152,13 +155,27 @@ type internal TypeProvidersClientBase(lifetimeDef: LifetimeDefinition, connectio
152155

153156
typeProviderProxies
154157

158+
member this.Scope = this.Scope
155159
member this.Context = tpContext
156160
member this.IsActive = connection.IsActive
157-
member this.Execute(action) = connection.Execute(fun _ -> action(connection))
158161
member this.Terminate() = lifetimeDef.Terminate()
159162

160163
member this.Dump() =
161-
$"{typeProviders.Dump()}\n\n{tpContext.Dump()}"
164+
let this = this :> ITypeProvidersClient
165+
let scope = this.Scope
166+
167+
if not this.IsActive then $"{scope}: Out-of-process disabled" else
168+
169+
let inProcessDump =
170+
$"[{scope} - In-Process dump]:\n\n" + $"{typeProviders.Dump()}\n\n{tpContext.Dump()}"
171+
172+
let outOfProcessDump =
173+
$"[{scope} - Out-Process dump]:\n\n{connection.ProtocolModel.RdTestHost.Dump.Sync(Unit.Instance)}"
174+
175+
$"{inProcessDump}\n\n{outOfProcessDump}"
176+
177+
member this.RuntimeVersion =
178+
connection.ProtocolModel.RdTestHost.RuntimeVersion.Sync(Unit.Instance)
162179

163180

164181
type internal SolutionTypeProvidersClient(lifetimeDef: LifetimeDefinition,
@@ -188,6 +205,8 @@ type internal SolutionTypeProvidersClient(lifetimeDef: LifetimeDefinition,
188205
use lock = lock.Push()
189206
projectsWithGenerativeProviders.Add(project.GetPersistentID()) |> ignore
190207

208+
override this.Scope = TypeProvidersHostingScope.Solution
209+
191210
override this.CreateTypeProviders(tps, context, resolutionEnv) =
192211
let psiModule =
193212
resolutionEnv.OutputFile
@@ -216,5 +235,7 @@ type internal ScriptTypeProvidersClient(lifetimeDef: LifetimeDefinition, connect
216235
scriptPsiModulesProvider.ModuleInvalidated.Advise(this.Lifetime, fun psiModule ->
217236
this.DisposeTypeProviders(psiModule.Path.FullPath))
218237

238+
override this.Scope = TypeProvidersHostingScope.Scripts
239+
219240
override this.CreateTypeProviders(tps, context, _) =
220241
[ for tp in tps -> new ProxyTypeProvider(tp, context, null) ]
Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ open JetBrains
1010
open JetBrains.Application.Environment
1111
open JetBrains.Application.Environment.Helpers
1212
open JetBrains.Application.Parts
13-
open JetBrains.Core
1413
open JetBrains.Diagnostics
1514
open JetBrains.Lifetimes
1615
open JetBrains.ProjectModel
@@ -48,7 +47,7 @@ type TypeProvidersShim(solution: ISolution, toolset: ISolutionToolset,
4847

4948
let getSolutionTypeProvidersClient () =
5049
let client = clients.GetValueSafe(TypeProvidersHostingScope.Solution)
51-
if isNull client then null.As<ITypeProvidersClient>() else client.Value
50+
if isNull client then Unchecked.defaultof<_> else client.Value
5251

5352
let terminateConnections () =
5453
for client in clients.Values do
@@ -144,36 +143,22 @@ type TypeProvidersShim(solution: ISolution, toolset: ISolutionToolset,
144143

145144
member this.RuntimeVersion() =
146145
let client = getSolutionTypeProvidersClient()
147-
if isNull client || not client.IsActive then null else
148-
149-
client.Execute(_.ProtocolModel.RdTestHost.RuntimeVersion.Sync(Unit.Instance))
146+
if isNull client then null else client.RuntimeVersion
150147

151148
member this.DumpTypeProvidersProcess() =
152149
clients
153-
|> Seq.map (fun (KeyValue(scope, client)) ->
154-
let client = client.Value
155-
156-
if not client.IsActive then $"{scope}: Out-of-process disabled" else
157-
158-
let inProcessDump =
159-
$"[{scope} - In-Process dump]:\n\n{client.Dump()}"
160-
161-
let outOfProcessDump =
162-
$"[{scope} - Out-Process dump]:\n\n{client.Execute( _.ProtocolModel.RdTestHost.Dump.Sync(Unit.Instance))}"
163-
164-
$"{inProcessDump}\n\n{outOfProcessDump}"
165-
)
150+
|> Seq.map (fun (KeyValue(_, client)) -> client.Value.Dump())
166151
|> String.concat "\n\n-----------------------------------------------------\n\n"
167152

153+
member this.SolutionTypeProvidersClient = getSolutionTypeProvidersClient ()
154+
168155
member this.HasGenerativeTypeProviders(project) =
169-
let client = getSolutionTypeProvidersClient()
156+
let client = getSolutionTypeProvidersClient ()
170157
// We can determine which projects contain generative provided types
171158
// only from type providers hosted out-of-process
172159
isNotNull client &&
173160
client.IsActive &&
174161
client.As<SolutionTypeProvidersClient>().HasGenerativeTypeProviders(project)
175162

176-
member this.SolutionTypeProvidersClient = getSolutionTypeProvidersClient ()
177-
178163
interface IDisposable with
179164
member this.Dispose() = terminateConnections ()

ReSharper.FSharp/src/FSharp/FSharp.TypeProviders.Protocol/src/Models/ProxyTypeProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Linq;
33
using System.Reflection;
4+
using JetBrains.Annotations;
45
using JetBrains.Rd.Tasks;
56
using JetBrains.ReSharper.Plugins.FSharp.TypeProviders.Protocol.Cache;
67
using JetBrains.ReSharper.Plugins.FSharp.TypeProviders.Protocol.Exceptions;
@@ -27,7 +28,7 @@ public class ProxyTypeProvider : IProxyTypeProvider
2728
public RdCustomAttributeData[] Attributes => EmptyArray<RdCustomAttributeData>.Instance;
2829

2930
public ProxyTypeProvider(RdTypeProvider rdTypeProvider, TypeProvidersContext typeProvidersContext,
30-
IPsiModule module)
31+
[CanBeNull] IPsiModule module)
3132
{
3233
PsiModule = module;
3334
myRdTypeProvider = rdTypeProvider;

0 commit comments

Comments
 (0)