private static Declarations ExecuteGetDeclarations(string lineText, IScanner scanner, IServiceProvider site) { // Create the authoring scope. ParseRequest request = new ParseRequest(false); request.Reason = ParseReason.DisplayMemberList; AuthoringScope scope = ConsoleAuthoringScope.CreateScope(request); Assert.IsNotNull(scope); // Create a mock IConsoleText BaseMock mockConsoleText = MockFactories.ConsoleTextFactory.GetInstance(); mockConsoleText.AddMethodReturnValues( string.Format("{0}.{1}", typeof(IConsoleText).FullName, "TextOfLine"), new object[] { lineText }); ConsoleAuthoringScope.PythonConsole = mockConsoleText as IConsoleText; // Create a language service. TestLanguage language = new TestLanguage(); // Set the scanner for this language. language.MockScanner = scanner; ConsoleAuthoringScope.Language = language; // Set the site for the scope. ConsoleAuthoringScope.Site = site; // Create the view and token info to call the scope. IVsTextView view = MockFactories.TextViewFactory.GetInstance() as IVsTextView; TokenInfo tokenInfo = new TokenInfo(); return(scope.GetDeclarations(view, 0, 0, tokenInfo, ParseReason.DisplayMemberList)); }
private static bool Parse(DomElement parentElement, AuthoringScope authoringScope, string text, Regex regex, TextBlockModifier expectedModifier) { Match match = regex.Match(text); if (match.Success) { // // Parsing prefix... ParsePrefix(parentElement, authoringScope, text, match); // // ...text block itself... TextBlock textBlock = new TextBlock(parentElement, CreateInlineElementAttributes(match), match.Groups["Text"].Value, expectedModifier); parentElement.AppendChild(textBlock); // // ...and finally parse suffux ParseSuffix(parentElement, authoringScope, text, match); return(true); } // if return(false); }
/// <summary> /// Parses <paramref name="text"/> which is the child of <paramref name="parentElement"/> in /// accordance with <paramref name="authoringScope"/>. /// </summary> /// <param name="parentElement">Parent DOM element.</param> /// <param name="authoringScope">Authoring scope.</param> /// <param name="text">The text to be parsed.</param> public override void Parse(DomElement parentElement, AuthoringScope authoringScope, string text) { if (Parse(parentElement, authoringScope, text, StrongEmphasisRegex, TextBlockModifier.StrongEmphasis)) { return; } if (Parse(parentElement, authoringScope, text, ItalicsRegex, TextBlockModifier.Italics)) { return; } if (Parse(parentElement, authoringScope, text, EmphasisRegex, TextBlockModifier.Emphasis)) { return; } if (Parse(parentElement, authoringScope, text, BoldRegex, TextBlockModifier.Bold)) { return; } if (Parse(parentElement, authoringScope, text, CitationRegex, TextBlockModifier.Citation)) { return; } if (Parse(parentElement, authoringScope, text, DeletedRegex, TextBlockModifier.Deleted)) { return; } if (Parse(parentElement, authoringScope, text, InsertedRegex, TextBlockModifier.Inserted)) { return; } if (Parse(parentElement, authoringScope, text, SuperscriptRegex, TextBlockModifier.Superscript)) { return; } if (Parse(parentElement, authoringScope, text, SubscriptRegex, TextBlockModifier.Subscript)) { return; } if (Parse(parentElement, authoringScope, text, SpanRegex, TextBlockModifier.Unknown)) { return; } parentElement.AppendChild(new TextBlock(parentElement, InlineElementAttributes.Empty, text, TextBlockModifier.Unknown)); }
public void GetMethodsTest() { // This method is not implemented, so the only check is that it does not // crashes and that returns null. ParseRequest request = new ParseRequest(false); request.Reason = ParseReason.DisplayMemberList; AuthoringScope scope = ConsoleAuthoringScope.CreateScope(request); Assert.IsNotNull(scope); Assert.IsNull(scope.GetMethods(0, 0, "")); }
/// <summary> /// Handles the Goto-command. /// We have to do that synchronous as the default async-operation SOMETIMES doesn't work due to internal error (Win32Exception: "Invalid window handle") /// </summary> /// <param name="cmd">The command id.</param> public override void HandleGoto(VsCommands cmd) { //we handle only th goto-definition command if (cmd != VsCommands.GotoDefn) { base.HandleGoto(cmd); return; } int line, col; // Get the caret position Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(TextView.GetCaretPos(out line, out col)); //parse the source synchronous AuthoringScope scope = Source.LanguageService.ParseSource(new ParseRequest(line, col, new TokenInfo(), Source.GetText(), Source.GetFilePath(), ParseReason.Goto, TextView, Source.CreateAuthoringSink(ParseReason.Goto, line, col), true)); //navigate to the found position string url = null; TextSpan span; if (scope != null) { url = scope.Goto(cmd, TextView, line, col, out span); } else { return; } if (url == null || url.Trim().Length == 0) // nothing to show { return; } // Open the referenced document, and scroll to the given location. IVsUIHierarchy hierarchy; uint itemID; IVsWindowFrame frame; IVsTextView view; Microsoft.VisualStudio.Shell.VsShellUtilities.OpenDocument(base.Source.LanguageService.Site, url, VSConstants.LOGVIEWID_Code, out hierarchy, out itemID, out frame, out view); if (view != null) { TextSpanHelper.MakePositive(ref span); Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(view.EnsureSpanVisible(span)); Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(view.SetSelection(span.iStartLine, span.iStartIndex, span.iEndLine, span.iEndIndex)); } }
public void GotoTest() { // This method is not implemented, so the only check is that it does not // crashes and that returns null. ParseRequest request = new ParseRequest(false); request.Reason = ParseReason.DisplayMemberList; AuthoringScope scope = ConsoleAuthoringScope.CreateScope(request); Assert.IsNotNull(scope); TextSpan span; Assert.IsNull(scope.Goto( Microsoft.VisualStudio.VSConstants.VSStd97CmdID.ClearPane, null, 0, 0, out span)); }
public void GetDeclarationsNullView() { // Create the authoring scope. ParseRequest request = new ParseRequest(false); request.Reason = ParseReason.DisplayMemberList; AuthoringScope scope = ConsoleAuthoringScope.CreateScope(request); Assert.IsNotNull(scope); // Create a mock IConsoleText BaseMock mockConsoleText = MockFactories.ConsoleTextFactory.GetInstance(); mockConsoleText.AddMethodReturnValues( string.Format("{0}.{1}", typeof(IConsoleText).FullName, "TextOfLine"), new object[] { "dte." }); ConsoleAuthoringScope.PythonConsole = mockConsoleText as IConsoleText; // Creeate a TokenInfo TokenInfo tokenInfo = new TokenInfo(); // Call GetDeclarations. bool exceptionThrown = false; try { scope.GetDeclarations(null, 0, 0, tokenInfo, ParseReason.DisplayMemberList); } catch (ArgumentNullException) { exceptionThrown = true; } catch (System.Reflection.TargetInvocationException e) { ArgumentNullException inner = e.InnerException as ArgumentNullException; if (null != inner) { exceptionThrown = true; } } Assert.IsTrue(exceptionThrown); }
public void GetDeclarationsNullText() { // Create a mock IConsoleText that will return null on TextOfLine. IConsoleText consoleText = MockFactories.ConsoleTextFactory.GetInstance() as IConsoleText; ConsoleAuthoringScope.PythonConsole = consoleText; // Create the authoring scope. ParseRequest request = new ParseRequest(false); request.Reason = ParseReason.DisplayMemberList; AuthoringScope scope = ConsoleAuthoringScope.CreateScope(request); Assert.IsNotNull(scope); // Create object with not null value for the parameters. IVsTextView view = MockFactories.TextViewFactory.GetInstance() as IVsTextView; TokenInfo tokenInfo = new TokenInfo(); // Call GetDeclarations. Declarations declarations = scope.GetDeclarations(view, 0, 0, tokenInfo, ParseReason.DisplayMemberList); Assert.IsTrue(0 == declarations.GetCount()); }
internal AuthoringScopeWrapper() { _data = new AuthoringScope(); }
/// <summary> /// Authors Textile <paramref name="source"/> and returns text which is /// formatted according to <paramref name="authoringScope"/>. /// </summary> /// <param name="source"></param> /// <param name="authoringScope"></param> /// <returns></returns> public String Author(String source, AuthoringScope authoringScope) { return(source); }