Esempio n. 1
0
        protected override void OnNewFile(LibraryTask task)
        {
            if (IsNonMemberItem(task.ModuleID.Hierarchy, task.ModuleID.ItemID))
            {
                return;
            }

            var project = task.ModuleID.Hierarchy
                          .GetProject()
                          .GetPythonProject();

            if (project == null)
            {
                return;
            }

            AnalysisCompleteHandler handler;

            lock (_handlers) {
                if (!_handlers.TryGetValue(project, out handler))
                {
                    _handlers[project] = handler = new AnalysisCompleteHandler(this, project);
                }
            }

            handler.AddTask(task);
        }
Esempio n. 2
0
        protected override void OnNewFile(LibraryTask task)
        {
            if (IsNonMemberItem(task.ModuleID.Hierarchy, task.ModuleID.ItemID))
            {
                return;
            }

            var analyzer = task.ModuleID.Hierarchy
                           .GetProject()
                           .GetPythonProject()
                           .GetAnalyzer();

            AnalysisEntry item;

            if (analyzer.GetAnalysisEntryFromPath(task.FileName) == null)
            {
                analyzer.AnalyzeFileAsync(task.FileName).ContinueWith(x => {
                    item = x.Result;

                    if (item != null)
                    {
                        // We subscribe to OnNewAnalysis here instead of OnNewParseTree so that
                        // in the future we can use the analysis to include type information in the
                        // object browser (for example we could include base type information with
                        // links elsewhere in the object browser).
                        item.AnalysisComplete += (sender, args) => {
                            _package.GetUIThread().InvokeAsync(() => FileParsed(task))
                            .HandleAllExceptions(_package, GetType())
                            .DoNotWait();
                        };
                    }
                });
            }
        }
Esempio n. 3
0
        protected override void OnNewFile(LibraryTask task)
        {
            IProjectEntry item;

            if (task.TextBuffer != null)
            {
                item = task.TextBuffer.GetAnalysis();
            }
            else
            {
                item = task.ModuleID.Hierarchy.GetProject().GetPythonProject().GetAnalyzer().AnalyzeFile(task.FileName);
            }

            IPythonProjectEntry pyCode;

            if (item != null && (pyCode = item as IPythonProjectEntry) != null)
            {
                // We subscribe to OnNewAnalysis here instead of OnNewParseTree so that
                // in the future we can use the analysis to include type information in the
                // object browser (for example we could include base type information with
                // links elsewhere in the object browser).
                pyCode.OnNewAnalysis += (sender, args) => {
                    FileParsed(task, new AstScopeNode(pyCode.Tree, pyCode));
                };
            }
        }
Esempio n. 4
0
        protected override void OnNewFile(LibraryTask task)
        {
            if (IsNonMemberItem(task.ModuleID.Hierarchy, task.ModuleID.ItemID))
            {
                return;
            }

/*
 *          IProjectEntry item;
 *          if (task.TextBuffer != null) {
 *              item = task.TextBuffer.GetAnalysis();
 *          } else {
 *              item = task.ModuleID.Hierarchy.GetProject().GetLuaProject().GetAnalyzer().AnalyzeFile(task.FileName);
 *          }
 *
 *          ILuaProjectEntry pyCode;
 *          if (item != null && (pyCode = item as ILuaProjectEntry) != null) {
 *              // We subscribe to OnNewAnalysis here instead of OnNewParseTree so that
 *              // in the future we can use the analysis to include type information in the
 *              // object browser (for example we could include base type information with
 *              // links elsewhere in the object browser).
 *              pyCode.OnNewAnalysis += (sender, args) => {
 *                  FileParsed(task, new AstScopeNode(pyCode.Tree, pyCode));
 *              };
 *          }*/
        }
Esempio n. 5
0
        protected override void OnNewFile(LibraryTask task)
        {
            if (IsNonMemberItem(task.ModuleID.Hierarchy, task.ModuleID.ItemID))
            {
                return;
            }
            IPythonProjectEntry item;

            if (task.TextBuffer == null || !task.TextBuffer.TryGetPythonProjectEntry(out item))
            {
                item = task.ModuleID.Hierarchy
                       .GetProject()
                       .GetPythonProject()
                       .GetAnalyzer()
                       .AnalyzeFile(task.FileName) as IPythonProjectEntry;
            }

            if (item != null)
            {
                // We subscribe to OnNewAnalysis here instead of OnNewParseTree so that
                // in the future we can use the analysis to include type information in the
                // object browser (for example we could include base type information with
                // links elsewhere in the object browser).
                item.OnNewAnalysis += (sender, args) => {
                    _package.GetUIThread().InvokeAsync(() => FileParsed(task, new AstScopeNode(item.Tree, item)))
                    .HandleAllExceptions(_package, GetType())
                    .DoNotWait();
                };
            }
        }
        private void CreateParseRequest(string file, string text, ModuleId id)
        {
            LibraryTask task = new LibraryTask(file, text);

            task.ModuleID = id;
            lock (requests) {
                requests.Enqueue(task);
            }
            requestPresent.Set();
        }
Esempio n. 7
0
        private void CreateUpdateTreeRequest(string file, XSharpModuleId id)
        {
            if (XSolution.IsClosing)
            {
                return;
            }
            LibraryTask task = new LibraryTask(file, id);

            task.ModuleID = id;
            lock (requests)
            {
                requests.Enqueue(task);
            }
            requestPresent.Set();
        }
Esempio n. 8
0
        protected override void OnNewFile(LibraryTask task)
        {
            //AnalysisItem item;
            //if (task.TextBuffer != null) {
            //    item = task.TextBuffer.GetAnalysis();
            //} else {
            //    item = IronRubyToolsPackage.Instance.Analyzer.AnalyzeFile(task.FileName);
            //}

            // We subscribe to OnNewAnalysis here instead of OnNewParseTree so that
            // in the future we can use the analysis to include type information in the
            // object browser (for example we could include base type information with
            // links elsewhere in the object browser).
            //item.OnNewAnalysis += (sender, args) => {
            //    FileParsed(task, new AstScopeNode(item.CurrentTree, item.Entry));
            //};
        }
Esempio n. 9
0
        /// <summary>
        /// Called by derived class when a file has been parsed.  The caller should
        /// provide the LibraryTask received from the OnNewFile call and an IScopeNode
        /// which represents the contents of the library.
        ///
        /// It is safe to call this method from any thread.
        /// </summary>
        protected void FileParsed(LibraryTask task, IScopeNode scope)
        {
            var project = task.ModuleID.Hierarchy as IProject;

            HierarchyNode fileNode = null;

            if (project != null)
            {
                fileNode = ((ProjectSmuggler)project.Project).Project.NodeFromItemId(task.ModuleID.ItemID);
            }

            LibraryNode module = CreateFileLibraryNode(
                fileNode,
                System.IO.Path.GetFileName(task.FileName),
                task.FileName,
                LibraryNodeType.PhysicalContainer
                );

            // TODO: Creating the module tree should be done lazily as needed
            // Currently we replace the entire tree and rely upon the libraries
            // update count to invalidate the whole thing.  We could do this
            // finer grained and only update the changed nodes.  But then we
            // need to make sure we're not mutating lists which are handed out.

            CreateModuleTree(module, module, scope, task.FileName + ":", task.ModuleID);

            if (null != task.ModuleID)
            {
                LibraryNode previousItem = null;
                lock (_files) {
                    if (_files.TryGetValue(task.ModuleID, out previousItem))
                    {
                        _files.Remove(task.ModuleID);
                    }
                }
                _library.RemoveNode(previousItem);
            }
            _library.AddNode(module);
            if (null != task.ModuleID)
            {
                lock (_files) {
                    _files.Add(task.ModuleID, module);
                }
            }
        }
        /// <summary>
        /// Main function of the parsing thread.
        /// This function waits on the queue of the parsing requests and build the parsing tree for
        /// a specific file. The resulting tree is built using LibraryNode objects so that it can
        /// be used inside the class view or object browser.
        /// </summary>
        private void ParseThread()
        {
            const int waitTimeout = 500;

            // Define the array of events this function is interest in.
            WaitHandle[] eventsToWait = new WaitHandle[] { requestPresent, shutDownStarted };
            // Execute the tasks.
            while (true)
            {
                // Wait for a task or a shutdown request.
                int waitResult = WaitHandle.WaitAny(eventsToWait, waitTimeout, false);
                if (1 == waitResult)
                {
                    // The shutdown of this component is started, so exit the thread.
                    return;
                }
                LibraryTask task = null;
                lock (requests) {
                    if (0 != requests.Count)
                    {
                        task = requests.Dequeue();
                    }
                    if (0 == requests.Count)
                    {
                        requestPresent.Reset();
                    }
                }
                if (null == task)
                {
                    continue;
                }
                ScopeNode scope = null;
                if (null == task.Text)
                {
                    if (System.IO.File.Exists(task.FileName))
                    {
                        scope = ScopeWalker.GetScopesFromFile(task.FileName);
                    }
                }
                else
                {
                    scope = ScopeWalker.GetScopesFromText(task.Text);
                }
                LibraryNode module = new LibraryNode(
                    System.IO.Path.GetFileName(task.FileName),
                    LibraryNode.LibraryNodeType.PhysicalContainer);
                CreateModuleTree(module, module, scope, "", task.ModuleID);
                if (null != task.ModuleID)
                {
                    LibraryNode previousItem = null;
                    lock (files) {
                        if (files.TryGetValue(task.ModuleID, out previousItem))
                        {
                            files.Remove(task.ModuleID);
                        }
                    }
                    library.RemoveNode(previousItem);
                }
                library.AddNode(module);
                if (null != task.ModuleID)
                {
                    lock (files) {
                        files.Add(task.ModuleID, module);
                    }
                }
            }
        }
Esempio n. 11
0
 public void AddTask(LibraryTask task)
 {
     lock (_tasks) {
         _tasks[task.FileName] = task;
     }
 }
Esempio n. 12
0
 protected override void OnNewFile(LibraryTask task)
 {
 }
Esempio n. 13
0
        /// <summary>
        /// Main function of the parsing thread.
        /// This function waits on the queue of the parsing requests and build the parsing tree for
        /// a specific file. The resulting tree is built using LibraryNode objects so that it can
        /// be used inside the class view or object browser.
        /// </summary>
        private void UpdateTreeThread()
        {
            const int waitTimeout = 500;

            // Define the array of events this function is interest in.
            WaitHandle[] eventsToWait = new WaitHandle[] { requestPresent, shutDownStarted };
            // Execute the tasks.
            while (true)
            {
                // Wait for a task or a shutdown request.
                int waitResult = WaitHandle.WaitAny(eventsToWait, waitTimeout, false);
                if (waitResult == 1)
                {
                    // The shutdown of this component is started, so exit the thread.
                    return;
                }
                if (waitResult == WaitHandle.WaitTimeout)
                {
                    continue;
                }
                //
                LibraryTask task = null;
                lock (requests)
                {
                    if (0 != requests.Count)
                    {
                        task = requests.Dequeue();
                    }
                    if (0 == requests.Count)
                    {
                        requestPresent.Reset();
                    }
                }
                if (null == task)
                {
                    continue;
                }
                //
                XFile scope = null;
                if (System.IO.File.Exists(task.FileName))
                {
                    scope = XSharpModel.XSolution.FindFile(task.FileName);
                    if (scope == null || (!scope.HasCode))
                    {
                        continue;
                    }
                }
                // If the file already exist
                lock (files)
                {
                    // These are the existing Modules
                    XSharpModuleId[] aTmp = new XSharpModuleId[files.Keys.Count];
                    files.Keys.CopyTo(aTmp, 0);
                    // Does this module already exist ?
                    XSharpModuleId found = Array.Find <XSharpModuleId>(aTmp, (x => x.Equals(task.ModuleID)));
                    if (found != null)
                    {
                        // Doesn't it have the same members?
                        if (found.ContentHashCode == task.ModuleID.ContentHashCode)
                        {
                            continue;
                        }
                        //
                        HashSet <XSharpLibraryNode> values = null;
                        // Ok, now remove ALL nodes for that key
                        if (files.TryGetValue(task.ModuleID, out values))
                        {
                            foreach (XSharpLibraryNode node in values)
                            {
                                if (node.Freeing(task.ModuleID.ItemID) == 0)
                                {
                                    if (node.parent != null)
                                    {
                                        node.parent.RemoveNode(node);
                                    }
                                }
                            }
                            // and then remove the key
                            files.Remove(task.ModuleID);
                        }
                    }
                    //
                    LibraryNode prjNode = this.library.SearchHierarchy(task.ModuleID.Hierarchy);
                    if (prjNode is XSharpLibraryProject)
                    {
                        //
                        CreateModuleTree((XSharpLibraryProject)prjNode, scope, task.ModuleID);
                        //
                        prjNode.updateCount += 1;
                        //this.prjNode.AddNode(node);
                        //library.AddNode(node);
                        this.library.Refresh();
                    }
                }
            }
        }
Esempio n. 14
0
 /// <summary>
 /// Overridden in the base class to receive notifications of when a file should
 /// be analyzed for inclusion in the library.  The derived class should queue
 /// the parsing of the file and when it's complete it should call FileParsed
 /// with the provided LibraryTask and an IScopeNode which provides information
 /// about the members of the file.
 /// </summary>
 protected virtual void OnNewFile(LibraryTask task)
 {
 }
Esempio n. 15
0
        /// <summary>
        /// Main function of the parsing thread.
        /// This function waits on the queue of the parsing requests and build the parsing tree for
        /// a specific file. The resulting tree is built using LibraryNode objects so that it can
        /// be used inside the class view or object browser.
        /// </summary>
        private void ParseThread()
        {
            const int waitTimeout = 500;

            // Define the array of events this function is interest in.
            WaitHandle[] eventsToWait = new WaitHandle[] { requestPresent, shutDownStarted };
            // Execute the tasks.
            while (true)
            {
                // Wait for a task or a shutdown request.
                int waitResult = WaitHandle.WaitAny(eventsToWait, waitTimeout, false);
                if (1 == waitResult)
                {
                    // The shutdown of this component is started, so exit the thread.
                    return;
                }
                LibraryTask task = null;
                lock (requests) {
                    if (0 != requests.Count)
                    {
                        task = requests.Dequeue();
                    }
                    if (0 == requests.Count)
                    {
                        requestPresent.Reset();
                    }
                }
                if (null == task)
                {
                    continue;
                }

                string sourceText = task.Text;
                if (sourceText == null)
                {
                    //should not happen, but to be robust
                    if (!System.IO.File.Exists(task.FileName))
                    {
                        continue;
                    }

                    //read file content as string
                    try {
                        using (System.IO.StreamReader sr = System.IO.File.OpenText(task.FileName)) {
                            sourceText = sr.ReadToEnd();
                        }
                    }
                    catch (Exception ex) {
                        System.Diagnostics.Trace.WriteLine(String.Format("Error when parsing file '{0}': {1}\n{2}", task.FileName, ex.Message, ex.StackTrace));
                        continue;
                    }
                }

                if (string.IsNullOrEmpty(sourceText))
                {
                    continue;
                }

                CocoParserProxy.CocoParseResult result = CocoParserProxy.Parse(sourceText, task.FileName);

                //maybe use coco-library entry (to avoid not-implemented exception in librarynode.getcategory2)
                CocoLibraryNode module = new CocoLibraryNode(
                    System.IO.Path.GetFileName(task.FileName),
                    1,
                    1,
                    1,
                    task.ModuleID.Hierarchy,
                    task.ModuleID.ItemID,
                    LibraryNode.LibraryNodeType.Classes);


                CreateLibraryEntry(module, result, task.ModuleID);

                if (null != task.ModuleID)
                {
                    LibraryNode previousItem = null;
                    lock (files) {
                        if (files.TryGetValue(task.ModuleID, out previousItem))
                        {
                            files.Remove(task.ModuleID);
                        }
                    }
                    library.RemoveNode(previousItem);
                }
                library.AddNode(module);
                if (null != task.ModuleID)
                {
                    lock (files) {
                        files.Add(task.ModuleID, module);
                    }
                }
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Main function of the parsing thread.
        /// This function waits on the queue of the parsing requests and build
        /// the parsing tree for a specific file. The resulting tree is built
        /// using LibraryNode objects so that it can be used inside the class
        /// view or object browser.
        /// </summary>
        void ParseThread()
        {
            const int waitTimeout = 500;

            // Define the array of events this function is interest in.
            //
            WaitHandle[] eventsToWait = new WaitHandle[] { _requestPresent, _shutDownStarted };

            // Execute the tasks.
            //
            while (true)
            {
                // Wait for a task or a shutdown request.
                //
                int waitResult = WaitHandle.WaitAny(eventsToWait, waitTimeout, false);

                if (1 == waitResult)
                {
                    // The shutdown of this component is started, so exit the thread.
                    return;
                }

                LibraryTask task = null;

                lock (_requests)
                {
                    if (_requests.Count != 0)
                    {
                        task = _requests.Dequeue();
                    }

                    if (_requests.Count == 0)
                    {
                        _requestPresent.Reset();
                    }
                }

                if (null == task)
                {
                    continue;
                }

                ScopeNode scope = null;

                if (task.Text == null)
                {
                    if (File.Exists(task.FileName))
                    {
                        Debug.WriteLine("Parse request (no text): " + task.FileName + " " + task.ModuleID);
                        return;
                    }
                }
                else
                {
                    Debug.WriteLine("Parse request: " + task.FileName + " " + task.ModuleID);
                    return;
                }

                LibraryNode module = new LibraryNode(
                    Path.GetFileName(task.FileName),
                    LibraryNode.LibraryNodeType.PhysicalContainer);

                CreateModuleTree(module, module, scope, "", task.ModuleID);

                if (task.ModuleID != null)
                {
                    LibraryNode previousItem;

                    lock (_files)
                        if (_files.TryGetValue(task.ModuleID, out previousItem))
                        {
                            _files.Remove(task.ModuleID);
                        }

                    _library.RemoveNode(previousItem);
                }

                _library.AddNode(module);

                if (task.ModuleID != null)
                {
                    lock (_files)
                        _files.Add(task.ModuleID, module);
                }
            }
        }
Esempio n. 17
0
        void CreateParseRequest(string file, string text, ModuleID id)
        {
            LibraryTask task = new LibraryTask(file, text);

            task.ModuleID = id;

            lock (_requests)
                _requests.Enqueue(task);

            _requestPresent.Set();
        }
Esempio n. 18
0
        public LibraryNode Parse(LibraryTask task)
        {
            this.filename = task.FileName;
            this.moduleId = task.ModuleID;

            LibraryNode filenode   = new LibraryNode(System.IO.Path.GetFileName(filename), LibraryNode.LibraryNodeType.PhysicalContainer, moduleId);
            LibraryNode globalnode = new LibraryNode("(Global Scope)", LibraryNode.LibraryNodeType.Package, moduleId);

            start = new SourceLocation(0, 0);
            end   = new SourceLocation(0, 0);
            globalnode.StartLine = start.line;
            globalnode.StartCol  = start.col;

            filenode.AddNode(globalnode);

            try
            {
                if (task.Text == null)
                {
                    lexer.SetSource(File.ReadAllText(filename), 0);
                }
                else
                {
                    lexer.SetSource(task.Text, 0);
                }

                Lex();

                while (_token > 0 && !lexer.IsEob())
                {
                    try
                    {
                        switch (_token)
                        {
                        case (int)Token.FUNCTION:
                            Lex();

                            if (_token == '(')      // ignoring function literals for now - josh
                            {
                                MatchBraces('{', '}');
                            }
                            else
                            {
                                LibraryNode fnode = ParseFunction(false);

                                if (fnode.NodeType == LibraryNode.LibraryNodeType.Members)
                                {
                                    globalnode.AddNode(fnode);
                                }
                                else
                                {
                                    filenode.AddNode(fnode);
                                }
                            }
                            break;

                        case (int)Token.DOUBLE_COLON:
                            Lex();
                            continue;

                        case (int)Token.IDENTIFIER:
                            LibraryNode inode = ParseClassOrTable(true);
                            if (inode != null)
                            {
                                globalnode.AddNode(inode);
                            }

                            /*
                             * else
                             * {
                             *  SkipToEndOfTheLine();
                             * }
                             */
                            break;

                        case (int)Token.CLASS:
                            Lex();
                            filenode.AddNode(ParseClassOrTable(false));
                            break;

                        case (int)Token.ENUM:
                            Lex();
                            LibraryNode enode = ParseEnum();
                            globalnode.AddNode(enode);
                            break;

                        case (int)Token.LINE_COMMENT:
                            Lex();
                            break;

                        default:
                            SkipToEndOfTheLine();
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        if (parselogging)
                        {
                            logger.Log(filename + ": " + e.Message);
                        }
                        Lex();
                    }
                }
            }
            catch (Exception e)
            {
                if (parselogging)
                {
                    logger.Log("cannot read " + filename + ": " + e.Message);
                }
            }

            if (filenode.Children[0].Children.Count == 0)
            {
                filenode.RemoveNode(filenode.Children[0]);
            }

            globalnode.EndLine = end.line;
            globalnode.EndCol  = end.col;

            return(filenode);
        }