本文整理汇总了C#中IDocument.GetLocation方法的典型用法代码示例。如果您正苦于以下问题:C# IDocument.GetLocation方法的具体用法?C# IDocument.GetLocation怎么用?C# IDocument.GetLocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDocument
的用法示例。
在下文中一共展示了IDocument.GetLocation方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToRegionStartingFromOpeningCurlyBrace
public DomRegion ToRegionStartingFromOpeningCurlyBrace(IDocument document)
{
int startOffset = GetOpeningCurlyBraceOffsetForRegion(document);
TextLocation start = document.GetLocation(startOffset);
TextLocation end = document.GetLocation(limChar);
return new DomRegion(start, end);
}
示例2: Format
/// <summary>
/// Formats the specified part of the document.
/// </summary>
public static void Format(IDocument document, int offset, int length, CSharpFormattingOptions options)
{
var syntaxTree = new CSharpParser().Parse(document);
var fv = new AstFormattingVisitor(options, document);
fv.FormattingRegion = new DomRegion(document.GetLocation(offset), document.GetLocation(offset + length));
syntaxTree.AcceptVisitor(fv);
fv.ApplyChanges(offset, length);
}
示例3: TestRefactoringContext
public TestRefactoringContext(string content)
{
int idx = content.IndexOf ("$");
if (idx >= 0)
content = content.Substring (0, idx) + content.Substring (idx + 1);
doc = new ReadOnlyDocument (content);
var parser = new CSharpParser ();
Unit = parser.Parse (content, "program.cs");
if (parser.HasErrors)
parser.ErrorPrinter.Errors.ForEach (e => Console.WriteLine (e.Message));
Assert.IsFalse (parser.HasErrors, "File contains parsing errors.");
parsedFile = Unit.ToTypeSystem();
IProjectContent pc = new CSharpProjectContent();
pc = pc.UpdateProjectContent(null, parsedFile);
pc = pc.AddAssemblyReferences(new[] { CecilLoaderTests.Mscorlib, CecilLoaderTests.SystemCore });
compilation = pc.CreateCompilation();
resolver = new CSharpAstResolver(compilation, Unit, parsedFile);
if (idx >= 0)
Location = doc.GetLocation (idx);
}
示例4: CSharpCompletionContext
/// <summary>
/// Initializes a new instance of the <see cref="CSharpCompletionContext"/> class.
/// </summary>
/// <param name="document">The document, make sure the FileName property is set on the document.</param>
/// <param name="offset">The offset.</param>
/// <param name="projectContent">Content of the project.</param>
/// <param name="usings">The usings.</param>
public CSharpCompletionContext(IDocument document, int offset, IProjectContent projectContent, string usings = null)
{
OriginalDocument = document;
OriginalOffset = offset;
//if the document is a c# script we have to soround the document with some code.
Document = PrepareCompletionDocument(document, ref offset, usings);
Offset = offset;
var syntaxTree = new CSharpParser().Parse(Document, Document.FileName);
syntaxTree.Freeze();
var unresolvedFile = syntaxTree.ToTypeSystem();
ProjectContent = projectContent.AddOrUpdateFiles(unresolvedFile);
//note: it's important that the project content is used that is returned after adding the unresolved file
Compilation = ProjectContent.CreateCompilation();
var location = Document.GetLocation(Offset);
Resolver = unresolvedFile.GetResolver(Compilation, location);
TypeResolveContextAtCaret = unresolvedFile.GetTypeResolveContext(Compilation, location);
CompletionContextProvider = new DefaultCompletionContextProvider(Document, unresolvedFile);
}
示例5: TryFix
public bool TryFix (IDocument document, int offset, out int newOffset)
{
newOffset = offset;
var syntaxTree = SyntaxTree.Parse(document, "a.cs");
var location = document.GetLocation(offset - 1);
foreach (var c in completer) {
if (c.TryFix(this, syntaxTree, document, location, ref newOffset)) {
return true;
}
}
return false;
}
示例6: ExtendLeft
/// <summary>
/// If the text at startPos is preceded by any of the prefixes, moves the start backwards to include one prefix
/// (the rightmost one).
/// </summary>
TextLocation ExtendLeft(TextLocation startPos, IDocument document, params String[] prefixes)
{
int startOffset = document.GetOffset(startPos);
foreach (string prefix in prefixes) {
if (startOffset < prefix.Length) continue;
string realPrefix = document.GetText(startOffset - prefix.Length, prefix.Length);
if (realPrefix == prefix) {
return document.GetLocation(startOffset - prefix.Length);
}
}
// no prefixes -> do not extend
return startPos;
}
示例7: ExtendSelectionToEndOfLineComments
/// <summary>
/// If there is a comment block behind selection on the same line ("var i = 5; // comment"), add it to selection.
/// </summary>
Selection ExtendSelectionToEndOfLineComments(IDocument document, TextLocation selectionStart, TextLocation selectionEnd, IEnumerable<AstNode> commentsBlankLines)
{
var lineComment = commentsBlankLines.FirstOrDefault(c => c.StartLocation.Line == selectionEnd.Line && c.StartLocation >= selectionEnd);
if (lineComment == null) {
return null;
}
// bool isWholeLineSelected = IsWhitespaceBetween(document, new TextLocation(selectionStart.Line, 1), selectionStart);
// if (!isWholeLineSelected) {
// // whole line must be selected before we add the comment
// return null;
// }
int endPos = document.GetOffset(lineComment.EndLocation);
return new Selection { Start = selectionStart, End = document.GetLocation(endPos) };
}
示例8: GetInsertionPoints
public static List<InsertionPoint> GetInsertionPoints (IDocument document, IUnresolvedTypeDefinition type)
{
if (type == null)
throw new ArgumentNullException ("type");
// update type from parsed document, since this is always newer.
//type = parsedDocument.GetInnermostTypeDefinition (type.GetLocation ()) ?? type;
List<InsertionPoint> result = new List<InsertionPoint> ();
int offset = document.GetOffset (type.Region.Begin);
if (offset < 0)
return result;
while (offset < document.TextLength && document.GetCharAt (offset) != '{') {
offset++;
}
var realStartLocation = document.GetLocation (offset);
result.Add (GetInsertionPosition (document, realStartLocation.Line, realStartLocation.Column));
result [0].LineBefore = NewLineInsertion.None;
foreach (var member in type.Members) {
TextLocation domLocation = member.BodyRegion.End;
if (domLocation.Line <= 0) {
domLocation = member.Region.End;
}
result.Add (GetInsertionPosition (document, domLocation.Line, domLocation.Column));
}
result [result.Count - 1].LineAfter = NewLineInsertion.None;
CheckStartPoint (document, result [0], result.Count == 1);
if (result.Count > 1) {
result.RemoveAt (result.Count - 1);
NewLineInsertion insertLine;
var lineBefore = GetLineOrNull(document, type.BodyRegion.EndLine - 1);
if (lineBefore != null && lineBefore.Length == GetLineIndent(document, lineBefore).Length) {
insertLine = NewLineInsertion.None;
} else {
insertLine = NewLineInsertion.Eol;
}
// search for line start
var line = document.GetLineByNumber (type.BodyRegion.EndLine);
int col = type.BodyRegion.EndColumn - 1;
while (col > 1 && char.IsWhiteSpace (document.GetCharAt (line.Offset + col - 2)))
col--;
result.Add (new InsertionPoint (new TextLocation (type.BodyRegion.EndLine, col), insertLine, NewLineInsertion.Eol));
CheckEndPoint (document, result [result.Count - 1], result.Count == 1);
}
/*foreach (var region in parsedDocument.UserRegions.Where (r => type.BodyRegion.IsInside (r.Region.Begin))) {
result.Add (new InsertionPoint (new DocumentLocation (region.Region.BeginLine + 1, 1), NewLineInsertion.Eol, NewLineInsertion.Eol));
result.Add (new InsertionPoint (new DocumentLocation (region.Region.EndLine, 1), NewLineInsertion.Eol, NewLineInsertion.Eol));
result.Add (new InsertionPoint (new DocumentLocation (region.Region.EndLine + 1, 1), NewLineInsertion.Eol, NewLineInsertion.Eol));
}*/
result.Sort ((left, right) => left.Location.CompareTo (right.Location));
return result;
}
示例9: Create
public static TypeScriptTask Create(FileName fileName, Diagnostic diagnostic, IDocument document)
{
TextLocation location = document.GetLocation(diagnostic.start);
return new TypeScriptTask(fileName, diagnostic, location.Column, location.Line);
}
示例10: ToRegion
public DomRegion ToRegion(IDocument document)
{
TextLocation start = document.GetLocation(minChar);
TextLocation end = document.GetLocation(limChar);
return new DomRegion(start, end);
}