本文整理汇总了C#中ICSharpCode.NRefactory.Editor.ReadOnlyDocument类的典型用法代码示例。如果您正苦于以下问题:C# ReadOnlyDocument类的具体用法?C# ReadOnlyDocument怎么用?C# ReadOnlyDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReadOnlyDocument类属于ICSharpCode.NRefactory.Editor命名空间,在下文中一共展示了ReadOnlyDocument类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:CSRedRat,项目名称:Omnisharp,代码行数:33,代码来源:AutoCompleteHandler.cs
示例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;
}
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:28,代码来源:Parser.cs
示例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);
}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:32,代码来源:SymbolCollectorTests.cs
示例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.");
}
}
开发者ID:scemino,项目名称:NRefactory,代码行数:25,代码来源:Helper.cs
示例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;
}
开发者ID:uluhonolulu,项目名称:QCCodingServices.NET,代码行数:32,代码来源:CodeCompletionUtils.cs
示例6: ReadOnlyDocumentLine
public ReadOnlyDocumentLine(ReadOnlyDocument doc, int lineNumber)
{
this.doc = doc;
this.lineNumber = lineNumber;
this.offset = doc.GetStartOffset(lineNumber);
this.endOffset = doc.GetEndOffset(lineNumber);
}
开发者ID:Netring,项目名称:ILSpy,代码行数:7,代码来源:ReadOnlyDocument.cs
示例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);
}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:28,代码来源:ReadOnlyDocumentTests.cs
示例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;
}
开发者ID:asiazhang,项目名称:SharpDevelop,代码行数:25,代码来源:TextPasteIndentEngineTests.cs
示例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);
}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:12,代码来源:DocumentPrinter.cs
示例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);
}
开发者ID:kristjan84,项目名称:SharpDevelop,代码行数:10,代码来源:XamlAstResolver.cs
示例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));
}
开发者ID:holmak,项目名称:NRefactory,代码行数:10,代码来源:TextEditorTestAdapter.cs
示例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);
}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:10,代码来源:InsertMissingTokensDecoratorTests.cs
示例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();
}
开发者ID:AkshayVats,项目名称:SuperShell,代码行数:13,代码来源:DocumentHighlighter.cs
示例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());
}
开发者ID:dgrunwald,项目名称:SharpDevelop,代码行数:12,代码来源:DebuggerDotCompletion.cs
示例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);
}
}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:12,代码来源:ParseSelfTests.cs
示例16: ParseAndCheckPositions
public void ParseAndCheckPositions()
{
CSharpParser parser = new CSharpParser();
foreach (string fileName in fileNames) {
this.currentDocument = new ReadOnlyDocument(File.ReadAllText(fileName));
CompilationUnit cu = parser.Parse(currentDocument.CreateReader(), fileName);
if (parser.HasErrors)
continue;
this.currentFileName = fileName;
CheckPositionConsistency(cu);
CheckMissingTokens(cu);
}
}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:13,代码来源:ParseSelfTests.cs
示例17: Roundtrip
public static void Roundtrip(CSharpParser parser, string fileName, string code)
{
// 1. Parse
CompilationUnit cu = parser.Parse(code, fileName);
if (parser.HasErrors)
throw new InvalidOperationException("There were parse errors.");
// 2. Output
StringWriter w = new StringWriter();
cu.AcceptVisitor(new CSharpOutputVisitor(w, FormattingOptionsFactory.CreateMono ()));
string generatedCode = w.ToString().TrimEnd();
// 3. Compare output with original (modulo whitespaces)
int pos2 = 0;
for (int pos1 = 0; pos1 < code.Length; pos1++) {
if (!char.IsWhiteSpace(code[pos1])) {
while (pos2 < generatedCode.Length && char.IsWhiteSpace(generatedCode[pos2]))
pos2++;
if (pos2 >= generatedCode.Length || code[pos1] != generatedCode[pos2]) {
ReadOnlyDocument doc = new ReadOnlyDocument(code);
File.WriteAllText(Path.Combine(Program.TempPath, "roundtrip-error.cs"), generatedCode);
throw new InvalidOperationException("Mismatch at " + doc.GetLocation(pos1) + " of file " + fileName);
}
pos2++;
}
}
if (pos2 != generatedCode.Length)
throw new InvalidOperationException("Mismatch at end of file " + fileName);
// 3b - validate that there are no lone \r
if (generatedCode.Replace(w.NewLine, "\n").IndexOf('\r') >= 0)
throw new InvalidOperationException(@"Got lone \r in " + fileName);
// 4. Parse generated output
CompilationUnit generatedCU;
try {
generatedCU = parser.Parse(generatedCode, fileName);
} catch {
File.WriteAllText(Path.Combine(Program.TempPath, "roundtrip-error.cs"), generatedCode, Encoding.Unicode);
throw;
}
if (parser.HasErrors) {
File.WriteAllText(Path.Combine(Program.TempPath, "roundtrip-error.cs"), generatedCode);
throw new InvalidOperationException("There were parse errors in the roundtripped " + fileName);
}
// 5. Compare AST1 with AST2
if (!cu.IsMatch(generatedCU))
throw new InvalidOperationException("AST match failed for " + fileName + ".");
}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:51,代码来源:RoundtripTest.cs
示例18: Create
public static XamlUnresolvedFile Create(FileName fileName, ITextSource fileContent, AXmlDocument document)
{
XamlUnresolvedFile file = new XamlUnresolvedFile(fileName);
ReadOnlyDocument textDocument = new ReadOnlyDocument(fileContent, fileName);
file.errors.AddRange(document.SyntaxErrors.Select(err => new Error(ErrorType.Error, err.Description, textDocument.GetLocation(err.StartOffset))));
var visitor = new XamlDocumentVisitor(file, textDocument);
visitor.VisitDocument(document);
if (visitor.TypeDefinition != null)
file.topLevel = new[] { visitor.TypeDefinition };
else
file.topLevel = new IUnresolvedTypeDefinition[0];
return file;
}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:15,代码来源:XamlUnresolvedFile.cs
示例19: EmptyReadOnlyDocument
public void EmptyReadOnlyDocument()
{
IDocument document = new ReadOnlyDocument(string.Empty);
Assert.AreEqual(string.Empty, document.Text);
Assert.AreEqual(0, document.TextLength);
Assert.AreEqual(1, document.LineCount);
Assert.AreEqual(0, document.GetOffset(1, 1));
Assert.AreEqual(new TextLocation(1, 1), document.GetLocation(0));
Assert.AreEqual(0, document.GetLineByNumber(1).Offset);
Assert.AreEqual(0, document.GetLineByNumber(1).EndOffset);
Assert.AreEqual(0, document.GetLineByNumber(1).Length);
Assert.AreEqual(0, document.GetLineByNumber(1).TotalLength);
Assert.AreEqual(0, document.GetLineByNumber(1).DelimiterLength);
Assert.AreEqual(1, document.GetLineByNumber(1).LineNumber);
}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:16,代码来源:ReadOnlyDocumentTests.cs
示例20: CheckMissingTokens
public static void CheckMissingTokens(AstNode node, string currentFileName, IDocument currentDocument = null)
{
if (currentDocument == null)
currentDocument = new ReadOnlyDocument(File.ReadAllText(currentFileName));
if (IsLeafNode(node)) {
Assert.IsNull(node.FirstChild, "Token nodes should not have children");
} else {
var prevNodeEnd = node.StartLocation;
var prevNode = node;
for (AstNode child = node.FirstChild; child != null; child = child.NextSibling) {
CheckWhitespace(prevNode, prevNodeEnd, child, child.StartLocation, currentFileName, currentDocument);
CheckMissingTokens(child, currentFileName, currentDocument);
prevNode = child;
prevNodeEnd = child.EndLocation;
}
CheckWhitespace(prevNode, prevNodeEnd, node, node.EndLocation, currentFileName, currentDocument);
}
}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:18,代码来源:ConsistencyChecker.cs
注:本文中的ICSharpCode.NRefactory.Editor.ReadOnlyDocument类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论