Ejemplo n.º 1
0
        internal static CommandBinding CreateComplexNormalBinding(
            string name,
            Func <KeyInput, bool> predicate,
            KeyRemapMode remapMode = null,
            CommandFlags flags     = CommandFlags.None)
        {
            var remapModeOption = FSharpOption.CreateForReference(remapMode);
            Func <KeyInput, BindResult <NormalCommand> > func = null;

            func = keyInput =>
            {
                if (predicate(keyInput))
                {
                    var data = new BindData <NormalCommand>(
                        remapModeOption,
                        func.ToFSharpFunc());
                    return(BindResult <NormalCommand> .NewNeedMoreInput(data));
                }

                return(BindResult <NormalCommand> .NewComplete(NormalCommand.NewPutAfterCaret(false)));
            };

            var bindData = new BindData <NormalCommand>(
                remapModeOption,
                func.ToFSharpFunc());
            var bindDataStorage = BindDataStorage <NormalCommand> .NewSimple(bindData);

            return(CommandBinding.NewComplexNormalBinding(
                       KeyNotationUtil.StringToKeyInputSet(name),
                       flags,
                       bindDataStorage));
        }
Ejemplo n.º 2
0
        public void Create_GetFromCache()
        {
            var runCount            = 0;
            Func <IClassifier> func =
                () =>
            {
                runCount++;
                return(_factory.Create <IClassifier>().Object);
            };
            var result1 = new CountedClassifier(_propertyCollection, _key, func.ToFSharpFunc());
            var result2 = new CountedClassifier(_propertyCollection, _key, func.ToFSharpFunc());

            Assert.Equal(1, runCount);
            Assert.Same(result1.Classifier, result2.Classifier);
        }
Ejemplo n.º 3
0
        internal static BindData <T> CreateBindData <T>(Func <KeyInput, BindResult <T> > func = null, KeyRemapMode remapMode = null)
        {
            func      = func ?? (x => BindResult <T> .Cancelled);
            remapMode = remapMode ?? KeyRemapMode.None;

            return(new BindData <T>(remapMode, func.ToFSharpFunc()));
        }
Ejemplo n.º 4
0
Archivo: VimUtil.cs Proyecto: otf/VsVim
 internal static Command CreateLongCommand(string name, Func<FSharpOption<int>, Register, LongCommandResult> func, CommandFlags flags = CommandFlags.None)
 {
     var fsharpFunc = func.ToFSharpFunc();
     var list = name.Select(KeyInputUtil.CharToKeyInput).ToFSharpList();
     var commandName = KeyInputSet.NewManyKeyInputs(list);
     return Command.NewLongCommand(commandName, flags, fsharpFunc);
 }
Ejemplo n.º 5
0
        internal static CommandBinding CreateLegacyBinding(string name, Func <FSharpOption <int>, Register, CommandResult> func)
        {
            var fsharpFunc  = func.ToFSharpFunc();
            var list        = name.Select(KeyInputUtil.CharToKeyInput).ToFSharpList();
            var commandName = KeyInputSet.NewManyKeyInputs(list);

            return(CommandBinding.NewLegacyBinding(commandName, CommandFlags.None, fsharpFunc));
        }
Ejemplo n.º 6
0
 /// <summary>
 ///     Applies a key-generating function to each element of a CloudFlow and return a CloudFlow yielding unique keys and the result of the threading an accumulator.
 /// </summary>
 /// <typeparam name="TSource">Source flow element type.</typeparam>
 /// <typeparam name="TKey">Element key type.</typeparam>
 /// <typeparam name="TState">Accumulated state type.</typeparam>
 /// <param name="flow">Source CloudFlow.</param>
 /// <param name="projection">Key projection function.</param>
 /// <param name="folder">State updater function on the initial inputs.</param>
 /// <param name="combiner">State combiner function.</param>
 /// <param name="initializer">State initializer function.</param>
 /// <returns>A CloudFlow that has grouped accumulated states by key.</returns>
 public static CloudFlow <KeyValuePair <TKey, TState> > AggregateBy <TSource, TKey, TState>(this CloudFlow <TSource> flow, Func <TSource, TKey> projection,
                                                                                            Func <TState> initializer,
                                                                                            Func <TState, TSource, TState> folder,
                                                                                            Func <TState, TState, TState> combiner)
 {
     return(CloudFlowModule
            .foldBy(projection.ToFSharpFunc(), folder.ToFSharpFunc(), combiner.ToFSharpFunc(), initializer.ToFSharpFunc(), flow)
            .Select(tuple => new KeyValuePair <TKey, TState>(tuple.Item1, tuple.Item2)));
 }
Ejemplo n.º 7
0
        internal static CommandBinding CreateNormalBinding(string name, Func <CommandData, CommandResult> func)
        {
            var fsharpFunc  = func.ToFSharpFunc();
            var list        = name.Select(KeyInputUtil.CharToKeyInput).ToFSharpList();
            var commandName = KeyInputSet.NewManyKeyInputs(list);
            var command     = NormalCommand.NewPing(new PingData(fsharpFunc));

            return(CommandBinding.NewNormalBinding(commandName, CommandFlags.None, command));
        }
Ejemplo n.º 8
0
        public static FSharpFunc <MotionArgument, FSharpOption <MotionResult> > CreateMotionFunc(Func <int, MotionResult> action)
        {
            Func <MotionArgument, FSharpOption <MotionResult> > func = arg =>
            {
                return(FSharpOption.Create(action(arg.Count)));
            };

            return(func.ToFSharpFunc());
        }
Ejemplo n.º 9
0
            public ReplaceTest()
            {
                _clipboardDevice = new Mock <IClipboardDevice>(MockBehavior.Loose);
                Func <FSharpOption <string> > func = () => FSharpOption <string> .None;

                _registerMap = new RegisterMap(
                    new VimData(_globalSettings),
                    _clipboardDevice.Object,
                    func.ToFSharpFunc());
            }
Ejemplo n.º 10
0
        public static FSharpFunc <MotionArgument, FSharpOption <MotionResult> > CreateMotionFunc(Action <int> action)
        {
            Func <MotionArgument, FSharpOption <MotionResult> > func = arg =>
            {
                action(arg.Count);
                return(FSharpOption <MotionResult> .None);
            };

            return(func.ToFSharpFunc());
        }
        IClassifier IClassifierProvider.GetClassifier(ITextBuffer textBuffer)
        {
            var classificationType = _classificationTypeRegistryService.GetClassificationType(DirectoryFormatDefinition.Name);
            Func <IBasicTaggerSource <IClassificationTag> > func = () => new DirectoryTaggerSource(textBuffer, classificationType);

            return(TaggerUtil.CreateBasicClassifier(
                       textBuffer.Properties,
                       s_key,
                       func.ToFSharpFunc()));
        }
Ejemplo n.º 12
0
        internal static RegisterMap CreateRegisterMap(IClipboardDevice device, Func <string> func)
        {
            Func <FSharpOption <string> > func2 = () =>
            {
                var result = func();
                return(string.IsNullOrEmpty(result) ? FSharpOption <string> .None : FSharpOption.Create(result));
            };

            return(new RegisterMap(new VimData(), device, func2.ToFSharpFunc()));
        }
Ejemplo n.º 13
0
        internal static NormalCommand CreatePing(Action <CommandData> action)
        {
            Func <CommandData, CommandResult> func =
                commandData =>
            {
                action(commandData);
                return(CommandResult.NewCompleted(ModeSwitch.NoSwitch));
            };
            var data = new PingData(func.ToFSharpFunc());

            return(NormalCommand.NewPing(data));
        }
Ejemplo n.º 14
0
        public static FSharpFunc <MotionArgument, FSharpOption <MotionResult> > CreateMotionFunc(Func <MotionResult> func)
        {
            Func <MotionArgument, FSharpOption <MotionResult> > inner = arg =>
            {
                var ret = func();
                return(ret != null
                    ? FSharpOption.Create(ret)
                    : FSharpOption <MotionResult> .None);
            };

            return(inner.ToFSharpFunc());
        }
Ejemplo n.º 15
0
        ITagger <T> IViewTaggerProvider.CreateTagger <T>(ITextView textView, ITextBuffer textBuffer)
        {
            if (textView.TextBuffer != textBuffer || !_vim.ShouldCreateVimBuffer(textView))
            {
                return(null);
            }

            Func <IBasicTaggerSource <IntraTextAdornmentTag> > func = () => CreateCharDisplayTaggerSource(textView);

            return(TaggerUtil.CreateBasicTagger(
                       textView.Properties,
                       _key,
                       func.ToFSharpFunc()) as ITagger <T>);
        }
Ejemplo n.º 16
0
        public void UsingFSharpFuncIfYouHaveTo()
        {
            // These are all using the module functions.
            // Module is just a static class to C#.
            var list = RecursiveList.EmptyList <string>();
            var listWithAddedData = RecursiveList.cons("Test", list);

            Func <string, string> mapFunction = s => "TEST2" + s;
            var fsharpFunc = mapFunction.ToFSharpFunc();

            var mappedList = RecursiveList.map(fsharpFunc, listWithAddedData);

            var expectedList = RecursiveList <string> .NewHead("TEST2Test", RecursiveList <string> .Empty);

            Assert.AreEqual(expectedList, mappedList);
        }
Ejemplo n.º 17
0
        public void Create_DoCreate()
        {
            var didRun = false;
            Func <IClassifier> func =
                () =>
            {
                didRun = true;
                return(_factory.Create <IClassifier>().Object);
            };
            var result = new CountedClassifier(
                _propertyCollection,
                _key,
                func.ToFSharpFunc());

            Assert.True(didRun);
        }
Ejemplo n.º 18
0
        public void LoadVimRc3()
        {
            // Setup the VimRc contents
            var fileName = "foo";
            var contents = new string[] { "set ai" };
            var tuple    = Tuple.Create(fileName, contents);

            _fileSystem.Setup(x => x.GetVimRcDirectories()).Returns(new string[] { "" }).Verifiable();
            _fileSystem.Setup(x => x.LoadVimRc()).Returns(FSharpOption.Create(tuple)).Verifiable();

            Func <ITextView> createViewFunc = () => EditorUtil.CreateTextView();

            Assert.IsTrue(_vim.LoadVimRc(createViewFunc.ToFSharpFunc()));

            Assert.IsTrue(_vim.VimRcLocalSettings.AutoIndent);
            _fileSystem.Verify();
        }
Ejemplo n.º 19
0
        void StartFaceDetection_Pipeline_FSharpFunc(string imagesFolder)
        {
            var files = Directory.GetFiles(ImagesFolder);

            Func <string, Image <Bgr, byte> > imageFn =
                (fileName) => new Image <Bgr, byte>(fileName);
            Func <Image <Bgr, byte>, Tuple <Image <Bgr, byte>, Image <Gray, byte> > > grayFn =
                image => Tuple.Create(image, image.Convert <Gray, byte>());
            Func <Tuple <Image <Bgr, byte>, Image <Gray, byte> >,
                  Tuple <Image <Bgr, byte>, System.Drawing.Rectangle[]> > detectFn =
                frames => Tuple.Create(frames.Item1,
                                       CascadeClassifierThreadLocal.Value.DetectMultiScale(
                                           frames.Item2, 1.1, 3, System.Drawing.Size.Empty));
            Func <Tuple <Image <Bgr, byte>, System.Drawing.Rectangle[]>, Bitmap> drawFn =
                faces =>
            {
                foreach (var face in faces.Item2)
                {
                    faces.Item1.Draw(face, new Bgr(System.Drawing.Color.BurlyWood), 3);
                }
                return(faces.Item1.ToBitmap());
            };

            var imagePipe =
                Pipeline <string, Image <Bgr, byte> >
                .Create(imageFn.ToFSharpFunc())
                .Then(grayFn.ToFSharpFunc())
                .Then(detectFn.ToFSharpFunc())
                .Then(drawFn.ToFSharpFunc());     // #A

            CancellationTokenSource cts = new CancellationTokenSource();

            imagePipe.Execute(4, cts.Token);  // #B

            foreach (string fileName in files)
            {
                imagePipe.Enqueue(fileName,
                                  FSharpFuncUtils.Create <Tuple <string, Bitmap>, Unit>
                                      ((tup) =>
                {
                    Application.Current.Dispatcher.Invoke(
                        () => Images.Add(tup.Item2.ToBitmapImage()));
                    return((Unit)Activator.CreateInstance(typeof(Unit), true));
                }));     // #C
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Try and process the given KeyInput for insert mode in the middle of an Exec.  This is
        /// called for commands which can't be processed directly like edits.  We'd prefer these
        /// go through Visual Studio's command system so items like Intellisense work properly.
        /// </summary>
        private bool TryProcessWithExec(Guid commandGroup, OleCommandData oleCommandData, IInsertMode insertMode, KeyInput originalKeyInput, KeyInput mappedKeyInput)
        {
            Func <bool> customProcess =
                () =>
            {
                var            versionNumber = _textBuffer.CurrentSnapshot.Version.VersionNumber;
                int?           hr            = null;
                Guid           mappedCommandGroup;
                OleCommandData mappedOleCommandData;
                if (originalKeyInput == mappedKeyInput)
                {
                    // No changes so just use the original OleCommandData
                    hr = _nextTarget.Exec(
                        ref commandGroup,
                        oleCommandData.CommandId,
                        oleCommandData.CommandExecOpt,
                        oleCommandData.VariantIn,
                        oleCommandData.VariantOut);
                }
                else if (OleCommandUtil.TryConvert(mappedKeyInput, out mappedCommandGroup, out mappedOleCommandData))
                {
                    hr = _nextTarget.Exec(
                        ref mappedCommandGroup,
                        mappedOleCommandData.CommandId,
                        mappedOleCommandData.CommandExecOpt,
                        mappedOleCommandData.VariantIn,
                        mappedOleCommandData.VariantOut);
                    OleCommandData.Release(ref mappedOleCommandData);
                }

                if (hr.HasValue)
                {
                    // Whether or not an Exec succeeded is a bit of a heuristic.  IOleCommandTarget implementations like
                    // C++ will return E_ABORT if Intellisense failed but the character was actually inserted into
                    // the ITextBuffer.  VsVim really only cares about the character insert.  However we must also
                    // consider cases where the character successfully resulted in no action as a success
                    return(ErrorHandler.Succeeded(hr.Value) || versionNumber < _textBuffer.CurrentSnapshot.Version.VersionNumber);
                }

                // Couldn't map to a Visual Studio command so it didn't succeed
                return(false);
            };

            return(insertMode.CustomProcess(mappedKeyInput, customProcess.ToFSharpFunc()));
        }
Ejemplo n.º 21
0
 private void MaybeLoadVimRc()
 {
     if (!_vim.IsVimRcLoaded && String.IsNullOrEmpty(_vim.Settings.VimRcPaths))
     {
         // Need to pass the LoadVimRc call a function to create an ITextView that
         // can be used to load the settings against.  We don't want this ITextView
         // coming back through TextViewCreated so give it a ITextViewRole that won't
         // hit our filter
         Func <ITextView> createViewFunc = () => _editorFactoryService.CreateTextView(
             _bufferFactoryService.CreateTextBuffer(),
             _editorFactoryService.NoRoles);
         if (!_vim.LoadVimRc(_fileSystem, createViewFunc.ToFSharpFunc()))
         {
             // If no VimRc file is loaded add a couple of sanity settings
             _vim.VimRcLocalSettings.AutoIndent = true;
         }
     }
 }
Ejemplo n.º 22
0
        ITagger <T> IViewTaggerProvider.CreateTagger <T>(ITextView textView, ITextBuffer textBuffer)
        {
            if (textView.TextBuffer != textBuffer)
            {
                return(null);
            }

            if (!_vim.TryGetOrCreateVimBufferForHost(textView, out IVimBuffer vimBuffer))
            {
                return(null);
            }
            var vimBufferData = vimBuffer.VimBufferData;

            Func <IBasicTaggerSource <MarkGlyphTag> > func =
                () => CreateMarkGlyphTaggerSource(vimBufferData);

            return(TaggerUtil.CreateBasicTagger(
                       textView.Properties,
                       _key,
                       func.ToFSharpFunc()) as ITagger <T>);
        }
Ejemplo n.º 23
0
        internal static CommandBinding CreateComplexNormalBinding(
            string name,
            Action <KeyInput> action,
            CommandFlags flags = CommandFlags.None)
        {
            Func <KeyInput, BindResult <NormalCommand> > func = keyInput =>
            {
                action(keyInput);
                return(BindResult <NormalCommand> .NewComplete(NormalCommand.NewPutAfterCaret(false)));
            };

            var bindData = new BindData <NormalCommand>(
                FSharpOption <KeyRemapMode> .None,
                func.ToFSharpFunc());
            var bindDataStorage = BindDataStorage <NormalCommand> .NewSimple(bindData);

            return(CommandBinding.NewComplexNormalBinding(
                       KeyNotationUtil.StringToKeyInputSet(name),
                       flags,
                       bindDataStorage));
        }
Ejemplo n.º 24
0
        public void Dispose_ManyInstance()
        {
            var tagger              = _factory.Create <IClassifier>();
            var disposable          = tagger.As <IDisposable>();
            Func <IClassifier> func = () => tagger.Object;
            var result1             = new CountedClassifier(_propertyCollection, _key, func.ToFSharpFunc());
            var result2             = new CountedClassifier(_propertyCollection, _key, func.ToFSharpFunc());

            result1.Dispose();
            disposable.Setup(x => x.Dispose()).Verifiable();
            result2.Dispose();
            disposable.Verify();
        }
Ejemplo n.º 25
0
 private CountedTagger <TextMarkerTag> Create(object key, PropertyCollection propertyCollection, Func <ITagger <TextMarkerTag> > func)
 {
     return(new CountedTagger <TextMarkerTag>(propertyCollection, key, func.ToFSharpFunc()));
 }
Ejemplo n.º 26
0
 private CommandRunData CreateCommand(
     Func<FSharpOption<int>, Register, CommandResult> func = null,
     KeyInputSet name = null,
     CommandFlags? flags = null,
     int? count = 0,
     MotionRunData motionRunData = null,
     VisualSpan visualRunData = null)
 {
     name = name ?? KeyInputSet.NewOneKeyInput(KeyInputUtil.CharToKeyInput('c'));
     var flagsRaw = flags ?? CommandFlags.None;
     var countRaw = count.HasValue ? FSharpOption.Create(count.Value) : FSharpOption<int>.None;
     var funcRaw = func.ToFSharpFunc();
     var cmd = Command.NewSimpleCommand(
         name,
         flagsRaw,
         func.ToFSharpFunc());
     return new CommandRunData(
         cmd,
         new Register('c'),
         countRaw,
         motionRunData != null ? FSharpOption.Create(motionRunData) : FSharpOption<MotionRunData>.None,
         visualRunData != null ? FSharpOption.Create(visualRunData) : FSharpOption<VisualSpan>.None);
 }
Ejemplo n.º 27
0
 private FSharpFunc<Unit, ITagger<TextMarkerTag>> CreateFunc(Func<ITagger<TextMarkerTag>> func)
 {
     return func.ToFSharpFunc();
 }
Ejemplo n.º 28
0
Archivo: VimUtil.cs Proyecto: otf/VsVim
 internal static Command CreateVisualCommand(
     string name = "c",
     CommandFlags? flags = null,
     VisualKind kind = null,
     Func<FSharpOption<int>, Register, VisualSpan, CommandResult> func = null)
 {
     var flagsArg = flags ?? CommandFlags.None;
     kind = kind ?? VisualKind.Line;
     if (func == null)
     {
         func = (x, y, z) => CommandResult.NewCompleted(ModeSwitch.NoSwitch);
     }
     return Command.NewVisualCommand(
         KeyNotationUtil.StringToKeyInputSet(name),
         flagsArg,
         kind,
         func.ToFSharpFunc());
 }
Ejemplo n.º 29
0
        public static BindResult <TResult> Convert <T, TResult>(this BindResult <T> res, Func <T, TResult> func)
        {
            var func2 = func.ToFSharpFunc();

            return(res.Convert(func2));
        }
Ejemplo n.º 30
0
 private FSharpFunc <Unit, ITagger <TextMarkerTag> > CreateFunc(Func <ITagger <TextMarkerTag> > func)
 {
     return(func.ToFSharpFunc());
 }
Ejemplo n.º 31
0
 private CountedTagger<TextMarkerTag> Create(object key, PropertyCollection propertyCollection, Func<ITagger<TextMarkerTag>> func)
 {
     return Create(key, propertyCollection, func.ToFSharpFunc());
 }
        public FSharpAsync <FSharpOption <AudioPlayer.AudioPlayerInfo> > GetCurrentState()
        {
            Func <FSharpAsyncReplyChannel <AudioPlayer.AudioPlayerInfo>, AudioPlayer.AudioPlayerCommand> func = (x) => AudioPlayer.AudioPlayerCommand.NewGetCurrentState(x);
            var result = StateMailbox.PostAndTryAsyncReply <AudioPlayer.AudioPlayerInfo>(func.ToFSharpFunc(), 2000);

            return(result);
        }
Ejemplo n.º 33
0
 internal static BindData <T> CreateBindData <T>(Func <KeyInput, BindResult <T> > func = null, KeyRemapMode remapMode = null)
 {
     func = func ?? (x => BindResult <T> .Cancelled);
     return(new BindData <T>(FSharpOption.CreateForReference(remapMode), func.ToFSharpFunc()));
 }
Ejemplo n.º 34
0
 /// <summary>
 ///     Returns true if all elements in the CloudFlow satisfy the supplied predicate.
 /// </summary>
 /// <typeparam name="TSource">Cloud flow element type.</typeparam>
 /// <param name="flow">Input cloud flow.</param>
 /// <param name="predicate">A function to test each source element for a condition.</param>
 /// <returns>Returns true if all elements in the CloudFlow satisfy the supplied predicate.</returns>
 public static Cloud <bool> All <TSource>(this CloudFlow <TSource> flow, Func <TSource, bool> predicate)
 {
     return(CloudFlowModule.forall(predicate.ToFSharpFunc(), flow));
 }
Ejemplo n.º 35
0
 internal static CommandBinding CreateMotionBinding(
     string name        = "default",
     CommandFlags flags = CommandFlags.None,
     Func <MotionData, NormalCommand> func = null)
 {
     func = func ?? NormalCommand.NewYank;
     return(CommandBinding.NewMotionBinding(KeyNotationUtil.StringToKeyInputSet(name), flags, func.ToFSharpFunc()));
 }