/////////////////////////////////////////////////////////////////////////////////////////////////////
        // OBJECT
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes an instance of the <c>MainControl</c> class.
        /// </summary>
        public MainControl()
        {
            InitializeComponent();

            //
            // NOTE: Make sure that you've read through the add-on language's 'Getting Started' topic
            //   since it tells you how to set up an ambient parse request dispatcher and an ambient
            //   code repository within your application OnStartup code, and add related cleanup in your
            //   application OnExit code.  These steps are essential to having the add-on perform well.
            //

            // Initialize the project assembly (enables support for automated IntelliPrompt features)
            projectAssembly = new VBProjectAssembly("SampleBrowser");
            projectAssembly.AssemblyReferences.ItemAdded   += OnAssemblyReferencesChanged;
            projectAssembly.AssemblyReferences.ItemRemoved += OnAssemblyReferencesChanged;
            var assemblyLoader = new BackgroundWorker();

            assemblyLoader.DoWork += DotNetProjectAssemblyReferenceLoader;
            assemblyLoader.RunWorkerAsync();

            // Load the .NET Languages Add-on VB language and register the project assembly on it
            var language = new VBSyntaxLanguage();

            language.RegisterProjectAssembly(projectAssembly);
            codeEditor.Document.Language = language;
        }
示例#2
0
        public SyntaxLanguage GetSyntaxLanguage(string file)
        {
            string documentType = this.GetDocumentType(file);

            if (documentType == "text.C#")
            {
                if (CodeProjectService.csharpSyntaxLanguage == null)
                {
                    CodeProjectService.csharpSyntaxLanguage = new CSharpSyntaxLanguage();
                }
                return((SyntaxLanguage)CodeProjectService.csharpSyntaxLanguage);
            }
            if (documentType == "text.VB")
            {
                if (CodeProjectService.vbSyntaxLanguage == null)
                {
                    CodeProjectService.vbSyntaxLanguage = new VBSyntaxLanguage();
                }
                return((SyntaxLanguage)CodeProjectService.vbSyntaxLanguage);
            }
            if (documentType == "text.JS")
            {
                if (CodeProjectService.jsSyntaxLanguage == null)
                {
                    using (Stream stream = (Stream) new MemoryStream(Microsoft.Expression.Code.FileTable.GetByteArray("Resources\\Actipro.JS.xml")))
                        CodeProjectService.jsSyntaxLanguage = DynamicSyntaxLanguage.LoadFromXml(stream, 0);
                }
                return((SyntaxLanguage)CodeProjectService.jsSyntaxLanguage);
            }
            if (documentType == "text.C++")
            {
                if (CodeProjectService.cppSyntaxLanguage == null)
                {
                    using (Stream stream = (Stream) new MemoryStream(Microsoft.Expression.Code.FileTable.GetByteArray("Resources\\Actipro.CPP.xml")))
                    {
                        try
                        {
                            CodeProjectService.cppSyntaxLanguage = DynamicSyntaxLanguage.LoadFromXml(stream, 0);
                        }
                        catch (Exception ex)
                        {
                            throw;
                        }
                    }
                }
                return((SyntaxLanguage)CodeProjectService.cppSyntaxLanguage);
            }
            if (documentType == "text")
            {
                return(SyntaxLanguage.PlainText);
            }
            return((SyntaxLanguage)null);
        }
示例#3
0
        /// <summary>
        /// Returns a language for the specified extension.
        /// </summary>
        /// <param name="extension">The file extension.</param>
        /// <returns>The <see cref="ISyntaxLanguage"/> to use.</returns>
        private ISyntaxLanguage GetOrCreateLanguage(string extension)
        {
            switch (extension)
            {
            case ".cs":
                if (cSharpSyntaxLanguage == null)
                {
                    cSharpSyntaxLanguage = new CSharpSyntaxLanguage();

                    var cSharpProjectAssembly = new CSharpProjectAssembly("Sample");
                    var assemblyLoader        = new BackgroundWorker();
                    assemblyLoader.DoWork += (sender, e) => {
                        // Add some common assemblies for reflection (any custom assemblies could be added using various Add overloads instead)
                        cSharpProjectAssembly.AssemblyReferences.AddMsCorLib();
                                                        #if !NETCORE
                        cSharpProjectAssembly.AssemblyReferences.Add("System");
                        cSharpProjectAssembly.AssemblyReferences.Add("System.Core");
                        cSharpProjectAssembly.AssemblyReferences.Add("System.Xml");
                                                        #endif
                    };
                    assemblyLoader.RunWorkerAsync();
                    cSharpSyntaxLanguage.RegisterProjectAssembly(cSharpProjectAssembly);
                }
                return(cSharpSyntaxLanguage);

            case ".js":
                if (javaScriptSyntaxLanguage == null)
                {
                    javaScriptSyntaxLanguage = new JavaScriptSyntaxLanguage();
                }
                return(javaScriptSyntaxLanguage);

            case ".py":
                if (pythonSyntaxLanguage == null)
                {
                    pythonSyntaxLanguage = new PythonSyntaxLanguage();
                }
                return(pythonSyntaxLanguage);

            case ".vb":
                if (vbSyntaxLanguage == null)
                {
                    vbSyntaxLanguage = new VBSyntaxLanguage();

                    var vbProjectAssembly = new VBProjectAssembly("Sample");
                    var assemblyLoader    = new BackgroundWorker();
                    assemblyLoader.DoWork += (sender, e) => {
                        // Add some common assemblies for reflection (any custom assemblies could be added using various Add overloads instead)
                        vbProjectAssembly.AssemblyReferences.AddMsCorLib();
                                                        #if !NETCORE
                        vbProjectAssembly.AssemblyReferences.Add("System");
                        vbProjectAssembly.AssemblyReferences.Add("System.Core");
                        vbProjectAssembly.AssemblyReferences.Add("System.Xml");
                                                        #endif
                    };
                    assemblyLoader.RunWorkerAsync();
                    vbSyntaxLanguage.RegisterProjectAssembly(vbProjectAssembly);
                }
                return(vbSyntaxLanguage);

            case ".xml":
                if (xmlSyntaxLanguage == null)
                {
                    xmlSyntaxLanguage = new XmlSyntaxLanguage();
                }
                return(xmlSyntaxLanguage);

            default:
                return(SyntaxLanguage.PlainText);
            }
        }
示例#4
0
        /// <summary>
        /// Parses the given code asynchronously and creates a VB.Net CodeRoot from it.
        /// </summary>
        /// <param name="filename">The name of the file being parsed. Informational use only.</param>
        /// <param name="code">The code to parse</param>
        /// <returns>A WaitHandle that will be signalled when the code is parsed and 
        /// the CodeRoot is ready for use.</returns>
        public WaitHandle ParseCodeAsync(string filename, string code)
        {
            Reset();
            parseWaitHandle.Reset();
            parseFinished = false;
            parserGuid = Guid.NewGuid();

            ISemanticParserServiceProcessor language = new VBSyntaxLanguage();
            // This is needed because the Actipro parser calculates the text offsets of parsed elements
            // by using /r/n for line breaks (on my windows machine) even if the original text had a /r or /n.
            // This manifests itself as a bunch of wierd Expressions, all type names, some variable names, and
            // various other elements will have completely the wrong text. The number of characters in the final
            // output is correct though.
            document = new Document();
            document.Text = Helper.StandardizeLineBreaks(code, Helper.LineBreaks.Windows);

            if (SemanticParserService.IsRunning == false)
                SemanticParserService.Start();
            else if (SemanticParserService.IsBusy)
            {
                SemanticParserService.Stop();
                SemanticParserService.Start();
            }
            // Make a request to the parser service (runs in a separate thread).
            SemanticParserServiceRequest request = new SemanticParserServiceRequest(
                SemanticParserServiceRequest.MediumPriority,
                document,
                new ActiproSoftware.SyntaxEditor.TextRange(0, document.Length),
                SemanticParseFlags.None,
                language,
                this
                );
            SemanticParserService.Parse(request);

            return parseWaitHandle;
        }