From b230519af24e5d1cc835d38cb6b13b590c64f86f Mon Sep 17 00:00:00 2001 From: dino Date: Mon, 18 May 2015 11:02:27 -0700 Subject: [PATCH 1/3] Fix REPL ANSI bugs, fix REPL lightbulb support --- .../Product/ReplWindow/Repl/OutputBuffer.cs | 2 +- .../PythonSuggestedActionsSource.cs | 18 ++++++++---- .../PythonSuggestedImportAction.cs | 7 +++-- .../Repl/BasePythonReplEvaluator.cs | 29 +++++++++---------- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/Common/Product/ReplWindow/Repl/OutputBuffer.cs b/Common/Product/ReplWindow/Repl/OutputBuffer.cs index 0c23c48f12..5dc599afad 100644 --- a/Common/Product/ReplWindow/Repl/OutputBuffer.cs +++ b/Common/Product/ReplWindow/Repl/OutputBuffer.cs @@ -199,7 +199,7 @@ private void AppendEscapedText(string text, bool isError, int escape) { }// else not an escape sequence, process as text } while (escape != -1); - if (start != text.Length - 1) { + if (start != text.Length) { AppendText(text.Substring(start), kind, color); } } diff --git a/Python/Product/PythonTools/PythonTools/Intellisense/PythonSuggestedActionsSource.cs b/Python/Product/PythonTools/PythonTools/Intellisense/PythonSuggestedActionsSource.cs index c50099297d..83063bbc4a 100644 --- a/Python/Product/PythonTools/PythonTools/Intellisense/PythonSuggestedActionsSource.cs +++ b/Python/Product/PythonTools/PythonTools/Intellisense/PythonSuggestedActionsSource.cs @@ -7,6 +7,7 @@ using Microsoft.VisualStudio.Text; using System.Threading; using Microsoft.VisualStudio.Text.Editor; +using Microsoft.PythonTools.Editor.Core; namespace Microsoft.PythonTools.Intellisense { #if DEV14_OR_LATER @@ -46,15 +47,20 @@ public IEnumerable GetSuggestedActions(ISuggestedActionCateg } public async Task HasSuggestedActionsAsync(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { - var textBuffer = _textBuffer; var pos = _view.Caret.Position.BufferPosition; - var lineStart = pos.GetContainingLine().Start; if (pos.Position < pos.Snapshot.Length - 1) { pos += 1; } - var span = pos.Snapshot.CreateTrackingSpan( - lineStart.Position, - pos.Position - lineStart.Position, + var targetPoint = _view.BufferGraph.MapDownToFirstMatch(pos, PointTrackingMode.Positive, EditorExtensions.IsPythonContent, PositionAffinity.Successor); + if (targetPoint == null) { + return false; + } + var textBuffer = targetPoint.Value.Snapshot.TextBuffer; + var lineStart = targetPoint.Value.GetContainingLine().Start; + + var span = targetPoint.Value.Snapshot.CreateTrackingSpan( + lineStart, + targetPoint.Value.Position - lineStart.Position, SpanTrackingMode.EdgePositive, TrackingFidelityMode.Forward ); @@ -68,7 +74,7 @@ public async Task HasSuggestedActionsAsync(ISuggestedActionCategorySet req var availableImports = await imports.GetAvailableImportsAsync(cancellationToken); suggestions.Add(new SuggestedActionSet( - availableImports.Select(s => new PythonSuggestedImportAction(this, s)).OrderBy(k => k) + availableImports.Select(s => new PythonSuggestedImportAction(this, textBuffer, s)).OrderBy(k => k) )); cancellationToken.ThrowIfCancellationRequested(); diff --git a/Python/Product/PythonTools/PythonTools/Intellisense/PythonSuggestedImportAction.cs b/Python/Product/PythonTools/PythonTools/Intellisense/PythonSuggestedImportAction.cs index d580c0e75d..64599e6832 100644 --- a/Python/Product/PythonTools/PythonTools/Intellisense/PythonSuggestedImportAction.cs +++ b/Python/Product/PythonTools/PythonTools/Intellisense/PythonSuggestedImportAction.cs @@ -11,6 +11,7 @@ using Microsoft.VisualStudio; using Microsoft.VisualStudio.Shell.Interop; using System.Diagnostics; +using Microsoft.VisualStudio.Text; #if DEV14_OR_LATER namespace Microsoft.PythonTools.Intellisense { @@ -18,11 +19,13 @@ class PythonSuggestedImportAction : ISuggestedAction, IComparable ActionSets { @@ -68,7 +71,7 @@ public void Invoke(CancellationToken cancellationToken) { MissingImportAnalysis.AddImport( _source._provider, - _source._textBuffer, + _buffer, _source._view, _fromModule, _name diff --git a/Python/Product/PythonTools/PythonTools/Repl/BasePythonReplEvaluator.cs b/Python/Product/PythonTools/PythonTools/Repl/BasePythonReplEvaluator.cs index c6680213d6..cb38e5bf75 100644 --- a/Python/Product/PythonTools/PythonTools/Repl/BasePythonReplEvaluator.cs +++ b/Python/Product/PythonTools/PythonTools/Repl/BasePythonReplEvaluator.cs @@ -1797,10 +1797,6 @@ public static void AbortCommand(this IReplEvaluator window) { window.AbortExecution(); } - public static void WriteAnsiLine(this IInteractiveWindow window, string line) { - AppendEscapedText(window, line + Environment.NewLine); - } - public static void SetPrompts(this IInteractiveWindow window, string primary, string secondary) { var eval = window.Evaluator as BasePythonReplEvaluator; eval.PrimaryPrompt = primary; @@ -1813,7 +1809,7 @@ public static void UseInterpreterPrompts(this IInteractiveWindow window) { eval.SecondaryPrompt = null; } - private static void AppendEscapedText(IInteractiveWindow window, string text) { + private static void AppendEscapedText(IInteractiveWindow window, string text, bool isError = false) { // http://en.wikipedia.org/wiki/ANSI_escape_code // process any ansi color sequences... ConsoleColor? color = null; @@ -1827,8 +1823,12 @@ private static void AppendEscapedText(IInteractiveWindow window, string text) { while (escape != -1) { if (escape != start) { // add unescaped text - var span = window.Write(text.Substring(start, escape - start)); - colors.Add(new ColoredSpan(span, color)); + if (isError) { + window.ErrorOutputWriter.Write(text.Substring(start, escape - start)); + } else { + var span = window.Write(text.Substring(start, escape - start)); + colors.Add(new ColoredSpan(span, color)); + } } // process the escape sequence @@ -1937,9 +1937,13 @@ private static void AppendEscapedText(IInteractiveWindow window, string text) { }// else not an escape sequence, process as text } - if (start != text.Length - 1) { - var span = window.Write(text.Substring(start)); - colors.Add(new ColoredSpan(span, color)); + if (start != text.Length) { + if (isError) { + window.ErrorOutputWriter.Write(text.Substring(start, escape - start)); + } else { + var span = window.Write(text.Substring(start)); + colors.Add(new ColoredSpan(span, color)); + } } } #else @@ -1956,11 +1960,6 @@ public static void UseInterpreterPrompts(this IReplWindow window) { public static void SetSmartUpDown(this IReplWindow window, bool setting) { window.SetOptionValue(ReplOptions.UseSmartUpDown, setting); } - - public static void WriteAnsiLine(this IReplWindow window, string line) { - window.WriteLine(line); - } - #endif } From 40abd80fb8fafafe41ec8e3d5f7dd11db6f5e808 Mon Sep 17 00:00:00 2001 From: dino Date: Mon, 18 May 2015 14:12:17 -0700 Subject: [PATCH 2/3] code review feedback, align w/ previous change --- .../PythonTools/Intellisense/PythonSuggestedActionsSource.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Python/Product/PythonTools/PythonTools/Intellisense/PythonSuggestedActionsSource.cs b/Python/Product/PythonTools/PythonTools/Intellisense/PythonSuggestedActionsSource.cs index 7ed26feba8..d4bd0ea8c4 100644 --- a/Python/Product/PythonTools/PythonTools/Intellisense/PythonSuggestedActionsSource.cs +++ b/Python/Product/PythonTools/PythonTools/Intellisense/PythonSuggestedActionsSource.cs @@ -21,7 +21,6 @@ using Microsoft.VisualStudio.Language.Intellisense; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Editor; -using Microsoft.PythonTools.Editor.Core; namespace Microsoft.PythonTools.Intellisense { #if DEV14_OR_LATER @@ -62,7 +61,7 @@ public IEnumerable GetSuggestedActions(ISuggestedActionCateg public async Task HasSuggestedActionsAsync(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { var pos = _view.Caret.Position.BufferPosition; - if (pos.Position < pos.Snapshot.Length - 1) { + if (pos.Position < pos.GetContainingLine().End.Position) { pos += 1; } var targetPoint = _view.BufferGraph.MapDownToFirstMatch(pos, PointTrackingMode.Positive, EditorExtensions.IsPythonContent, PositionAffinity.Successor); From 44cb7b331c9ccf7c4e8c26125a23739e33a31806 Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Mon, 18 May 2015 14:59:09 -0700 Subject: [PATCH 3/3] #200 PTVS does not compile at ToT with VS 2013 Fixes build with VS 2013 --- .../EnvironmentsList/PipExtensionProvider.cs | 4 ++-- Python/Product/PythonTools/PythonTools.csproj | 20 +++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Python/Product/EnvironmentsList/PipExtensionProvider.cs b/Python/Product/EnvironmentsList/PipExtensionProvider.cs index 666faad8ad..92bd727556 100644 --- a/Python/Product/EnvironmentsList/PipExtensionProvider.cs +++ b/Python/Product/EnvironmentsList/PipExtensionProvider.cs @@ -349,7 +349,7 @@ public async Task InstallPackage(string package, bool upgrade) { } finally { if (!success) { // Check whether we failed because pip is missing - await CheckPipInstalledAsync(); + CheckPipInstalledAsync().DoNotWait(); } OnOperationFinished(string.Format( @@ -402,7 +402,7 @@ public async Task UninstallPackage(string package) { } finally { if (!success) { // Check whether we failed because pip is missing - await CheckPipInstalledAsync(); + CheckPipInstalledAsync().DoNotWait(); } OnOperationFinished(string.Format( diff --git a/Python/Product/PythonTools/PythonTools.csproj b/Python/Product/PythonTools/PythonTools.csproj index 8fc45eda06..b41437f864 100644 --- a/Python/Product/PythonTools/PythonTools.csproj +++ b/Python/Product/PythonTools/PythonTools.csproj @@ -175,9 +175,6 @@ False - - $(DevEnvDir)PrivateAssemblies\Microsoft.VisualStudio.InteractiveWindow.dll - @@ -211,9 +208,6 @@ False - - $(DevEnvDir)PrivateAssemblies\Microsoft.VisualStudio.VsInteractiveWindow.dll - @@ -267,6 +261,20 @@ + + + + + $(DevEnvDir)PrivateAssemblies\Microsoft.VisualStudio.InteractiveWindow.dll + false + + + $(DevEnvDir)PrivateAssemblies\Microsoft.VisualStudio.VsInteractiveWindow.dll + false + + + + IEnumerableExtensions.cs