Beispiel #1
0
        private static void initPlugins(PluginLocator locator)
        {
            var plugins = locator.Locate();

            foreach (var plugin in plugins)
            {
                try {
                    plugin.Initialize(_path);
                    plugin.GetCrawlFileTypes();
                    ThreadPool.QueueUserWorkItem(
                        (o) => {
                        try {
                            var currentPlugin = (LanguagePlugin)o;
                            var handler       = new CrawlHandler(_cache, (s) => Logger.Write(s));
                            handler.SetLanguage(currentPlugin.GetLanguage());
                            currentPlugin.Crawl(new string[] { _path }, (line) => handler.Handle(line));
                        } catch (Exception ex) {
                            Logger.Write(ex.ToString());
                        }
                    },
                        plugin);
                } catch (Exception ex) {
                    Logger.Write(ex.ToString());
                }
            }
            Logger.Write("Plugins initialized");
        }
Beispiel #2
0
 public void Handle(CrawlHandler cacheHandler)
 {
     if (FilesToHandle.Count == 0)
     {
         return;
     }
     cacheHandler.SetLanguage(Plugin.GetLanguage());
     Plugin.Crawl(FilesToHandle, (line) => cacheHandler.Handle(line));
     FilesToHandle.Clear();
 }
Beispiel #3
0
        public void When_given_files_and_types_it_will_add_them_to_cache()
        {
            var lines = new string[]
            {
                "file|/some/file.cs",
                "signature|NS|NS.MyClass|MyClass|class|private|2|3|",
                "signature|NS|NS.MyOtherClass|MyOtherClass|class|public|54|6|{\"property\":\"value\"}",
                "reference|NS.MyOtherClass|63|18"
            };

            lines.ToList()
            .ForEach(x => _crawlHandler.Handle(x));

            Assert.That(_cache.Files[0].File, Is.EqualTo("/some/file.cs"));
            Assert.That(_cache.Files[0].Project, Is.Null);

            Assert.That(_cache.References[0].Type, Is.EqualTo("class"));
            Assert.That(_cache.References[0].File, Is.EqualTo("/some/file.cs"));
            Assert.That(_cache.References[0].Signature, Is.EqualTo("NS.MyClass"));
            Assert.That(_cache.References[0].Name, Is.EqualTo("MyClass"));
            Assert.That(_cache.References[0].Scope, Is.EqualTo("private"));
            Assert.That(_cache.References[0].Line, Is.EqualTo(2));
            Assert.That(_cache.References[0].Column, Is.EqualTo(3));
            Assert.That(_cache.References[0].JSON, Is.EqualTo(""));

            Assert.That(_cache.References[1].Type, Is.EqualTo("class"));
            Assert.That(_cache.References[1].File, Is.EqualTo("/some/file.cs"));
            Assert.That(_cache.References[1].Signature, Is.EqualTo("NS.MyOtherClass"));
            Assert.That(_cache.References[1].Name, Is.EqualTo("MyOtherClass"));
            Assert.That(_cache.References[1].Scope, Is.EqualTo("public"));
            Assert.That(_cache.References[1].Line, Is.EqualTo(54));
            Assert.That(_cache.References[1].Column, Is.EqualTo(6));
            Assert.That(_cache.References[1].JSON, Is.EqualTo("{\"property\":\"value\"}"));

            Assert.That(_cache.SignatureReferences[0].Signature, Is.EqualTo("NS.MyOtherClass"));
            Assert.That(_cache.SignatureReferences[0].Line, Is.EqualTo(63));
            Assert.That(_cache.SignatureReferences[0].Column, Is.EqualTo(18));
        }
Beispiel #4
0
 public void Handle(CrawlHandler cacheHandler)
 {
     if (FilesToHandle.Count == 0)
     {
         return;
     }
     try {
         cacheHandler.SetLanguage(Plugin.GetLanguage());
         Plugin.Crawl(FilesToHandle, (line) => cacheHandler.Handle(line));
         FilesToHandle.Clear();
     } catch (Exception ex) {
         Logger.Write(ex);
     }
 }
Beispiel #5
0
        private void consoleSearch(Instance instance, string search)
        {
            var result       = instance.FindTypes(search);
            var searchResult = new SearchResult();
            var handler      = new CrawlHandler(searchResult, (s) => {});

            handler.TypeSearchAllTheThings();
            result
            .Split(new[] { Environment.NewLine }, StringSplitOptions.None)
            .ToList()
            .ForEach(x => {
                var line           = x;
                var signatureStart = line.IndexOf("|signature|");
                if (signatureStart > 0)
                {
                    line = line.Substring(signatureStart + 1, line.Length - (signatureStart + 1));
                }
                handler.Handle(line);
            });
            for (int i = 0; i < searchResult.Signatures.Count; i++)
            {
                Console.WriteLine("{0} - {1}",
                                  i + 1,
                                  searchResult.Signatures[i].Signature);
            }
            if (searchResult.Signatures.Count == 0)
            {
                return;
            }
            var selection = Console.ReadLine();
            int number;

            if (!int.TryParse(selection, out number))
            {
                return;
            }
            if (number < 1 || number > (searchResult.Signatures.Count))
            {
                return;
            }
            var signature = searchResult.Signatures[number - 1];
            var editor    = _editorEngineFactory.GetInstance(Environment.CurrentDirectory);

            if (editor == null)
            {
                return;
            }
            editor.GoTo(signature.File, signature.Line, signature.Column);
        }