简体   繁体   中英

Get current source file methods in Visual Studio Text Editor Extension

I try to write extension for Visual Studio, but I can't find documentation about my question. In SDK examples only for some things like text hightliting, but no any example which demostrate how directly work with Intelliscense. Documentations from MSDN - also not good. It is possible - get list of all methods from current opened source file, if I have IWpfTextView?

It is possible - get list of all methods from current opened source file, if I have IWpfTextView?

You can get list of all methods via CodeElement and check if it a CodeFunction object. The following code for your reference.

You can get current opened source file via DTE.ActiveDocument

DTE2 dte = this.ServiceProvider.GetService(typeof(DTE)) as DTE2;
            FileCodeModel fcm = dte.ActiveDocument.ProjectItem.FileCodeModel as FileCodeModel;
            foreach (CodeElement element in fcm.CodeElements)
            {
                if (element is CodeNamespace)
                {
                    CodeNamespace nsp = element as CodeNamespace;

                    foreach (CodeElement subElement in nsp.Children)
                    {
                        if (subElement is CodeClass)
                        {
                            CodeClass c2 = subElement as CodeClass;
                            foreach (CodeElement item in c2.Children)
                            {
                                if (item is CodeFunction)
                                {
                                    CodeFunction cf = item as CodeFunction;
                                    MessageBox.Show(cf.Name);
                                }
                            }
                        }
                    }
                }
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM