예제 #1
0
        public Tuple <string, string, ISymbol> GetType(TextEditor textEditor)
        {
            int position = textEditor.TextArea.Caret.Offset;

            string word = GetWordUnderMouse(textEditor.Document, textEditor.TextArea.Caret.Position);

            if (string.IsNullOrEmpty(word))
            {
                return(new Tuple <string, string, ISymbol>(null, null, null));
            }

            string FileName = SolutionToLoad; // "C:\\MSBuildProjects-beta\\VSExplorer\\VSExplorer.csproj";

            string filename = FileToLoad;     // "C:\\MSBuildProjects-beta\\VSExplorer\\ExplorerForms.cs";

            string content = StringReplace.Replace(textEditor.Document.Text);

            vp = vs.GetProjectbyCompileItem(FileToLoad);

            string file = null;

            if (vp != null)
            {
                file = vp.FileName;
            }

            ISymbol r = vs.GetSymbolAtLocation(vp, FileToLoad, position, content);

            if (word.Contains("."))
            {
                if (r != null)
                {
                    if (r.Kind == SymbolKind.Method)
                    {
                        return(new Tuple <string, string, ISymbol>(CSParsers.TypeToString(r.ContainingType), "", r));
                    }
                    else if (r.Kind == SymbolKind.Property)
                    {
                        IPropertySymbol ps = r as IPropertySymbol;
                        return(new Tuple <string, string, ISymbol>(CSParsers.TypeToString(ps.Type), "", r));
                    }
                    else if (r.Kind == SymbolKind.NamedType)
                    {
                        INamedTypeSymbol ps = r as INamedTypeSymbol;
                        return(new Tuple <string, string, ISymbol>(CSParsers.TypeToString(ps), "", r));
                    }
                }
            }
            else
            {
                if (r != null)
                {
                    if (r.Kind == SymbolKind.Method)
                    {
                        ISymbol containigType = r.ContainingType;

                        if (containigType != null)
                        {
                            if (containigType.Locations != null)
                            {
                                if (containigType.Locations[0] != null)
                                {
                                    if (containigType.Locations[0].IsInSource)
                                    {
                                        return(new Tuple <string, string, ISymbol>("", containigType.Locations[0].SourceTree.FilePath, r));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            List <INamespaceOrTypeSymbol> s = /*vp.*/ vs.GetAllTypes(file);

            word = word.ToLower();

            // var data = s.Select(bc => bc).Where(cd => cd.Name.ToLower().Contains(word)).ToList();

            foreach (INamespaceOrTypeSymbol b in s)
            {
                if (word.Contains("."))
                {
                }
                else if (b.Name.ToLower() == word)
                {
                    if (b.IsType)
                    {
                        if (b.Locations != null)
                        {
                            if (b.Locations[0] != null)
                            {
                                if (b.Locations[0].IsInSource)
                                {
                                    return(new Tuple <string, string, ISymbol>("", b.Locations[0].SourceTree.FilePath, b));
                                }
                            }
                        }
                        return(new Tuple <string, string, ISymbol>(CSParsers.TypeToString(b), "", b));
                    }
                }
            }
            return(new Tuple <string, string, ISymbol>("", "", null));
        }
예제 #2
0
        public void FindNextCalls(List <ReferencedSymbol> b, TreeViewItem v)
        {
            TreeViewItem v0 = CreateTreeViewItem(kind.method, "method");
            TreeViewItem v1 = CreateTreeViewItem(kind.folder, "folder");

            foreach (var s in b)
            {
                if (s.Locations != null)
                {
                    foreach (var pl in s.Locations)
                    {
                        if (!pl.Location.IsInSource)
                        {
                            continue;
                        }
                        SourceRefData d = new SourceRefData();
                        {
                            int    length = 10;
                            string cs     = pl.Location.SourceTree.GetRoot().GetText().ToString();
                            var    method = pl.Location.SourceTree.GetRoot().FindNode(pl.Location.SourceSpan).FirstAncestorOrSelf <BaseMethodDeclarationSyntax>();
                            {
                                if (method is ConstructorDeclarationSyntax)
                                {
                                    d.Offset = ((ConstructorDeclarationSyntax)method).Identifier.SpanStart;
                                    length   = ((ConstructorDeclarationSyntax)method).Identifier.Span.Length;
                                }
                                else if (method is DestructorDeclarationSyntax)
                                {
                                    d.Offset = ((DestructorDeclarationSyntax)method).Identifier.SpanStart;
                                    length   = ((DestructorDeclarationSyntax)method).Identifier.Span.Length;
                                }
                                else if (method is MethodDeclarationSyntax)
                                {
                                    d.Offset = ((MethodDeclarationSyntax)method).Identifier.SpanStart;
                                    length   = ((MethodDeclarationSyntax)method).Identifier.Span.Length;
                                }
                                else
                                {
                                    continue;
                                }

                                var lineNumber = cs.Take(d.Offset).Count(c => c == '\n');
                                d.name = cs.Split("\n".ToCharArray())[lineNumber].Trim();
                                d.Line = lineNumber.ToString();
                                d.Span = new Microsoft.CodeAnalysis.Text.TextSpan(lineNumber, length);
                            }
                        }
                        int Line  = pl.Location.GetLineSpan().StartLinePosition.Line;
                        var Lines = pl.Location.SourceTree.GetText().Lines;
                        d.Name = pl.Location.SourceTree.GetText().Lines[Line].ToString().Trim();

                        d.File     = Path.GetFileName(pl.Location.SourceTree.FilePath);
                        d.FileName = pl.Location.SourceTree.FilePath;
                        int    line = pl.Location.GetLineSpan().StartLinePosition.Line;
                        string bcs  = pl.Location.SourceTree.GetRoot().GetText().ToString();
                        line    -= StringReplace.FindExtended(bcs, pl.Location.SourceSpan.Start);
                        d.Line   = line.ToString();
                        d.Column = pl.Location.GetLineSpan().StartLinePosition.Character.ToString();
                        d.refs   = pl;
                        TreeViewItem v2 = CreateTreeViewItem(kind.none, d.name);
                        TreeViewItem v3 = CreateTreeViewItem(kind.folder, "Folder");
                        TreeViewItem v4 = CreateTreeViewItem(kind.folder, "Searching for calls");
                        v3.Items.Add(v4);
                        v2.Expanded += V3_Expanded;
                        v3.Tag       = d;
                        v2.Items.Add(v3);
                        v2.Tag       = d;
                        v2.Selected += V2_Selected;
                        v.Items.Add(v2);
                    }
                }
            }
        }
예제 #3
0
        public void LoadData(ISymbol symbol, List <ReferencedSymbol> b, VSSolution vs)
        {
            List <string> tw = editorWindow.GetTypesNames();
            List <string> kw = (List <string>)editorWindow.Words;

            object[] aw = new object[2];
            aw[0] = tw;
            aw[1] = kw;

            Dictionary <string, List <SourceData> > dict = new Dictionary <string, List <SourceData> >();

            //Sources.Clear();

            Sources = new ObservableCollection <Source>();

            Source c = new Source();

            c.Name = symbol.Name;

            List <SourceRefData> data = new List <SourceRefData>();

            // c.Data = data;

            foreach (var s in b)
            {
                if (s.Locations != null)
                {
                    foreach (var pl in s.Locations)
                    {
                        if (!pl.Location.IsInSource)
                        {
                            continue;
                        }
                        VSProject vp   = vs.GetProjectbyCompileItem(pl.Location.SourceTree.FilePath);
                        string    name = Path.GetFileNameWithoutExtension(vp.FileName);

                        if (dict.ContainsKey(name))
                        {
                            List <SourceData>    datasource = dict[name];
                            List <SourceRefData> dataref    = datasource[0].Data;
                            data = dataref;// dataref[0].Data;
                        }
                        else
                        {
                            c      = new Source();
                            c.Name = name;
                            List <SourceData> datasource = new List <SourceData>();
                            c.Data = datasource;
                            SourceData sourcedata = new SourceData();
                            sourcedata.Name = s.Definition.ToDisplayString();
                            datasource.Add(sourcedata);
                            List <SourceRefData> dataref = new List <SourceRefData>();
                            sourcedata.Data = dataref;

                            data = dataref;

                            dict.Add(name, datasource);

                            Sources.Add(c);
                        }

                        SourceRefData d     = new SourceRefData();
                        int           Line  = pl.Location.GetLineSpan().StartLinePosition.Line;
                        var           Lines = pl.Location.SourceTree.GetText().Lines;
                        d.Name = pl.Location.SourceTree.GetText().Lines[Line].ToString();
                        List <string> list  = new List <string>();
                        int           min   = Int32.MaxValue;
                        string        lines = "";
                        int           i     = Line - 3;
                        if (i < 0)
                        {
                            Line = 0;
                        }
                        while (i <= Line)
                        {
                            string loc = Lines[i].ToString();

                            loc = loc.Replace("\t", " ");
                            int pos = loc.TakeWhile(sa => char.IsWhiteSpace(sa)).Count();
                            if (pos < min)
                            {
                                min = pos;
                            }
                            //lines += Lines[i].ToString().TrimStart() + "\n";
                            list.Add(loc + "\n");
                            i++;
                        }
                        i = Line + 1;
                        while (i <= Line + 3 && i < Lines.Count - 1)
                        {
                            string loc = Lines[i].ToString();
                            loc = loc.Replace("\t", " ");
                            int pos = loc.TakeWhile(sa => char.IsWhiteSpace(sa)).Count();
                            if (pos < min)
                            {
                                min = pos;
                            }
                            list.Add(loc + "\n");
                            //lines += Lines[i].ToString().TrimStart() + "\n";
                            i++;
                        }
                        foreach (string st in list)
                        {
                            lines += " " + st.Substring(min, st.Length - min);
                        }
                        d.Lines    = lines;
                        d.Project  = Path.GetFileNameWithoutExtension(vp.FileName);
                        d.File     = Path.GetFileName(pl.Location.SourceTree.FilePath);
                        d.FileName = pl.Location.SourceTree.FilePath;
                        d.Words    = (object)aw;
                        int line = pl.Location.GetLineSpan().StartLinePosition.Line;
                        //line = editorWindow.textEditor.Document.GetLineByNumber(line).LineNumberExtended;

                        string cs = vs.GetSyntaxTreeText(pl.Location.SourceTree.FilePath);

                        line -= StringReplace.FindExtended(cs, pl.Location.SourceSpan.Start);

                        //int nw = StringReplace.FindExtended(cs, pl.Location.SourceSpan.Start);

                        d.Line   = line.ToString();
                        d.Column = pl.Location.GetLineSpan().StartLinePosition.Character.ToString();
                        d.refs   = pl;
                        data.Add(d);
                    }
                }
            }

            treeListView.ItemsSource = Sources;

            ExpandAll();
        }