コード例 #1
0
        void RunFormatter(MonoDevelop.Ide.Editor.DocumentLocation location)
        {
            if (!OnTheFlyFormatting || Editor == null || Editor.EditMode != EditMode.Edit)
            {
                return;
            }
            var offset = Editor.LocationToOffset(location);

            OnTheFlyFormatter.Format(Editor, DocumentContext, offset, offset, optionSet: optionSet);
        }
コード例 #2
0
        protected override async Task <ICompletionDataList> HandleCodeCompletion(
            CodeCompletionContext completionContext, bool forced, CancellationToken token)
        {
            var  currentLocation = new MonoDevelop.Ide.Editor.DocumentLocation(completionContext.TriggerLine, completionContext.TriggerLineOffset);
            char currentChar     = completionContext.TriggerOffset < 1 ? ' ' : Editor.GetCharAt(completionContext.TriggerOffset - 1);

            var codeState = Tracker.Engine.CurrentState as RazorCodeFragmentState;

            if (currentChar == '<' && codeState != null)
            {
                if (!codeState.IsInsideParentheses && !codeState.IsInsideGenerics)
                {
                    var list = await GetElementCompletions(token);

                    return(list);
                }
            }
            else if (currentChar == '>' && Tracker.Engine.CurrentState is RazorCodeFragmentState)
            {
                return(ClosingTagCompletion(Editor, currentLocation));
            }

            return(await base.HandleCodeCompletion(completionContext, forced, token));
        }
コード例 #3
0
 public DocumentLocationEventArgs(DocumentLocation location)
 {
     this.location = location;
 }
コード例 #4
0
 public bool Contains(DocumentLocation loc)
 {
     return(Anchor <= loc && loc <= Lead || Lead < loc && loc < Anchor);
 }
コード例 #5
0
ファイル: Selection.cs プロジェクト: zcf7822/monodevelop
 public bool IsSelected(DocumentLocation loc)
 {
     return(anchor <= loc && loc <= lead || lead <= loc && loc <= anchor);
 }
コード例 #6
0
        public static void FormatStatmentAt(TextEditor editor, DocumentContext context, MonoDevelop.Ide.Editor.DocumentLocation location, OptionSet optionSet = null)
        {
            var offset        = editor.LocationToOffset(location);
            var policyParent  = context.Project != null ? context.Project.Policies : PolicyService.DefaultPolicies;
            var mimeTypeChain = DesktopService.GetMimeTypeInheritanceChain(CSharpFormatter.MimeType);

            Format(policyParent, mimeTypeChain, editor, context, offset, offset, false, true, optionSet: optionSet);
        }
コード例 #7
0
 static DocumentLocation LimitColumn(TextEditor data, DocumentLocation loc)
 {
     return(new DocumentLocation(loc.Line, System.Math.Min(loc.Column, data.GetLine(loc.Line).Length + 1)));
 }
コード例 #8
0
 public CaretLocationEventArgs(DocumentLocation location, Microsoft.VisualStudio.Text.ITextSnapshot textSnapshot, CaretChangeReason reason) : base(location)
 {
     Snapshot          = textSnapshot;
     CaretChangeReason = reason;
 }
コード例 #9
0
ファイル: DocumentRegion.cs プロジェクト: noah1510/dotdevelop
 public bool Contains(DocumentLocation location)
 {
     return(Begin <= location && location < End);
 }
コード例 #10
0
        void UpdateFoldings(ParsedDocument parsedDocument, DocumentLocation caretLocation, bool firstTime = false, CancellationToken token = default(CancellationToken))
        {
            if (parsedDocument == null || !textEditor.Options.ShowFoldMargin || isDisposed)
            {
                return;
            }
            // don't update parsed documents that contain errors - the foldings from there may be invalid.
            if (parsedDocument.HasErrors)
            {
                return;
            }

            try {
                var foldSegments = new List <IFoldSegment> ();

                foreach (FoldingRegion region in parsedDocument.GetFoldingsAsync(token).Result)
                {
                    if (token.IsCancellationRequested)
                    {
                        return;
                    }
                    var  type      = FoldingType.Unknown;
                    bool setFolded = false;
                    bool folded    = false;
                    //decide whether the regions should be folded by default
                    switch (region.Type)
                    {
                    case FoldType.Member:
                        type = FoldingType.TypeMember;
                        break;

                    case FoldType.Type:
                        type = FoldingType.TypeDefinition;
                        break;

                    case FoldType.UserRegion:
                        type      = FoldingType.Region;
                        setFolded = DefaultSourceEditorOptions.Instance.DefaultRegionsFolding;
                        folded    = true;
                        break;

                    case FoldType.Comment:
                        type      = FoldingType.Comment;
                        setFolded = DefaultSourceEditorOptions.Instance.DefaultCommentFolding;
                        folded    = true;
                        break;

                    case FoldType.CommentInsideMember:
                        type      = FoldingType.Comment;
                        setFolded = DefaultSourceEditorOptions.Instance.DefaultCommentFolding;
                        folded    = false;
                        break;

                    case FoldType.Undefined:
                        setFolded = true;
                        folded    = region.IsFoldedByDefault;
                        break;
                    }
                    var start  = textEditor.LocationToOffset(region.Region.Begin);
                    var end    = textEditor.LocationToOffset(region.Region.End);
                    var marker = textEditor.CreateFoldSegment(start, end - start);
                    foldSegments.Add(marker);
                    marker.CollapsedText = region.Name;
                    marker.FoldingType   = type;
                    //and, if necessary, set its fold state
                    if (marker != null && setFolded && firstTime)
                    {
                        // only fold on document open, later added folds are NOT folded by default.
                        marker.IsCollapsed = folded;
                        continue;
                    }
                    if (marker != null && region.Region.Contains(caretLocation.Line, caretLocation.Column))
                    {
                        marker.IsCollapsed = false;
                    }
                }
                if (firstTime)
                {
                    textEditor.SetFoldings(foldSegments);
                }
                else
                {
                    Application.Invoke(delegate {
                        if (!token.IsCancellationRequested)
                        {
                            textEditor.SetFoldings(foldSegments);
                        }
                    });
                }
            } catch (Exception ex) {
                LoggingService.LogError("Unhandled exception in ParseInformationUpdaterWorkerThread", ex);
            }
        }
コード例 #11
0
 public InsertionPoint(DocumentLocation location, NewLineInsertion lineBefore, NewLineInsertion lineAfter)
 {
     this.Location   = location;
     this.LineBefore = lineBefore;
     this.LineAfter  = lineAfter;
 }
コード例 #12
0
 public static ISmartTagMarker CreateSmartTagMarker(TextEditor editor, int offset, DocumentLocation realLocation)
 {
     return(editor.TextMarkerFactory.CreateSmartTagMarker(editor, offset, realLocation));
 }
コード例 #13
0
ファイル: Selection.cs プロジェクト: zcf7822/monodevelop
 Selection(bool empty)
 {
     anchor        = lead = DocumentLocation.Empty;
     selectionMode = SelectionMode.Normal;
 }
コード例 #14
0
ファイル: Selection.cs プロジェクト: zcf7822/monodevelop
 public bool Contains(DocumentLocation loc)
 {
     return(anchor <= loc && loc <= lead || lead < loc && loc < anchor);
 }
コード例 #15
0
 public static string GetTextBetween(this IReadonlyTextDocument document, DocumentLocation start, DocumentLocation end)
 {
     if (document == null)
     {
         throw new ArgumentNullException("document");
     }
     return(document.GetTextBetween(document.LocationToOffset(start), document.LocationToOffset(end)));
 }
コード例 #16
0
ファイル: DocumentRegion.cs プロジェクト: noah1510/dotdevelop
 public bool IsInside(DocumentLocation location)
 {
     return(Begin <= location && location <= End);
 }
コード例 #17
0
		protected override async Task<ICompletionDataList> HandleCodeCompletion (
			CodeCompletionContext completionContext, bool forced, CancellationToken token)
		{
			var currentLocation = new MonoDevelop.Ide.Editor.DocumentLocation (completionContext.TriggerLine, completionContext.TriggerLineOffset);
			char currentChar = completionContext.TriggerOffset < 1 ? ' ' : Editor.GetCharAt (completionContext.TriggerOffset - 1);

			var codeState = Tracker.Engine.CurrentState as RazorCodeFragmentState;
			if (currentChar == '<' && codeState != null) {
				if (!codeState.IsInsideParentheses && !codeState.IsInsideGenerics) {
					var list = await GetElementCompletions (token);
					return list;
				}
			} else if (currentChar == '>' && Tracker.Engine.CurrentState is RazorCodeFragmentState)
				return ClosingTagCompletion (Editor, currentLocation);

			return await base.HandleCodeCompletion (completionContext, forced, token);
		}
コード例 #18
0
 public Selection WithAnchor(DocumentLocation newAnchor)
 {
     return(new Selection(newAnchor, Lead, SelectionMode));
 }
コード例 #19
0
		public SmartTagMarker (int offset, MonoDevelop.Ide.Editor.DocumentLocation realLocation) : base (offset, 0)
		{
			this.loc = realLocation;
		}
コード例 #20
0
 public Selection WithRange(DocumentLocation newAnchor, DocumentLocation newLead)
 {
     return(new Selection(newAnchor, newLead, SelectionMode));
 }
コード例 #21
0
        public override IEnumerable <MonoDevelop.CodeActions.CodeAction> GetActions(TextEditor editor, DocumentContext doc, object refactoringContext, MonoDevelop.Ide.Editor.DocumentLocation loc, CancellationToken cancellationToken)
        {
            var mdCtx = refactoringContext as MDRefactoringContext;

            if (mdCtx == null || mdCtx.IsInvalid)
            {
                yield break;
            }

            VariableInitializer currentVariable = mdCtx.GetNode <VariableInitializer>();

            if (currentVariable == null)
            {
                yield break;
            }

            FieldDeclaration currentField = currentVariable.Parent as FieldDeclaration;

            if (currentField == null)
            {
                yield break;
            }

            if (!currentField.Modifiers.HasFlag(Modifiers.Const))
            {
                yield break;
            }

            PrimitiveType baseType = TypeToIntegerPrimitive(mdCtx, currentField.ReturnType);

            if (baseType == null)
            {
                //Can't make enums of these types
                yield break;
            }

            TypeDeclaration containerType = currentVariable.GetParent <TypeDeclaration>();

            //Get all the fields/variables that the enum can possibly cover
            //Don't check the name just yet. That'll come later.

            var constFields = containerType.Members.OfType <FieldDeclaration>()
                              .Where(field => field.GetParent <TypeDeclaration>() == containerType && field.HasModifier(Modifiers.Const)).ToList();

            var constVariables = constFields.SelectMany(field => field.Variables).ToList();

            //Now, it's time to check the name of the selected variable
            //We'll use this to search for prefixes later

            var    names       = constVariables.Select(variable => variable.Name).ToList();
            string currentName = currentVariable.Name;

            //Now, find the common name prefixes
            //If the variable is called 'A_B_C_D', then 'A', 'A_B' and 'A_B_C' are
            //the potentially available prefixes.
            //Note that the common prefixes are the ones that more than one variable
            //has.
            //Each prefix has an associated action.

            foreach (var prefix in GetCommonPrefixes(currentName, names))
            {
                string title = string.Format(GettextCatalog.GetString("Create enum '{0}'"), prefix);

                yield return(new DefaultCodeAction(title, (ctx, script) => {
                    PrepareToRunAction(prefix, baseType, containerType, constVariables, cancellationToken, ctx, script);
                }));
            }
        }
コード例 #22
0
 public bool IsSelected(DocumentLocation loc)
 {
     return(Anchor <= loc && loc <= Lead || Lead <= loc && loc <= Anchor);
 }
コード例 #23
0
 public SmartTagMarker(int offset, MonoDevelop.Ide.Editor.DocumentLocation realLocation) : base(offset, 0)
 {
     this.loc = realLocation;
 }
コード例 #24
0
 public bool IsSelected(DocumentLocation start, DocumentLocation end)
 {
     return(IsSelected(start) && IsSelected(end));
 }
コード例 #25
0
//		public static void QueueQuickFixAnalysis (Document doc, TextLocation loc, CancellationToken token, Action<List<CodeAction>> callback)
//		{
//			var ext = doc.GetContent<MonoDevelop.AnalysisCore.Gui.ResultsEditorExtension> ();
//			var issues = ext != null ? ext.GetResultsAtOffset (doc.Editor.LocationToOffset (loc), token).OrderBy (r => r.Level).ToList () : new List<Result> ();
//
//			ThreadPool.QueueUserWorkItem (delegate {
//				try {
//					var result = new List<CodeAction> ();
//					foreach (var r in issues) {
//						if (token.IsCancellationRequested)
//							return;
//						var fresult = r as FixableResult;
//						if (fresult == null)
//							continue;
////						foreach (var action in FixOperationsHandler.GetActions (doc, fresult)) {
////							result.Add (new AnalysisContextActionProvider.AnalysisCodeAction (action, r) {
////								DocumentRegion = action.DocumentRegion
////							});
////						}
//					}
//					result.AddRange (GetValidActions (doc, loc).Result);
//					callback (result);
//				} catch (Exception ex) {
//					LoggingService.LogError ("Error in analysis service", ex);
//				}
//			});
//		}

        public static MonoDevelop.Ide.Editor.DocumentLocation GetCorrectResolveLocation(IReadonlyTextDocument editor, MonoDevelop.Ide.Editor.DocumentLocation location)
        {
            if (editor == null || location.Column == 1)
            {
                return(location);
            }

            /*if (editor is TextEditor) {
             *      if (((TextEditor)editor).IsSomethingSelected)
             *              return ((TextEditor)editor).SelectionRegion.Begin;
             * }*/
            var line = editor.GetLine(location.Line);

            if (line == null || location.Column > line.LengthIncludingDelimiter)
            {
                return(location);
            }
            int offset = editor.LocationToOffset(location);

            if (offset > 0 && !char.IsLetterOrDigit(editor.GetCharAt(offset)) && char.IsLetterOrDigit(editor.GetCharAt(offset - 1)))
            {
                return(new MonoDevelop.Ide.Editor.DocumentLocation(location.Line, location.Column - 1));
            }
            return(location);
        }
コード例 #26
0
ファイル: Caret.cs プロジェクト: zcf7822/monodevelop
 public CaretLocationEventArgs(DocumentLocation location, CaretChangeReason reason) : base(location)
 {
     CaretChangeReason = reason;
 }