From 10f152991287116d05ee52f41666fb3e6fbe187b Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Thu, 14 May 2015 11:36:09 -0700 Subject: [PATCH] Prevents exceptions in projection buffers when suggesting missing imports. --- .../PythonSuggestedActionsSource.cs | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/Python/Product/PythonTools/PythonTools/Intellisense/PythonSuggestedActionsSource.cs b/Python/Product/PythonTools/PythonTools/Intellisense/PythonSuggestedActionsSource.cs index c50099297d..241402cd28 100644 --- a/Python/Product/PythonTools/PythonTools/Intellisense/PythonSuggestedActionsSource.cs +++ b/Python/Product/PythonTools/PythonTools/Intellisense/PythonSuggestedActionsSource.cs @@ -1,11 +1,25 @@ -using Microsoft.VisualStudio.Language.Intellisense; +/* **************************************************************************** + * + * Copyright (c) Microsoft Corporation. + * + * This source code is subject to terms and conditions of the Apache License, Version 2.0. A + * copy of the license can be found in the License.html file at the root of this distribution. If + * you cannot locate the Apache License, Version 2.0, please send an email to + * vspython@microsoft.com. By using this source code in any fashion, you are agreeing to be bound + * by the terms of the Apache License, Version 2.0. + * + * You must not remove this notice, or any other, from this software. + * + * ***************************************************************************/ + using System; using System.Collections.Generic; using System.Linq; -using System.Text; +using System.Threading; using System.Threading.Tasks; +using Microsoft.PythonTools.Editor.Core; +using Microsoft.VisualStudio.Language.Intellisense; using Microsoft.VisualStudio.Text; -using System.Threading; using Microsoft.VisualStudio.Text.Editor; namespace Microsoft.PythonTools.Intellisense { @@ -48,13 +62,14 @@ 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 = _view.BufferGraph.MapDownToFirstMatch(pos, PointTrackingMode.Positive, EditorExtensions.IsPythonContent, PositionAffinity.Successor) ?? pos; + var line = pos.GetContainingLine(); + if (pos.Position < line.End.Position) { pos += 1; } var span = pos.Snapshot.CreateTrackingSpan( - lineStart.Position, - pos.Position - lineStart.Position, + line.Start.Position, + pos.Position - line.Start.Position, SpanTrackingMode.EdgePositive, TrackingFidelityMode.Forward );