public ResolveResult ResolveAtLocation(TextLocation location, CancellationToken cancellationToken = default(CancellationToken)) { int offset = textDocument.GetOffset(location); var line = textDocument.GetLineByNumber(location.Line); if (offset == line.EndOffset) { return(ErrorResolveResult.UnknownError); } if (char.IsWhiteSpace(textDocument.GetCharAt(offset))) { return(ErrorResolveResult.UnknownError); } AXmlObject innermost = parseInfo.Document.GetChildAtOffset(offset); if (innermost is AXmlText) { return(ResolveText((AXmlText)innermost, cancellationToken)); } if (innermost is AXmlTag) { return(ResolveTag((AXmlTag)innermost, cancellationToken)); } if (innermost is AXmlElement) { return(ResolveElement((AXmlElement)innermost, cancellationToken)); } if (innermost is AXmlAttribute) { return(ResolveAttribute((AXmlAttribute)innermost, offset, cancellationToken)); } return(ErrorResolveResult.UnknownError); }
internal static IParameterDataProvider CreateProvider(string text) { string parsedText; string editorText; int cursorPosition = text.IndexOf('$'); int endPos = text.IndexOf('$', cursorPosition + 1); if (endPos == -1) { parsedText = editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1); } else { parsedText = text.Substring(0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring(endPos + 1); editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring(endPos + 1); cursorPosition = endPos - 1; } var doc = new ReadOnlyDocument(editorText); IProjectContent pctx = new CSharpProjectContent(); pctx = pctx.AddAssemblyReferences(new [] { CecilLoaderTests.Mscorlib, CecilLoaderTests.SystemCore }); var compilationUnit = new CSharpParser().Parse(parsedText, "program.cs"); var parsedFile = compilationUnit.ToTypeSystem(); pctx = pctx.UpdateProjectContent(null, parsedFile); var cmp = pctx.CreateCompilation(); var loc = doc.GetLocation(cursorPosition); var engine = new CSharpParameterCompletionEngine(doc, new TestFactory(pctx)); var rctx = new CSharpTypeResolveContext(cmp.MainAssembly); rctx = rctx.WithUsingScope(parsedFile.GetUsingScope(loc).Resolve(cmp)); var curDef = parsedFile.GetInnermostTypeDefinition(loc); if (curDef != null) { rctx = rctx.WithCurrentTypeDefinition(curDef.Resolve(rctx).GetDefinition()); var curMember = parsedFile.GetMember(loc); if (curMember != null) { rctx = rctx.WithCurrentMember(curMember.CreateResolved(rctx)); } } engine.ctx = rctx; engine.CSharpParsedFile = parsedFile; engine.ProjectContent = pctx; engine.Unit = compilationUnit; return(engine.GetParameterDataProvider(cursorPosition, doc.GetCharAt(cursorPosition - 1))); }
private void AppendHtmlSafeCharacter(StringBuilder sb, int index) { var ch = Document.GetCharAt(index); if (ch == '<') { sb.Append("<"); } else if (ch == '>') { sb.Append(">"); } else { sb.Append(ch); } }