Skip to content

Commit

Permalink
Prevents exceptions in projection buffers when suggesting missing imp…
Browse files Browse the repository at this point in the history
…orts.
  • Loading branch information
zooba committed May 14, 2015
1 parent b47a34c commit 10f1529
Showing 1 changed file with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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
* [email protected]. 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 {
Expand Down Expand Up @@ -48,13 +62,14 @@ 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;
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
);
Expand Down

0 comments on commit 10f1529

Please sign in to comment.