// Returns the nearest node to the cursor position. If the node has child nodes returns the nearest child node. public static TexlNode FindNode(TexlNode rootNode, int cursorPosition) { Contracts.AssertValue(rootNode); Contracts.Assert(cursorPosition >= 0); return(FindNodeVisitor.Run(rootNode, cursorPosition)); }
protected ResolveResult Resolve(string code) { CompilationUnit cu = new CSharpParser().Parse(new StringReader(code.Replace("$", "")), "code.cs"); TextLocation[] dollars = FindDollarSigns(code).ToArray(); Assert.AreEqual(2, dollars.Length, "Expected 2 dollar signs marking start+end of desired node"); SetUp(); CSharpParsedFile parsedFile = cu.ToTypeSystem(); project = project.UpdateProjectContent(null, parsedFile); compilation = project.CreateCompilation(); FindNodeVisitor fnv = new FindNodeVisitor(dollars[0], dollars[1]); cu.AcceptVisitor(fnv, null); Assert.IsNotNull(fnv.ResultNode, "Did not find DOM node at the specified location"); Debug.WriteLine(new string('=', 70)); Debug.WriteLine("Starting new resolver for " + fnv.ResultNode); CSharpAstResolver resolver = new CSharpAstResolver(compilation, cu, parsedFile); ResolveResult rr = resolver.Resolve(fnv.ResultNode); Assert.IsNotNull(rr, "ResolveResult is null - did something go wrong while navigating to the target node?"); Debug.WriteLine("ResolveResult is " + rr); return(rr); }
protected ResolveResult Resolve(string code) { CompilationUnit cu = new CSharpParser().Parse(new StringReader(code.Replace("$", ""))); TextLocation[] dollars = FindDollarSigns(code).ToArray(); Assert.AreEqual(2, dollars.Length, "Expected 2 dollar signs marking start+end of desired node"); SetUp(); CSharpParsedFile parsedFile = new CSharpParsedFile("test.cs", resolver.CurrentUsingScope); TypeSystemConvertVisitor convertVisitor = new TypeSystemConvertVisitor(parsedFile, resolver.CurrentUsingScope, null); cu.AcceptVisitor(convertVisitor, null); project.UpdateProjectContent(null, convertVisitor.ParsedFile); FindNodeVisitor fnv = new FindNodeVisitor(dollars[0], dollars[1]); cu.AcceptVisitor(fnv, null); Assert.IsNotNull(fnv.ResultNode, "Did not find DOM node at the specified location"); Debug.WriteLine(new string('=', 70)); Debug.WriteLine("Starting new resolver for " + fnv.ResultNode); var navigator = new NodeListResolveVisitorNavigator(new[] { fnv.ResultNode }); ResolveResult rr; using (var context = this.context.Synchronize()) { ResolveVisitor rv = new ResolveVisitor(new CSharpResolver(context), convertVisitor.ParsedFile, navigator); rv.Scan(cu); rr = rv.GetResolveResult(fnv.ResultNode); } Assert.IsNotNull(rr, "ResolveResult is null - did something go wrong while navigating to the target node?"); Debug.WriteLine("ResolveResult is " + rr); return(rr); }
protected AstNode FindNode(SyntaxTree syntaxTree, TextLocation start, TextLocation end) { FindNodeVisitor fnv = new FindNodeVisitor(start, end); syntaxTree.AcceptVisitor(fnv); Assert.IsNotNull(fnv.ResultNode, "Did not find DOM node at the specified location"); return(fnv.ResultNode); }
protected AstNode FindNode(CompilationUnit cu, TextLocation start, TextLocation end) { FindNodeVisitor fnv = new FindNodeVisitor(start, end); cu.AcceptVisitor(fnv); Assert.IsNotNull(fnv.ResultNode, "Did not find DOM node at the specified location"); return(fnv.ResultNode); }
protected Tuple <CSharpAstResolver, AstNode> PrepareResolver(string code) { CompilationUnit cu = new CSharpParser().Parse(new StringReader(code.Replace("$", "")), "code.cs"); TextLocation[] dollars = FindDollarSigns(code).ToArray(); Assert.AreEqual(2, dollars.Length, "Expected 2 dollar signs marking start+end of desired node"); SetUp(); CSharpParsedFile parsedFile = cu.ToTypeSystem(); project = project.UpdateProjectContent(null, parsedFile); compilation = project.CreateCompilation(); FindNodeVisitor fnv = new FindNodeVisitor(dollars[0], dollars[1]); cu.AcceptVisitor(fnv, null); Assert.IsNotNull(fnv.ResultNode, "Did not find DOM node at the specified location"); CSharpAstResolver resolver = new CSharpAstResolver(compilation, cu, parsedFile); return(Tuple.Create(resolver, fnv.ResultNode)); }