public static bool ExampleRevisionId(this FSharpOption <Domain.Summary.Stack> stack, out Tuple <Guid, int> exampleRevisionId) { var b = stack.IsSome() && stack.Value.ExampleRevisionId.IsSome(); exampleRevisionId = b ? stack.Value.ExampleRevisionId.Value : null; return(b); }
public static void IfSome <T>(this FSharpOption <T> o, Action <T> act) { if (o.IsSome()) { act(o.Value); } }
public static void Do <T>(this FSharpOption <T> o, Action <T> action) { if (o.IsSome()) { action(o.Value); } }
public static async Task DoAsync <T>(this FSharpOption <T> o, Func <T, Task> action) { if (o.IsSome()) { await action(o.Value); } }
public FSharpOption <ListItem> NavigateToListItem(ListKind listKind, NavigationKind navigationKind, FSharpOption <int> argumentOption, bool hasBang) { if (listKind == ListKind.Error) { var errors = IdeServices.TaskService.Errors; if (errors.Count > 0) { var argument = argumentOption.IsSome() ? new int?(argumentOption.Value) : null; var currentIndex = errors.CurrentLocationTask == null ? -1 : errors.IndexOf(errors.CurrentLocationTask); var index = GetListItemIndex(navigationKind, argument, currentIndex, errors.Count); if (index.HasValue) { var errorItem = errors.ElementAt(index.Value); errors.CurrentLocationTask = errorItem; errorItem.SelectInPad(); errorItem.JumpToPosition(); // Item number is one-based. var listItem = new ListItem(index.Value + 1, errors.Count, errorItem.Message); return(FSharpOption.CreateForReference(listItem)); } } } return(FSharpOption <ListItem> .None); }
protected void AssertPosition(int lineNumber, int column, FSharpOption <VirtualSnapshotPoint> option) { Assert.True(option.IsSome()); var line = VirtualSnapshotPointUtil.GetPoint(option.value).GetColumn(); Assert.Equal(lineNumber, line.LineNumber); Assert.Equal(column, line.Column); }
public static void Match <T>(this FSharpOption <T> o, Action <T> some, Action none) { if (o.IsSome()) { some.Invoke(o.Value); } else { none.Invoke(); } }
public static async Task Match <T>(this FSharpOption <T> o, Func <T, Task> some, Func <Task> none) { if (o.IsSome()) { await some.Invoke(o.Value); } else { await none.Invoke(); } }
public void SetProjectRootFolder(FSharpOption <string> rootFolder) { var tempDirectory = DetermineDirectoryForTestProjects(); if (rootFolder.IsSome()) { tempDirectory = Path.Combine(tempDirectory, rootFolder.Value); } _solutionFolder = Path.Combine(tempDirectory, "Project_" + ProjectGuid.ToString("D")); }
public static T?AsNullable <T>(this FSharpOption <T> o) where T : struct { if (o.IsSome()) { return(new T?(o.Value)); } else { return(null); } }
private static bool IsAccessorAccessible(IEnumerable <string> propertyVisiblity, FSharpOption <AccessorDefinition> definition) { if (!definition.IsSome()) { return(false); } var accessor = definition.Value; var visibility = string.Join(" ", propertyVisiblity).ToLower(); HashSet <string> precedence; if (!VisibilityPrecedence.TryGetValue(visibility, out precedence)) { return(true); } return(!precedence.Contains(string.Join(" ", accessor.AccessModifiers).ToLower())); }
/// <summary> /// Open up a new document window with the specified file /// </summary> public override bool LoadFileIntoNewWindow(string filePath, FSharpOption <int> line, FSharpOption <int> column) { try { // Open the document in a window. VsShellUtilities.OpenDocument(_vsAdapter.ServiceProvider, filePath, VSConstants.LOGVIEWID_Primary, out IVsUIHierarchy hierarchy, out uint itemID, out IVsWindowFrame windowFrame); if (line.IsSome()) { // Get the VS text view for the window. var vsTextView = VsShellUtilities.GetTextView(windowFrame); // Get the WPF text view for the VS text view. var wpfTextView = _editorAdaptersFactoryService.GetWpfTextView(vsTextView); // Move the caret to its initial position. var snapshotLine = wpfTextView.TextSnapshot.GetLineFromLineNumber(line.Value); var point = snapshotLine.Start; if (column.IsSome()) { point = point.Add(column.Value); wpfTextView.Caret.MoveTo(point); } else { // Default column implies moving to the first non-blank. wpfTextView.Caret.MoveTo(point); var editorOperations = EditorOperationsFactoryService.GetEditorOperations(wpfTextView); editorOperations.MoveToStartOfLineAfterWhiteSpace(false); } } return(true); } catch (Exception e) { _vim.ActiveStatusUtil.OnError(e.Message); return(false); } }
public async Task <bool> Collect(Tuple <Guid, int> exampleRevisionId, FSharpOption <Guid> deckId) // highTODO this needs serious fixing { var meta = await _metaFactory.Create(); var exampleState = await _dexie.GetExampleState(exampleRevisionId.Item1); var exampleRevision = Domain.Example.getRevision(exampleRevisionId.Item1, exampleRevisionId.Item2, exampleState).ResultValue; var templateState = await _dexie.GetTemplateState(exampleRevision.TemplateRevisionId.Item1); var templateRevision = toTemplateRevision(await _dexie.GetTemplateInstance(exampleRevision.TemplateRevisionId)); var pointers = PublicTemplate.getCardTemplatePointers(templateRevision, exampleRevision.FieldValues).ResultValue; var user = await _userProvider.ForceSummary(); var cardSetting = user.CardSettings.Single(x => x.IsDefault); var deckIds = deckId.IsSome() ? SetModule.Singleton(deckId.Value) : (await _dexie.GetViewDecks()).Where(x => x.IsDefault).Select(x => x.Id).Pipe(SetModule.OfSeq); var cards = pointers.Select(p => Stack.initCard(_clock.GetCurrentInstant(), cardSetting.Id, cardSetting.NewCardsStartingEaseFactor, p)).ToFList(); var stackId = Guid.NewGuid(); var created = Stack.init(stackId, meta, exampleRevision.TemplateRevisionId.Item1, exampleRevision.TemplateRevisionId.Item2, deckIds, exampleRevision.Title, exampleRevision.FieldValues, cards); var stackState = await _dexie.GetStackState(stackId); return(await _transact(stackId, Stack.decideCreate(created, templateState, stackState))); }
public override bool LoadFileIntoNewWindow(string filePath, FSharpOption <int> line, FSharpOption <int> column) { try { var textDocument = TextDocumentFactoryService.CreateAndLoadTextDocument(filePath, TextBufferFactoryService.TextContentType); var wpfTextView = MainWindow.CreateTextView(textDocument.TextBuffer); MainWindow.AddNewTab(System.IO.Path.GetFileName(filePath), wpfTextView); if (line.IsSome()) { // Move the caret to its initial position. if (column.IsSome()) { wpfTextView.MoveCaretToLine(line.Value, column.Value); } else { // Default column implies moving to the first non-blank. wpfTextView.MoveCaretToLine(line.Value); var editorOperations = EditorOperationsFactoryService.GetEditorOperations(wpfTextView); editorOperations.MoveToStartOfLineAfterWhiteSpace(false); } } // Give the focus to the new buffer. var point = wpfTextView.Caret.Position.VirtualBufferPosition; NavigateTo(point); return(true); } catch (Exception ex) { _vim.ActiveStatusUtil.OnError(ex.Message); return(false); } }
/// <summary> /// Is the F# option both Some and equal to the provided value? /// </summary> public static bool IsSome <T>(this FSharpOption <T> option, T value) { return(option.IsSome() && EqualityComparer <T> .Default.Equals(option.Value, value)); }
public static bool IsSome <T>(this FSharpOption <T> option, Func <T, bool> func) { Assert.IsTrue(option.IsSome()); Assert.IsTrue(func(option.Value)); return(true); }
public static bool IsSome <T>(this FSharpOption <T> option, T value) { Assert.IsTrue(option.IsSome(), "Option is None"); Assert.AreEqual(value, option.Value); return(true); }
public static FSharpOption <TOut> Map <TIn, TOut>(this FSharpOption <TIn> o, Func <TIn, TOut> f) => (o.IsSome()) ? Some(f(o.Value)) : None <TOut>();
public static IEnumerable <T> AsEnumerable <T>(this FSharpOption <T> o) => o.IsSome() ? Enumerable.Repeat(o.Value, 1) : Enumerable.Empty <T>();
private static void AssertColumn(FSharpOption <SnapshotOverlapColumn> actual, SnapshotColumn?expected = null, int?spacesBefore = null, int?spacesAfter = null, int?spacesTotal = null) { Assert.True(actual.IsSome()); AssertColumn(actual.Value, expected, spacesBefore, spacesAfter, spacesTotal); }
public static Nullable <T> ToNullable <T>(this FSharpOption <T> opt) where T : struct => opt.IsSome() ? opt.Value : (Nullable <T>)null;
public void IsSomeOnNonNullObjectIsTrue() { Assert.IsTrue(nonNullOption.IsSome()); }
public static bool IsSome <T>(this FSharpOption <T> o, Func <T, bool> predicate) => o.IsSome() && predicate(o.Value);
public static T Default <T>(this FSharpOption <T> o, T defaultValue) => (o.IsSome()) ? o.Value : defaultValue;
public static T GetOr <T>(this FSharpOption <T> o, T ifNone) => o.IsSome() ? o.Value : ifNone;
public static bool IsSomeValue <T>(this FSharpOption <T> o, T value) => o.IsSome() && o.Value.Equals(value);
public static Task <TOut> Match <TOp, TOut>(this FSharpOption <TOp> o, Func <TOp, Task <TOut> > some, Func <Task <TOut> > none) => (o.IsSome()) ? some.Invoke(o.Value) : none.Invoke();
public void IsSomeOnNullObjectIsFalse() { Assert.IsFalse(nullOption.IsSome()); }
protected void AssertPosition(int lineNumber, int column, FSharpOption<VirtualSnapshotPoint> option) { Assert.True(option.IsSome()); var line = VirtualSnapshotPointUtil.GetPoint(option.value).GetColumn(); Assert.Equal(lineNumber, line.LineNumber); Assert.Equal(column, line.Column); }