コード例 #1
0
		public void TestProjectionUpdate ()
		{
			var editor = TextEditorFactory.CreateNewEditor ();
			editor.Text = "1234567890";

			var projectedDocument = TextEditorFactory.CreateNewDocument (
				new StringTextSource ("__12__34__56__78__90"),
				"a"
			);

			var segments = new List<ProjectedSegment> ();
			for (int i = 0; i < 5; i++) {
				segments.Add (new ProjectedSegment (i * 2, 2 + i * 4, 2));
			}
			var projection = new Projection.Projection (projectedDocument, segments);
			var tww = new TestWorkbenchWindow ();
			var content = new TestViewContent ();
			tww.ViewContent = content;

			var originalContext = new Document (tww);
			var projectedEditor = projection.CreateProjectedEditor (originalContext);
			editor.SetOrUpdateProjections (originalContext, new [] { projection }, TypeSystem.DisabledProjectionFeatures.All);
			editor.InsertText (1, "foo");
			Assert.AreEqual ("__1foo2__34__56__78__90", projectedEditor.Text);

			Assert.AreEqual (2, projection.ProjectedSegments.ElementAt (0).ProjectedOffset);
			Assert.AreEqual (2 + "foo".Length, projection.ProjectedSegments.ElementAt (0).Length);
			for (int i = 1; i < 5; i++) {
				Assert.AreEqual (2 + i * 4 + "foo".Length, projection.ProjectedSegments.ElementAt (i).ProjectedOffset);
				Assert.AreEqual (2, projection.ProjectedSegments.ElementAt (i).Length);
			}
		}
コード例 #2
0
		public ProjectedTooltipProvider (Projection projection, TooltipProvider projectedTooltipProvider)
		{
			if (projection == null)
				throw new ArgumentNullException ("projection");
			if (projectedTooltipProvider == null)
				throw new ArgumentNullException ("projectedTooltipProvider");
			this.projectedTooltipProvider = projectedTooltipProvider;
			this.projection = projection;
		}
コード例 #3
0
        public void TestProjectionCompletion()
        {
            var editor  = TextEditorFactory.CreateNewEditor();
            var options = new CustomEditorOptions(editor.Options);

            options.EditorTheme = "Tango";
            editor.Options      = options;
            editor.Text         = "12345678901234567890";

            var projectedDocument = TextEditorFactory.CreateNewDocument(
                new StringTextSource("__12__34__56__78__90"),
                "a"
                );

            var segments = new List <ProjectedSegment> ();

            for (int i = 0; i < 5; i++)
            {
                segments.Add(new ProjectedSegment(i * 2, 2 + i * 4, 2));
            }
            var projection = new Projection.Projection(projectedDocument, segments);
            var tww        = new TestWorkbenchWindow();
            var content    = new TestViewContent();

            tww.ViewContent = content;

            var originalContext = new Document(tww);
            var projectedEditor = projection.CreateProjectedEditor(originalContext);
            TestCompletionExtension orignalExtension;

            editor.SetExtensionChain(originalContext, new [] { orignalExtension = new TestCompletionExtension(editor)
                                                               {
                                                                   CompletionWidget = new EmptyCompletionWidget(editor)
                                                               } });
            TestCompletionExtension projectedExtension;

            projectedEditor.SetExtensionChain(originalContext, new [] { projectedExtension = new TestCompletionExtension(editor)
                                                                        {
                                                                            CompletionWidget = new EmptyCompletionWidget(projectedEditor)
                                                                        } });

            editor.SetOrUpdateProjections(originalContext, new [] { projection }, TypeSystem.DisabledProjectionFeatures.None);
            editor.CaretOffset = 1;

            var service = new CommandManager();

            service.LoadCommands("/MonoDevelop/Ide/Commands");
            service.DispatchCommand(TextEditorCommands.ShowCompletionWindow, null, editor.CommandRouter);
            Assert.IsFalse(orignalExtension.CompletionRun);
            Assert.IsTrue(projectedExtension.CompletionRun);

            editor.CaretOffset = 15;
            CompletionWindowManager.HideWindow();
            service.DispatchCommand(TextEditorCommands.ShowCompletionWindow, null, editor.CommandRouter);
            Assert.IsTrue(orignalExtension.CompletionRun);
        }
コード例 #4
0
		public ProjectedTooltipProvider (TextEditor editor, DocumentContext ctx, Projection projection, TooltipProvider projectedTooltipProvider)
		{
			if (editor == null)
				throw new ArgumentNullException ("editor");
			if (ctx == null)
				throw new ArgumentNullException ("ctx");
			if (projection == null)
				throw new ArgumentNullException ("projection");
			if (projectedTooltipProvider == null)
				throw new ArgumentNullException ("projectedTooltipProvider");
			this.projectedTooltipProvider = projectedTooltipProvider;
			this.projection = projection;
		}
コード例 #5
0
        public void TestProjectionUpdate()
        {
            var editor = TextEditorFactory.CreateNewEditor();

            editor.Text = "1234567890";

            var projectedDocument = TextEditorFactory.CreateNewDocument(
                new StringTextSource("__12__34__56__78__90"),
                "a"
                );

            var segments = new List <ProjectedSegment> ();

            for (int i = 0; i < 5; i++)
            {
                segments.Add(new ProjectedSegment(i * 2, 2 + i * 4, 2));
            }
            var projection = new Projection.Projection(projectedDocument, segments);
            var tww        = new TestWorkbenchWindow();
            var content    = new TestViewContent();

            tww.ViewContent = content;

            var originalContext = new Document(tww);

            using (var testCase = new TextEditorExtensionTestCase(originalContext, content, tww, null, false)) {
                var projectedEditor = projection.CreateProjectedEditor(originalContext);
                editor.SetOrUpdateProjections(originalContext, new [] { projection }, TypeSystem.DisabledProjectionFeatures.All);
                editor.InsertText(1, "foo");
                Assert.AreEqual("__1foo2__34__56__78__90", projectedEditor.Text);

                Assert.AreEqual(2, projection.ProjectedSegments.ElementAt(0).ProjectedOffset);
                Assert.AreEqual(2 + "foo".Length, projection.ProjectedSegments.ElementAt(0).Length);
                for (int i = 1; i < 5; i++)
                {
                    Assert.AreEqual(2 + i * 4 + "foo".Length, projection.ProjectedSegments.ElementAt(i).ProjectedOffset);
                    Assert.AreEqual(2, projection.ProjectedSegments.ElementAt(i).Length);
                }
            }
        }
コード例 #6
0
        public void TestProjectionHighlighting()
        {
            var editor  = TextEditorFactory.CreateNewEditor();
            var options = new CustomEditorOptions(editor.Options);

            options.EditorTheme = "Tango";
            editor.Options      = options;
            editor.Text         = "1234567890";

            var projectedDocument = TextEditorFactory.CreateNewDocument(
                new StringTextSource("__12__34__56__78__90"),
                "a"
                );

            var segments = new List <ProjectedSegment> ();

            for (int i = 0; i < 5; i++)
            {
                segments.Add(new ProjectedSegment(i * 2, 2 + i * 4, 2));
            }
            var projection = new Projection.Projection(projectedDocument, segments);
            var tww        = new TestWorkbenchWindow();
            var content    = new TestViewContent();

            tww.ViewContent = content;

            var originalContext = new Document(tww);

            using (var testCase = new TextEditorExtensionTestCase(originalContext, content, tww, null, false)) {
                var projectedEditor = projection.CreateProjectedEditor(originalContext);
                projectedEditor.SemanticHighlighting = new TestSemanticHighlighting(projectedEditor, originalContext);
                editor.SetOrUpdateProjections(originalContext, new [] { projection }, TypeSystem.DisabledProjectionFeatures.None);

                var markup = editor.GetMarkup(0, editor.Length, new MarkupOptions(MarkupFormat.Pango));
                var color  = "#3363a4";
                Assert.AreEqual("<span foreground=\"" + color + "\">1</span><span foreground=\"#222222\">234</span><span foreground=\"" + color + "\">5</span><span foreground=\"#222222\">678</span><span foreground=\"" + color + "\">9</span><span foreground=\"#222222\">0</span>", markup);
            }
        }
コード例 #7
0
        public async Task TestProjectionUpdate()
        {
            var editor = TextEditorFactory.CreateNewEditor();

            editor.Text = "1234567890";

            var projectedDocument = TextEditorFactory.CreateNewDocument(
                new StringTextSource("__12__34__56__78__90"),
                "a"
                );

            var segments = new List <ProjectedSegment> ();

            for (int i = 0; i < 5; i++)
            {
                segments.Add(new ProjectedSegment(i * 2, 2 + i * 4, 2));
            }
            var projection = new Projection.Projection(projectedDocument, segments);
            var content    = new TestViewContent();
            await content.Initialize(new FileDescriptor ("Foo.cs", null, null));

            using (var testCase = await TextEditorExtensionTestCase.Create(content, null, false)) {
                var originalContext = testCase.Document.DocumentContext;
                var projectedEditor = projection.CreateProjectedEditor(originalContext);
                editor.SetOrUpdateProjections(originalContext, new [] { projection }, TypeSystem.DisabledProjectionFeatures.All);
                editor.InsertText(1, "foo");
                Assert.AreEqual("__1foo2__34__56__78__90", projectedEditor.Text);

                Assert.AreEqual(2, projection.ProjectedSegments.ElementAt(0).ProjectedOffset);
                Assert.AreEqual(2 + "foo".Length, projection.ProjectedSegments.ElementAt(0).Length);
                for (int i = 1; i < 5; i++)
                {
                    Assert.AreEqual(2 + i * 4 + "foo".Length, projection.ProjectedSegments.ElementAt(i).ProjectedOffset);
                    Assert.AreEqual(2, projection.ProjectedSegments.ElementAt(i).Length);
                }
            }
        }
コード例 #8
0
		static int ApplyChanges (Projection projection, ITextDocument data, List<TextChange> changes)
		{
			int delta = 0;
			foreach (var change in changes) {
				var offset = change.Span.Start;

				if (projection != null) {
					int originalOffset;
					//If change is outside projection segments don't apply it...
					if (projection.TryConvertFromProjectionToOriginal (offset, out originalOffset)) {
						offset = originalOffset;
						data.ReplaceText (offset, change.Span.Length, change.NewText);
						delta += change.Span.Length - change.NewText.Length;
					}
				} else {
					data.ReplaceText (offset, change.Span.Length, change.NewText);
					delta += change.Span.Length - change.NewText.Length;
				}
			}

			return delta;
		}
コード例 #9
0
        static CodeCompletionContext ImportContext(CodeCompletionContext completionContext, Projection projection)
        {
            int offset     = completionContext.TriggerOffset;
            int line       = completionContext.TriggerLine;
            int lineOffset = completionContext.TriggerLineOffset;

            if (projection != null)
            {
                foreach (var seg in projection.ProjectedSegments)
                {
                    if (seg.ContainsProjected(offset))
                    {
                        offset = seg.FromProjectedToOriginal(offset);
                        var loc = projection.ProjectedEditor.OffsetToLocation(offset);
                        line       = loc.Line;
                        lineOffset = loc.Column - 1;
                        break;
                    }
                }
            }

            return(new MonoDevelop.Ide.CodeCompletion.CodeCompletionContext {
                TriggerOffset = offset,
                TriggerLine = line,
                TriggerLineOffset = lineOffset,
                TriggerXCoord = completionContext.TriggerXCoord,
                TriggerYCoord = completionContext.TriggerYCoord,
                TriggerTextHeight = completionContext.TriggerTextHeight,
                TriggerWordLength = completionContext.TriggerWordLength
            });
        }
コード例 #10
0
		static CodeCompletionContext ImportContext (CodeCompletionContext completionContext, Projection projection)
		{
			int offset = completionContext.TriggerOffset;
			int line = completionContext.TriggerLine;
			int lineOffset = completionContext.TriggerLineOffset;

			if (projection != null) {
				foreach (var seg in projection.ProjectedSegments) {
					if (seg.ContainsProjected (offset)) {
						offset = seg.FromProjectedToOriginal (offset);
						var loc = projection.ProjectedEditor.OffsetToLocation (offset);
						line = loc.Line;
						lineOffset = loc.Column - 1;
						break;
					}
				}
			}

			return new MonoDevelop.Ide.CodeCompletion.CodeCompletionContext {
				TriggerOffset = offset,
				TriggerLine = line,
				TriggerLineOffset  = lineOffset,
				TriggerXCoord  = completionContext.TriggerXCoord,
				TriggerYCoord  = completionContext.TriggerYCoord,
				TriggerTextHeight  = completionContext.TriggerTextHeight,
				TriggerWordLength  = completionContext.TriggerWordLength
			};
		}
コード例 #11
0
			public ProjectedCompletionWidget (ICompletionWidget completionWidget, Projection projection)
			{
				if (completionWidget == null)
					throw new ArgumentNullException ("completionWidget");
				if (projection == null)
					throw new ArgumentNullException ("projection");
				this.projection = projection;
				this.completionWidget = completionWidget;
			}
コード例 #12
0
		public void TestProjectionHighlighting ()
		{
			var editor = TextEditorFactory.CreateNewEditor ();
			var options = new CustomEditorOptions (editor.Options);
			options.ColorScheme = "Tango";
			editor.Options = options;
			editor.Text = "1234567890";

			var projectedDocument = TextEditorFactory.CreateNewDocument (
				new StringTextSource ("__12__34__56__78__90"),
				"a"
			);

			var segments = new List<ProjectedSegment> ();
			for (int i = 0; i < 5; i++) {
				segments.Add (new ProjectedSegment (i * 2, 2 + i * 4, 2));
			}
			var projection = new Projection.Projection (projectedDocument, segments);
			var tww = new TestWorkbenchWindow ();
			var content = new TestViewContent ();
			tww.ViewContent = content;

			var originalContext = new Document (tww);
			var projectedEditor = projection.CreateProjectedEditor (originalContext);
			projectedEditor.SemanticHighlighting = new TestSemanticHighlighting (projectedEditor, originalContext);
			editor.SetOrUpdateProjections (originalContext, new [] { projection }, TypeSystem.DisabledProjectionFeatures.None);

			var markup = editor.GetPangoMarkup (0, editor.Length);
			var color = "#75507B";
			Assert.AreEqual ("<span foreground=\"" + color + "\">1</span><span foreground=\"#222222\">234</span><span foreground=\"" + color + "\">5</span><span foreground=\"#222222\">678</span><span foreground=\"" + color + "\">9</span><span foreground=\"#222222\">0</span>", markup);
		}
コード例 #13
0
		public void TestProjectionCompletion ()
		{
			var editor = TextEditorFactory.CreateNewEditor ();
			var options = new CustomEditorOptions (editor.Options);
			options.ColorScheme = "Tango";
			editor.Options = options;
			editor.Text = "12345678901234567890";

			var projectedDocument = TextEditorFactory.CreateNewDocument (
				new StringTextSource ("__12__34__56__78__90"),
				"a"
			);

			var segments = new List<ProjectedSegment> ();
			for (int i = 0; i < 5; i++) {
				segments.Add (new ProjectedSegment (i * 2, 2 + i * 4, 2));
			}
			var projection = new Projection.Projection (projectedDocument, segments);
			var tww = new TestWorkbenchWindow ();
			var content = new TestViewContent ();
			tww.ViewContent = content;

			var originalContext = new Document (tww);
			var projectedEditor = projection.CreateProjectedEditor (originalContext);
			TestCompletionExtension orignalExtension;
			editor.SetExtensionChain (originalContext, new [] { orignalExtension = new TestCompletionExtension (editor) });
			TestCompletionExtension projectedExtension;
			projectedEditor.SetExtensionChain (originalContext, new [] { projectedExtension = new TestCompletionExtension (editor) });

			orignalExtension.CompletionWidget = new EmptyCompletionWidget (editor);
			projectedExtension.CompletionWidget = new EmptyCompletionWidget (projectedEditor);

			editor.SetOrUpdateProjections (originalContext, new [] { projection }, TypeSystem.DisabledProjectionFeatures.None);
			editor.CaretOffset = 1;

			var service = new CommandManager ();
			service.LoadCommands ("/MonoDevelop/Ide/Commands");
			service.DispatchCommand (TextEditorCommands.ShowCompletionWindow, null, editor.CommandRouter);
			Assert.IsFalse (orignalExtension.CompletionRun);
			Assert.IsTrue (projectedExtension.CompletionRun);

			editor.CaretOffset = 15;

			service.DispatchCommand (TextEditorCommands.ShowCompletionWindow, null, editor.CommandRouter);
			Assert.IsTrue (orignalExtension.CompletionRun);
		}
コード例 #14
0
        static CodeCompletionContext ConvertContext(CodeCompletionContext completionContext, Projection projection)
        {
            int offset     = completionContext.TriggerOffset;
            int line       = completionContext.TriggerLine;
            int lineOffset = completionContext.TriggerLineOffset;

            if (projection != null)
            {
                foreach (var seg in projection.ProjectedSegments)
                {
                    if (seg.ContainsOriginal(offset))
                    {
                        offset = seg.FromOriginalToProjected(offset);
                        var loc = projection.ProjectedEditor.OffsetToLocation(offset);
                        line       = loc.Line;
                        lineOffset = loc.Column - 1;
                    }
                }
            }

            return(new ProjectedContext(completionContext)
            {
                TriggerOffset = offset,
                TriggerLine = line,
                TriggerLineOffset = lineOffset,
                TriggerWordLength = completionContext.TriggerWordLength
            });
        }