예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XmlDocumentationLoader"/> class.
        /// </summary>
        /// <param name="declarationCodeSenseProvider">The declaration CodeSense provider to add the declarations to.</param>
        public FrameXmlDeclarationParser(TableDeclarationProvider declarationCodeSenseProvider)
        {
            if (declarationCodeSenseProvider == null)
                throw new ArgumentNullException("declarationCodeSenseProvider");

            this.declarationCodeSenseProvider = declarationCodeSenseProvider;
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AstDeclarationParser"/> class.
        /// </summary>
        /// <param name="tableDeclarationProvider">The table declaration provider to add the declarations to.</param>
        public AstDeclarationParser(TableDeclarationProvider tableDeclarationProvider)
        {
            if (tableDeclarationProvider == null)
                throw new ArgumentNullException("tableDeclarationProvider");

            this.tableDeclarationProvider = tableDeclarationProvider;
        }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AstDeclarationParser"/> class.
        /// </summary>
        /// <param name="tableDeclarationProvider">The table declaration provider to add the declarations to.</param>
        public AstDeclarationParser(TableDeclarationProvider tableDeclarationProvider)
        {
            if (tableDeclarationProvider == null)
            {
                throw new ArgumentNullException("tableDeclarationProvider");
            }

            this.tableDeclarationProvider = tableDeclarationProvider;
        }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XmlDocumentationLoader"/> class.
        /// </summary>
        /// <param name="declarationCodeSenseProvider">The declaration CodeSense provider to add the declarations to.</param>
        public FrameXmlDeclarationParser(TableDeclarationProvider declarationCodeSenseProvider)
        {
            if (declarationCodeSenseProvider == null)
            {
                throw new ArgumentNullException("declarationCodeSenseProvider");
            }

            this.declarationCodeSenseProvider = declarationCodeSenseProvider;
        }
예제 #5
0
        /// <summary>
        /// Adds the declaration.
        /// </summary>
        /// <param name="tableDeclarationProvider">The table declaration provider.</param>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="element">The element.</param>
        private static void AddDeclaration(TableDeclarationProvider tableDeclarationProvider, string tableName, XElement element)
        {
            try
            {
                Declaration declaration = XmlDocumentationLoader.CreateDeclaration(element);

                // Add the declaration
                if (declaration != null)
                    tableDeclarationProvider.AddFieldDeclaration(tableName, declaration);
            }
            catch (ArgumentException)
            {
                // Enum.Parse could not parse the declaration type, there's nothing we can do.
            }
        }
예제 #6
0
        /// <summary>
        /// Adds the declaration.
        /// </summary>
        /// <param name="tableDeclarationProvider">The table declaration provider.</param>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="element">The element.</param>
        private static void AddDeclaration(TableDeclarationProvider tableDeclarationProvider, string tableName, XElement element, string src = null)
        {
            try
            {
                Declaration declaration = XmlDocumentationLoader.CreateDeclaration(element, src);

                // Add the declaration
                if (declaration != null)
                {
                    tableDeclarationProvider.AddFieldDeclaration(tableName, declaration);
                }
            }
            catch (ArgumentException)
            {
                // Enum.Parse could not parse the declaration type, there's nothing we can do.
            }
        }
예제 #7
0
        /// <summary>
        /// Adds the declarations from the documentation to a TableDeclarationProvider.
        /// </summary>
        /// <param name="tableDeclarationProvider"></param>
        public void AddDeclarations(TableDeclarationProvider tableDeclarationProvider)
        {
            if (tableDeclarationProvider == null)
                throw new ArgumentNullException("tableDeclarationProvider");

            foreach (XElement doc in docs)
            {
                // Query the documentation for tables and add them
                doc.XPathSelectElements("./tables/table").ForEach(table => this.AddTableDeclaration(tableDeclarationProvider, doc, table));

                if (doc.Element("globals") != null)
                {
                    // Query the documentation for global declarations and add them to the global table
                    doc.Element("globals").Elements().ForEach(element => AddDeclaration(tableDeclarationProvider, TableDeclarationProvider.DeclarationsTable, element));
                }
            }
        }
예제 #8
0
        /// <summary>
        /// Adds the declarations from the documentation to a TableDeclarationProvider.
        /// </summary>
        /// <param name="tableDeclarationProvider"></param>
        public void AddDeclarations(TableDeclarationProvider tableDeclarationProvider)
        {
            if (tableDeclarationProvider == null)
            {
                throw new ArgumentNullException("tableDeclarationProvider");
            }

            foreach (XElement doc in docs)
            {
                // Query the documentation for tables and add them
                doc.XPathSelectElements("./tables/table").ForEach(table => this.AddTableDeclaration(tableDeclarationProvider, doc, table));

                if (doc.Element("globals") != null)
                {
                    // Query the documentation for global declarations and add them to the global table
                    doc.Element("globals").Elements().ForEach(element => AddDeclaration(tableDeclarationProvider, TableDeclarationProvider.DeclarationsTable, element));
                }
            }
        }
예제 #9
0
        /// <summary>
        /// Adds the lua declarations.
        /// </summary>
        /// <param name="luaFile">The lua file.</param>
        private void AddLuaDeclarations(string luaFile)
        {
            // Make sure file exists and skip the one that triggered the request
            if (File.Exists(luaFile))
            {
                LuaParser parser;

                // Try to get a source for the file
                Source fileSource = (Source)GetSource(luaFile);

                if (fileSource != null)
                    parser = LanguageService.CreateParser(fileSource);
                else
                    parser = LanguageService.CreateParser(File.ReadAllText(luaFile));

                // Trigger the parse
                bool yyresult = parser.Parse();

                if (yyresult)
                {
                    luaFileDeclarationProviders[luaFile] = new TableDeclarationProvider();
                    AstDeclarationParser declarationParser = new AstDeclarationParser(luaFileDeclarationProviders[luaFile]);
                    // Parse the AST and add the declaarations
                    declarationParser.AddChunk(parser.Chunk);
                }
            }
        }
예제 #10
0
        /// <summary>
        /// Adds the frame XML declarations.
        /// </summary>
        /// <param name="frameXmlFile">The frame XML file.</param>
        private void AddFrameXmlDeclarations(string frameXmlFile)
        {
            frameXmlDeclarationProviders[frameXmlFile] = new TableDeclarationProvider();

            FrameXmlDeclarationParser frameXmlDeclarationParser =
                new FrameXmlDeclarationParser(frameXmlDeclarationProviders[frameXmlFile]);
            ParseFrameXml(frameXmlDeclarationParser, frameXmlFile);
        }
예제 #11
0
        /// <summary>
        /// Initializes the Language Service and loads the documentation.
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();

            // Initialize providers
            snippetDeclarationProvider = new SnippetDeclarationProvider(this);
            keywordDeclarationProvider = new KeywordDeclarationProvider();
            xmlDeclarationProvider = new TableDeclarationProvider();

            // By Xizhi: we will also load ${SolutionDir}/Documentation/*.xml when opening a new solution file.
            LoadXmlDocumentation();
            authoringScope = new DeclarationAuthoringScope(this);
            DTE = GetService(typeof(DTE)) as DTE2;
        }
예제 #12
0
        private void AddTableDeclaration(TableDeclarationProvider tableDeclarationProvider, XElement doc, XElement table)
        {
            //Add a declaration to the global list
            var      name            = (string)table.Attribute("name");
            string   src             = (string)table.Attribute("src");
            XElement variableElement = doc.XPathSelectElement(String.Format("./variables/variable[@name='{0}']", name));

            /// Added by LiXizhi. 2008.10.21. we now support namespace (ns) attribute to variables, so that a table can reside in a nested namespace. such as
            /// <variable name="Class1" type="Class1" ns="MyCompany.MyProject.Class1"/>
            String nameSpace = null;

            if (variableElement != null)
            {
                nameSpace = (String)variableElement.Attribute("ns");
            }
            bool bSkipRootDeclaration = false;

            if (!String.IsNullOrEmpty(nameSpace))
            {
                if (nameSpace.IndexOf('.') > 0)
                {
                    bSkipRootDeclaration = true;
                    String LastTableName = null;
                    foreach (Match tableField in Regex.Matches(nameSpace, @"\w+"))
                    {
                        if (tableField.Value != null)
                        {
                            if (LastTableName == null)
                            {
                                LastTableName = tableField.Value;
                                var d = new Declaration
                                {
                                    Name            = tableField.Value,
                                    DeclarationType = DeclarationType.Table,
                                    Description     = string.Empty,
                                    Type            = tableField.Value,
                                };
                                tableDeclarationProvider.AddDeclaration(d);
                            }
                            else
                            {
                                var d = new Declaration
                                {
                                    Name            = tableField.Value,
                                    DeclarationType = DeclarationType.Table,
                                    Description     = string.Empty,
                                    Type            = tableField.Value,
                                };
                                tableDeclarationProvider.AddFieldDeclaration(LastTableName, d);
                                LastTableName = tableField.Value;
                            }
                        }
                    }
                    if (LastTableName != name)
                    {
                        var d = new Declaration
                        {
                            Name            = name,
                            DeclarationType = DeclarationType.Table,
                            Description     = string.Empty,
                            Type            = name,
                        };
                        tableDeclarationProvider.AddFieldDeclaration(LastTableName, d);
                    }
                }
            }

            if (!bSkipRootDeclaration)
            {
                var d = new Declaration
                {
                    Name            = name,
                    DeclarationType = DeclarationType.Table,
                    Description     = string.Empty,
                    Type            = variableElement == null ? name : variableElement.Attribute("type").Value,
                };
                tableDeclarationProvider.AddDeclaration(d);
            }

            // Check whether the table inherits declarations from another table
            XAttribute inherits = table.Attribute("inherits");

            if (inherits != null)
            {
                // inherits is a comma-delimited list of tables that this table inherits from
                string[] inheritValues = inherits.Value.Split(',');

                foreach (string inheritValue in inheritValues)
                {
                    // Query the table that the declarations should be inherited from
                    XElement baseTable = doc.XPathSelectElement(String.Format("./tables/table[@name='{0}']", inheritValue.Trim()));

                    // If the table was found, add each declaration from the base table
                    if (baseTable != null)
                    {
                        baseTable.Elements().ForEach(element => AddDeclaration(tableDeclarationProvider, name, element));
                    }
                }
            }

            // Go through all declarations and add them to the table
            table.Elements().ForEach(element => AddDeclaration(tableDeclarationProvider, name, element, src));
        }
예제 #13
0
        private void AddTableDeclaration(TableDeclarationProvider tableDeclarationProvider, XElement doc, XElement table)
        {
            //Add a declaration to the global list
            var name = (string)table.Attribute("name");
            XElement variableElement = doc.XPathSelectElement(String.Format("./variables/variable[@name='{0}']", name));

            /// Added by LiXizhi. 2008.10.21. we now support namespace (ns) attribute to variables, so that a table can reside in a nested namespace. such as
            /// <variable name="Class1" type="Class1" ns="MyCompany.MyProject.Class1"/>
            String nameSpace = (String)variableElement.Attribute("ns");
            bool bSkipRootDeclaration = false;
            if (!String.IsNullOrEmpty(nameSpace))
            {
                if(nameSpace.IndexOf('.')>0)
                {
                    bSkipRootDeclaration = true;
                    String LastTableName=null;
                    foreach (Match tableField in Regex.Matches(nameSpace, @"\w+"))
                    {
                        if(tableField.Value!=null)
                        {
                            if(LastTableName==null)
                            {
                                LastTableName = tableField.Value;
                                var d = new Declaration
                                {
                                    Name = tableField.Value,
                                    DeclarationType = DeclarationType.Table,
                                    Description = string.Empty,
                                    Type = tableField.Value,
                                };
                                tableDeclarationProvider.AddDeclaration(d);
                            }
                            else
                            {
                                var d = new Declaration
                                {
                                    Name = tableField.Value,
                                    DeclarationType = DeclarationType.Table,
                                    Description = string.Empty,
                                    Type = tableField.Value,
                                };
                                tableDeclarationProvider.AddFieldDeclaration(LastTableName, d);
                                LastTableName = tableField.Value;
                            }
                        }
                    }
                    if(LastTableName != name)
                    {
                        var d = new Declaration
                        {
                            Name = name,
                            DeclarationType = DeclarationType.Table,
                            Description = string.Empty,
                            Type = name,
                        };
                        tableDeclarationProvider.AddFieldDeclaration(LastTableName, d);
                    }
                }
            }

            if (!bSkipRootDeclaration)
            {
                var d = new Declaration
                {
                    Name = name,
                    DeclarationType = DeclarationType.Table,
                    Description = string.Empty,
                    Type = variableElement.Attribute("type").Value
                };

                tableDeclarationProvider.AddDeclaration(d);
            }

            // Check whether the table inherits declarations from another table
            XAttribute inherits = table.Attribute("inherits");
            if (inherits != null)
            {
                // inherits is a comma-delimited list of tables that this table inherits from
                string[] inheritValues = inherits.Value.Split(',');

                foreach (string inheritValue in inheritValues)
                {
                    // Query the table that the declarations should be inherited from
                    XElement baseTable = doc.XPathSelectElement(String.Format("./tables/table[@name='{0}']", inheritValue.Trim()));

                    // If the table was found, add each declaration from the base table
                    if (baseTable != null)
                        baseTable.Elements().ForEach(element => AddDeclaration(tableDeclarationProvider, name, element));
                }
            }

            // Go through all declarations and add them to the table
            table.Elements().ForEach(element => AddDeclaration(tableDeclarationProvider, name, element));
        }