Skip to content

Commit

Permalink
Merge remote-tracking branch 'Microsoft/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Turner committed May 18, 2015
2 parents 81b49e0 + b78acaa commit 4bbdf9c
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Common/Product/ReplWindow/Repl/OutputBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Python/Product/EnvironmentsList/PipExtensionProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
20 changes: 14 additions & 6 deletions Python/Product/PythonTools/PythonTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,6 @@
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="Microsoft.VisualStudio.Editor, Version=$(VSTarget).0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Microsoft.VisualStudio.InteractiveWindow">
<HintPath>$(DevEnvDir)PrivateAssemblies\Microsoft.VisualStudio.InteractiveWindow.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.Language.Intellisense, Version=$(VSTarget).0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Microsoft.VisualStudio.Language.NavigateTo.Interfaces, Version=$(VSTarget).0.0, Culture=neutral" />
<Reference Include="Microsoft.VisualStudio.Language.StandardClassification, Version=$(VSTarget).0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
Expand Down Expand Up @@ -211,9 +208,6 @@
<Reference Include="Microsoft.VisualStudio.VSHelp, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="Microsoft.VisualStudio.VsInteractiveWindow">
<HintPath>$(DevEnvDir)PrivateAssemblies\Microsoft.VisualStudio.VsInteractiveWindow.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.WizardFramework, Version=$(VSTarget).0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
Expand Down Expand Up @@ -267,6 +261,20 @@
</ItemGroup>
</Otherwise>
</Choose>
<Choose>
<When Condition="$(Dev14OrLater)">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.InteractiveWindow">
<HintPath>$(DevEnvDir)PrivateAssemblies\Microsoft.VisualStudio.InteractiveWindow.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.VsInteractiveWindow">
<HintPath>$(DevEnvDir)PrivateAssemblies\Microsoft.VisualStudio.VsInteractiveWindow.dll</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<ItemGroup>
<Compile Include="..\Analysis\IEnumerableExtensions.cs">
<Link>IEnumerableExtensions.cs</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,20 @@ public IEnumerable<SuggestedActionSet> GetSuggestedActions(ISuggestedActionCateg
}

public async Task<bool> HasSuggestedActionsAsync(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) {
var textBuffer = _textBuffer;
var pos = _view.Caret.Position.BufferPosition;
pos = _view.BufferGraph.MapDownToFirstMatch(pos, PointTrackingMode.Positive, EditorExtensions.IsPythonContent, PositionAffinity.Successor) ?? pos;
var line = pos.GetContainingLine();
if (pos.Position < line.End.Position) {
if (pos.Position < pos.GetContainingLine().End.Position) {
pos += 1;
}
var span = pos.Snapshot.CreateTrackingSpan(
line.Start.Position,
pos.Position - line.Start.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
);
Expand All @@ -83,7 +87,7 @@ public async Task<bool> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell.Interop;
using System.Diagnostics;
using Microsoft.VisualStudio.Text;

#if DEV14_OR_LATER
namespace Microsoft.PythonTools.Intellisense {
class PythonSuggestedImportAction : ISuggestedAction, IComparable<PythonSuggestedImportAction> {
private readonly PythonSuggestedActionsSource _source;
private readonly string _name;
private readonly string _fromModule;
private readonly ITextBuffer _buffer;

public PythonSuggestedImportAction(PythonSuggestedActionsSource source, ExportedMemberInfo import) {
public PythonSuggestedImportAction(PythonSuggestedActionsSource source, ITextBuffer buffer, ExportedMemberInfo import) {
_source = source;
_fromModule = import.FromName;
_name = import.ImportName;
_buffer = buffer;
}

public IEnumerable<SuggestedActionSet> ActionSets {
Expand Down Expand Up @@ -68,7 +71,7 @@ public void Invoke(CancellationToken cancellationToken) {

MissingImportAnalysis.AddImport(
_source._provider,
_source._textBuffer,
_buffer,
_source._view,
_fromModule,
_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

}
Expand Down

0 comments on commit 4bbdf9c

Please sign in to comment.