Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 40 additions & 100 deletions vsintegration/src/FSharp.Editor/Common/Extensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ open Microsoft.CodeAnalysis.Host
open FSharp.Compiler.Text
open FSharp.Compiler.Ast
open FSharp.Compiler.SourceCodeServices
open Microsoft.CodeAnalysis.ExternalAccess.FSharp

type private FSharpGlyph = FSharp.Compiler.SourceCodeServices.FSharpGlyph
type private Glyph = Microsoft.CodeAnalysis.ExternalAccess.FSharp.FSharpGlyph
type private FSharpRoslynGlyph = Microsoft.CodeAnalysis.ExternalAccess.FSharp.FSharpGlyph


type Path with
Expand Down Expand Up @@ -136,79 +135,77 @@ type SourceText with
SourceText.weakTable.GetValue(this, Runtime.CompilerServices.ConditionalWeakTable<_,_>.CreateValueCallback(SourceText.create))

type FSharpNavigationDeclarationItem with
member x.RoslynGlyph : Glyph =
member x.RoslynGlyph : FSharpRoslynGlyph =
match x.Glyph with
| FSharpGlyph.Class
| FSharpGlyph.Typedef
| FSharpGlyph.Type
| FSharpGlyph.Exception ->
match x.Access with
| Some SynAccess.Private -> Glyph.ClassPrivate
| Some SynAccess.Internal -> Glyph.ClassInternal
| _ -> Glyph.ClassPublic
| Some SynAccess.Private -> FSharpRoslynGlyph.ClassPrivate
| Some SynAccess.Internal -> FSharpRoslynGlyph.ClassInternal
| _ -> FSharpRoslynGlyph.ClassPublic
| FSharpGlyph.Constant ->
match x.Access with
| Some SynAccess.Private -> Glyph.ConstantPrivate
| Some SynAccess.Internal -> Glyph.ConstantInternal
| _ -> Glyph.ConstantPublic
| Some SynAccess.Private -> FSharpRoslynGlyph.ConstantPrivate
| Some SynAccess.Internal -> FSharpRoslynGlyph.ConstantInternal
| _ -> FSharpRoslynGlyph.ConstantPublic
| FSharpGlyph.Delegate ->
match x.Access with
| Some SynAccess.Private -> Glyph.DelegatePrivate
| Some SynAccess.Internal -> Glyph.DelegateInternal
| _ -> Glyph.DelegatePublic
| Some SynAccess.Private -> FSharpRoslynGlyph.DelegatePrivate
| Some SynAccess.Internal -> FSharpRoslynGlyph.DelegateInternal
| _ -> FSharpRoslynGlyph.DelegatePublic
| FSharpGlyph.Union
| FSharpGlyph.Enum ->
match x.Access with
| Some SynAccess.Private -> Glyph.EnumPrivate
| Some SynAccess.Internal -> Glyph.EnumInternal
| _ -> Glyph.EnumPublic
| Some SynAccess.Private -> FSharpRoslynGlyph.EnumPrivate
| Some SynAccess.Internal -> FSharpRoslynGlyph.EnumInternal
| _ -> FSharpRoslynGlyph.EnumPublic
| FSharpGlyph.EnumMember
| FSharpGlyph.Variable
| FSharpGlyph.Field ->
match x.Access with
| Some SynAccess.Private -> Glyph.FieldPrivate
| Some SynAccess.Internal -> Glyph.FieldInternal
| _ -> Glyph.FieldPublic
| Some SynAccess.Private -> FSharpRoslynGlyph.FieldPrivate
| Some SynAccess.Internal -> FSharpRoslynGlyph.FieldInternal
| _ -> FSharpRoslynGlyph.FieldPublic
| FSharpGlyph.Event ->
match x.Access with
| Some SynAccess.Private -> Glyph.EventPrivate
| Some SynAccess.Internal -> Glyph.EventInternal
| _ -> Glyph.EventPublic
| Some SynAccess.Private -> FSharpRoslynGlyph.EventPrivate
| Some SynAccess.Internal -> FSharpRoslynGlyph.EventInternal
| _ -> FSharpRoslynGlyph.EventPublic
| FSharpGlyph.Interface ->
match x.Access with
| Some SynAccess.Private -> Glyph.InterfacePrivate
| Some SynAccess.Internal -> Glyph.InterfaceInternal
| _ -> Glyph.InterfacePublic
| Some SynAccess.Private -> FSharpRoslynGlyph.InterfacePrivate
| Some SynAccess.Internal -> FSharpRoslynGlyph.InterfaceInternal
| _ -> FSharpRoslynGlyph.InterfacePublic
| FSharpGlyph.Method
| FSharpGlyph.OverridenMethod ->
match x.Access with
| Some SynAccess.Private -> Glyph.MethodPrivate
| Some SynAccess.Internal -> Glyph.MethodInternal
| _ -> Glyph.MethodPublic
| Some SynAccess.Private -> FSharpRoslynGlyph.MethodPrivate
| Some SynAccess.Internal -> FSharpRoslynGlyph.MethodInternal
| _ -> FSharpRoslynGlyph.MethodPublic
| FSharpGlyph.Module ->
match x.Access with
| Some SynAccess.Private -> Glyph.ModulePrivate
| Some SynAccess.Internal -> Glyph.ModuleInternal
| _ -> Glyph.ModulePublic
| FSharpGlyph.NameSpace -> Glyph.Namespace
| Some SynAccess.Private -> FSharpRoslynGlyph.ModulePrivate
| Some SynAccess.Internal -> FSharpRoslynGlyph.ModuleInternal
| _ -> FSharpRoslynGlyph.ModulePublic
| FSharpGlyph.NameSpace -> FSharpRoslynGlyph.Namespace
| FSharpGlyph.Property ->
match x.Access with
| Some SynAccess.Private -> Glyph.PropertyPrivate
| Some SynAccess.Internal -> Glyph.PropertyInternal
| _ -> Glyph.PropertyPublic
| Some SynAccess.Private -> FSharpRoslynGlyph.PropertyPrivate
| Some SynAccess.Internal -> FSharpRoslynGlyph.PropertyInternal
| _ -> FSharpRoslynGlyph.PropertyPublic
| FSharpGlyph.Struct ->
match x.Access with
| Some SynAccess.Private -> Glyph.StructurePrivate
| Some SynAccess.Internal -> Glyph.StructureInternal
| _ -> Glyph.StructurePublic
| Some SynAccess.Private -> FSharpRoslynGlyph.StructurePrivate
| Some SynAccess.Internal -> FSharpRoslynGlyph.StructureInternal
| _ -> FSharpRoslynGlyph.StructurePublic
| FSharpGlyph.ExtensionMethod ->
match x.Access with
| Some SynAccess.Private -> Glyph.ExtensionMethodPrivate
| Some SynAccess.Internal -> Glyph.ExtensionMethodInternal
| _ -> Glyph.ExtensionMethodPublic
| FSharpGlyph.Error -> Glyph.Error


| Some SynAccess.Private -> FSharpRoslynGlyph.ExtensionMethodPrivate
| Some SynAccess.Internal -> FSharpRoslynGlyph.ExtensionMethodInternal
| _ -> FSharpRoslynGlyph.ExtensionMethodPublic
| FSharpGlyph.Error -> FSharpRoslynGlyph.Error

[<RequireQualifiedAccess>]
module String =
Expand All @@ -234,21 +231,6 @@ module Option =

let attempt (f: unit -> 'T) = try Some <| f() with _ -> None

let inline ofNull value =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice.

if obj.ReferenceEquals(value, null) then None else Some value

/// Gets the option if Some x, otherwise try to get another value
let inline orTry f =
function
| Some x -> Some x
| None -> f()

/// Gets the value if Some x, otherwise try to get another value by calling a function
let inline getOrTry f =
function
| Some x -> x
| None -> f()

/// Returns 'Some list' if all elements in the list are Some, otherwise None
let ofOptionList (xs : 'a option list) : 'a list option =

Expand All @@ -273,48 +255,6 @@ module Array =
i <- i + 1
state

/// Optimized arrays equality. ~100x faster than `array1 = array2` on strings.
/// ~2x faster for floats
/// ~0.8x slower for ints
let areEqual (xs: 'T []) (ys: 'T []) =
match xs, ys with
| null, null -> true
| [||], [||] -> true
| null, _ | _, null -> false
| _ when xs.Length <> ys.Length -> false
| _ ->
let mutable stop = false
let mutable i = 0
let mutable result = true
while i < xs.Length && not stop do
if xs.[i] <> ys.[i] then
stop <- true
result <- false
i <- i + 1
result

/// check if subArray is found in the wholeArray starting
/// at the provided index
let isSubArray (subArray: 'T []) (wholeArray:'T []) index =
if isNull subArray || isNull wholeArray then false
elif subArray.Length = 0 then true
elif subArray.Length > wholeArray.Length then false
elif subArray.Length = wholeArray.Length then areEqual subArray wholeArray else
let rec loop subidx idx =
if subidx = subArray.Length then true
elif subArray.[subidx] = wholeArray.[idx] then loop (subidx+1) (idx+1)
else false
loop 0 index

/// Returns true if one array has another as its subset from index 0.
let startsWith (prefix: _ []) (whole: _ []) =
isSubArray prefix whole 0

/// Returns true if one array has trailing elements equal to another's.
let endsWith (suffix: _ []) (whole: _ []) =
isSubArray suffix whole (whole.Length-suffix.Length)


[<RequireQualifiedAccess>]
module Exception =

Expand Down
12 changes: 1 addition & 11 deletions vsintegration/src/FSharp.Editor/Common/Pervasive.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ module Microsoft.VisualStudio.FSharp.Editor.Pervasive

open System
open System.IO
open System.Threading.Tasks
open System.Diagnostics

type IOleServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider

/// Checks if the filePath ends with ".fsi"
let isSignatureFile (filePath:string) =
String.Equals (Path.GetExtension filePath, ".fsi", StringComparison.OrdinalIgnoreCase)
Expand All @@ -17,12 +14,8 @@ let isScriptFile (filePath:string) =
let ext = Path.GetExtension filePath
String.Equals (ext, ".fsx", StringComparison.OrdinalIgnoreCase) || String.Equals (ext, ".fsscript", StringComparison.OrdinalIgnoreCase)

/// Path combination operator
let (</>) path1 path2 = Path.Combine (path1, path2)

type internal ISetThemeColors = abstract member SetColors: unit -> unit


[<Sealed>]
type MaybeBuilder () =
// 'T -> M<'T>
Expand Down Expand Up @@ -199,7 +192,4 @@ module Async =
let! replyCh = agent.Receive ()
replyCh.Reply res
}
async { return! agent.PostAndAsyncReply id }



async { return! agent.PostAndAsyncReply id }