本文整理汇总了C#中TextLocation类的典型用法代码示例。如果您正苦于以下问题:C# TextLocation类的具体用法?C# TextLocation怎么用?C# TextLocation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TextLocation类属于命名空间,在下文中一共展示了TextLocation类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: FindUsages
public FindUsagesResponse FindUsages(FindUsagesRequest request)
{
var res = _parser.ParsedContent(request.Buffer, request.FileName);
var loc = new TextLocation(request.Line, request.Column);
var result = new ConcurrentBag<AstNode>();
var findReferences = new FindReferences();
ResolveResult resolveResult = ResolveAtLocation.Resolve(res.Compilation, res.UnresolvedFile, res.SyntaxTree, loc);
if (resolveResult is LocalResolveResult)
{
var variable = (resolveResult as LocalResolveResult).Variable;
findReferences.FindLocalReferences(variable, res.UnresolvedFile, res.SyntaxTree, res.Compilation, (node, rr) => result.Add(node), CancellationToken.None);
}
else
{
IEntity entity = null;
if (resolveResult is TypeResolveResult)
{
entity = (resolveResult as TypeResolveResult).Type.GetDefinition();
}
if (resolveResult is MemberResolveResult)
{
entity = (resolveResult as MemberResolveResult).Member;
}
if (entity == null)
{
return new FindUsagesResponse {Usages = new List<Usage>()};
}
var searchScopes = findReferences.GetSearchScopes(entity);
var interesting = new List<CSharpUnresolvedFile>();
foreach (var scope in searchScopes)
{
var scopeInteresting = findReferences.GetInterestingFiles(scope, res.Compilation);
interesting.AddRange(scopeInteresting);
}
Parallel.ForEach(interesting, file =>
{
ParsedResult parsedResult = _parser.ParsedContent(
_solution.GetFile(file.FileName).Content.Text, file.FileName);
findReferences.FindReferencesInFile(searchScopes, file, parsedResult.SyntaxTree,
parsedResult.Compilation,
(node, rr) => result.Add(node), CancellationToken.None);
});
}
var usages = result.Select(node => new Usage
{
FileName = node.GetRegion().FileName,
Text = node.Preview(_solution.GetFile(node.GetRegion().FileName)).Replace("'", "''"),
Line = node.StartLocation.Line,
Column = node.StartLocation.Column,
});
return new FindUsagesResponse { Usages = usages };
}
开发者ID:CSRedRat,项目名称:Omnisharp,代码行数:60,代码来源:FindUsagesHandler.cs
示例2: writeLine
/// <summary>
/// Write a text in a label.
/// </summary>
/// <param name="line"></param>
/// <param name="location"></param>
public static void writeLine(Line line, TextLocation location)
{
int textLength = line.Text.Length;
switch (location)
{
case TextLocation.Up:
writeLine(line, new Rect(
(Screen.width - GUI.skin.label.fontSize / 2 * textLength) / 2,
0,
Screen.width,
GUI.skin.label.fontSize * 2
));
break;
case TextLocation.Middle:
writeLine(line, new Rect(
(Screen.width - GUI.skin.label.fontSize / 2 * textLength) / 2,
Screen.height / 2 - GUI.skin.label.fontSize,
Screen.width,
GUI.skin.label.fontSize * 2
));
break;
case TextLocation.Down:
writeLine(line, new Rect(
(Screen.width - GUI.skin.label.fontSize / 2 * textLength) / 2,
Screen.height - GUI.skin.label.fontSize * 2,
Screen.width,
GUI.skin.label.fontSize * 2
));
break;
}
}
开发者ID:fernandoRoman,项目名称:UnityPruebas,代码行数:36,代码来源:Commands.cs
示例3: GetSuggestions
public override IEnumerable<CodeSuggestion> GetSuggestions(TextLocation location)
{
var node = File.CompilationUnit.GetClosestNodeBeforeLocation(location);
var scope = node.GetDeclaringScope();
while (true)
{
if (node is Statement)
break;
var reference = node as MemberReferenceExpression;
if (reference != null)
{
var result = reference.Target.Resolve(scope);
if (result.ScopeProvider != null)
{
foreach (var definition in result.ScopeProvider.GetScope().GetDefinitions())
yield return new CodeSuggestion(definition.Name, definition.FullName, definition.Name);
yield break;
}
}
node = node.Parent;
}
foreach (var definition in scope.GetAllDefinitions())
{
yield return new CodeSuggestion(definition.Name, definition.FullName, definition.Name);
}
}
开发者ID:JerreS,项目名称:AbstractCode,代码行数:30,代码来源:CSharpCompletionEngine.cs
示例4: 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
示例5: DebuggerTooltipControl
public DebuggerTooltipControl(TextLocation logicalPosition)
{
this.logicalPosition = logicalPosition;
InitializeComponent();
Loaded += new RoutedEventHandler(OnLoaded);
}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:7,代码来源:DebuggerTooltipControl.xaml.cs
示例6: AnchorDeleted
void AnchorDeleted(object sender, EventArgs e)
{
// the anchor just became invalid, so don't try to use it again
location = TextLocation.Empty;
anchor = null;
RemoveMark();
}
开发者ID:kristjan84,项目名称:SharpDevelop,代码行数:7,代码来源:BookmarkBase.cs
示例7: GetResult
public GenerateNamespaceImport GetResult (IUnresolvedFile unit, IType type, MonoDevelop.Ide.Gui.Document doc)
{
GenerateNamespaceImport result;
if (cache.TryGetValue (type.Namespace, out result))
return result;
result = new GenerateNamespaceImport ();
cache[type.Namespace] = result;
TextEditorData data = doc.Editor;
result.InsertNamespace = false;
var loc = new TextLocation (data.Caret.Line, data.Caret.Column);
foreach (var ns in RefactoringOptions.GetUsedNamespaces (doc, loc)) {
if (type.Namespace == ns) {
result.GenerateUsing = false;
return result;
}
}
result.GenerateUsing = true;
string name = type.Name;
foreach (string ns in RefactoringOptions.GetUsedNamespaces (doc, loc)) {
if (doc.Compilation.MainAssembly.GetTypeDefinition (ns, name, type.TypeParameterCount) != null) {
result.GenerateUsing = false;
result.InsertNamespace = true;
return result;
}
}
return result;
}
开发者ID:rajeshpillai,项目名称:monodevelop,代码行数:30,代码来源:ImportSymbolHandler.cs
示例8: Message
public static void Message(this IErrorReporter reporter, int code, string file, TextLocation location, params object[] args)
{
var msg = Messages.Get(code);
if (msg == null)
reporter.InternalError("Message " + code + " does not exist" + (args.Length > 0 ? " (arguments were " + string.Join(", ", args) + ")" : "") + ".", file, location);
reporter.Message(msg.Item1, code, file, location, msg.Item2, args);
}
开发者ID:arnauddias,项目名称:SaltarelleCompiler,代码行数:7,代码来源:IErrorReporter.cs
示例9: CheckSegments
void CheckSegments(IList<IFormatStringSegment> segments, TextLocation formatStart, IList<Expression> formatArguments, AstNode anchor)
{
int argumentCount = formatArguments.Count;
foreach (var segment in segments) {
var errors = segment.Errors.ToList();
var formatItem = segment as FormatItem;
if (formatItem != null) {
var segmentEnd = new TextLocation(formatStart.Line, formatStart.Column + segment.EndLocation + 1);
var segmentStart = new TextLocation(formatStart.Line, formatStart.Column + segment.StartLocation + 1);
if (formatItem.Index >= argumentCount) {
var outOfBounds = context.TranslateString("The index '{0}' is out of bounds of the passed arguments");
AddIssue(segmentStart, segmentEnd, string.Format(outOfBounds, formatItem.Index));
}
if (formatItem.HasErrors) {
var errorMessage = string.Join(Environment.NewLine, errors.Select(error => error.Message).ToArray());
string messageFormat;
if (errors.Count > 1) {
messageFormat = context.TranslateString("Multiple:\n{0}");
} else {
messageFormat = context.TranslateString("{0}");
}
AddIssue(segmentStart, segmentEnd, string.Format(messageFormat, errorMessage));
}
} else if (segment.HasErrors) {
foreach (var error in errors) {
var errorStart = new TextLocation(formatStart.Line, formatStart.Column + error.StartLocation + 1);
var errorEnd = new TextLocation(formatStart.Line, formatStart.Column + error.EndLocation + 1);
AddIssue(errorStart, errorEnd, error.Message);
}
}
}
}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:32,代码来源:FormatStringIssue.cs
示例10: Resolve
public static ResolveResult Resolve(Lazy<ICompilation> compilation, CSharpUnresolvedFile unresolvedFile, SyntaxTree syntaxTree, TextLocation location, out AstNode node,
CancellationToken cancellationToken = default(CancellationToken))
{
node = syntaxTree.GetNodeAt(location);
if (node == null || node is ArrayInitializerExpression)
return null;
if (node.Parent is UsingAliasDeclaration && node.Role == UsingAliasDeclaration.AliasRole) {
var r = new CSharpAstResolver(compilation.Value, syntaxTree, unresolvedFile);
return r.Resolve(((UsingAliasDeclaration)node.Parent).Import, cancellationToken);
}
if (CSharpAstResolver.IsUnresolvableNode(node)) {
if (node is Identifier) {
node = node.Parent;
} else if (node.NodeType == NodeType.Token) {
if (node.Parent is IndexerExpression || node.Parent is ConstructorInitializer) {
// There's no other place where one could hover to see the indexer's tooltip,
// so we need to resolve it when hovering over the '[' or ']'.
// For constructor initializer, the same applies to the 'base'/'this' token.
node = node.Parent;
} else {
return null;
}
} else {
// don't resolve arbitrary nodes - we don't want to show tooltips for everything
return null;
}
} else {
// It's a resolvable node.
// However, we usually don't want to show the tooltip everywhere
// For example, hovering with the mouse over an empty line between two methods causes
// node==TypeDeclaration, but we don't want to show any tooltip.
if (!node.GetChildByRole(Roles.Identifier).IsNull) {
// We'll suppress the tooltip for resolvable nodes if there is an identifier that
// could be hovered over instead:
return null;
}
}
if (node == null)
return null;
if (node.Parent is ObjectCreateExpression && node.Role == Roles.Type) {
node = node.Parent;
}
InvocationExpression parentInvocation = null;
if ((node is IdentifierExpression || node is MemberReferenceExpression || node is PointerReferenceExpression) && node.Role != Roles.Argument) {
// we also need to resolve the invocation
parentInvocation = node.Parent as InvocationExpression;
}
// TODO: I think we should provide an overload so that an existing CSharpAstResolver can be reused
CSharpAstResolver resolver = new CSharpAstResolver(compilation.Value, syntaxTree, unresolvedFile);
ResolveResult rr = resolver.Resolve(node, cancellationToken);
if (rr is MethodGroupResolveResult && parentInvocation != null)
return resolver.Resolve(parentInvocation);
else
return rr;
}
开发者ID:riviti,项目名称:NRefactory,代码行数:60,代码来源:ResolveAtLocation.cs
示例11: GetActions
public override IEnumerable<MonoDevelop.CodeActions.CodeAction> GetActions (MonoDevelop.Ide.Gui.Document document, object refactoringContext, TextLocation loc, CancellationToken cancellationToken)
{
var context = refactoringContext as MDRefactoringContext;
if (context == null)
return Enumerable.Empty<MonoDevelop.CodeActions.CodeAction> ();
return GetActions (context);
}
开发者ID:fedorw,项目名称:monodevelop,代码行数:7,代码来源:MoveTypeToFile.cs
示例12: CreateWidget
void CreateWidget (IEnumerable<CodeAction> fixes, TextLocation loc)
{
this.loc = loc;
var editor = document.Editor;
var container = editor.Parent;
var point = editor.Parent.LocationToPoint (loc);
point.Y += (int)editor.LineHeight;
if (widget == null) {
widget = new CodeActionWidget (this, Document);
container.AddTopLevelWidget (
widget,
point.X,
point.Y
);
widget.Show ();
} else {
if (!widget.Visible)
widget.Show ();
container.MoveTopLevelWidget (
widget,
point.X,
point.Y
);
}
widget.SetFixes (fixes, loc);
}
开发者ID:pvergara,项目名称:monodevelop,代码行数:26,代码来源:CodeActionEditorExtension.cs
示例13: DebuggerTooltipControl
public DebuggerTooltipControl(TextLocation logicalPosition)
{
this.logicalPosition = logicalPosition;
InitializeComponent();
Loaded += OnLoaded;
}
开发者ID:BahNahNah,项目名称:dnSpy,代码行数:7,代码来源:DebuggerTooltipControl.xaml.cs
示例14: CreateWidget
void CreateWidget (IEnumerable<CodeAction> fixes, TextLocation loc)
{
Fixes = fixes;
if (!QuickTaskStrip.EnableFancyFeatures)
return;
var editor = document.Editor;
if (editor == null || editor.Parent == null || !editor.Parent.IsRealized)
return;
if (!fixes.Any ()) {
ICSharpCode.NRefactory.TypeSystem.DomRegion region;
var resolveResult = document.GetLanguageItem (editor.Caret.Offset, out region);
if (resolveResult != null) {
var possibleNamespaces = ResolveCommandHandler.GetPossibleNamespaces (document, resolveResult);
if (!possibleNamespaces.Any ())
return;
} else
return;
}
var container = editor.Parent.Parent as TextEditorContainer;
if (container == null)
return;
if (widget == null) {
widget = new CodeActionWidget (this, Document);
container.AddTopLevelWidget (widget,
2 + (int)editor.Parent.TextViewMargin.XOffset,
-2 + (int)editor.Parent.LineToY (document.Editor.Caret.Line));
} else {
container.MoveTopLevelWidget (widget,
2 + (int)editor.Parent.TextViewMargin.XOffset,
-2 + (int)editor.Parent.LineToY (document.Editor.Caret.Line));
}
widget.Show ();
widget.SetFixes (fixes, loc);
}
开发者ID:gary-b,项目名称:monodevelop,代码行数:35,代码来源:CodeActionEditorExtension.cs
示例15: ApplyTo
public TextLocation ApplyTo(TextLocation location, bool negativeTracking, out bool updated)
{
if ((this.Start > location) || (negativeTracking && (this.Start == location)))
{
// This change happened after the location given, so it doesn't move.
updated = false;
return location;
}
updated = true;
if (this.OldEnd >= location)
{
// The location is within the modified portion of the edit, so the location
// snaps to the start (negativeTracking) or end (!negativeTracking).
return negativeTracking ? this.Start : this.NewEnd;
}
// The location is fully after the edit, so it moves according to the size of the
// insertion/deletion.
if (location.Line == this.OldEnd.Line)
{
// The location was on the old end line of the changed text, so both the line
// and index get updated.
return new TextLocation(this.NewEnd.Line, location.Index - this.OldEnd.Index + this.NewEnd.Index);
}
// The location was on a line not affected by the edit, so only the line changes
return new TextLocation(location.Line + this.NewEnd.Line - this.OldEnd.Line, location.Index);
}
开发者ID:UnaNancyOwen,项目名称:Kinect-Studio-Sample,代码行数:29,代码来源:TextChange.cs
示例16: SearchBrackets
public static BracketSearchResult SearchBrackets(TextDocument doc, int caretOffset, TextLocation caret)
{
var caretLocation = new CodeLocation(caret.Column, caret.Line);
try
{
if (caretOffset < 1 || caretOffset>=doc.TextLength-2)
return null;
// Search backward
DToken lastToken=null;
var tk_start = SearchBackward(doc, caretOffset, caretLocation,out lastToken);
if (tk_start == null)
return null;
// Search forward
var tk_end = SearchForward(doc,
doc.GetOffset(lastToken.EndLocation.Line,lastToken.EndLocation.Column),
lastToken.EndLocation,
getOppositeBracketToken(tk_start.Kind));
if (tk_end == null)
return null;
int start = doc.GetOffset(tk_start.Location.Line, tk_start.Location.Column),
end = doc.GetOffset(tk_end.Location.Line, tk_end.Location.Column);
return new BracketSearchResult(start, 1, end, 1);
}
catch { return null; }
}
开发者ID:cessationoftime,项目名称:D-IDE,代码行数:31,代码来源:DBracketSearcher.cs
示例17: DebuggerPopup
public DebuggerPopup(DebuggerTooltipControl parentControl, TextLocation logicalPosition, bool showPins = true)
{
this.contentControl = new DebuggerTooltipControl(parentControl, logicalPosition, showPins);
this.contentControl.containingPopup = this;
this.Child = this.contentControl;
this.IsLeaf = false;
}
开发者ID:BahNahNah,项目名称:dnSpy,代码行数:7,代码来源:DebuggerPopup.cs
示例18: TryGetFormattingParameters
public static bool TryGetFormattingParameters(CSharpInvocationResolveResult invocationResolveResult, InvocationExpression invocationExpression,
out Expression formatArgument, out TextLocation formatStart, out IList<Expression> arguments,
Func<IParameter, Expression, bool> argumentFilter)
{
if (argumentFilter == null)
argumentFilter = (p, e) => true;
formatArgument = null;
formatStart = default(TextLocation);
arguments = new List<Expression>();
var argumentToParameterMap = invocationResolveResult.GetArgumentToParameterMap();
var resolvedParameters = invocationResolveResult.Member.Parameters;
var allArguments = invocationExpression.Arguments.ToArray();
for (int i = 0; i < allArguments.Length; i++) {
var parameterIndex = argumentToParameterMap[i];
if (parameterIndex < 0 || parameterIndex >= resolvedParameters.Count) {
// No valid mapping for this parameter, skip it
continue;
}
var parameter = resolvedParameters[parameterIndex];
var argument = allArguments[i];
if (parameter.Type.IsKnownType(KnownTypeCode.String) && parameterNames.Contains(parameter.Name)) {
formatArgument = argument;
formatStart = argument.StartLocation;
} else if ((formatArgument != null || parameter.IsParams) && argumentFilter(parameter, argument)) {
arguments.Add(argument);
}
}
return formatArgument != null;
}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:30,代码来源:FormatStringHelper.cs
示例19: Resolve
public ResolveResult Resolve(ParseInformation parseInfo, TextLocation location, ICompilation compilation, CancellationToken cancellationToken)
{
var decompiledParseInfo = parseInfo as ILSpyFullParseInformation;
if (decompiledParseInfo == null)
throw new ArgumentException("ParseInfo does not have SyntaxTree");
return ResolveAtLocation.Resolve(compilation, null, decompiledParseInfo.SyntaxTree, location, cancellationToken);
}
开发者ID:fanyjie,项目名称:SharpDevelop,代码行数:7,代码来源:ILSpyParser.cs
示例20: Execute
/// <summary>
/// Executes the action on a certain <see cref="TextArea"/>.
/// </summary>
/// <param name="textArea">The text area on which to execute the action.</param>
public override void Execute(TextArea textArea)
{
LineSegment curLine;
TextLocation newPos = textArea.Caret.Position;
bool jumpedIntoFolding;
do
{
curLine = textArea.Document.GetLineSegment(newPos.Y);
newPos.X = curLine.Length;
List<Fold> foldings = textArea.Document.FoldingManager.GetFoldsFromPosition(newPos.Y, newPos.X);
jumpedIntoFolding = false;
foreach (Fold fold in foldings)
{
if (fold.IsFolded)
{
newPos = new TextLocation(fold.EndColumn, fold.EndLine);
jumpedIntoFolding = true;
break;
}
}
} while (jumpedIntoFolding);
if (newPos != textArea.Caret.Position)
{
textArea.Caret.Position = newPos;
textArea.SetDesiredColumn();
}
}
开发者ID:cavaliercoder,项目名称:expression-lab,代码行数:33,代码来源:HomeEndActions.cs
注:本文中的TextLocation类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论