private bool TryTriggerExpansion() { if (_expansionMgr != null) { var snapshot = _textView.TextBuffer.CurrentSnapshot; var span = new SnapshotSpan(snapshot, new Span(_textView.Caret.Position.BufferPosition.Position - 1, 1)); var classification = _textView.TextBuffer.GetPythonClassifier().GetClassificationSpans(span); if (classification.Count == 1) { var clsSpan = classification.First().Span; var text = classification.First().Span.GetText(); TextSpan[] textSpan = new TextSpan[1]; textSpan[0].iStartLine = clsSpan.Start.GetContainingLine().LineNumber; textSpan[0].iStartIndex = clsSpan.Start.Position - clsSpan.Start.GetContainingLine().Start; textSpan[0].iEndLine = clsSpan.End.GetContainingLine().LineNumber; textSpan[0].iEndIndex = clsSpan.End.Position - clsSpan.End.GetContainingLine().Start; string expansionPath, title; int hr = _expansionMgr.GetExpansionByShortcut( _expansionClient, GuidList.guidPythonLanguageServiceGuid, text, GetViewAdapter(), textSpan, 1, out expansionPath, out title ); if (ErrorHandler.Succeeded(hr)) { // hr may be S_FALSE if there are multiple expansions, // so we don't want to InsertNamedExpansion yet. VS will // pop up a selection dialog in this case. if (hr == VSConstants.S_OK) { return(ErrorHandler.Succeeded(_expansionClient.InsertNamedExpansion(title, expansionPath, textSpan[0]))); } return(true); } } } return(false); }
private bool TryTriggerExpansion() { if (_expansionMgr != null) { var snapshot = _textView.TextBuffer.CurrentSnapshot; var span = new SnapshotSpan(snapshot, new Span(_textView.Caret.Position.BufferPosition.Position - 1, 1)); var classification = _textView.TextBuffer.GetPythonClassifier().GetClassificationSpans(span); if (classification.Count == 1) { var clsSpan = classification.First().Span; var text = classification.First().Span.GetText(); TextSpan[] textSpan = new TextSpan[1]; textSpan[0].iStartLine = clsSpan.Start.GetContainingLine().LineNumber; textSpan[0].iStartIndex = clsSpan.Start.Position - clsSpan.Start.GetContainingLine().Start; textSpan[0].iEndLine = clsSpan.End.GetContainingLine().LineNumber; textSpan[0].iEndIndex = clsSpan.End.Position - clsSpan.End.GetContainingLine().Start; string expansionPath, title; int hr = _expansionMgr.GetExpansionByShortcut( _expansionClient, GuidList.guidPythonLanguageServiceGuid, text, GetViewAdapter(), textSpan, 1, out expansionPath, out title ); if (ErrorHandler.Succeeded(hr) && ErrorHandler.Succeeded(_expansionClient.InsertNamedExpansion(title, expansionPath, textSpan[0]))) { return(true); } } } return(false); }