Esempio n. 1
0
        private AspNetTag GetAspNetTag(string text)
        {
            text = CSharpFormattingTools.RemoveUnwantedText(text);

            string[] split1 = text.Split('<');
            string[] split2 = split1[split1.Length - 1].Split('>');
            string   tag    = split2[0];

            AspNetTag aspNetTag = new AspNetTag(text);

            if (split2.Length > 1)
            {
                return(null);
            }

            /*
             * Check tag is ASP.NET and get the type.
             */

            Regex re = new Regex(@"^/?(\w+):(\w*)(\s*)");
            Match m  = re.Match(tag);

            if (m.Success)
            {
                aspNetTag.TagPrefix      = m.Groups[1].Value;
                aspNetTag.LookAhead      = m.Groups[2].Value;
                aspNetTag.ClosingTag     = tag.StartsWith("/");
                aspNetTag.WantAttributes =
                    m.Groups[3].Value != String.Empty;

                return(aspNetTag);
            }

            return(null);
        }
        private void ColourizeVariablesAndTypes(
            QuickSharp.Editor.ScintillaEditForm document)
        {
            string source = document.GetContent() as string;

            source = CSharpFormattingTools.RemoveUnwantedText(source);
            source = CSharpFormattingTools.RemoveUnwantedBracketText(source);

            List <string> namespaces = GetNamespaceList(source);

            if (settingsManager.ColorizeTypes)
            {
                // Lexer WORD2 - types

                List <string> assemblies = new List <string>();

                foreach (string ns in namespaces)
                {
                    List <string> names =
                        referenceManager.GetNamespaceAssemblies(ns);

                    foreach (string name in names)
                    {
                        if (!assemblies.Contains(name))
                        {
                            assemblies.Add(name);
                        }
                    }
                }

                assemblies.AddRange(workspaceAssemblyList);

                document.Editor.Lexing.Keywords[1] =
                    "Array Boolean Date Enumerator Error Function Number Object RegExp String VBArray " +
                    CodeAssistTools.GetNamespaceTypesAsString(
                        namespaces, assemblies);
            }

            if (settingsManager.ColorizeVariables)
            {
                // Lexer GLOBALCLASS - variables
                DeclaredVariables declaredVariables =
                    new DeclaredVariables(source, fullNamespaceList, false);

                StringBuilder sb = new StringBuilder();

                foreach (Variable v in declaredVariables.Items)
                {
                    sb.Append(v.Name);
                    sb.Append(" ");
                }

                document.Editor.Lexing.Keywords[3] = sb.ToString();
            }

            document.Editor.Lexing.Colorize();
        }
Esempio n. 3
0
        public LookupContext(string fullSource, string preSource,
                             string line, int lineStartPos, int currentPos, bool insideClass)
        {
            _fullSource   = fullSource;
            _preSource    = preSource;
            _line         = line;
            _lineStartPos = lineStartPos;
            _currentPos   = currentPos;
            _beforeClass  = insideClass;

            /*
             * Cleanup the source code.
             */

            _preSource = CSharpFormattingTools.RemoveUnwantedText(_preSource);
            _preSource = CSharpFormattingTools.RemoveUnwantedBracketText(_preSource);
            _line      = CSharpFormattingTools.RemoveUnwantedText(_line);
            _line      = CSharpFormattingTools.RemoveUnwantedBracketText(_line);

            /*
             * Get rid of 'global::' - we don't do anything with them
             * so we might as well not have them.
             */

            _line = _line.Replace("global::", String.Empty);

            /*
             * We remove the content of any balanced brackets to
             * allow indexed variables to identified and classified.
             */

            _line = CSharpFormattingTools.RemoveUnwantedParentheses(Line);

            /*
             * Create the target.
             */

            _target = new LookupTarget(_line);

            /*
             * Find the visible methods and properties.
             */

            _localMethods    = new LocalMethods(_fullSource);
            _localProperties = new LocalProperties(_fullSource);
        }
        private void ColourizeVariablesAndTypes(ScintillaEditForm document)
        {
            string source = CSharpFormattingTools.
                            RemoveUnwantedText(document.GetContent() as string);

            source = CSharpFormattingTools.
                     RemoveUnwantedBracketText(source);

            List <string> namespaces = GetNamespaceList(source);

            if (settingsManager.ColorizeTypes)
            {
                /*
                 * Lexer WORD2 - types
                 */

                List <string> assemblies = new List <string>();

                foreach (string ns in namespaces)
                {
                    List <string> names =
                        referenceManager.GetNamespaceAssemblies(ns);

                    foreach (string name in names)
                    {
                        if (!assemblies.Contains(name))
                        {
                            assemblies.Add(name);
                        }
                    }
                }

                assemblies.AddRange(workspaceAssemblyList);

                document.Editor.Lexing.Keywords[1] =
                    CodeAssistTools.GetNamespaceTypesAsString(
                        namespaces, assemblies);
            }

            if (settingsManager.ColorizeVariables)
            {
                /*
                 * Lexer GLOBALCLASS - variables
                 */

                DeclaredVariables declaredVariables =
                    new DeclaredVariables(
                        source, namespaces, false,
                        DeclarationContext.All);

                InheritedVariablesBase inheritedVariables
                    = new InheritedVariablesCode(
                          source,
                          DeclarationContext.All,
                          workspaceAssemblyList,
                          fullNamespaceList,
                          rootNamespaceList,
                          configNamespaceList);

                StringBuilder sb = new StringBuilder();

                foreach (Variable v in declaredVariables.Items)
                {
                    sb.Append(v.Name);
                    sb.Append(" ");
                }

                foreach (Variable v in inheritedVariables.Items)
                {
                    sb.Append(v.Name);
                    sb.Append(" ");
                }

                document.Editor.Lexing.Keywords[3] = sb.ToString();
            }

            document.Editor.Lexing.Colorize();
        }
        protected string GetFullSource(string text, ref int pos)
        {
            /*
             * This is pretty crude - it just attempts to remove
             * class definitions outside the current one from
             * the text so that we don't get out of scope methods
             * and properties showing up. It will also get confused
             * by nested classes - the scope of the current class will start
             * at the beginning of the last nested class before the caret.
             *
             * We also need to preserve the current cursor location within
             * the source so that the method/property and declaration
             * context detection will work correctly.
             */

            text = text.Insert(pos, "¬¬");
            text = CSharpFormattingTools.RemoveUnwantedText(text);

            pos = text.IndexOf("¬¬");
            if (pos == -1)
            {
                return(String.Empty);
            }

            string src1 = text.Substring(0, pos);
            string src2 = text.Substring(pos);

            int start = src1.LastIndexOf("class ");
            int end   = src2.IndexOf("class ");

            if (start != -1)
            {
                src1 = src1.Substring(start);
            }

            if (end != -1)
            {
                src2 = src2.Substring(0, end);
            }

            text = src1 + src2;

            pos = text.IndexOf("¬¬");

            text = text.Replace("¬¬", String.Empty);

            /*
             * Find the location of the closing '}'.
             */

            int i          = 0;
            int braceLevel = 0;

            while (i < text.Length && text[i] != '{')
            {
                i++;
            }

            while (i < text.Length)
            {
                if (text[i] == '{')
                {
                    braceLevel++;
                }
                if (text[i] == '}')
                {
                    braceLevel--;
                }

                if (braceLevel == 0)
                {
                    break;
                }

                i++;
            }

            return(text.Substring(0, i));
        }