public override void Execute() { rm = new ResourceManager(typeof(Resources)); System.Diagnostics.Debug.WriteLine("Get Functions"); IEnumerable <ISyntaxEntity> functions = new List <ISyntaxEntity>(); CodeFile codeFile; //Getting the code text from the active document var path = TalkCodePackage.vsOperations.GetActiveDocumentPath(); var codeText = TalkCodePackage.vsOperations.GetActiveDocumentCode(); //Creating a language service var lService = new Language(path); try { //Parsing the code codeFile = lService.Parse(codeText, path); } catch (CodeTalkLanguageServiceException) { MessageBox.Show(rm.GetString("CompilationErrorMessage", CultureInfo.CurrentCulture), rm.GetString("CodeTalkString", CultureInfo.CurrentCulture), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //Creating a function collector for getting all the functions var functionCollector = new FunctionCollector(); functionCollector.VisitCodeFile(codeFile); //Getting all the functions functions = functionCollector.FunctionsInFile; if (0 == functions.Count()) { MessageBox.Show(rm.GetString("NoFunctionsString", CultureInfo.CurrentCulture), rm.GetString("CodeTalkString", CultureInfo.CurrentCulture), MessageBoxButtons.OK); return; } ToolWindowPane listFunctionsWindow = TalkCodePackage.currentPackage.FindToolWindow(typeof(AccessibilityToolWindow), 0, true); if ((null == listFunctionsWindow) || (null == listFunctionsWindow.Frame)) { throw new NotSupportedException("Cannot create tool window"); } IVsWindowFrame windowFrame = (IVsWindowFrame)listFunctionsWindow.Frame; windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_Caption, rm.GetString("FunctionsListTitle", CultureInfo.CurrentCulture)); Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show()); (listFunctionsWindow as AccessibilityToolWindow).windowControl.SetListView(functions, rm.GetString("FunctionsListTitle", CultureInfo.CurrentCulture)); }
public void CollectFunctionsTest() { Trace.Listeners.Add(new ConsoleTraceListener()); CSharp obj = new CSharp(); CodeFile cf = obj.Parse(System.IO.File.ReadAllText(@".\Programs\CSharp\NestedClasses.txt"), @".\Programs\CSharp\NestedClasses.txt"); FunctionCollector collector = new FunctionCollector(); collector.Visit(cf); foreach (var function in collector.FunctionsInFile) { Trace.WriteLine(obj.SpokenText(function)); } }
public IEnumerable <ISyntaxEntity> GetFunctions() { ResourceManager rm = new ResourceManager(typeof(Resources)); System.Diagnostics.Debug.WriteLine("Get Functions"); IEnumerable <ISyntaxEntity> functions = new List <ISyntaxEntity>(); CodeFile codeFile; //Getting the code text from the active document var path = TalkCodePackage.vsOperations.GetActiveDocumentPath(); var codeText = TalkCodePackage.vsOperations.GetActiveDocumentCode(); //Creating a language service var lService = new Language(path); try { //Parsing the code codeFile = lService.Parse(codeText, path); } catch (CodeTalkLanguageServiceException) { MessageBox.Show(rm.GetString("CompilationErrorMessage", CultureInfo.CurrentCulture), rm.GetString("CodeTalkString", CultureInfo.CurrentCulture), MessageBoxButtons.OK, MessageBoxIcon.Error); return(functions); } //Creating a function collector for getting all the functions var functionCollector = new FunctionCollector(); functionCollector.VisitCodeFile(codeFile); //Getting all the functions functions = functionCollector.FunctionsInFile; return(functions); }