-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathFSharpExperimentalFeatures.fs
More file actions
62 lines (50 loc) · 2.33 KB
/
FSharpExperimentalFeatures.fs
File metadata and controls
62 lines (50 loc) · 2.33 KB
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
namespace JetBrains.ReSharper.Plugins.FSharp
open System
open System.Runtime.CompilerServices
open JetBrains.ProjectModel
open JetBrains.ReSharper.Plugins.FSharp.Settings
open JetBrains.ReSharper.Psi.Tree
open JetBrains.Util
type ExperimentalFeature =
| Formatter = 1
| PostfixTemplates = 2
| RedundantParenAnalysis = 3
| AssemblyReaderShim = 4
type FSharpExperimentalFeatureCookie(feature: ExperimentalFeature) =
static let cookies = OneToListMap<ExperimentalFeature, IDisposable>()
static member Create(feature: ExperimentalFeature) =
lock cookies (fun _ ->
let cookie = new FSharpExperimentalFeatureCookie(feature)
cookies.Add(feature, cookie)
cookie
)
static member IsEnabled(feature: ExperimentalFeature) =
lock cookies (fun _ ->
cookies.ContainsKey(feature)
)
interface IDisposable with
member this.Dispose() =
lock cookies (fun _ ->
cookies.Remove(feature, this) |> ignore
)
[<AbstractClass; Sealed; Extension>]
type FSharpExperimentalFeatures() =
static let isEnabledInSettings (solution: ISolution) feature =
match feature with
| ExperimentalFeature.AssemblyReaderShim ->
let fsOptions = solution.GetComponent<FSharpOptionsProvider>()
fsOptions.NonFSharpProjectInMemoryReferences
| _ ->
let experimentalFeatures = solution.GetComponent<FSharpExperimentalFeaturesProvider>()
match feature with
| ExperimentalFeature.Formatter -> experimentalFeatures.RedundantParensAnalysis.Value
| ExperimentalFeature.PostfixTemplates -> experimentalFeatures.EnablePostfixTemplates.Value
| ExperimentalFeature.RedundantParenAnalysis -> experimentalFeatures.RedundantParensAnalysis.Value
| _ -> failwith $"Unexpected feature: {feature}"
[<Extension>]
static member IsFSharpExperimentalFeatureEnabled(solution: ISolution, feature: ExperimentalFeature) =
FSharpExperimentalFeatureCookie.IsEnabled(feature) || isEnabledInSettings solution feature
[<Extension>]
static member IsFSharpExperimentalFeatureEnabled(node: ITreeNode, feature: ExperimentalFeature) =
let solution = node.GetSolution()
FSharpExperimentalFeatures.IsFSharpExperimentalFeatureEnabled(solution, feature)