本文整理汇总了C#中ICSharpCode.NRefactory.Editor.ReadOnlyDocument类的典型用法代码示例。如果您正苦于以下问题:C# ReadOnlyDocument类的具体用法?C# ReadOnlyDocument怎么用?C# ReadOnlyDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReadOnlyDocument类属于ICSharpCode.NRefactory.Editor命名空间,在下文中一共展示了ReadOnlyDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateProvider
public IEnumerable<ICompletionData> CreateProvider(AutoCompleteRequest request)
{
var editorText = request.Buffer ?? "";
var filename = request.FileName;
var partialWord = request.WordToComplete ?? "";
var doc = new ReadOnlyDocument(editorText);
var loc = new TextLocation(request.Line, request.Column - partialWord.Length);
int cursorPosition = doc.GetOffset(loc);
//Ensure cursorPosition only equals 0 when editorText is empty, so line 1,column 1
//completion will work correctly.
cursorPosition = Math.Max(cursorPosition, 1);
cursorPosition = Math.Min(cursorPosition, editorText.Length);
var res = _parser.ParsedContent(editorText, filename);
var rctx = res.UnresolvedFile.GetTypeResolveContext(res.Compilation, loc);
ICompletionContextProvider contextProvider = new DefaultCompletionContextProvider(doc, res.UnresolvedFile);
var engine = new CSharpCompletionEngine(doc, contextProvider, new CompletionDataFactory(partialWord), res.ProjectContent, rctx)
{
EolMarker = Environment.NewLine
};
_logger.Debug("Getting Completion Data");
IEnumerable<ICompletionData> data = engine.GetCompletionData(cursorPosition, true);
_logger.Debug("Got Completion Data");
return data.Where(d => d != null && d.DisplayText.IsValidCompletionFor(partialWord))
.FlattenOverloads()
.RemoveDupes()
.OrderBy(d => d.DisplayText);
}
示例2: Parse
public ParseInformation Parse(FileName fileName, ITextSource fileContent, bool fullParseInformationRequested,
IProject parentProject, CancellationToken cancellationToken)
{
var csharpProject = parentProject as CSharpProject;
CSharpParser parser = new CSharpParser(csharpProject != null ? csharpProject.CompilerSettings : null);
SyntaxTree cu = parser.Parse(fileContent, fileName);
cu.Freeze();
CSharpUnresolvedFile file = cu.ToTypeSystem();
ParseInformation parseInfo;
if (fullParseInformationRequested)
parseInfo = new CSharpFullParseInformation(file, fileContent.Version, cu);
else
parseInfo = new ParseInformation(file, fileContent.Version, fullParseInformationRequested);
IDocument document = fileContent as IDocument;
AddCommentTags(cu, parseInfo.TagComments, fileContent, parseInfo.FileName, ref document);
if (fullParseInformationRequested) {
if (document == null)
document = new ReadOnlyDocument(fileContent, parseInfo.FileName);
((CSharpFullParseInformation)parseInfo).newFoldings = CreateNewFoldings(cu, document);
}
return parseInfo;
}
示例3: CollectMembers
void CollectMembers(string code, string memberName, bool includeOverloads = true)
{
StringBuilder sb = new StringBuilder();
List<int> offsets = new List<int>();
foreach (var ch in code) {
if (ch == '$') {
offsets.Add(sb.Length);
continue;
}
sb.Append(ch);
}
var syntaxTree = SyntaxTree.Parse(sb.ToString (), "test.cs");
var unresolvedFile = syntaxTree.ToTypeSystem();
var compilation = TypeSystemHelper.CreateCompilation(unresolvedFile);
var symbol = FindReferencesTest.GetSymbol(compilation, memberName);
var col = new SymbolCollector();
col.IncludeOverloads = includeOverloads;
col.GroupForRenaming = true;
var result = col.GetRelatedSymbols (new Lazy<TypeGraph>(() => new TypeGraph (compilation.Assemblies)),
symbol);
if (offsets.Count != result.Count()) {
foreach (var a in result)
Console.WriteLine(a);
}
Assert.AreEqual(offsets.Count, result.Count());
var doc = new ReadOnlyDocument(sb.ToString ());
result
.Select(r => doc.GetOffset ((r as IEntity).Region.Begin))
.SequenceEqual(offsets);
}
示例4: RandomTests
public static void RandomTests(string filePath, int count, CSharpFormattingOptions policy = null, TextEditorOptions options = null)
{
if (File.Exists(filePath))
{
var code = File.ReadAllText(filePath);
var document = new ReadOnlyDocument(code);
policy = policy ?? FormattingOptionsFactory.CreateMono();
options = options ?? new TextEditorOptions { IndentBlankLines = false };
var engine = new CacheIndentEngine(new CSharpIndentEngine(document, options, policy) { EnableCustomIndentLevels = true });
Random rnd = new Random();
for (int i = 0; i < count; i++) {
int offset = rnd.Next(document.TextLength);
engine.Update(offset);
if (engine.CurrentIndent.Length == 0)
continue;
}
}
else
{
Assert.Fail("File " + filePath + " doesn't exist.");
}
}
示例5: DoCodeComplete
public static IEnumerable<ICompletionData> DoCodeComplete(string editorText, int offset) // not the best way to put in the whole string every time
{
var doc = new ReadOnlyDocument(editorText);
var location = doc.GetLocation(offset);
string parsedText = editorText; // TODO: Why are there different values in test cases?
var syntaxTree = new CSharpParser().Parse(parsedText, "program.cs");
syntaxTree.Freeze();
var unresolvedFile = syntaxTree.ToTypeSystem();
var mb = new DefaultCompletionContextProvider(doc, unresolvedFile);
IProjectContent pctx = new CSharpProjectContent();
var refs = new List<IUnresolvedAssembly> { mscorlib.Value, systemCore.Value, systemAssembly.Value };
pctx = pctx.AddAssemblyReferences(refs);
pctx = pctx.AddOrUpdateFiles(unresolvedFile);
var cmp = pctx.CreateCompilation();
var resolver3 = unresolvedFile.GetResolver(cmp, location);
var engine = new CSharpCompletionEngine(doc, mb, new TestCompletionDataFactory(resolver3), pctx, resolver3.CurrentTypeResolveContext);
engine.EolMarker = Environment.NewLine;
engine.FormattingPolicy = FormattingOptionsFactory.CreateMono();
var data = engine.GetCompletionData(offset, controlSpace: false);
return data;
}
示例6: ReadOnlyDocumentLine
public ReadOnlyDocumentLine(ReadOnlyDocument doc, int lineNumber)
{
this.doc = doc;
this.lineNumber = lineNumber;
this.offset = doc.GetStartOffset(lineNumber);
this.endOffset = doc.GetEndOffset(lineNumber);
}
示例7: SimpleDocument
public void SimpleDocument()
{
string text = "Hello\nWorld!\r\n";
IDocument document = new ReadOnlyDocument(text);
Assert.AreEqual(text, document.Text);
Assert.AreEqual(3, document.LineCount);
Assert.AreEqual(0, document.GetLineByNumber(1).Offset);
Assert.AreEqual(5, document.GetLineByNumber(1).EndOffset);
Assert.AreEqual(5, document.GetLineByNumber(1).Length);
Assert.AreEqual(6, document.GetLineByNumber(1).TotalLength);
Assert.AreEqual(1, document.GetLineByNumber(1).DelimiterLength);
Assert.AreEqual(1, document.GetLineByNumber(1).LineNumber);
Assert.AreEqual(6, document.GetLineByNumber(2).Offset);
Assert.AreEqual(12, document.GetLineByNumber(2).EndOffset);
Assert.AreEqual(6, document.GetLineByNumber(2).Length);
Assert.AreEqual(8, document.GetLineByNumber(2).TotalLength);
Assert.AreEqual(2, document.GetLineByNumber(2).DelimiterLength);
Assert.AreEqual(2, document.GetLineByNumber(2).LineNumber);
Assert.AreEqual(14, document.GetLineByNumber(3).Offset);
Assert.AreEqual(14, document.GetLineByNumber(3).EndOffset);
Assert.AreEqual(0, document.GetLineByNumber(3).Length);
Assert.AreEqual(0, document.GetLineByNumber(3).TotalLength);
Assert.AreEqual(0, document.GetLineByNumber(3).DelimiterLength);
Assert.AreEqual(3, document.GetLineByNumber(3).LineNumber);
}
示例8: CreateEngine
public static CacheIndentEngine CreateEngine(string text, CSharpFormattingOptions formatOptions = null, TextEditorOptions options = null)
{
if (formatOptions == null) {
formatOptions = FormattingOptionsFactory.CreateMono();
formatOptions.AlignToFirstIndexerArgument = formatOptions.AlignToFirstMethodCallArgument = true;
}
var sb = new StringBuilder();
int offset = 0;
for (int i = 0; i < text.Length; i++) {
var ch = text [i];
if (ch == '$') {
offset = i;
continue;
}
sb.Append(ch);
}
var document = new ReadOnlyDocument(sb.ToString());
options = options ?? new TextEditorOptions { EolMarker = "\n" };
var result = new CacheIndentEngine(new CSharpIndentEngine(document, options, formatOptions));
result.Update(offset);
return result;
}
示例9: ConvertTextDocumentToBlock
/// <summary>
/// Converts a readonly TextDocument to a Block and applies the provided highlighting definition.
/// </summary>
public static Block ConvertTextDocumentToBlock(ReadOnlyDocument document, IHighlightingDefinition highlightingDefinition)
{
IHighlighter highlighter;
if (highlightingDefinition != null)
highlighter = new DocumentHighlighter(document, highlightingDefinition);
else
highlighter = null;
return ConvertTextDocumentToBlock(document, highlighter);
}
示例10: XamlAstResolver
public XamlAstResolver(ICompilation compilation, XamlFullParseInformation parseInfo)
{
if (compilation == null)
throw new ArgumentNullException("compilation");
if (parseInfo == null)
throw new ArgumentNullException("parseInfo");
this.compilation = compilation;
this.parseInfo = parseInfo;
this.textDocument = new ReadOnlyDocument(parseInfo.Text, parseInfo.FileName);
}
示例11: GetResult
protected static IDocument GetResult(CSharpFormattingOptions policy, string input)
{
var adapter = new ReadOnlyDocument (input);
var visitor = new AstFormattingVisitor (policy, adapter, factory);
var compilationUnit = new CSharpParser ().Parse (new StringReader (input), "test.cs");
compilationUnit.AcceptVisitor (visitor, null);
return new ReadOnlyDocument (ApplyChanges (input, visitor.Changes));
}
示例12: AssertOutput
void AssertOutput(AstNode node)
{
RemoveTokens(node);
StringWriter w = new StringWriter();
w.NewLine = "\n";
node.AcceptVisitor(new CSharpOutputVisitor(TokenWriter.CreateWriterThatSetsLocationsInAST(w), FormattingOptionsFactory.CreateSharpDevelop()));
var doc = new ReadOnlyDocument(w.ToString());
ConsistencyChecker.CheckMissingTokens(node, "test.cs", doc);
ConsistencyChecker.CheckPositionConsistency(node, "test.cs", doc);
}
示例13: DocumentHighlighter
/// <summary>
/// Creates a new DocumentHighlighter instance.
/// </summary>
public DocumentHighlighter(ReadOnlyDocument document, IHighlightingDefinition definition)
{
if (document == null)
throw new ArgumentNullException("document");
if (definition == null)
throw new ArgumentNullException("definition");
this.document = document;
this.definition = definition;
InvalidateHighlighting();
}
示例14: PrepareDotCompletion
public static ICodeCompletionBinding PrepareDotCompletion(string expressionToComplete, DebuggerCompletionContext context)
{
var lang = SD.LanguageService.GetLanguageByFileName(context.FileName);
if (lang == null)
return null;
string content = GeneratePartialClassContextStub(context);
const string caretPoint = "$__Caret_Point__$;";
int caretOffset = content.IndexOf(caretPoint, StringComparison.Ordinal) + expressionToComplete.Length;
SD.Log.DebugFormatted("context used for dot completion: {0}", content.Replace(caretPoint, "$" + expressionToComplete + "|$"));
var doc = new ReadOnlyDocument(content.Replace(caretPoint, expressionToComplete));
return lang.CreateCompletionBinding(context.FileName, doc.GetLocation(caretOffset), doc.CreateSnapshot());
}
示例15: ParseAndCheckPositions
public void ParseAndCheckPositions()
{
CSharpParser parser = new CSharpParser();
foreach (string fileName in fileNames) {
var currentDocument = new ReadOnlyDocument(File.ReadAllText(fileName));
SyntaxTree syntaxTree = parser.Parse(currentDocument, fileName);
if (parser.HasErrors)
continue;
ConsistencyChecker.CheckPositionConsistency(syntaxTree, fileName, currentDocument);
ConsistencyChecker.CheckMissingTokens(syntaxTree, fileName, currentDocument);
}
}