public int FDoIdle(uint grfidlef)
        {
            bool bPeriodic = (grfidlef & (uint)_OLEIDLEF.oleidlefPeriodic) != 0;
            IOleComponentManager cmpMgr = (IOleComponentManager)Package.GetGlobalService(typeof(SOleComponentManager));

            if (bPeriodic && cmpMgr != null)
            {
                //var changes = FileUtilities.Instance.getCurrentTextSnapShot().Version.Changes;

                ////var changes = FileUtilities.Instance.GetIWpfTextView((string)document).TextSnapshot.Version.Changes;
                //if (changes != null)
                //{
                //    StaDynParser parser = new StaDynParser();
                //    parser.parseAll();
                //    SourceHelper.refreshHighlighting();
                //}

                Trace.WriteLine("Entering timer");

                StaDynParser parser = new StaDynParser();
                parser.parseAll();
                SourceHelper.refreshHighlighting();

                cmpMgr.FRevokeComponent(m_componentID);
            }

            return(0);
        }
Exemplo n.º 2
0
        void Connect_DocumentOpened(Document Document)
        {
            StaDynParser parser = new StaDynParser();

            parser.parseAll();
            //Document.Activate();
            SourceHelper.refreshHighlighting(Document.FullName);
        }
Exemplo n.º 3
0
        private void parseAndRefreshHighlingting()
        {
            StaDynParser parser = new StaDynParser();

            parser.parseAll();
            currentFile = ProjectFileAST.Instance.getAstFile(FileUtilities.Instance.getCurrentOpenDocumentFilePath());

            // if (parseResult == null || parseResult.Ast == null)

            SourceHelper.refreshHighlighting();
        }
Exemplo n.º 4
0
        //Other public methods

        #region DeclareExcplicit

        /// <summary>
        /// Modify var reference declaration changing from "var" to its actual type if possible.
        /// This method is public in order to be called by <see cref="CommandHandler.DeclareExplicitCommand"/>
        /// and <see cref="DeclareEverythingExplicitVisitor"/>.
        /// The operation will fail if the declaration has more than one type along its scope (counting as well
        /// types inside UnionType types).
        /// </summary>
        /// <param name="id">IdDeclaration node for the var reference declaration.</param>
        /// <param name="method">MethodDefinition node containing the var reference declaration.</param>
        /// <param name="buffer">IVsTextLines object containing document's content.</param>
        /// <param name="doc">TextDocument object for the document.</param>
        /// public void DeclareExplicit
        //public void DeclareExplicit(IdDeclaration id, MethodDefinition method, IVsTextLines buffer, TextDocument doc)
        //public void DeclareExplicit()
        //{

        //    int lineNumber = this.currentCaretPosition.X ;
        //    int column = this.currentCaretPosition.Y;
        //    var snapshot = FileUtilities.Instance.getCurrentTextSnapShot();
        //    int start = FileUtilities.Instance.getCurrentCaretPosition();

        //    StaDynVariablesInScopeTable infoVariablesInScope = StaDynIntellisenseHelper.Instance.getVariablesInCurrentScope(lineNumber +1, column, snapshot, start,true);

        //    string varName = ((IdDeclaration)foundNode).Identifier;

        //    var SSAVariablesList = new List<Declaration>();
        //    //Look for the same variable in the current scope
        //    for (int i = 0; i < infoVariablesInScope.Table.Count; i++)
        //    {
        //        if (infoVariablesInScope.Table[i].Count > 0)
        //        {
        //            foreach (KeyValuePair<string, IdDeclaration> variable in infoVariablesInScope.Table[i])
        //            {
        //                var type = variable.Value.TypeExpr;
        //                if (variable.Key.StartsWith(varName) && type is TypeVariable && ((TypeVariable)type).Substitution !=null)
        //                    SSAVariablesList.Add(variable.Value);

        //            }
        //        }
        //    }
        //    if (SSAVariablesList.Count !=1)
        //    {
        //         string message;
        //         if (SSAVariablesList.Count == 0)
        //             message = "The var reference named '" + varName +
        //             "' cannot be declared explicitly since it has no type yet\n";
        //         else
        //         {
        //             message = "The var reference named '" + varName +
        //                 "' cannot be declared explicitly since it has more than one type within its scope:\n";
        //             foreach (Declaration node in SSAVariablesList)
        //                 message += " - " + ((TypeVariable)node.TypeExpr).Substitution.FullName + "\n";
        //             message += "To be able to declare explicitly this reference, create a new type from which "
        //                 + "all this types will inherit";
        //         }
        //        MessageBox.Show(
        //            message,
        //            "Cannot declare explicit",
        //            MessageBoxButtons.OK, MessageBoxIcon.Information);
        //        return;
        //    }

        //    SourceHelper.replaceWord(snapshot, lineNumber, "var", ((TypeVariable)SSAVariablesList[0].TypeExpr).Substitution.FullName);

        //}

        #endregion

        #region GetAllTypes

        /// <summary>
        /// Get all types a reference has or may have along the method where it is declared.
        /// </summary>
        /// <param name="identifier">Name of the identifier.</param>
        /// <param name="method">Method where the identifier is declared.</param>
        /// <returns>Set of types assigned to the identifier. Types contained in
        /// UnionTypes are recursively inserted in the set.</returns>
        //public HashSet<TypeExpression> GetAllTypes(string identifier, MethodDefinition method)
        //{
        //    //Verify that the variable has only one type along the block
        //    //(Making use of SSA duplicated IdDeclaration nodes for that)

        //    //SearchInfo info = new SearchInfo(-1, -1, SearchReason.VarIdDeclarationSearch, StoreMode.StoreAll);
        //    //if (method != null)
        //    //    method.Accept(new SearchVisitor(), info);

        //    //HashSet<TypeExpression> types = new HashSet<TypeExpression>();
        //    //IdDeclaration id;
        //    //foreach (AstNode node in info.NodeList)
        //    //{
        //    //    id = node as IdDeclaration;
        //    //    if (id == null | !id.Identifier.Equals(identifier))
        //    //        continue;

        //    //    TypeVariable varType = id.TypeExpr as TypeVariable;
        //    //    TypeExpression substitutionType = varType != null ? varType.Substitution : null;
        //    //    if (substitutionType == null)
        //    //        continue;

        //    //    if (substitutionType is UnionType)
        //    //    {
        //    //        types.UnionWith(getTypesFromUnion(substitutionType as UnionType));
        //    //        continue;
        //    //    }

        //    //    types.Add(substitutionType);
        //    //}

        //    //return types;
        //}

        #endregion

        // Private methods

        #region searchDynVarInfo

        //private SearchInfo searchDynVarInfo()
        //{
        //    TokenInfo token = null;
        //    int line;
        //    int column;
        //    string tokenText = TextTools.GetCurrentTokenInfo(out token, out line, out column);

        //    StaDynLanguage lang = Package.GetGlobalService(typeof(StaDynLanguage)) as StaDynLanguage;

        //    DTE dte = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SDTE)) as DTE;
        //    StaDynScope scope = lang.GetParseResult(dte.ActiveDocument.FullName);

        //    TextTools.VsToInference(ref line, ref column);
        //    SearchInfo searchInfo = new SearchInfo(line, column, tokenText, SearchReason.AnyVarSearch, StoreMode.NamesAndNodes);
        //    scope.Ast.Accept(new SearchVisitor(), searchInfo);

        //    return searchInfo;
        //}

        #endregion

        #region  beforeQueryStatusCommonTasks

        /// <summary>
        /// Performs several tasks useful for the commands' BeforeQueryStatus handlers.
        /// Stores in lastSearchInfo information retrieved by <see cref="CommandHandler.searchDynVarInfo"/>.
        /// </summary>
        /// <param name="isStaDynFile">Active document is a ".stadyn" file.</param>
        /// <param name="isVar">Token at cursor's location is a var reference.</param>
        /// <param name="isDynamic">Token at cursor's location is a dynamic var reference.</param>
        private void beforeQueryStatusCommonTasks(out bool isStaDynFile, out bool isVar, out bool isDynamic)
        {
            isStaDynFile = isVar = isDynamic = false;

            isStaDynFile = FileUtilities.Instance.checkCurrentFileExtension(".stadyn");

            //Get the span of the current word (caret on)
            var currentWordTextSpan = SourceHelper.getCurrentTextSpan();

            this.currentCaretPosition.X = currentWordTextSpan.iStartLine;
            this.currentCaretPosition.Y = currentWordTextSpan.iEndIndex;

            int line   = currentWordTextSpan.iStartLine;
            int column = currentWordTextSpan.iEndIndex + 1;

            StaDynParser parser = new StaDynParser();

            parser.parseAll();
            currentFile = ProjectFileAST.Instance.getAstFile(FileUtilities.Instance.getCurrentOpenDocumentFilePath());

            if (currentFile == null || currentFile.Ast == null)
            {
                return;
            }
            //string currentWord = SourceHelper.getCurrentWord();
            //this.foundNode = (AstNode)currentFile.Ast.Accept(new VisitorFindNode(), new Location(Path.GetFileName(currentFile.FileName), line + 1, column));
            this.foundNode = (AstNode)currentFile.Ast.Accept(new VisitorFindNode(), new Location(currentFile.FileName, line + 1, column));

            if (foundNode is Declaration)
            {
                //Declaration dec = foundNode as Declaration;

                IdDeclaration idDec = foundNode as IdDeclaration;

                isVar = idDec.TypeExpr is TypeVariable;

                isDynamic = StaDynDynamicHelper.Instance.checkDynamicVar(idDec.Identifier, line, column, currentFile);
                //isDynamic = idDec.TypeExpr.IsDynamic;
            }
        }
Exemplo n.º 5
0
        public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures)
        {
            ITextSnapshot snapshot = m_textBuffer.CurrentSnapshot;
            int           position = session.GetTriggerPoint(m_textBuffer).GetPosition(snapshot);

            ITrackingSpan applicableToSpan = m_textBuffer.CurrentSnapshot.CreateTrackingSpan(
                new Span(position, 0), SpanTrackingMode.EdgeInclusive, 0);

            //First try to get a compilable source code
            snapshot = snapshot.TextBuffer.Insert(position, "();");
            Span spanToRemove = new Span(position, 3);

            //StaDynParser parser = new StaDynParser(snapshot.TextBuffer, FileUtilities.Instance.getCurrentOpenDocumentFilePath());

            ////Parse source
            //StaDynSourceFileAST parseResult = parser.parseSource();

            //parseResult = DecorateAST.Instance.completeDecorateAndUpdate(parseResult);
            StaDynParser parser = new StaDynParser();

            parser.parseAll();
            StaDynSourceFileAST parseResult = ProjectFileAST.Instance.getAstFile(FileUtilities.Instance.getCurrentOpenDocumentFilePath());

            if (parseResult == null || parseResult.Ast == null)
            {
                snapshot = snapshot.TextBuffer.Delete(spanToRemove);
                return;
            }

            System.Drawing.Point caretPosition = FileUtilities.Instance.getCurrentCaretPoint();

            int column = caretPosition.Y;
            int line   = caretPosition.X + 1;

            //AstNode foundNode = (AstNode)parseResult.Ast.Accept(new VisitorFindNode(), new Location(Path.GetFileName(parseResult.FileName), line, column));
            AstNode foundNode = (AstNode)parseResult.Ast.Accept(new VisitorFindNode(), new Location(parseResult.FileName, line, column));

            //Signature help is not needed on method definition
            if (foundNode is MethodDefinition)
            {
                snapshot = snapshot.TextBuffer.Delete(spanToRemove);
                return;
            }
            AstNode lastInvocationNode = StaDynIntellisenseHelper.Instance.getCurrentInvocation(parseResult, snapshot, position, line, column);

            //StaDynSourceFileAST file = ProjectFileAST.Instance.getAstFile(FileUtilities.Instance.getCurrentOpenDocumentFilePath());
            //if (file.Ast == null) return ;
            //AstNode foundNode = (AstNode)file.Ast.Accept(new VisitorFindNode(), new Location(Path.GetFileName(file.FileName), line, column));
            //Remove added chars
            snapshot = snapshot.TextBuffer.Delete(spanToRemove);

            if (lastInvocationNode == null)
            {
                return;
            }

            this.createSignatures(lastInvocationNode, m_textBuffer, applicableToSpan, signatures);

            /*****************************************/

            //signatures.Add(CreateSignature(m_textBuffer, "add(int firstInt, int secondInt)", "Documentation for adding integers.", applicableToSpan));
            //signatures.Add(CreateSignature(m_textBuffer, "add(double firstDouble, double secondDouble)", "Documentation for adding doubles.", applicableToSpan));
        }