diff --git a/vsintegration/src/FSharp.Editor/Common/Extensions.fs b/vsintegration/src/FSharp.Editor/Common/Extensions.fs index f9695e68ecf..9862253aba9 100644 --- a/vsintegration/src/FSharp.Editor/Common/Extensions.fs +++ b/vsintegration/src/FSharp.Editor/Common/Extensions.fs @@ -71,14 +71,14 @@ type Project with type TextViewEventsHandler ( - onChangeCaretHandler: (IVsTextView * int * int -> unit) option, - onKillFocus: (IVsTextView -> unit) option, - onSetFocus: (IVsTextView -> unit) option + onChangeCaretHandler: (IVsTextView * int * int -> unit) voption, + onKillFocus: (IVsTextView -> unit) voption, + onSetFocus: (IVsTextView -> unit) voption ) = interface IVsTextViewEvents with member this.OnChangeCaretLine(view: IVsTextView, newline: int, oldline: int) = onChangeCaretHandler - |> Option.iter (fun handler -> handler (view, newline, oldline)) + |> ValueOption.iter (fun handler -> handler (view, newline, oldline)) member this.OnChangeScrollInfo (_view: IVsTextView, _iBar: int, _iMinUnit: int, _iMaxUnits: int, _iVisibleUnits: int, _iFirstVisibleUnit: int) @@ -86,14 +86,14 @@ type TextViewEventsHandler () member this.OnKillFocus(view: IVsTextView) = - onKillFocus |> Option.iter (fun handler -> handler (view)) + onKillFocus |> ValueOption.iter (fun handler -> handler (view)) member this.OnSetBuffer(_view: IVsTextView, _buffer: IVsTextLines) = () member this.OnSetFocus(view: IVsTextView) = - onSetFocus |> Option.iter (fun handler -> handler (view)) + onSetFocus |> ValueOption.iter (fun handler -> handler (view)) -type ConnectionPointSubscription = System.IDisposable option +type ConnectionPointSubscription = System.IDisposable voption // Usage example: // If a handler is None, to not handle that event @@ -108,16 +108,16 @@ let subscribeToTextViewEvents (textView: IVsTextView, onChangeCaretHandler, onKi let mutable cookie = 0u match cpContainer.FindConnectionPoint(ref riid) with - | null -> None + | null -> ValueNone | cp -> - Some( + ValueSome( cp.Advise(handler, &cookie) { new IDisposable with member _.Dispose() = cp.Unadvise(cookie) } ) - | _ -> None + | _ -> ValueNone type Document with @@ -129,7 +129,7 @@ type Document with | null -> None | languageServices -> languageServices.GetService<'T>() |> Some - member this.TryGetIVsTextView() : IVsTextView option = + member this.TryGetIVsTextView() : IVsTextView voption = match ServiceProvider.GlobalProvider.GetService(typeof) with | :? IVsTextManager as textManager -> // Grab IVsRunningDocumentTable @@ -140,20 +140,20 @@ type Document with match Marshal.GetObjectForIUnknown docData with | :? IVsTextBuffer as ivsTextBuffer -> match textManager.GetActiveView(0, ivsTextBuffer) with - | hr, vsTextView when ErrorHandler.Succeeded(hr) -> Some vsTextView - | _ -> None - | _ -> None - | _ -> None - | _ -> None - | _ -> None - - member this.TryGetTextViewAndCaretPos() : (IVsTextView * Position) option = + | hr, vsTextView when ErrorHandler.Succeeded(hr) -> ValueSome vsTextView + | _ -> ValueNone + | _ -> ValueNone + | _ -> ValueNone + | _ -> ValueNone + | _ -> ValueNone + + member this.TryGetTextViewAndCaretPos() : (IVsTextView * Position) voption = match this.TryGetIVsTextView() with - | Some textView -> + | ValueSome textView -> match textView.GetCaretPos() with - | hr, line, column when ErrorHandler.Succeeded(hr) -> Some(textView, Position.fromZ line column) - | _ -> None - | None -> None + | hr, line, column when ErrorHandler.Succeeded(hr) -> ValueSome(textView, Position.fromZ line column) + | _ -> ValueNone + | ValueNone -> ValueNone member this.IsFSharpScript = isScriptFile this.FilePath diff --git a/vsintegration/src/FSharp.Editor/LanguageService/FSharpProjectOptionsManager.fs b/vsintegration/src/FSharp.Editor/LanguageService/FSharpProjectOptionsManager.fs index db73206996b..0bef8da3f61 100644 --- a/vsintegration/src/FSharp.Editor/LanguageService/FSharpProjectOptionsManager.fs +++ b/vsintegration/src/FSharp.Editor/LanguageService/FSharpProjectOptionsManager.fs @@ -204,7 +204,7 @@ type private FSharpProjectOptionsReactor(checker: FSharpChecker) = cancellableTask { let! ct = CancellableTask.getCancellationToken () let! fileStamp = document.GetTextVersionAsync(ct) - let textViewAndCaret () : (IVsTextView * Position) option = document.TryGetTextViewAndCaretPos() + let textViewAndCaret () : (IVsTextView * Position) voption = document.TryGetTextViewAndCaretPos() match singleFileCache.TryGetValue(document.Id) with | false, _ -> @@ -214,7 +214,7 @@ type private FSharpProjectOptionsReactor(checker: FSharpChecker) = let caret = textViewAndCaret () match caret with - | None -> + | ValueNone -> checker.GetProjectOptionsFromScript( document.FilePath, sourceText.ToFSharpSourceText(), @@ -223,7 +223,7 @@ type private FSharpProjectOptionsReactor(checker: FSharpChecker) = userOpName = userOpName ) - | Some(_, caret) -> + | ValueSome(_, caret) -> checker.GetProjectOptionsFromScript( document.FilePath, sourceText.ToFSharpSourceText(), @@ -286,9 +286,14 @@ type private FSharpProjectOptionsReactor(checker: FSharpChecker) = | projectId, fileStamp, parsingOptions, projectOptions, _ -> let subscription = match textViewAndCaret () with - | Some(textView, _) -> - subscribeToTextViewEvents (textView, (Some onChangeCaretHandler), (Some onKillFocus), (Some onSetFocus)) - | None -> None + | ValueSome(textView, _) -> + subscribeToTextViewEvents ( + textView, + (ValueSome onChangeCaretHandler), + (ValueSome onKillFocus), + (ValueSome onSetFocus) + ) + | ValueNone -> ValueNone (projectId, fileStamp, parsingOptions, projectOptions, subscription) @@ -296,7 +301,7 @@ type private FSharpProjectOptionsReactor(checker: FSharpChecker) = document.Id, // The key to the cache (fun _ value -> addToCacheAndSubscribe value), // Function to add the cached value if the key does not exist (fun _ _ value -> value), // Function to update the value if the key exists - (document.Project, fileStamp, parsingOptions, projectOptions, None) // The value to add or update + (document.Project, fileStamp, parsingOptions, projectOptions, ValueNone) // The value to add or update ) |> ignore @@ -305,7 +310,7 @@ type private FSharpProjectOptionsReactor(checker: FSharpChecker) = | true, (oldProject, oldFileStamp, parsingOptions, projectOptions, _) -> if fileStamp <> oldFileStamp || isProjectInvalidated document.Project oldProject ct then match singleFileCache.TryRemove(document.Id) with - | true, (_, _, _, _, Some subscription) -> subscription.Dispose() + | true, (_, _, _, _, ValueSome subscription) -> subscription.Dispose() | _ -> () return! tryComputeOptionsBySingleScriptOrFile document userOpName @@ -521,7 +526,7 @@ type private FSharpProjectOptionsReactor(checker: FSharpChecker) = | true, (_, _, _, projectOptions, subscription) -> lastSuccessfulCompilations.TryRemove(documentId.ProjectId) |> ignore checker.ClearCache([ projectOptions ]) - subscription |> Option.iter (fun handler -> handler.Dispose()) + subscription |> ValueOption.iter (fun handler -> handler.Dispose()) | _ -> () }