Ejemplo n.º 1
0
        public void Insert(TextEditor editor, DocumentContext context)
        {
            var handler = context.GetContent <ICodeTemplateHandler> ();

            using (var undo = editor.OpenUndoGroup()) {
                editor.EnsureCaretIsNotVirtual();
                if (handler != null)
                {
                    handler.InsertTemplate(this, editor, context);
                }
                else
                {
                    InsertTemplateContents(editor, context);
                }
            }
        }
Ejemplo n.º 2
0
        void UpdateOwnerProjects()
        {
            if (IdeApp.Workspace == null)
            {
                ownerProjects = new List <DotNetProject> ();
                return;
            }
            if (DocumentContext == null)
            {
                return;                //This can happen if this object is disposed
            }
            var view = DocumentContext.GetContent <BaseViewContent> ();

            if (view != null && view.ProjectReloadCapability == ProjectReloadCapability.None)
            {
                return;
            }
            var projects = new HashSet <DotNetProject> (IdeApp.Workspace.GetAllItems <DotNetProject> ().Where(p => p.IsFileInProject(DocumentContext.Name)));

            if (ownerProjects == null || !projects.SetEquals(ownerProjects))
            {
                ownerProjects = projects.OrderBy(p => p.Name).ToList();
                var dnp = DocumentContext.Project as DotNetProject;
                if (ownerProjects.Count > 0 && (dnp == null || !ownerProjects.Contains(dnp)))
                {
                    // If the project for the document is not a DotNetProject but there is a project containing this file
                    // in the current solution, then use that project
                    var pp = DocumentContext.Project != null?ownerProjects.FirstOrDefault(p => p.ParentSolution == DocumentContext.Project.ParentSolution) : null;

                    if (pp != null)
                    {
                        DocumentContext.AttachToProject(pp);
                    }
                }
            }
            if (DocumentContext == null)
            {
                return;                //This can happen if this object is disposed, which is likely to happen in DocumentContext.AttachToProject (pp);
            }
            if (DocumentContext.Project == null && ownerProjects.Count > 0)
            {
                DocumentContext.AttachToProject(ownerProjects[0]);
            }
            UpdatePath();
        }
Ejemplo n.º 3
0
        protected override void Initialize()
        {
            base.Initialize();

            defaultCompletionWidget = CompletionWidget;
            defaultDocumentContext  = DocumentContext;
            defaultEditor           = Editor;
            completionBuilder       = RazorCompletionBuilderService.GetBuilder("C#");

            defaultEditor.TextChanging += UnderlyingDocument_TextReplacing;
            syntaxMode = new RazorSyntaxMode(DocumentContext);
            var textEditorData = DocumentContext.GetContent <TextEditorData> ();

            if (textEditorData != null)
            {
                textEditorData.Document.SyntaxMode = syntaxMode;
            }
        }
Ejemplo n.º 4
0
		public override bool IsValidInContext (DocumentContext context)
		{
			//can only attach if there is not already an attached BaseXmlEditorExtension
			return context.GetContent<BaseXmlEditorExtension> () == null;
		}
Ejemplo n.º 5
0
		public void Insert (TextEditor editor, DocumentContext context)
		{
			var handler = context.GetContent<ICodeTemplateHandler> ();
			if (handler != null) {
				handler.InsertTemplate (this, editor, context);
			} else {
				InsertTemplateContents (editor, context);
			}	
		}
 public void CheckShowCodeGenerationWindow(CommandInfo info)
 {
     info.Enabled = Editor != null && DocumentContext.GetContent <ICompletionWidget> () != null;
 }
Ejemplo n.º 7
0
 public override bool IsValidInContext(DocumentContext context)
 {
     return(context.GetContent <CSharpCompletionTextEditorExtension> () != null);
 }
		public override bool IsValidInContext (DocumentContext context)
		{
			return context.GetContent<CSharpCompletionTextEditorExtension> () != null;
		}
 public override bool IsValidInContext(DocumentContext context)
 {
     //can only attach if there is not already an attached BaseXmlEditorExtension
     return(context.GetContent <BaseXmlEditorExtension> () == null);
 }
        public override async Task <TooltipItem> GetItem(TextEditor editor, DocumentContext ctx, int offset, CancellationToken token = default(CancellationToken))
        {
            if (offset >= editor.Length)
            {
                return(null);
            }

            if (!DebuggingService.IsPaused)
            {
                return(null);
            }

            StackFrame frame = DebuggingService.CurrentFrame;

            if (frame == null)
            {
                return(null);
            }

            var ed = CompileErrorTooltipProvider.GetExtensibleTextEditor(editor);

            if (ed == null)
            {
                return(null);
            }
            string expression = null;
            int    startOffset;

            if (ed.IsSomethingSelected && offset >= ed.SelectionRange.Offset && offset <= ed.SelectionRange.EndOffset)
            {
                startOffset = ed.SelectionRange.Offset;
                expression  = ed.SelectedText;
            }
            else
            {
                if (ctx == null)
                {
                    return(null);
                }

                var resolver = ctx.GetContent <IDebuggerExpressionResolver> ();
                var data     = ctx.GetContent <SourceEditorView> ();

                if (resolver != null)
                {
                    var result = await resolver.ResolveExpressionAsync(editor, ctx, offset, token);

                    expression  = result.Text;
                    startOffset = result.Span.Start;
                }
                else
                {
                    int endOffset = data.GetTextEditorData().FindCurrentWordEnd(offset);
                    startOffset = data.GetTextEditorData().FindCurrentWordStart(offset);

                    expression = editor.GetTextAt(startOffset, endOffset - startOffset);
                }
            }

            if (string.IsNullOrEmpty(expression))
            {
                return(null);
            }

            var options = DebuggingService.DebuggerSession.EvaluationOptions.Clone();

            options.AllowMethodEvaluation = true;
            options.AllowTargetInvoke     = true;

            var val = frame.GetExpressionValue(expression, options);

            if (val == null || val.IsUnknown || val.IsNotSupported)
            {
                return(null);
            }

            val.Name = expression;

            return(new TooltipItem(val, startOffset, expression.Length));
        }