Example #1
0
        private void ParserThread()
        {
            BeginInvoke(new MethodInvoker(() => parserThreadLabel.Text = "Loading mscorlib..."));
            MyProjectContent.AddReferencedContent(PcRegistry.Mscorlib);

            // do one initial parser step to enable code-completion while other
            // references are loading
            ParseStep();
            try
            {
                string appPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\";

                string[] referencedAssemblies = { "System", "System.Data", "System.Drawing", "System.Xml", "System.Windows.Forms", "Microsoft.VisualBasic", appPath + "DotSpatial.Controls.dll", appPath + "DotSpatial.Data.dll", appPath + "DotSpatial.Topology.dll" };
                foreach (string assemblyName in referencedAssemblies)
                {
                    string assemblyNameCopy = assemblyName; // copy for anonymous method
                    BeginInvoke(new MethodInvoker(() => parserThreadLabel.Text = "Loading " + assemblyNameCopy + "..."));
                    IProjectContent referenceProjectContent = PcRegistry.GetProjectContentForReference(assemblyName, assemblyName);

                    MyProjectContent.AddReferencedContent(referenceProjectContent);
                    (referenceProjectContent as ReflectionProjectContent)?.InitializeReferences();
                }
            }
            catch
            {
            }

            if (IsVisualBasic)
            {
                MyProjectContent.DefaultImports = new DefaultUsing(MyProjectContent);
                MyProjectContent.DefaultImports.Usings.Add("System");
                MyProjectContent.DefaultImports.Usings.Add("System.Text");
                MyProjectContent.DefaultImports.Usings.Add("Microsoft.VisualBasic");
            }

            BeginInvoke(new MethodInvoker(() => parserThreadLabel.Text = "Ready"));

            // Parse the current file every 2 seconds
            while (!IsDisposed)
            {
                ParseStep();

                Thread.Sleep(2000);
            }
        }
Example #2
0
        private void ParseStep()
        {
            string code = null;

            Invoke(new MethodInvoker(() => code = textEditorControl1.Text));
            TextReader       textReader = new StringReader(code);
            ICompilationUnit newCompilationUnit;
            var supportedLanguage = IsVisualBasic ? SupportedLanguage.VBNet : SupportedLanguage.CSharp;

            using (IParser p = ParserFactory.CreateParser(supportedLanguage, textReader))
            {
                // we only need to parse types and method definitions, no method bodies
                // so speed up the parser and make it more resistent to syntax
                // errors in methods
                p.ParseMethodBodies = false;
                p.Parse();
                newCompilationUnit = ConvertCompilationUnit(p.CompilationUnit);
            }

            // Remove information from lastCompilationUnit and add information from newCompilationUnit.
            MyProjectContent.UpdateCompilationUnit(LastCompilationUnit, newCompilationUnit, DummyFileName);
            LastCompilationUnit = newCompilationUnit;
            ParseInformation.SetCompilationUnit(newCompilationUnit);
        }