void TestCreateMethod (string input, string outputString, bool returnWholeFile) { var generator = new CSharpCodeGeneratorNode (); MonoDevelop.Projects.CodeGeneration.CodeGenerator.AddGenerator (generator); var refactoring = new CreateMethodCodeGenerator (); RefactoringOptions options = ExtractMethodTests.CreateRefactoringOptions (input); Assert.IsTrue (refactoring.IsValid (options)); if (returnWholeFile) { refactoring.SetInsertionPoint (CodeGenerationService.GetInsertionPoints (options.Document, refactoring.DeclaringType).First ()); } else { DocumentLocation loc = new DocumentLocation (1, 1); refactoring.SetInsertionPoint (new InsertionPoint (loc, NewLineInsertion.Eol, NewLineInsertion.Eol)); } List<Change> changes = refactoring.PerformChanges (options, null); // changes.ForEach (c => Console.WriteLine (c)); // get just the generated method. string output = ExtractMethodTests.GetOutput (options, changes); if (returnWholeFile) { Assert.IsTrue (ExtractMethodTests.CompareSource (output, outputString), "Expected:" + Environment.NewLine + outputString + Environment.NewLine + "was:" + Environment.NewLine + output); return; } output = output.Substring (0, output.IndexOf ('}') + 1).Trim (); // crop 1 level of indent Document doc = new Document (output); foreach (LineSegment line in doc.Lines) { if (doc.GetCharAt (line.Offset) == '\t') ((IBuffer)doc).Remove (line.Offset, 1); } output = doc.Text; Assert.IsTrue (ExtractMethodTests.CompareSource (output, outputString), "Expected:" + Environment.NewLine + outputString + Environment.NewLine + "was:" + Environment.NewLine + output); MonoDevelop.Projects.CodeGeneration.CodeGenerator.RemoveGenerator (generator); }
public static void Left (TextEditorData data) { if (Platform.IsMac && data.IsSomethingSelected && !data.Caret.PreserveSelection) { data.Caret.Offset = System.Math.Min (data.SelectionAnchor, data.Caret.Offset); data.ClearSelection (); return; } if (data.Caret.Column > DocumentLocation.MinColumn) { DocumentLine line = data.Document.GetLine (data.Caret.Line); if (data.Caret.Column > line.Length + 1) { if (data.Caret.AllowCaretBehindLineEnd) { data.Caret.Column--; } else { data.Caret.Column = line.Length + 1; } } else { int offset = data.Caret.Offset - 1; foreach (var folding in data.Document.GetFoldingsFromOffset (offset).Where (f => f.IsFolded && f.Offset < offset)) { offset = System.Math.Min (offset, folding.Offset); } data.Caret.Offset = offset; } } else if (data.Caret.Line > DocumentLocation.MinLine) { DocumentLine prevLine = data.Document.GetLine (data.Caret.Line - 1); var nextLocation = new DocumentLocation (data.Caret.Line - 1, prevLine.Length + 1); if (data.HasIndentationTracker && data.Options.IndentStyle == IndentStyle.Virtual && nextLocation.Column == DocumentLocation.MinColumn) nextLocation = new DocumentLocation (data.Caret.Line - 1, data.GetVirtualIndentationColumn (nextLocation)); data.Caret.Location = nextLocation; } }
protected override void Update(CommandInfo info) { Document doc = IdeApp.Workbench.ActiveDocument; var editor = doc.GetContent<ITextEditorDataProvider> (); info.Enabled = false; if (doc != null && editor != null && doc.Project is MonoDroidProject) { var data = editor.GetTextEditorData (); var loc = new DocumentLocation (data.Caret.Line, data.Caret.Column); ResolveResult result; AstNode node; if (!doc.TryResolveAt (loc, out result, out node)) { return; } var memberResolve = result as MemberResolveResult; if (memberResolve == null) { return; } info.Enabled = ResourceHelper.IsResourcesMemberField(memberResolve); } }
public static void FormatStatmentAt (MonoDevelop.Ide.Gui.Document data, DocumentLocation location) { var offset = data.Editor.LocationToOffset (location); var policyParent = data.Project != null ? data.Project.Policies : PolicyService.DefaultPolicies; var mimeTypeChain = DesktopService.GetMimeTypeInheritanceChain (CSharpFormatter.MimeType); Format (policyParent, mimeTypeChain, data, offset, offset, false, true); }
public static bool TryResolveAt(this Document doc, DocumentLocation loc, out ResolveResult result, out AstNode node) { if(doc == null) throw new ArgumentNullException("doc"); result = null; node = null; var parsed_doc = doc.ParsedDocument; if(parsed_doc == null) return false; var unit = parsed_doc.GetAst<SyntaxTree>(); var parsed_file = parsed_doc.ParsedFile as BVE5UnresolvedFile; if(unit == null || parsed_file == null) return false; try{ result = ResolveAtLocation.Resolve(new Lazy<ICompilation>(() => doc.Compilation), parsed_file, unit, loc, out node); if(result == null || node is Statement) return false; }catch(Exception e){ Console.WriteLine("Got resolver exception:" + e); return false; } return true; }
public Selection (DocumentLocation anchor, DocumentLocation lead, SelectionMode selectionMode) { if (anchor.Line < DocumentLocation.MinLine || anchor.Column < DocumentLocation.MinColumn) throw new ArgumentException ("anchor"); if (lead.Line < DocumentLocation.MinLine || lead.Column < DocumentLocation.MinColumn) throw new ArgumentException ("lead"); this.Anchor = anchor; this.Lead = lead; this.SelectionMode = selectionMode; }
public Selection (DocumentLocation anchor, DocumentLocation lead, SelectionMode selectionMode = SelectionMode.Normal) { if (anchor.Line < DocumentLocation.MinLine || anchor.Column < DocumentLocation.MinColumn) throw new ArgumentOutOfRangeException ("anchor", anchor + " is out of range."); if (lead.Line < DocumentLocation.MinLine || lead.Column < DocumentLocation.MinColumn) throw new ArgumentOutOfRangeException ("lead", lead + " is out of range."); this.Anchor = anchor; this.Lead = lead; this.SelectionMode = selectionMode; }
string GetIndentationString (DocumentLocation loc) { var line = data.Document.GetLine (loc.Line); if (line == null) return ""; // Get context to the end of the line w/o changing the main engine's state var offset = line.Offset; string curIndent = line.GetIndentation (data.Document); try { stateTracker.Update (Math.Min (data.Length, offset + Math.Min (line.Length, loc.Column - 1))); int nlwsp = curIndent.Length; if (!stateTracker.LineBeganInsideMultiLineComment || (nlwsp < line.LengthIncludingDelimiter && data.Document.GetCharAt (offset + nlwsp) == '*')) return stateTracker.ThisLineIndent; } catch (Exception e) { LoggingService.LogError ("Error while indenting at "+ loc, e); } return curIndent; }
protected override void Run() { Document doc = IdeApp.Workbench.ActiveDocument; var editor = doc.GetContent<ITextEditorDataProvider> (); if (doc != null && editor != null && doc.Project is MonoDroidProject) { var data = editor.GetTextEditorData (); var offset = data.Caret.Offset; var loc = new DocumentLocation (data.Caret.Line, data.Caret.Column); ResolveResult result; AstNode node; if (!doc.TryResolveAt (loc, out result, out node)) { return; } var memberResolve = result as MemberResolveResult; if (memberResolve == null) { return; } if (ResourceHelper.IsResourcesMemberField(memberResolve)) { MonoDevelop.Projects.Project project; if (memberResolve.Type.TryGetSourceProject (out project)) { var androidProject = project as MonoDroidProject; var fileNames = ResourceHelper.ResolveToFilenames (memberResolve, androidProject, ResourceFolders.LAYOUT); if (fileNames.Count == 1) { IdeApp.Workbench.OpenDocument(new FileOpenInformation(fileNames[0], project)); } else if (fileNames.Count > 1) { OpenAutoOpenWindow (doc, data, project, fileNames); } else { Console.WriteLine ("Failed to resolve the layout"); } } } } }
string GetIndentationString (int offset, DocumentLocation loc) { stateTracker.UpdateEngine (Math.Min (data.Length, offset + 1)); LineSegment line = data.Document.GetLine (loc.Line); // Get context to the end of the line w/o changing the main engine's state var ctx = (CSharpIndentEngine)stateTracker.Engine.Clone (); for (int max = offset; max < line.Offset + line.Length; max++) { ctx.Push (data.Document.GetCharAt (max)); } // int pos = line.Offset; string curIndent = line.GetIndentation (data.Document); int nlwsp = curIndent.Length; // int o = offset > pos + nlwsp ? offset - (pos + nlwsp) : 0; if (!stateTracker.Engine.LineBeganInsideMultiLineComment || (nlwsp < line.LengthIncludingDelimiter && data.Document.GetCharAt (line.Offset + nlwsp) == '*')) { return ctx.ThisLineIndent; } return curIndent; }
void OnQuickFixCommand () { if (!QuickTaskStrip.EnableFancyFeatures) { Fixes = RefactoringService.GetValidActions (Document, Document.Editor.Caret.Location).Result; currentSmartTagBegin = Document.Editor.Caret.Location; PopupQuickFixMenu (null, null); return; } if (currentSmartTag == null) return; currentSmartTag.Popup (); }
public Cairo.Point LocationToPoint(DocumentLocation loc) { return(TextViewMargin.LocationToPoint(loc)); }
public Cairo.Point LocationToPoint(DocumentLocation loc, bool useAbsoluteCoordinates) { return(TextViewMargin.LocationToPoint(loc, useAbsoluteCoordinates)); }
static ResolveResult GetHeuristicResult (Document doc, DocumentLocation location, ref AstNode node) { int offset = doc.Editor.Caret.Offset; bool wasLetter = false, wasWhitespaceAfterLetter = false; while (offset < doc.Editor.Length) { char ch = doc.Editor.GetCharAt (offset); bool isLetter = char.IsLetterOrDigit (ch) || ch == '_'; bool isWhiteSpace = char.IsWhiteSpace (ch); bool isValidPunc = ch == '.' || ch == '<' || ch == '>'; if (!(wasLetter && wasWhitespaceAfterLetter) && (isLetter || isWhiteSpace || isValidPunc)) { if (isValidPunc) { wasWhitespaceAfterLetter = false; wasLetter = false; } offset++; } else { offset--; while (offset > 1) { ch = doc.Editor.GetCharAt (offset - 1); if (!(ch == '.' || char.IsWhiteSpace (ch))) break; offset--; } break; } wasLetter |= isLetter; if (wasLetter) wasWhitespaceAfterLetter |= isWhiteSpace; } var unit = SyntaxTree.Parse (CreateStub (doc, offset), doc.FileName); return ResolveAtLocation.Resolve ( doc.Compilation, doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile, unit, location, out node); }
public Selection(DocumentLocation anchor, DocumentLocation lead, SelectionMode selectionMode) { this.Anchor = anchor; this.Lead = lead; this.SelectionMode = selectionMode; }
public DocumentLocationEventArgs(DocumentLocation location) { this.location = location; }
public static void Left(TextEditorData data) { using (var undo = data.OpenUndoGroup()) { if (Platform.IsMac && data.IsSomethingSelected && !data.Caret.PreserveSelection) { data.Caret.Offset = System.Math.Min(data.SelectionAnchor, data.Caret.Offset); data.ClearSelection(); return; } if (data.Caret.Column > DocumentLocation.MinColumn) { DocumentLine line = data.Document.GetLine(data.Caret.Line); if (data.Caret.Column > line.Length + 1) { if (data.Caret.AllowCaretBehindLineEnd) { data.Caret.Column--; } else { data.Caret.Column = line.Length + 1; } } else { int offset = data.Caret.Offset - 1; bool foundFolding = false; foreach (var folding in data.Document.GetFoldingsFromOffset(offset).Where(f => f.IsCollapsed && f.Offset < offset)) { offset = System.Math.Min(offset, folding.Offset); foundFolding = true; } if (!foundFolding) { var layout = data.Parent?.TextViewMargin?.GetLayout(line); if (layout != null && data.Caret.Column < line.Length) { uint curIndex = 0, byteIndex = 0; int utf8ByteIndex = (int)layout.TranslateToUTF8Index((uint)(offset - line.Offset), ref curIndex, ref byteIndex); layout.Layout.GetCursorPos(utf8ByteIndex, out var strong_pos, out var weak_pos); if (strong_pos.X != weak_pos.X) { offset--; } } } data.Caret.Offset = offset; } } else if (data.Caret.Line > DocumentLocation.MinLine) { DocumentLine prevLine = data.Document.GetLine(data.Caret.Line - 1); var nextLocation = new DocumentLocation(data.Caret.Line - 1, prevLine.Length + 1); if (data.HasIndentationTracker && data.Options.IndentStyle == IndentStyle.Virtual && nextLocation.Column == DocumentLocation.MinColumn) { nextLocation = new DocumentLocation(data.Caret.Line - 1, data.GetVirtualIndentationColumn(nextLocation)); } data.Caret.Location = nextLocation; } } }
public void SetSelection(DocumentLocation anchor, DocumentLocation lead) { textArea.SetSelection(anchor, lead); }
public void ExtendSelectionTo(DocumentLocation location) { textArea.ExtendSelectionTo(location); }
public void ScrollTo(DocumentLocation p) { textArea.ScrollTo(p); }
public void CenterTo(DocumentLocation p) { textArea.CenterTo(p); }
public DocumentLocation LogicalToVisualLocation(DocumentLocation location) { return(textArea.LogicalToVisualLocation(location)); }
public void SetToOffsetWithDesiredColumn (int desiredOffset) { DocumentLocation old = Location; int line = TextEditorData.Document.OffsetToLineNumber (desiredOffset); int column = desiredOffset - TextEditorData.Document.GetLine (line).Offset + 1; location = new DocumentLocation (line, column); SetColumn (); OnPositionChanged (new DocumentLocationEventArgs (old)); }
public static string GetIndentationString(this IIndentationTracker thisObject, DocumentLocation loc) { return(thisObject.GetIndentationString(loc.Line, loc.Column)); }
public Selection (DocumentLocation anchor, DocumentLocation lead) : this (anchor, lead, SelectionMode.Normal) { }
public static int GetVirtualIndentationColumn(this IIndentationTracker thisObject, DocumentLocation loc) { return(thisObject.GetVirtualIndentationColumn(loc.Line, loc.Column)); }
public override TooltipItem GetItem (Mono.TextEditor.TextEditor editor, int offset) { if (offset >= editor.Document.TextLength) return null; if (!DebuggingService.IsDebugging || DebuggingService.IsRunning) return null; StackFrame frame = DebuggingService.CurrentFrame; if (frame == null) return null; var ed = (ExtensibleTextEditor)editor; string expression = null; int startOffset = 0, length = 0; if (ed.IsSomethingSelected && offset >= ed.SelectionRange.Offset && offset <= ed.SelectionRange.EndOffset) { expression = ed.SelectedText; startOffset = ed.SelectionRange.Offset; length = ed.SelectionRange.Length; } else { ICSharpCode.NRefactory.TypeSystem.DomRegion expressionRegion; ResolveResult res = ed.GetLanguageItem (offset, out expressionRegion); if (res == null || res.IsError || res.GetType () == typeof (ResolveResult)) return null; //Console.WriteLine ("res is a {0}", res.GetType ().Name); if (expressionRegion.IsEmpty) return null; if (res is NamespaceResolveResult || res is ConversionResolveResult || res is ForEachResolveResult || res is TypeIsResolveResult || res is TypeOfResolveResult || res is ErrorResolveResult) return null; var start = new DocumentLocation (expressionRegion.BeginLine, expressionRegion.BeginColumn); var end = new DocumentLocation (expressionRegion.EndLine, expressionRegion.EndColumn); startOffset = editor.Document.LocationToOffset (start); int endOffset = editor.Document.LocationToOffset (end); length = endOffset - startOffset; if (res is LocalResolveResult) { var lr = (LocalResolveResult) res; // Capture only the local variable portion of the expression... expression = lr.Variable.Name; length = expression.Length; // Calculate start offset based on the variable region because we don't want to include the type information. // Note: We might not actually need to do this anymore? if (lr.Variable.Region.BeginLine != start.Line || lr.Variable.Region.BeginColumn != start.Column) { start = new DocumentLocation (lr.Variable.Region.BeginLine, lr.Variable.Region.BeginColumn); startOffset = editor.Document.LocationToOffset (start); } } else if (res is InvocationResolveResult) { var ir = (InvocationResolveResult) res; if (ir.Member.Name != ".ctor") return null; expression = ir.Member.DeclaringType.FullName; } else if (res is MemberResolveResult) { var mr = (MemberResolveResult) res; if (mr.TargetResult == null) { // User is hovering over a member definition... if (mr.Member is IProperty) { // Visual Studio will evaluate Properties if you hover over their definitions... var prop = (IProperty) mr.Member; if (prop.CanGet) { if (prop.IsStatic) expression = prop.FullName; else expression = prop.Name; } else { return null; } } else if (mr.Member is IField) { var field = (IField) mr.Member; if (field.IsStatic) expression = field.FullName; else expression = field.Name; } else { return null; } } // If the TargetResult is not null, then treat it like any other ResolveResult. } else if (res is ConstantResolveResult) { // Fall through... } else if (res is ThisResolveResult) { // Fall through... } else if (res is TypeResolveResult) { // Fall through... } else { return null; } if (expression == null) expression = ed.GetTextBetween (start, end); } if (string.IsNullOrEmpty (expression)) return null; ObjectValue val; if (!cachedValues.TryGetValue (expression, out val)) { val = frame.GetExpressionValue (expression, true); cachedValues [expression] = val; } if (val == null || val.IsUnknown || val.IsNotSupported) return null; val.Name = expression; return new TooltipItem (val, startOffset, length); }
public InsertionPoint(DocumentLocation location, NewLineInsertion lineBefore, NewLineInsertion lineAfter) { this.Location = location; this.LineBefore = lineBefore; this.LineAfter = lineAfter; }
public Gdk.Point DocumentToScreenLocation (DocumentLocation location) { var p = widget.TextEditor.LocationToPoint (location); int tx, ty; widget.Vbox.ParentWindow.GetOrigin (out tx, out ty); tx += widget.TextEditorContainer.Allocation.X + p.X; ty += widget.TextEditorContainer.Allocation.Y + p.Y + (int)TextEditor.LineHeight; return new Gdk.Point (tx, ty); }
public DocumentLocation LogicalToVisualLocation(DocumentLocation location) { return(Document.LogicalToVisualLocation(this, location)); }
/// <summary> /// Initiate a pulse at the specified document location /// </summary> /// <param name="pulseStart"> /// A <see cref="DocumentLocation"/> /// </param> public void PulseCharacter(DocumentLocation pulseStart) { textArea.PulseCharacter(pulseStart); }
public void SetSelection(DocumentLocation anchor, DocumentLocation lead) { MainSelection = new Selection(anchor, lead); }
public void GetLineColumnFromPosition(int position, out int line, out int column) { Mono.TextEditor.DocumentLocation loc = document.OffsetToLocation(position); line = loc.Line; column = loc.Column; }
static DocumentLocation LimitColumn(TextEditorData data, DocumentLocation loc) { return(new DocumentLocation(loc.Line, System.Math.Min(loc.Column, data.GetLine(loc.Line).Length + 1))); }
public Selection(DocumentLocation anchor, DocumentLocation lead) : this(anchor, lead, SelectionMode.Normal) { }
public bool Contains(DocumentLocation location) { return(Begin <= location && location < End); }
void CopyData(TextEditorData data, Selection selection) { copiedDocument = null; monoDocument = null; if (!selection.IsEmpty && data != null && data.Document != null) { copiedDocument = new TextDocument(); monoDocument = new TextDocument(); this.docStyle = data.ColorStyle; this.options = data.Options; copyData = null; copiedColoredChunks = ColoredSegment.GetChunks(data, data.SelectionRange); switch (selection.SelectionMode) { case SelectionMode.Normal: isBlockMode = false; var segment = selection.GetSelectionRange(data); var pasteHandler = data.TextPasteHandler; if (pasteHandler != null) { copyData = pasteHandler.GetCopyData(segment); } var text = data.GetTextAt(segment); copiedDocument.Text = text; monoDocument.Text = text; var line = data.Document.GetLineByOffset(segment.Offset); var spanStack = line.StartSpan.Clone(); this.copiedDocument.GetLine(DocumentLocation.MinLine).StartSpan = spanStack; break; case SelectionMode.Block: isBlockMode = true; DocumentLocation visStart = data.LogicalToVisualLocation(selection.Anchor); DocumentLocation visEnd = data.LogicalToVisualLocation(selection.Lead); int startCol = System.Math.Min(visStart.Column, visEnd.Column); int endCol = System.Math.Max(visStart.Column, visEnd.Column); for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++) { DocumentLine curLine = data.Document.GetLine(lineNr); int col1 = curLine.GetLogicalColumn(data, startCol) - 1; int col2 = System.Math.Min(curLine.GetLogicalColumn(data, endCol) - 1, curLine.Length); if (col1 < col2) { copiedDocument.Insert(copiedDocument.TextLength, data.Document.GetTextAt(curLine.Offset + col1, col2 - col1)); monoDocument.Insert(monoDocument.TextLength, data.Document.GetTextAt(curLine.Offset + col1, col2 - col1)); } if (lineNr < selection.MaxLine) { // Clipboard line end needs to be system dependend and not the document one. copiedDocument.Insert(copiedDocument.TextLength, Environment.NewLine); // \r in mono document stands for block selection line end. monoDocument.Insert(monoDocument.TextLength, "\r"); } } line = data.Document.GetLine(selection.MinLine); spanStack = line.StartSpan.Clone(); this.copiedDocument.GetLine(DocumentLocation.MinLine).StartSpan = spanStack; break; } } else { copiedDocument = null; } }
public bool IsSelected(DocumentLocation loc) { return(anchor <= loc && loc <= lead || lead <= loc && loc <= anchor); }
void CreateSmartTag (List<CodeAction> fixes, DocumentLocation loc) { Fixes = fixes; if (!QuickTaskStrip.EnableFancyFeatures) { RemoveWidget (); return; } var editor = document.Editor; if (editor == null || editor.Parent == null || !editor.Parent.IsRealized) { RemoveWidget (); return; } if (document.ParsedDocument == null || document.ParsedDocument.IsInvalid) { RemoveWidget (); return; } var container = editor.Parent; if (container == null) { RemoveWidget (); return; } bool first = true; DocumentLocation smartTagLocBegin = loc; foreach (var fix in fixes) { if (fix.DocumentRegion.IsEmpty) continue; if (first || loc < fix.DocumentRegion.Begin) { smartTagLocBegin = fix.DocumentRegion.Begin; } first = false; } if (smartTagLocBegin.Line != loc.Line) smartTagLocBegin = new DocumentLocation (loc.Line, 1); // got no fix location -> try to search word start if (first) { int offset = document.Editor.LocationToOffset (smartTagLocBegin); while (offset > 0) { char ch = document.Editor.GetCharAt (offset - 1); if (!char.IsLetterOrDigit (ch) && ch != '_') break; offset--; } smartTagLocBegin = document.Editor.OffsetToLocation (offset); } if (currentSmartTag != null && currentSmartTagBegin == smartTagLocBegin) { currentSmartTag.fixes = fixes; return; } RemoveWidget (); currentSmartTagBegin = smartTagLocBegin; var line = document.Editor.GetLine (smartTagLocBegin.Line); currentSmartTag = new SmartTagMarker ((line.NextLine ?? line).Offset, this, fixes, smartTagLocBegin); document.Editor.Document.AddMarker (currentSmartTag); }
// for markup syntax mode the syntax highlighting information need to be taken into account // when calculating the selection offsets. int PosToOffset (TextEditorData data, DocumentLocation loc) { LineSegment line = data.GetLine (loc.Line); if (line == null) return 0; Chunk startChunk = data.Document.SyntaxMode.GetChunks (data.Document, data.Parent.ColorStyle, line, line.Offset, line.Length); int col = 1; for (Chunk chunk = startChunk; chunk != null; chunk = chunk != null ? chunk.Next : null) { if (col <= loc.Column && loc.Column < col + chunk.Length) return chunk.Offset - col + loc.Column; col += chunk.Length; } return line.Offset + line.EditableLength; }
void StoreWidgetState () { // vSave = textEditor.VAdjustment.Value; // hSave = textEditor.HAdjustment.Value; caretSave = textEditor.Caret.Location; }
void RunFormatter (DocumentLocation location) { if (OnTheFlyFormatting && textEditorData != null && !(textEditorData.CurrentMode is TextLinkEditMode) && !(textEditorData.CurrentMode is InsertionCursorEditMode)) { OnTheFlyFormatter.Format (Document, location); } }
public bool Contains (DocumentLocation loc) { return anchor <= loc && loc <= lead || lead <= loc && loc <= anchor; }
bool IsInsideSelection (DocumentLocation clickLocation) { var selection = textEditor.MainSelection; if (selection.SelectionMode == SelectionMode.Block) { int minColumn = System.Math.Min (selection.Anchor.Column, selection.Lead.Column); int maxColumn = System.Math.Max (selection.Anchor.Column, selection.Lead.Column); return selection.MinLine <= clickLocation.Line && clickLocation.Line <= selection.MaxLine && minColumn <= clickLocation.Column && clickLocation.Column <= maxColumn; } return selection.Start <= clickLocation && clickLocation < selection.End; }
public bool IsSelected(DocumentLocation start, DocumentLocation end) { return(IsSelected(start) && IsSelected(end)); }
public Cairo.Point LocationToPoint (DocumentLocation loc) { return LocationToPoint (loc, false); }
static IEnumerable<string> GetPossibleNamespaces (Document doc, AstNode node, ResolveResult resolveResult, DocumentLocation location) { var unit = doc.ParsedDocument.GetAst<CompilationUnit> (); if (unit == null) yield break; int tc = GetTypeParameterCount (node); var attribute = unit.GetNodeAt<ICSharpCode.NRefactory.CSharp.Attribute> (location); bool isInsideAttributeType = attribute != null && attribute.Type.Contains (location); var lookup = new MemberLookup (null, doc.Compilation.MainAssembly); if (resolveResult is AmbiguousTypeResolveResult) { var aResult = resolveResult as AmbiguousTypeResolveResult; var file = doc.ParsedDocument.ParsedFile as CSharpParsedFile; var scope = file.GetUsingScope (location).Resolve (doc.Compilation); while (scope != null) { foreach (var u in scope.Usings) { foreach (var typeDefinition in u.Types) { if (typeDefinition.Name == aResult.Type.Name && typeDefinition.TypeParameterCount == tc && lookup.IsAccessible (typeDefinition, false)) { yield return typeDefinition.Namespace; } } } scope = scope.Parent; } yield break; } if (resolveResult is UnknownIdentifierResolveResult) { var uiResult = resolveResult as UnknownIdentifierResolveResult; string possibleAttributeName = isInsideAttributeType ? uiResult.Identifier + "Attribute" : null; foreach (var typeDefinition in doc.Compilation.GetAllTypeDefinitions ()) { if ((typeDefinition.Name == uiResult.Identifier || typeDefinition.Name == possibleAttributeName) && typeDefinition.TypeParameterCount == tc && lookup.IsAccessible (typeDefinition, false)) { yield return typeDefinition.Namespace; } } yield break; } if (resolveResult is UnknownMemberResolveResult) { var umResult = (UnknownMemberResolveResult)resolveResult; string possibleAttributeName = isInsideAttributeType ? umResult.MemberName + "Attribute" : null; var compilation = doc.Compilation; foreach (var typeDefinition in compilation.GetAllTypeDefinitions ().Where (t => t.HasExtensionMethods)) { foreach (var method in typeDefinition.Methods.Where (m => m.IsExtensionMethod && (m.Name == umResult.MemberName || m.Name == possibleAttributeName))) { IType[] inferredTypes; if (CSharpResolver.IsEligibleExtensionMethod ( compilation.Import (umResult.TargetType), method, true, out inferredTypes )) { yield return typeDefinition.Namespace; goto skipType; } } skipType: ; } yield break; } if (resolveResult is ErrorResolveResult) { var identifier = unit != null ? unit.GetNodeAt<ICSharpCode.NRefactory.CSharp.Identifier> (location) : null; if (identifier != null) { var uiResult = resolveResult as UnknownIdentifierResolveResult; if (uiResult != null) { string possibleAttributeName = isInsideAttributeType ? uiResult.Identifier + "Attribute" : null; foreach (var typeDefinition in doc.Compilation.GetAllTypeDefinitions ()) { if ((identifier.Name == uiResult.Identifier || identifier.Name == possibleAttributeName) && typeDefinition.TypeParameterCount == tc && lookup.IsAccessible (typeDefinition, false)) yield return typeDefinition.Namespace; } } } yield break; } }
public bool Contains(DocumentLocation loc) { return(anchor <= loc && loc <= lead || lead <= loc && loc <= anchor); }
LayoutWrapper GetVirtualSpaceLayout (DocumentLine line, DocumentLocation location) { string virtualSpace = ""; var data = textEditor.GetTextEditorData (); if (data.HasIndentationTracker && line.Length == 0) { virtualSpace = this.textEditor.GetTextEditorData ().GetIndentationString (location); } if (location.Column > line.Length + 1 + virtualSpace.Length) virtualSpace += new string (' ', location.Column - line.Length - 1 - virtualSpace.Length); // predit layout already contains virtual space. if (!string.IsNullOrEmpty (textEditor.preeditString)) virtualSpace = ""; LayoutWrapper wrapper = new LayoutWrapper (textEditor.LayoutCache.RequestLayout ()); wrapper.LineChars = virtualSpace.ToCharArray (); wrapper.Layout.SetText (virtualSpace); wrapper.Layout.Tabs = tabArray; wrapper.Layout.FontDescription = textEditor.Options.Font; int vy, vx; wrapper.Layout.GetSize (out vx, out vy); wrapper.Width = wrapper.LastLineWidth = vx / Pango.Scale.PangoScale; return wrapper; }
Selection(bool empty) { anchor = lead = DocumentLocation.Empty; selectionMode = SelectionMode.Normal; }
internal bool CalculateClickLocation (double x, double y, out DocumentLocation clickLocation) { VisualLocationTranslator trans = new VisualLocationTranslator (this); clickLocation = trans.PointToLocation (x, y); if (clickLocation.Line < DocumentLocation.MinLine || clickLocation.Column < DocumentLocation.MinColumn) return false; DocumentLine line = Document.GetLine (clickLocation.Line); if (line != null && clickLocation.Column >= line.Length + 1 && GetWidth (Document.GetTextAt (line.SegmentIncludingDelimiter) + "-") < x) { clickLocation = new DocumentLocation (clickLocation.Line, line.Length + 1); if (textEditor.GetTextEditorData ().HasIndentationTracker && textEditor.Options.IndentStyle == IndentStyle.Virtual && clickLocation.Column == 1) { int indentationColumn = this.textEditor.GetTextEditorData ().GetVirtualIndentationColumn (clickLocation); if (indentationColumn > clickLocation.Column) clickLocation = new DocumentLocation (clickLocation.Line, indentationColumn); } } return true; }
public Selection WithLead(DocumentLocation newLead) { return(new Selection(Anchor, newLead, SelectionMode)); }
public Cairo.Point LocationToPoint (DocumentLocation loc, bool useAbsoluteCoordinates) { DocumentLine line = Document.GetLine (loc.Line); if (line == null) return new Cairo.Point (-1, -1); int x = (int)(ColumnToX (line, loc.Column) + this.XOffset + this.TextStartPosition); int y = (int)LineToY (loc.Line); return useAbsoluteCoordinates ? new Cairo.Point (x, y) : new Cairo.Point (x - (int)this.textEditor.HAdjustment.Value, y - (int)this.textEditor.VAdjustment.Value); }
public Selection WithAnchor(DocumentLocation newAnchor) { return(new Selection(newAnchor, Lead, SelectionMode)); }
public InsertionPoint (DocumentLocation location, NewLineInsertion lineBefore, NewLineInsertion lineAfter) { this.Location = location; this.LineBefore = lineBefore; this.LineAfter = lineAfter; }
internal void ShowListWindow <T> (ListWindow <T> window, DocumentLocation loc) { textArea.ShowListWindow <T> (window, loc); }
static IEnumerable<PossibleNamespace> GetPossibleNamespaces (Document doc, AstNode node, ResolveResult resolveResult, DocumentLocation location) { var unit = doc.ParsedDocument.GetAst<SyntaxTree> (); if (unit == null) yield break; var project = doc.Project; if (project == null) yield break; int tc = GetTypeParameterCount (node); var attribute = unit.GetNodeAt<ICSharpCode.NRefactory.CSharp.Attribute> (location); bool isInsideAttributeType = attribute != null && attribute.Type.Contains (location); var compilations = new List<Tuple<ICompilation, MonoDevelop.Projects.ProjectReference>> (); compilations.Add (Tuple.Create (doc.Compilation, (MonoDevelop.Projects.ProjectReference)null)); var referencedItems = IdeApp.Workspace != null ? project.GetReferencedItems (IdeApp.Workspace.ActiveConfiguration).ToList () : (IEnumerable<SolutionItem>) new SolutionItem[0]; var solution = project != null ? project.ParentSolution : null; if (solution != null) { foreach (var curProject in solution.GetAllProjects ()) { if (curProject == project || referencedItems.Contains (curProject)) continue; var otherRefes = IdeApp.Workspace != null ? curProject.GetReferencedItems (IdeApp.Workspace.ActiveConfiguration).ToList () : (IEnumerable<SolutionItem>) new SolutionItem[0]; if (otherRefes.Contains (project)) continue; var comp = TypeSystemService.GetCompilation (curProject); if (comp == null) continue; compilations.Add (Tuple.Create (comp, new MonoDevelop.Projects.ProjectReference (curProject))); } } var netProject = project as DotNetProject; if (netProject == null) yield break; FrameworkLookup frameworkLookup; if (!TypeSystemService.TryGetFrameworkLookup (netProject, out frameworkLookup)) frameworkLookup = null; if (frameworkLookup != null && resolveResult is UnknownMemberResolveResult) { var umResult = (UnknownMemberResolveResult)resolveResult; try { foreach (var r in frameworkLookup.GetExtensionMethodLookups (umResult)) { var systemAssembly = netProject.AssemblyContext.GetAssemblyFromFullName (r.FullName, r.Package, netProject.TargetFramework); if (systemAssembly == null) continue; if (CanBeReferenced (doc.Project, systemAssembly)) compilations.Add (Tuple.Create (TypeSystemService.GetCompilation (systemAssembly, doc.Compilation), new MonoDevelop.Projects.ProjectReference (systemAssembly))); } } catch (Exception e) { if (!TypeSystemService.RecreateFrameworkLookup (netProject)) LoggingService.LogError (string.Format ("Error while looking up extension method {0}", umResult.MemberName), e); } } bool foundIdentifier = false; var lookup = new MemberLookup (null, doc.Compilation.MainAssembly); foreach (var comp in compilations) { var compilation = comp.Item1; var requiredReference = comp.Item2; if (resolveResult is AmbiguousTypeResolveResult) { if (compilation != doc.Compilation) continue; var aResult = resolveResult as AmbiguousTypeResolveResult; var file = doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile; var scope = file.GetUsingScope (location).Resolve (compilation); while (scope != null) { foreach (var u in scope.Usings) { foreach (var typeDefinition in u.Types) { if (typeDefinition.Name == aResult.Type.Name && typeDefinition.TypeParameterCount == tc && lookup.IsAccessible (typeDefinition, false)) { yield return new PossibleNamespace (typeDefinition.Namespace, true, requiredReference); } } } scope = scope.Parent; } } var allTypes = compilation == doc.Compilation ? compilation.GetAllTypeDefinitions () : compilation.MainAssembly.GetAllTypeDefinitions (); if (resolveResult is UnknownIdentifierResolveResult) { var uiResult = resolveResult as UnknownIdentifierResolveResult; string possibleAttributeName = isInsideAttributeType ? uiResult.Identifier + "Attribute" : uiResult.Identifier; foreach (var typeDefinition in allTypes) { if ((typeDefinition.Name == possibleAttributeName || typeDefinition.Name == uiResult.Identifier) && typeDefinition.TypeParameterCount == tc && lookup.IsAccessible (typeDefinition, false)) { if (typeDefinition.DeclaringTypeDefinition != null) { var builder = new TypeSystemAstBuilder (new CSharpResolver (doc.Compilation)); foundIdentifier = true; yield return new PossibleNamespace (builder.ConvertType (typeDefinition.DeclaringTypeDefinition).ToString (), false, requiredReference); } else { foundIdentifier = true; yield return new PossibleNamespace (typeDefinition.Namespace, true, requiredReference); } } } } if (resolveResult is UnknownMemberResolveResult) { var umResult = (UnknownMemberResolveResult)resolveResult; string possibleAttributeName = isInsideAttributeType ? umResult.MemberName + "Attribute" : umResult.MemberName; foreach (var typeDefinition in allTypes.Where (t => t.HasExtensionMethods)) { if (!lookup.IsAccessible (typeDefinition, false)) continue; foreach (var method in typeDefinition.Methods.Where (m => m.IsExtensionMethod && (m.Name == possibleAttributeName || m.Name == umResult.MemberName))) { if (!lookup.IsAccessible (method, false)) continue; IType[] inferredTypes; if (CSharpResolver.IsEligibleExtensionMethod ( compilation.Import (umResult.TargetType), method, true, out inferredTypes )) { yield return new PossibleNamespace (typeDefinition.Namespace, true, requiredReference); goto skipType; } } skipType: ; } } if (resolveResult is ErrorResolveResult) { var identifier = unit != null ? unit.GetNodeAt<Identifier> (location) : null; if (identifier != null) { var uiResult = resolveResult as UnknownIdentifierResolveResult; if (uiResult != null) { string possibleAttributeName = isInsideAttributeType ? uiResult.Identifier + "Attribute" : uiResult.Identifier; foreach (var typeDefinition in allTypes) { if ((identifier.Name == possibleAttributeName || identifier.Name == uiResult.Identifier) && typeDefinition.TypeParameterCount == tc && lookup.IsAccessible (typeDefinition, false)) yield return new PossibleNamespace (typeDefinition.Namespace, true, requiredReference); } } } } } // Try to search framework types if (!foundIdentifier && frameworkLookup != null && resolveResult is UnknownIdentifierResolveResult && node is AstType) { var uiResult = resolveResult as UnknownIdentifierResolveResult; if (uiResult != null) { var lookups = new List<Tuple<FrameworkLookup.AssemblyLookup, SystemAssembly>> (); try { foreach (var r in frameworkLookup.GetLookups (uiResult, tc, isInsideAttributeType)) { var systemAssembly = netProject.AssemblyContext.GetAssemblyFromFullName (r.FullName, r.Package, netProject.TargetFramework); if (systemAssembly == null) continue; if (CanBeReferenced (doc.Project, systemAssembly)) lookups.Add (Tuple.Create (r, systemAssembly)); } } catch (Exception e) { if (!TypeSystemService.RecreateFrameworkLookup (netProject)) LoggingService.LogError (string.Format ("Error while looking up identifier {0}", uiResult.Identifier), e); } foreach(var kv in lookups) yield return new PossibleNamespace (kv.Item1.Namespace, true, new MonoDevelop.Projects.ProjectReference (kv.Item2)); } } if (!foundIdentifier && frameworkLookup != null && resolveResult is UnknownMemberResolveResult) { var uiResult = resolveResult as UnknownMemberResolveResult; if (uiResult != null) { var lookups = new List<Tuple<FrameworkLookup.AssemblyLookup, SystemAssembly>> (); try { foreach (var r in frameworkLookup.GetLookups (uiResult, node.ToString (), tc, isInsideAttributeType)) { var systemAssembly = netProject.AssemblyContext.GetAssemblyFromFullName (r.FullName, r.Package, netProject.TargetFramework); if (systemAssembly == null) continue; if (CanBeReferenced (doc.Project, systemAssembly)) lookups.Add (Tuple.Create (r, systemAssembly)); } } catch (Exception e) { if (!TypeSystemService.RecreateFrameworkLookup (netProject)) LoggingService.LogError (string.Format ("Error while looking up member resolve result {0}", node), e); } foreach(var kv in lookups) yield return new PossibleNamespace (kv.Item1.Namespace, true, new MonoDevelop.Projects.ProjectReference (kv.Item2)); } } }
public string GetTextBetween(DocumentLocation start, DocumentLocation end) { return(Document.GetTextBetween(start, end)); }
void MoveToTask (QuickTask task) { if (task.Location.IsEmpty) { Console.WriteLine ("empty:" + task.Description); } var loc = new DocumentLocation ( Math.Max (DocumentLocation.MinLine, task.Location.Line), Math.Max (DocumentLocation.MinColumn, task.Location.Column) ); TextEditor.Caret.Location = loc; TextEditor.CenterToCaret (); TextEditor.StartCaretPulseAnimation (); TextEditor.GrabFocus (); }
public int LocationToOffset(DocumentLocation location) { return(Document.LocationToOffset(location)); }