-
Notifications
You must be signed in to change notification settings - Fork 676
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from zooba/repl-exception
Prevents exceptions in projection buffers when suggesting missing imports
- Loading branch information
Showing
1 changed file
with
22 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
@@ -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 | ||
); | ||
|