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

            parser.parseAll();
            //Document.Activate();
            SourceHelper.refreshHighlighting(Document.FullName);
        }
Exemplo n.º 2
0
        public int OnAfterSave(uint docCookie)
        {
            //StaDynParser parser = new StaDynParser();
            //parser.parseAll();

            SourceHelper.refreshHighlighting();

            //Must save file again because refreshHighlighting "dirties" the code.
            string file = FileUtilities.Instance.getCurrentOpenDocumentFilePath();

            FileUtilities.Instance.SaveDocument(file);

            return(VSConstants.S_OK);
        }
Exemplo n.º 3
0
        public static void DeclareExplicit(AstNode node, bool showMessageBox)
        {
            if (!(node is IdDeclaration))
            {
                return;
            }

            string varName    = ((IdDeclaration)node).Identifier;
            int    lineNumber = node.Location.Line;
            int    column     = node.Location.Column;

            var snapshot = FileUtilities.Instance.getCurrentTextSnapShot();

            //if (node is Definition) {
            //  if (((Definition)node).FrozenTypeExpression != null) {
            //    SourceHelper.replaceWord(snapshot, lineNumber - 1, "var", ((Definition)node).FrozenTypeExpression.FullName);
            //    return;
            //  }
            //}


            // int start = FileUtilities.Instance.getCurrentCaretPosition();
            int start = FileUtilities.Instance.getPositionFromSpan(lineNumber - 1, column);
            StaDynVariablesInScopeTable infoVariablesInScope = StaDynIntellisenseHelper.Instance.getVariablesInCurrentScope(lineNumber + 1, column, snapshot, start, true);

            //var SSAVariablesList = new List<Declaration>();
            var substitutionTypes = new HashSet <TypeExpression>();

            //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])
                    {
                        //string SSAVarName="";
                        //var type = variable.Value.TypeExpr;

                        var type = ((Declaration)variable.Value).ILTypeExpression;

                        //if(variable.Key.Length>varName.Length)
                        //    SSAVarName = variable.Key.Substring(0, varName.Length);
                        //if (variable.Key.StartsWith(varName) && type is TypeVariable && ((TypeVariable)type).Substitution != null)

                        //if (SSAVarName.Equals(varName) && type is TypeVariable)
                        if (variable.Value.Identifier == varName && type != null)
                        {
                            //SSAVariablesList.Add(variable.Value);
                            substitutionTypes.UnionWith(TypeSystemHelper.Instance.getSubstitutionType(type));
                        }
                    }
                }
            }
            //if (SSAVariablesList.Count != 1)
            if (substitutionTypes.Count != 1)
            {
                string message;
                if (substitutionTypes.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 (TypeExpression type in substitutionTypes)
                    {
                        message += " - " + type.FullName + "\n";
                    }
                    message += "To be able to declare explicitly this reference, create a new type from which "
                               + "all this types will inherit";
                }

                Trace.WriteLine(message);

                if (showMessageBox)
                {
                    MessageBox.Show(
                        message,
                        "Cannot declare explicit",
                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                return;
            }

            ////var t = substitutionTypes.ElementAt(0);
            //TypeExpression t= substitutionTypes.ToList()[0];
            //string description = t.AcceptOperation(new GetTypeSystemName(), null) as string;
            //var changeType = description.Split(':');

            //SourceHelper.replaceWord(snapshot, lineNumber - 1, "var", changeType[changeType.Length -1]);
            SourceHelper.replaceWord(snapshot, lineNumber - 1, "var", substitutionTypes.ElementAt(0).FullName);
        }