From 7c63693e5f72eb9135f1772b8d3cc872281d80f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Karlas=CC=8C?= Date: Fri, 18 May 2018 15:06:35 +0200 Subject: Fix 4822: Toggle line comment menu no longer exists --- .../VSEditor/TagBasedSyntaxHighlighting.cs | 12 +++++++-- .../DefaultCommandTextEditorExtension.cs | 2 +- .../Commands/CodeCommentTests.cs | 29 ++++++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/main/src/addins/MonoDevelop.SourceEditor2/VSEditor/TagBasedSyntaxHighlighting.cs b/main/src/addins/MonoDevelop.SourceEditor2/VSEditor/TagBasedSyntaxHighlighting.cs index 7d765e5d51..282eccdaac 100644 --- a/main/src/addins/MonoDevelop.SourceEditor2/VSEditor/TagBasedSyntaxHighlighting.cs +++ b/main/src/addins/MonoDevelop.SourceEditor2/VSEditor/TagBasedSyntaxHighlighting.cs @@ -26,6 +26,7 @@ using Microsoft.VisualStudio.Utilities; using Microsoft.VisualStudio.Text.Editor; using static Microsoft.VisualStudio.Language.Intellisense.Implementation.MDUtils; using Microsoft.VisualStudio.Language.StandardClassification; +using MonoDevelop.Core.Text; namespace Microsoft.VisualStudio.Platform { @@ -97,9 +98,16 @@ namespace Microsoft.VisualStudio.Platform return Task.FromResult(new HighlightedLine (line, coloredSegments)); } - public Task GetScopeStackAsync (int offset, CancellationToken cancellationToken) + public async Task GetScopeStackAsync (int offset, CancellationToken cancellationToken) { - return Task.FromResult (ScopeStack.Empty); + var line = textDocument.GetLineByOffset (offset); + var highligthedLine = await GetHighlightedLineAsync (line, cancellationToken).ConfigureAwait (false); + offset -= line.Offset; + foreach (var segment in highligthedLine.Segments) { + if (segment.Offset <= offset && segment.EndOffset >= offset) + return segment.ScopeStack; + } + return ScopeStack.Empty; } private EventHandler _highlightingStateChanged; diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor.Extension/DefaultCommandTextEditorExtension.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor.Extension/DefaultCommandTextEditorExtension.cs index 747ed32eaf..4d2ff642ea 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor.Extension/DefaultCommandTextEditorExtension.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor.Extension/DefaultCommandTextEditorExtension.cs @@ -103,7 +103,7 @@ namespace MonoDevelop.Ide.Editor.Extension [CommandUpdateHandler (EditCommands.AddCodeComment)] [CommandUpdateHandler (EditCommands.RemoveCodeComment)] [CommandUpdateHandler (EditCommands.ToggleCodeComment)] - void OnUpdateToggleComment (CommandInfo info) + internal void OnUpdateToggleComment (CommandInfo info) { var scope = Editor.SyntaxHighlighting.GetScopeStackAsync (Editor.CaretOffset, CancellationToken.None).WaitAndGetResult (CancellationToken.None); var lang = TextMateLanguage.Create (scope); diff --git a/main/tests/Ide.Tests/MonoDevelop.Ide.Editor/Commands/CodeCommentTests.cs b/main/tests/Ide.Tests/MonoDevelop.Ide.Editor/Commands/CodeCommentTests.cs index c14e1a4253..c2fd9e61ff 100644 --- a/main/tests/Ide.Tests/MonoDevelop.Ide.Editor/Commands/CodeCommentTests.cs +++ b/main/tests/Ide.Tests/MonoDevelop.Ide.Editor/Commands/CodeCommentTests.cs @@ -27,6 +27,8 @@ using System.Text; using NUnit.Framework; using MonoDevelop.Ide.Editor.Extension; using MonoDevelop.Ide.Gui; +using System.Threading.Tasks; +using MonoDevelop.Core; namespace MonoDevelop.Ide.Editor { @@ -171,6 +173,33 @@ namespace MonoDevelop.Ide.Editor }"); } + [Test] + public async Task TestToggle_Visible () + { + IdeApp.Initialize (new Core.ProgressMonitor ()); + //This dummyEditor is just so we can reuse CreateTextEditor code + //to resolve offset for us + var dummyEditor = CreateTextEditor (@"class Foo +{ + void Bar () + { + //$test + } +}"); + //We need to create full document and not just editor + //so extensions are initialized which set custom C# + //tagger based syntax highligthing + var document = IdeApp.Workbench.NewDocument ("a.cs", "text/x-csharp", dummyEditor.Text); + document.Editor.CaretOffset = dummyEditor.CaretOffset; + //Call UpdateParseDocument so AdHock Roslyn Workspace is created for file + await document.UpdateParseDocument (); + var info = new Components.Commands.CommandInfo (); + //Finnaly call command Update so it sets values which we assert + GetExtension (document.Editor).OnUpdateToggleComment (info); + Assert.AreEqual (true, info.Visible); + Assert.AreEqual (true, info.Enabled); + } + [Test] public void TestToggle_Add() { -- cgit v1.2.3 From a1d062b96a1f3b35b8c99deea18a9ea8c0ec5e55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Karlas=CC=8C?= Date: Fri, 25 May 2018 15:18:02 +0200 Subject: Fix failing unit tests Problem was that document remained open and later when some other unit tests ran code touched documents list problems appeared. --- main/tests/Ide.Tests/MonoDevelop.Ide.Editor/Commands/CodeCommentTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/main/tests/Ide.Tests/MonoDevelop.Ide.Editor/Commands/CodeCommentTests.cs b/main/tests/Ide.Tests/MonoDevelop.Ide.Editor/Commands/CodeCommentTests.cs index c2fd9e61ff..3864525e13 100644 --- a/main/tests/Ide.Tests/MonoDevelop.Ide.Editor/Commands/CodeCommentTests.cs +++ b/main/tests/Ide.Tests/MonoDevelop.Ide.Editor/Commands/CodeCommentTests.cs @@ -196,6 +196,7 @@ namespace MonoDevelop.Ide.Editor var info = new Components.Commands.CommandInfo (); //Finnaly call command Update so it sets values which we assert GetExtension (document.Editor).OnUpdateToggleComment (info); + await document.Close (); Assert.AreEqual (true, info.Visible); Assert.AreEqual (true, info.Enabled); } -- cgit v1.2.3