public Task<bool> HasSuggestedActionsAsync(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { return Task.Factory.StartNew(() => { return false; TextExtent extent; if (!this.TryGetWordUnderCaret(out extent)) { return false; } var extentToken = new PSharpLexer().Tokenize(extent.Span.GetText()).FirstOrDefault(); if (extentToken == null) { return false; } var snapshot = extent.Span.Snapshot; var trackSpan = range.Snapshot.CreateTrackingSpan(extent.Span, SpanTrackingMode.EdgeInclusive); var preSpan = new SnapshotSpan(snapshot, new Span(snapshot.GetLineFromLineNumber(0).Start, trackSpan.GetStartPoint(snapshot).Position)); var tokens = new PSharpLexer().Tokenize(preSpan.GetText()); var parser = new PSharpParser(ParsingOptions.CreateDefault()); parser.ParseTokens(tokens); var expected = parser.GetExpectedTokenTypes(); if (this.IsExpectedTokenType(extentToken, expected)) { return false; } return extent.IsSignificant; }); }
public Task<bool> HasSuggestedActionsAsync(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { return Task.Factory.StartNew(() => { return !_view.Selection.IsEmpty; }); }
public IEnumerable<SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested || !range.Snapshot.TextBuffer.ContentType.TypeName.EqualsOrdinal(RContentTypeDefinition.ContentType)) { return Enumerable.Empty<SuggestedActionSet>(); } List<SuggestedActionSet> actionSets = new List<SuggestedActionSet>(); var caretPosition = _textView.Caret.Position.BufferPosition; SnapshotPoint? bufferPoint = _textView.MapDownToR(caretPosition); if (bufferPoint.HasValue) { AstRoot ast = _document?.EditorTree.AstRoot; int bufferPosition = bufferPoint.Value.Position; _lastNode = ast?.GetNodeOfTypeFromPosition<TokenNode>(bufferPosition); if (_lastNode != null) { foreach (IRSuggestedActionProvider actionProvider in _suggestedActionProviders) { if (actionProvider.HasSuggestedActions(_textView, _textBuffer, bufferPosition)) { IEnumerable<ISuggestedAction> actions = actionProvider.GetSuggestedActions(_textView, _textBuffer, bufferPosition); Span applicableSpan = new Span(_lastNode.Start, _lastNode.Length); SuggestedActionSet actionSet = new SuggestedActionSet(actions, applicableToSpan: applicableSpan); actionSets.Add(actionSet); } } } } return actionSets; }
public IEnumerable<SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { var span = new SnapshotSpan(_view.Selection.Start.Position, _view.Selection.End.Position); var startLine = span.Start.GetContainingLine().Extent; var endLine = span.End.GetContainingLine().Extent; var selectionStart = _view.Selection.Start.Position.Position; var selectionEnd = _view.Selection.End.Position.Position; var SelectedSpan = new SnapshotSpan(span.Snapshot, selectionStart, selectionEnd - selectionStart); var list = new List<SuggestedActionSet>(); if (!_view.Selection.IsEmpty && startLine == endLine) { var convertToLink = new ConvertToLinkAction(SelectedSpan, _view); var convertToImage = new ConvertToImageAction(SelectedSpan, _file); list.AddRange(CreateActionSet(convertToLink, convertToImage)); } var convertToQuote = new ConvertToQuoteAction(SelectedSpan, _view); var convertToCodeBlock = new ConvertToCodeBlockAction(SelectedSpan, _view); list.AddRange(CreateActionSet(convertToQuote, convertToCodeBlock)); return list; }
public IEnumerable<SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { return ( // code fixes from tagSpan in _aggregator.GetTags(range) where tagSpan.Tag is DiagnosticErrorTag let diagnostic = tagSpan.Tag as DiagnosticErrorTag from provider in _codeFixProviders where provider.CanFix(diagnostic.Id) let span = tagSpan.Span.GetSpans(_buffer).First() from fix in provider.GetFixes(span) group fix by provider into set where set.Any() select set as IEnumerable<CodeAction> ).Union( // code refactorings from provider in _refactoringProviders from refactoring in provider.GetRefactorings(range) group refactoring by provider into set where set.Any() select set as IEnumerable<CodeAction> ) .Select(s => s.Select(ca => ca.ToSuggestedAction())) .Select(s => new SuggestedActionSet(s)) ; }
public IEnumerable<SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { lock (_currentLock) { if (_currentSpan == range) { return _current; } } return null; }
public IEnumerable<SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { TextExtent extent; if (TryGetWordUnderCaret(out extent) && extent.IsSignificant) { ITrackingSpan trackingSpan = range.Snapshot.CreateTrackingSpan(extent.Span, SpanTrackingMode.EdgeInclusive); var upperAction = new UpperCaseSuggestedAction(trackingSpan); var lowerAction = new LowerCaseSuggestedAction(trackingSpan); return new SuggestedActionSet[] { new SuggestedActionSet(new ISuggestedAction[] { upperAction, lowerAction }) }; } return Enumerable.Empty<SuggestedActionSet>(); }
public Task<bool> HasSuggestedActionsAsync(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { return Task.Factory.StartNew(() => { TextExtent extent; if (TryGetWordUnderCaret(out extent)) { // don't display the tag if the extent has whitespace return extent.IsSignificant; } return false; }); }
public async Task<bool> HasSuggestedActionsAsync(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { var pos = _view.Caret.Position.BufferPosition; if (pos.Position < pos.GetContainingLine().End.Position) { pos += 1; } 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 ); var imports = await _provider .GetUIThread() .InvokeAsync(() => textBuffer.CurrentSnapshot.GetMissingImports(_provider, span)); if (imports == MissingImportAnalysis.Empty) { return false; } var suggestions = new List<SuggestedActionSet>(); var availableImports = await imports.GetAvailableImportsAsync(cancellationToken); suggestions.Add(new SuggestedActionSet( availableImports.Select(s => new PythonSuggestedImportAction(this, textBuffer, s)) .OrderBy(k => k) .Distinct() )); cancellationToken.ThrowIfCancellationRequested(); if (!suggestions.SelectMany(s => s.Actions).Any()) { return false; } lock (_currentLock) { cancellationToken.ThrowIfCancellationRequested(); _current = suggestions; _currentSpan = range; } return true; }
private async Task <bool> HasRefactoringsAsync( IDocumentSupportsSuggestionService supportSuggestion, ISuggestedActionCategorySet requestedActionCategories, SuggestedActionsSourceProvider provider, Document document, ITextBuffer buffer, ITextView view, SnapshotSpan range, CancellationToken cancellationToken) { var optionService = document.Project.Solution.Workspace.Services.GetService <IOptionService>(); if (optionService.GetOption(EditorComponentOnOffOptions.CodeRefactorings) && provider._codeRefactoringService != null && supportSuggestion.SupportsRefactorings(document) && requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.Refactoring)) { TextSpan?selection = null; if (IsForeground()) { // This operation needs to happen on UI thread because it needs to access textView.Selection. selection = TryGetCodeRefactoringSelection(buffer, view, range); } else { await InvokeBelowInputPriority(() => { // This operation needs to happen on UI thread because it needs to access textView.Selection. selection = TryGetCodeRefactoringSelection(buffer, view, range); }).ConfigureAwait(false); } if (!selection.HasValue) { // this is here to fail test and see why it is failed. Trace.WriteLine("given range is not current"); return(false); } return(await Task.Run( async() => await provider._codeRefactoringService.HasRefactoringsAsync( document, selection.Value, cancellationToken).ConfigureAwait(false), cancellationToken).ConfigureAwait(false)); } return(false); }
public IEnumerable <SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { AssertIsForeground(); using (Logger.LogBlock(FunctionId.SuggestedActions_GetSuggestedActions, cancellationToken)) { if (range.IsEmpty) { return(null); } var documentAndSnapshot = GetMatchingDocumentAndSnapshotAsync(range.Snapshot, cancellationToken).WaitAndGetResult(cancellationToken); if (!documentAndSnapshot.HasValue) { // this is here to fail test and see why it is failed. System.Diagnostics.Trace.WriteLine("given range is not current"); return(null); } var document = documentAndSnapshot.Value.Item1; var snapshot = documentAndSnapshot.Value.Item2; var workspace = document.Project.Solution.Workspace; var optionService = workspace.Services.GetService <IOptionService>(); var supportSuggestion = workspace.Services.GetService <IDocumentSupportsSuggestionService>(); IEnumerable <SuggestedActionSet> result = null; if (supportSuggestion.SupportsCodeFixes(document) && requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.CodeFix)) { var suggestions = Task.Run( async() => await _owner._codeFixService.GetFixesAsync(document, range.Span.ToTextSpan(), cancellationToken).ConfigureAwait(false), cancellationToken).WaitAndGetResult(cancellationToken); result = OrganizeFixes(workspace, suggestions); } if (supportSuggestion.SupportsRefactorings(document)) { var refactoringResult = GetRefactorings(requestedActionCategories, document, snapshot, workspace, optionService, cancellationToken); result = result == null ? refactoringResult : refactoringResult == null ? result : result.Concat(refactoringResult); } return(result); } }
public IEnumerable <SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { ThreadHelper.ThrowIfNotOnUIThread(); AlfredSuggestedAction alfredAction = null; if (VisualStudioHandler.GetCurrentLineErrorList().Count > 0) { alfredAction = new AlfredSuggestedAction(m_factory, m_textView, m_textBuffer); return(new SuggestedActionSet[] { new SuggestedActionSet(new ISuggestedAction[] { alfredAction }) }); } else { return(null); } }
public IEnumerable <SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { return(new SuggestedActionSet[1] { new SuggestedActionSet(m_classifier.GetClassificationSpans(range).Where(c => { if (c.ClassificationType.Classification == Constants.classifier_asm_cxxdecname) { return true; } if (c.ClassificationType.Classification == Constants.classifier_asm_label && c.Span.GetText().StartsWith("?")) { return true; } return false; }).Select(c => new CopyCxxUndnameSuggestedAction(c.Span))) }); }
public IEnumerable <SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { TextExtent extent; if (!cancellationToken.IsCancellationRequested && TryGetWordUnderCaret(out extent) && extent.IsSignificant) { //// Posso fazer um centralizador de "possíveis" instâncias... mas, só efetivar as instâncias aqui... //// Utilizando o using para da Dispose sempre que //ISuggestedAction comparison = new ComparisonOperatorsSuggestd(this.TextBuffer, this.TextView, range, extent); var suggestedActionSet = new SuggestedActionSet(_listSuggestedActionBase, "Teste Rá!"); Dispose(); return(new SuggestedActionSet[] { suggestedActionSet }); } return(Enumerable.Empty <SuggestedActionSet>()); }
public async Task <bool> HasSuggestedActionsAsync(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { var line = range.GetText(); if (LineParser.IsSearchable(line)) { var searchItem = LineParser.GetSearchableItem(line); if (!searchItem.IsEmpty()) { var queryResponse = await m_query.RunTextQueryWithAstrixIfNotFoundAsync(searchItem); m_recommendations.UpdateRecommendations(searchItem, queryResponse); return(m_recommendations.HasRecommendation()); } } return(false); }
public Task <bool> HasSuggestedActionsAsync(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { //return Task.Factory.StartNew(() => //{ // TextExtent extent; // if (TryGetWordUnderCaret(out extent)) // { // // don't display the action if the extent has whitespace // return extent.IsSignificant; // } // return false; //}); return(Task.Run(() => { return SearchMissingMembers(); })); }
public Task <bool> HasSuggestedActionsAsync(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { if (!_textView.Caret.InVirtualSpace) { var rPosition = _textView.MapDownToR(_textView.Caret.Position.BufferPosition); if (rPosition.HasValue) { foreach (IRSuggestedActionProvider actionProvider in _suggestedActionProviders) { if (actionProvider.HasSuggestedActions(_textView, _textBuffer, rPosition.Value.Position)) { return(Task.FromResult(true)); } } } } return(Task.FromResult(false)); }
public IEnumerable <SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { var fixes = GetSuggestedActionsAsync(requestedActionCategories, range, cancellationToken).WaitAndGetResult(cancellationToken); if (fixes == null) { yield break; } foreach (var fix in fixes) { yield return(new SuggestedActionSet( fix.Category, new ISuggestedAction[] { provider.SuggestedActionFactory.CreateSuggestedAction(provider.PreviewService, textView, textBuffer, fix) })); } }
public IEnumerable <SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { DevSkimError error = GetErrorUnderCaret(range); if (error != null) { List <ISuggestedAction> fixActions = new List <ISuggestedAction>(); ITrackingSpan trackingSpan = range.Snapshot.CreateTrackingSpan(error.Span, SpanTrackingMode.EdgeInclusive); // Create list of fixes if the rule has them.. if (error.Rule.Fixes != null) { foreach (FixRecord fix in error.Rule.Fixes) { fixActions.Add(new FixSuggestedAction(trackingSpan, fix)); } } int suppressDays = Settings.GetSettings().SuppressDays; List <ISuggestedAction> suppActions = new List <ISuggestedAction>(); var line = range.Snapshot.GetLineFromPosition(range.Start); trackingSpan = line.Snapshot.CreateTrackingSpan(line.Extent, SpanTrackingMode.EdgeInclusive); suppActions.Add(new SuppressSuggestedAction(trackingSpan, error.Rule)); suppActions.Add(new SuppressSuggestedAction(trackingSpan, error.Rule, suppressDays)); suppActions.Add(new SuppressSuggestedAction(trackingSpan, null)); suppActions.Add(new SuppressSuggestedAction(trackingSpan, null, suppressDays)); // We don't want empty group and spacer in the pop-up menu if (fixActions.Count > 0) { return new SuggestedActionSet[] { new SuggestedActionSet(fixActions), new SuggestedActionSet(suppActions) } } ; else { return new SuggestedActionSet[] { new SuggestedActionSet(suppActions) } }; } return(Enumerable.Empty <SuggestedActionSet>()); }
private IEnumerable <SuggestedActionSet> GetRefactorings( IDocumentSupportsFeatureService supportsFeatureService, ISuggestedActionCategorySet requestedActionCategories, Workspace workspace, Document document, SnapshotSpan range, CancellationToken cancellationToken) { this.AssertIsForeground(); var optionService = workspace.Services.GetService <IOptionService>(); if (optionService.GetOption(EditorComponentOnOffOptions.CodeRefactorings) && _owner._codeRefactoringService != null && supportsFeatureService.SupportsRefactorings(document) && requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.Refactoring)) { // Get the selection while on the UI thread. var selection = TryGetCodeRefactoringSelection(_subjectBuffer, _textView, range); if (!selection.HasValue) { // this is here to fail test and see why it is failed. Trace.WriteLine("given range is not current"); return(null); } var refactorings = Task.Run( async() => { var stream = await _owner._codeRefactoringService.GetRefactoringsAsync( document, selection.Value, cancellationToken).ConfigureAwait(false); return(stream.ToList()); }, cancellationToken).WaitAndGetResult(cancellationToken); var filteredRefactorings = FilterOnUIThread(refactorings, workspace); return(filteredRefactorings.Select(r => OrganizeRefactorings(workspace, r))); } return(null); }
public IEnumerable <SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { var span = new SnapshotSpan(_view.Selection.Start.Position, _view.Selection.End.Position); var startLine = span.Start.GetContainingLine().Extent; var endLine = span.End.GetContainingLine().Extent; var selectionStart = _view.Selection.Start.Position.Position; var selectionEnd = _view.Selection.End.Position.Position; var SelectedSpan = new SnapshotSpan(span.Snapshot, selectionStart, selectionEnd - selectionStart); var list = new List <SuggestedActionSet>(); //AddMissingFile var addMissingFileAction = AddMissingFileAction.Create(GetErrorTags(_view, SelectedSpan), _file, _view); if (addMissingFileAction != null) { list.AddRange(CreateActionSet(addMissingFileAction)); } if (!_view.Selection.IsEmpty && startLine == endLine) { var convertToLink = new ConvertToLinkAction(SelectedSpan, _view); var convertToImage = new ConvertToImageAction(SelectedSpan, _file); list.AddRange(CreateActionSet(convertToLink, convertToImage)); } // Blocks var convertToQuote = new ConvertToQuoteAction(SelectedSpan, _view); var convertToCodeBlock = new ConvertToCodeBlockAction(SelectedSpan, _view); list.AddRange(CreateActionSet(convertToQuote, convertToCodeBlock)); // Lists var convertToUnorderedList = new ConvertToUnorderedList(SelectedSpan, _view); var convertToOrderedList = new ConvertToOrderedList(SelectedSpan, _view); var convertToTaskList = new ConvertToTaskList(SelectedSpan, _view); list.AddRange(CreateActionSet(convertToUnorderedList, convertToOrderedList, convertToTaskList)); return(list); }
public IEnumerable <SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { var list = new List <SuggestedActionSet>(); if (_section != null) { var removeDuplicate = new RemoveDuplicatePropertiesAction(_section, _view); if (removeDuplicate.IsEnabled) { list.AddRange(CreateActionSet(removeDuplicate)); } var sortProperties = new SortPropertiesAction(_section, _view); var sortAllProperties = new SortAllPropertiesAction(_document, _view); list.AddRange(CreateActionSet(sortProperties, sortAllProperties)); var deleteSection = new DeleteSectionAction(range.Snapshot.TextBuffer, _section); list.AddRange(CreateActionSet(deleteSection)); // Suppressions IEnumerable <ParseItem> items = _document.ItemsInSpan(range).Where(p => p.HasErrors); if (items.Any()) { IEnumerable <DisplayError> errors = items.SelectMany(i => i.Errors); var actions = new List <SuppressErrorAction>(); foreach (DisplayError error in errors) { var action = new SuppressErrorAction(_document, error.Name); if (action.IsEnabled) { actions.Add(action); } } list.AddRange(CreateActionSet(actions.ToArray())); } } return(list); }
public IEnumerable <SuggestedActionSet> GetSuggestedActions( ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { AssertIsForeground(); if (IsDisposed) { return(null); } using (Logger.LogBlock(FunctionId.SuggestedActions_GetSuggestedActions, cancellationToken)) { var document = range.Snapshot.GetOpenDocumentInCurrentContextWithChanges(); if (document == null) { // this is here to fail test and see why it is failed. Trace.WriteLine("given range is not current"); return(null); } var workspace = document.Project.Solution.Workspace; var supportsFeatureService = workspace.Services.GetService <IDocumentSupportsFeatureService>(); var fixes = GetCodeFixes(supportsFeatureService, requestedActionCategories, workspace, document, range, cancellationToken); var refactorings = GetRefactorings(supportsFeatureService, requestedActionCategories, workspace, document, range, cancellationToken); var result = fixes.Concat(refactorings); if (result.IsEmpty) { return(null); } var allActionSets = InlineActionSetsIfDesirable(result); var orderedActionSets = OrderActionSets(allActionSets); var filteredSets = FilterActionSetsByTitle(orderedActionSets); return(filteredSets); } }
public IEnumerable <SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { TextExtent extent; bool isSignificant = TryGetWordUnderCaret(out extent) && extent.IsSignificant; if (isSignificant) { lock (_suggestedActions) { if (_suggestedActions.Count > 0) { return(new List <SuggestedActionSet> { new SuggestedActionSet(_suggestedActions) }); } } } return(Enumerable.Empty <SuggestedActionSet>()); }
public IEnumerable <SuggestedActionSet> GetSuggestedActions( ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { try { return(_baseActions .Where(a => a.LastDocument != null) .Select(a => { a.SnapshotSpan = range; a.CaretPosition = GetCaretPosition(); return new SuggestedActionSet(PredefinedSuggestedActionCategoryNames.Any, new[] { a }); }).ToArray()); } catch { return(Enumerable.Empty <SuggestedActionSet>()); } }
public IEnumerable <SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { // Do we have members to Add ? if (SearchMissingMembers()) { List <SuggestedActionSet> suggest = new List <SuggestedActionSet>(); foreach (KeyValuePair <string, List <IXMemberSymbol> > intfaces in _members) { // "Simple" Name var ImplementInterfaceAction = new ImplementInterfaceSuggestedAction(this.m_textView, this.m_textBuffer, intfaces.Key, this._classEntity, intfaces.Value, this._range, false); suggest.Add(new SuggestedActionSet(new ISuggestedAction[] { ImplementInterfaceAction })); // "Fully Qualified Name" ImplementInterfaceAction = new ImplementInterfaceSuggestedAction(this.m_textView, this.m_textBuffer, intfaces.Key, this._classEntity, intfaces.Value, this._range, true); suggest.Add(new SuggestedActionSet(new ISuggestedAction[] { ImplementInterfaceAction })); } return(suggest.ToArray()); } return(Enumerable.Empty <SuggestedActionSet>()); }
private ImmutableArray <SuggestedActionSet> GetRefactorings( IDocumentSupportsFeatureService supportsFeatureService, ISuggestedActionCategorySet requestedActionCategories, Workspace workspace, Document document, TextSpan?selectionOpt, CancellationToken cancellationToken) { this.AssertIsForeground(); if (!selectionOpt.HasValue) { // this is here to fail test and see why it is failed. Trace.WriteLine("given range is not current"); return(ImmutableArray <SuggestedActionSet> .Empty); } var selection = selectionOpt.Value; if (workspace.Options.GetOption(EditorComponentOnOffOptions.CodeRefactorings) && _owner._codeRefactoringService != null && supportsFeatureService.SupportsRefactorings(document) && requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.Refactoring)) { // It may seem strange that we kick off a task, but then immediately 'Wait' on // it. However, it's deliberate. We want to make sure that the code runs on // the background so that no one takes an accidentally dependency on running on // the UI thread. var refactorings = Task.Run( () => _owner._codeRefactoringService.GetRefactoringsAsync( document, selection, cancellationToken), cancellationToken).WaitAndGetResult(cancellationToken); var filteredRefactorings = FilterOnUIThread(refactorings, workspace); return(filteredRefactorings.SelectAsArray( r => OrganizeRefactorings(workspace, r, selection.ToSpan()))); } return(ImmutableArray <SuggestedActionSet> .Empty); }
async Task <List <MSBuildCodeFix> > GetSuggestedActionsAsync(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { // grab selection first as we are on the UI thread at this point, and can avoid switching to it later var possibleSelection = TryGetSelectedSpan(); var result = await parser.GetOrProcessAsync(range.Snapshot, cancellationToken); List <MSBuildCodeFix> actions = null; var severities = CategoriesToSeverity(requestedActionCategories); if (severities != 0) { actions = await provider.CodeFixService.GetFixes(textBuffer, result, range, severities, cancellationToken); for (int i = 0; i < actions.Count; i++) { if (!requestedActionCategories.Contains(actions[i].Category)) { actions.RemoveAt(i); i--; } } } if (possibleSelection is SnapshotSpan selection && requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.Refactoring)) { var refactorings = await provider.RefactoringService.GetRefactorings(result, selection, cancellationToken); if (actions != null) { actions.AddRange(refactorings); } else { actions = refactorings; } } return(actions); }
public IEnumerable <SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { return(Enumerable.Empty <SuggestedActionSet>()); TextExtent extent; if (!this.TryGetWordUnderCaret(out extent) || !extent.IsSignificant) { return(Enumerable.Empty <SuggestedActionSet>()); } var extentToken = new PSharpLexer().Tokenize(extent.Span.GetText()).FirstOrDefault(); if (extentToken == null) { return(Enumerable.Empty <SuggestedActionSet>()); } var snapshot = extent.Span.Snapshot; var trackSpan = range.Snapshot.CreateTrackingSpan(extent.Span, SpanTrackingMode.EdgeInclusive); var preSpan = new SnapshotSpan(snapshot, new Span(snapshot.GetLineFromLineNumber(0).Start, trackSpan.GetStartPoint(snapshot).Position)); var tokens = new PSharpLexer().Tokenize(preSpan.GetText()); var parser = new PSharpParser(ParsingOptions.CreateDefault()); parser.ParseTokens(tokens); var expected = parser.GetExpectedTokenTypes(); if (this.IsExpectedTokenType(extentToken, expected)) { return(Enumerable.Empty <SuggestedActionSet>()); } var errorFixAction = new ErrorFixSuggestedAction(trackSpan); return(new SuggestedActionSet[] { new SuggestedActionSet(new ISuggestedAction[] { errorFixAction }) }); }
/// <summary> /// Method returns a "show" lightbulb for each issue in the range that has secondary locations /// and a single "hide" lightbulb if the range contains any selected locations /// </summary> public IEnumerable <SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { var allActions = new List <ISuggestedAction>(); if (IsOnIssueWithSecondaryLocations(range, out var issueVisualizations)) { var actions = issueVisualizations.Select(x => new SelectIssueVisualizationAction(vsUiShell, selectionService, x)); allActions.AddRange(actions); } if (IsOnSelectedVisualization(range)) { allActions.Add(new DeselectIssueVisualizationAction(selectionService)); } if (allActions.Any()) { return(new[] { new SuggestedActionSet(allActions) }); } return(Enumerable.Empty <SuggestedActionSet>()); }
public Task <bool> HasSuggestedActionsAsync(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { return(Task.Run(async() => { if (!TryGetLintChecker(out var lintChecker)) { return false; } // wait for linting to complete await lintChecker.Linting.WithCancellation(cancellationToken); if (!lintChecker.HasSnapshot) { return false; } // we can't actually traverse the to see if the suggested action is a Some (fix) or None // because we'd have to evaluate the lazy return lintChecker.LastErrorsSnapshot.Count > 0; }, cancellationToken)); }
public IEnumerable <SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet req, SnapshotSpan range, CancellationToken token) { if (TryGetHighLightChecker(out _errors)) { List <SuggestedActionSet> suggestedActionSets = new List <SuggestedActionSet>(); foreach (ErrorInformation err in _errors) { Span span = new Span(err.StartIndex, err.Length); if (span.Contains(_textView.Caret.Position.BufferPosition.Position) && err.HasReplace) { ITrackingSpan trackingSpan = range.Snapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeInclusive); var action = new LightBulbSuggestedAction(trackingSpan, err.ReplaceCode, err.DisplayText); suggestedActionSets.Add(new SuggestedActionSet(new ISuggestedAction[] { action })); } } return(suggestedActionSets); } else { return(null); } }
public async Task <bool> HasSuggestedActionsAsync(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { // Explicitly hold onto below fields in locals and use these locals throughout this code path to avoid crashes // if these fields happen to be cleared by Dispose() below. This is required since this code path involves // code that can run asynchronously from background thread. var view = _textView; var buffer = _subjectBuffer; var provider = _owner; if (view == null || buffer == null || provider == null) { return(false); } using (var asyncToken = provider._listener.BeginAsyncOperation("HasSuggestedActionsAsync")) { var documentAndSnapshot = await GetMatchingDocumentAndSnapshotAsync(range.Snapshot, cancellationToken).ConfigureAwait(false); if (!documentAndSnapshot.HasValue) { // this is here to fail test and see why it is failed. Trace.WriteLine("given range is not current"); return(false); } var document = documentAndSnapshot.Value.Item1; var workspace = document.Project.Solution.Workspace; var supportSuggestion = workspace.Services.GetService <IDocumentSupportsSuggestionService>(); return (await HasFixesAsync( supportSuggestion, requestedActionCategories, provider, document, range, cancellationToken).ConfigureAwait(false) || await HasRefactoringsAsync( supportSuggestion, requestedActionCategories, provider, document, buffer, view, range, cancellationToken).ConfigureAwait(false)); } }
public Task <bool> HasSuggestedActionsAsync(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { return(Task.Factory.StartNew(() => { TextExtent extent; if (!TryGetWordUnderCaret(out extent)) { return false; } // don't display the action if the extent has whitespace if (!extent.IsSignificant) { return false; } UE4MacroStatement ue4Statement; if (!_ue4Processor.TryGetUE4Macro(range.Start, out ue4Statement)) { return false; } return true; }, cancellationToken)); }
public Task <bool> HasSuggestedActionsAsync(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { int line = range.Start.GetContainingLine().LineNumber; return(Task.Factory.StartNew(() => { APICheckerWindowTaskProvider taskProvider = APICheckerWindowTaskProvider.GetTaskProvider(); if (taskProvider == null) { return false; } foreach (Microsoft.VisualStudio.Shell.Task task in taskProvider.Tasks) { if (task.Line == line) { return true; } } return false; })); }
public Task <bool> HasSuggestedActionsAsync(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { return(Task.Factory.StartNew(() => { return false; TextExtent extent; if (!this.TryGetWordUnderCaret(out extent)) { return false; } var extentToken = new PSharpLexer().Tokenize(extent.Span.GetText()).FirstOrDefault(); if (extentToken == null) { return false; } var snapshot = extent.Span.Snapshot; var trackSpan = range.Snapshot.CreateTrackingSpan(extent.Span, SpanTrackingMode.EdgeInclusive); var preSpan = new SnapshotSpan(snapshot, new Span(snapshot.GetLineFromLineNumber(0).Start, trackSpan.GetStartPoint(snapshot).Position)); var tokens = new PSharpLexer().Tokenize(preSpan.GetText()); var parser = new PSharpParser(ParsingOptions.CreateDefault()); parser.ParseTokens(tokens); var expected = parser.GetExpectedTokenTypes(); if (this.IsExpectedTokenType(extentToken, expected)) { return false; } return extent.IsSignificant; })); }
public async Task <ISuggestedActionCategorySet> GetSuggestedActionCategoriesAsync( ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { SnapshotSpan?possibleSelection = provider.JoinableTaskContext.IsOnMainThread ? TryGetSelectedSpan() : null; var result = await parser.GetOrProcessAsync(range.Snapshot, cancellationToken); var categories = new List <string> (); var requestedSeverities = CategoriesToSeverity(requestedActionCategories); if (requestedSeverities != 0) { var severities = await provider.CodeFixService.GetFixSeverity(textBuffer, result, range, requestedSeverities, cancellationToken); if ((severities & MSBuildDiagnosticSeverity.Error) != 0) { categories.Add(PredefinedSuggestedActionCategoryNames.ErrorFix); } if ((severities & (MSBuildDiagnosticSeverity.Warning | MSBuildDiagnosticSeverity.Suggestion)) != 0) { categories.Add(PredefinedSuggestedActionCategoryNames.CodeFix); } } if (requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.Refactoring)) { possibleSelection ??= await GetSelectedSpanAsync(cancellationToken); if (possibleSelection is SnapshotSpan selection && await provider.RefactoringService.HasRefactorings(result, selection, cancellationToken)) { categories.Add(PredefinedSuggestedActionCategoryNames.Refactoring); } } return(provider.CategoryRegistry.CreateSuggestedActionCategorySet(categories)); }
public IEnumerable<SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { return Enumerable.Empty<SuggestedActionSet>(); TextExtent extent; if (!this.TryGetWordUnderCaret(out extent) || !extent.IsSignificant) { return Enumerable.Empty<SuggestedActionSet>(); } var extentToken = new PSharpLexer().Tokenize(extent.Span.GetText()).FirstOrDefault(); if (extentToken == null) { return Enumerable.Empty<SuggestedActionSet>(); } var snapshot = extent.Span.Snapshot; var trackSpan = range.Snapshot.CreateTrackingSpan(extent.Span, SpanTrackingMode.EdgeInclusive); var preSpan = new SnapshotSpan(snapshot, new Span(snapshot.GetLineFromLineNumber(0).Start, trackSpan.GetStartPoint(snapshot).Position)); var tokens = new PSharpLexer().Tokenize(preSpan.GetText()); var parser = new PSharpParser(ParsingOptions.CreateDefault()); parser.ParseTokens(tokens); var expected = parser.GetExpectedTokenTypes(); if (this.IsExpectedTokenType(extentToken, expected)) { return Enumerable.Empty<SuggestedActionSet>(); } var errorFixAction = new ErrorFixSuggestedAction(trackSpan); return new SuggestedActionSet[] { new SuggestedActionSet(new ISuggestedAction[] { errorFixAction }) }; }
public async Task <bool> HasSuggestedActionsAsync(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { var view = _textView; var buffer = _subjectBuffer; var provider = _owner; if (view == null || buffer == null || provider == null) { return(false); } using (var asyncToken = provider._listener.BeginAsyncOperation("HasSuggesetedActionsAsync")) { var result = await HasSuggesetedActionCoreAsync(view, buffer, provider._codeFixService, range, cancellationToken).ConfigureAwait(false); if (!result.HasValue) { return(false); } if (result.Value.HasFix) { Logger.Log(FunctionId.SuggestedActions_HasSuggestedActionsAsync); return(true); } if (result.Value.PartialResult) { // reset solution version number so that we can raise suggested action changed event Volatile.Write(ref _lastSolutionVersionReported, InvalidSolutionVersion); return(false); } return(false); } }
public IEnumerable <SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { var classifications = this._classifier.GetClassificationSpans(range); foreach (var classification in classifications) { if (classification.ClassificationType.IsOfType(IgnoreClassificationTypes.Path)) { var deleteMatches = new DeleteMatchesSuggestedAction(classification.Span); var excludeFromProj = new ExcludeMatchesFromProjectSuggestedAction(classification.Span); return(this.CreateActionSet(deleteMatches, excludeFromProj)); } else if (classification.ClassificationType.IsOfType(IgnoreClassificationTypes.PathNoMatch)) { var removeNonMatch = new RemoveNonMatchSuggestedAction(classification.Span); var removeAllNonMatch = new RemoveAllNonMatchSuggestedAction(classification.Span); return(this.CreateActionSet(removeNonMatch, removeAllNonMatch)); } } return(Enumerable.Empty <SuggestedActionSet>()); }
private async Task<bool> HasRefactoringsAsync( IDocumentSupportsFeatureService supportsFeatureService, ISuggestedActionCategorySet requestedActionCategories, SuggestedActionsSourceProvider provider, Document document, ITextBuffer buffer, ITextView view, SnapshotSpan range, CancellationToken cancellationToken) { var optionService = document.Project.Solution.Workspace.Services.GetService<IOptionService>(); if (optionService.GetOption(EditorComponentOnOffOptions.CodeRefactorings) && provider._codeRefactoringService != null && supportsFeatureService.SupportsRefactorings(document) && requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.Refactoring)) { TextSpan? selection = null; if (IsForeground()) { // This operation needs to happen on UI thread because it needs to access textView.Selection. selection = TryGetCodeRefactoringSelection(buffer, view, range); } else { await InvokeBelowInputPriority(() => { // This operation needs to happen on UI thread because it needs to access textView.Selection. selection = TryGetCodeRefactoringSelection(buffer, view, range); }).ConfigureAwait(false); } if (!selection.HasValue) { // this is here to fail test and see why it is failed. Trace.WriteLine("given range is not current"); return false; } return await Task.Run( async () => await provider._codeRefactoringService.HasRefactoringsAsync( document, selection.Value, cancellationToken).ConfigureAwait(false), cancellationToken).ConfigureAwait(false); } return false; }
private async Task<bool> HasFixesAsync( IDocumentSupportsFeatureService supportsFeatureService, ISuggestedActionCategorySet requestedActionCategories, SuggestedActionsSourceProvider provider, Document document, SnapshotSpan range, CancellationToken cancellationToken) { if (provider._codeFixService != null && supportsFeatureService.SupportsCodeFixes(document) && requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.CodeFix)) { // We only consider suppressions if lightbulb is asking for everything. // If the light bulb is only asking for code fixes, then we don't consider suppressions. var considerSuppressionFixes = requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.Any); var result = await Task.Run( async () => await provider._codeFixService.GetFirstDiagnosticWithFixAsync( document, range.Span.ToTextSpan(), considerSuppressionFixes, cancellationToken).ConfigureAwait(false), cancellationToken).ConfigureAwait(false); if (result.HasFix) { Logger.Log(FunctionId.SuggestedActions_HasSuggestedActionsAsync); return true; } if (result.PartialResult) { // reset solution version number so that we can raise suggested action changed event Volatile.Write(ref _lastSolutionVersionReported, InvalidSolutionVersion); return false; } } return false; }
public async Task<bool> HasSuggestedActionsAsync(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { // Explicitly hold onto below fields in locals and use these locals throughout this code path to avoid crashes // if these fields happen to be cleared by Dispose() below. This is required since this code path involves // code that can run asynchronously from background thread. var view = _textView; var buffer = _subjectBuffer; var provider = _owner; if (view == null || buffer == null || provider == null) { return false; } using (var asyncToken = provider._listener.BeginAsyncOperation("HasSuggestedActionsAsync")) { var documentAndSnapshot = await GetMatchingDocumentAndSnapshotAsync(range.Snapshot, cancellationToken).ConfigureAwait(false); if (!documentAndSnapshot.HasValue) { // this is here to fail test and see why it is failed. Trace.WriteLine("given range is not current"); return false; } var document = documentAndSnapshot.Value.Item1; var workspace = document.Project.Solution.Workspace; var supportsFeatureService = workspace.Services.GetService<IDocumentSupportsFeatureService>(); return await HasFixesAsync( supportsFeatureService, requestedActionCategories, provider, document, range, cancellationToken).ConfigureAwait(false) || await HasRefactoringsAsync( supportsFeatureService, requestedActionCategories, provider, document, buffer, view, range, cancellationToken).ConfigureAwait(false); } }
private IEnumerable<SuggestedActionSet> GetRefactorings( IDocumentSupportsFeatureService supportsFeatureService, ISuggestedActionCategorySet requestedActionCategories, Workspace workspace, Document document, SnapshotSpan range, CancellationToken cancellationToken) { var optionService = workspace.Services.GetService<IOptionService>(); if (optionService.GetOption(EditorComponentOnOffOptions.CodeRefactorings) && _owner._codeRefactoringService != null && supportsFeatureService.SupportsRefactorings(document) && requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.Refactoring)) { // Get the selection while on the UI thread. var selection = TryGetCodeRefactoringSelection(_subjectBuffer, _textView, range); if (!selection.HasValue) { // this is here to fail test and see why it is failed. Trace.WriteLine("given range is not current"); return null; } var refactorings = Task.Run( async () => await _owner._codeRefactoringService.GetRefactoringsAsync( document, selection.Value, cancellationToken).ConfigureAwait(false), cancellationToken).WaitAndGetResult(cancellationToken); return refactorings.Select(r => OrganizeRefactorings(workspace, r)); } return null; }
private IEnumerable<SuggestedActionSet> GetCodeFixes( IDocumentSupportsFeatureService supportsFeatureService, ISuggestedActionCategorySet requestedActionCategories, Workspace workspace, Document document, SnapshotSpan range, CancellationToken cancellationToken) { if (_owner._codeFixService != null && supportsFeatureService.SupportsCodeFixes(document) && requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.CodeFix)) { // We only include suppressions if lightbulb is asking for everything. // If the light bulb is only asking for code fixes, then we don't include suppressions. var includeSuppressionFixes = requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.Any); var fixes = Task.Run( async () => await _owner._codeFixService.GetFixesAsync( document, range.Span.ToTextSpan(), includeSuppressionFixes, cancellationToken).ConfigureAwait(false), cancellationToken).WaitAndGetResult(cancellationToken); return OrganizeFixes(workspace, fixes, hasSuppressionFixes: includeSuppressionFixes); } return null; }
public IEnumerable<SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { AssertIsForeground(); using (Logger.LogBlock(FunctionId.SuggestedActions_GetSuggestedActions, cancellationToken)) { var documentAndSnapshot = GetMatchingDocumentAndSnapshotAsync(range.Snapshot, cancellationToken).WaitAndGetResult(cancellationToken); if (!documentAndSnapshot.HasValue) { // this is here to fail test and see why it is failed. Trace.WriteLine("given range is not current"); return null; } var document = documentAndSnapshot.Value.Item1; var workspace = document.Project.Solution.Workspace; var supportsFeatureService = workspace.Services.GetService<IDocumentSupportsFeatureService>(); var fixes = GetCodeFixes(supportsFeatureService, requestedActionCategories, workspace, document, range, cancellationToken); var refactorings = GetRefactorings(supportsFeatureService, requestedActionCategories, workspace, document, range, cancellationToken); var result = fixes == null ? refactorings : refactorings == null ? fixes : fixes.Concat(refactorings); if (result == null) { return null; } var allActionSets = result.ToList(); allActionSets = InlineActionSetsIfDesirable(allActionSets); return allActionSets; } }
public IEnumerable<SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { AssertIsForeground(); using (Logger.LogBlock(FunctionId.SuggestedActions_GetSuggestedActions, cancellationToken)) { if (range.IsEmpty) { return null; } var documentAndSnapshot = GetMatchingDocumentAndSnapshotAsync(range.Snapshot, cancellationToken).WaitAndGetResult(cancellationToken); if (!documentAndSnapshot.HasValue) { // this is here to fail test and see why it is failed. System.Diagnostics.Trace.WriteLine("given range is not current"); return null; } var document = documentAndSnapshot.Value.Item1; var snapshot = documentAndSnapshot.Value.Item2; var workspace = document.Project.Solution.Workspace; var optionService = workspace.Services.GetService<IOptionService>(); var supportSuggestion = workspace.Services.GetService<IDocumentSupportsSuggestionService>(); IEnumerable<SuggestedActionSet> result = null; if (supportSuggestion.SupportsCodeFixes(document) && requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.CodeFix)) { var suggestions = Task.Run( async () => await _owner._codeFixService.GetFixesAsync(document, range.Span.ToTextSpan(), cancellationToken).ConfigureAwait(false), cancellationToken).WaitAndGetResult(cancellationToken); result = OrganizeFixes(workspace, suggestions); } if (supportSuggestion.SupportsRefactorings(document)) { var refactoringResult = GetRefactorings(requestedActionCategories, document, snapshot, workspace, optionService, cancellationToken); result = result == null ? refactoringResult : refactoringResult == null ? result : result.Concat(refactoringResult); } return result; } }
private ImmutableArray<SuggestedActionSet> GetCodeFixes( IDocumentSupportsFeatureService supportsFeatureService, ISuggestedActionCategorySet requestedActionCategories, Workspace workspace, Document document, SnapshotSpan range, CancellationToken cancellationToken) { this.AssertIsForeground(); if (_owner._codeFixService != null && supportsFeatureService.SupportsCodeFixes(document) && requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.CodeFix)) { // We only include suppressions if lightbulb is asking for everything. // If the light bulb is only asking for code fixes, then we don't include suppressions. var includeSuppressionFixes = requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.Any); var fixes = Task.Run( () => _owner._codeFixService.GetFixesAsync( document, range.Span.ToTextSpan(), includeSuppressionFixes, cancellationToken), cancellationToken).WaitAndGetResult(cancellationToken); var filteredFixes = FilterOnUIThread(fixes, workspace); return OrganizeFixes(workspace, filteredFixes, includeSuppressionFixes); } return ImmutableArray<SuggestedActionSet>.Empty; }
public Task<bool> HasSuggestedActionsAsync(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { if (!_textView.Caret.InVirtualSpace) { var rPosition = _textView.MapDownToR(_textView.Caret.Position.BufferPosition); if (rPosition.HasValue) { foreach (IRSuggestedActionProvider actionProvider in _suggestedActionProviders) { if (actionProvider.HasSuggestedActions(_textView, _textBuffer, rPosition.Value.Position)) { return Task.FromResult(true); } } } } return Task.FromResult(false); }
public Task<bool> HasSuggestedActionsAsync(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { ITextBuffer buffer = range.Snapshot.TextBuffer; return Task.FromResult( _aggregator.GetTags(range) .Select(s => s.Tag) .OfType<DiagnosticErrorTag>() .Any(t => IsFixable(t.Id)) || _refactoringProviders .SelectMany(rp => rp.GetRefactorings(range)) .Any() ); }
private async Task<bool> HasRefactoringsAsync( IDocumentSupportsFeatureService supportsFeatureService, ISuggestedActionCategorySet requestedActionCategories, SuggestedActionsSourceProvider provider, Document document, ITextBuffer buffer, ITextView view, SnapshotSpan range, CancellationToken cancellationToken) { if (!requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.Refactoring)) { // See if we should still show the light bulb, even if we weren't explicitly // asked for refactorings. We'll show the lightbulb if we're currently // flighting the "Refactoring" A/B test, or if a special option is set // enabling this internally. var workspace = document.Project.Solution.Workspace; var experimentationService = workspace.Services.GetService<IExperimentationService>(); if (!experimentationService.IsExperimentEnabled("Refactoring") && !workspace.Options.GetOption(EditorComponentOnOffOptions.ShowCodeRefactoringsWhenQueriedForCodeFixes)) { return false; } } if (document.Project.Solution.Options.GetOption(EditorComponentOnOffOptions.CodeRefactorings) && provider._codeRefactoringService != null && supportsFeatureService.SupportsRefactorings(document)) { TextSpan? selection = null; if (IsForeground()) { // This operation needs to happen on UI thread because it needs to access textView.Selection. selection = TryGetCodeRefactoringSelection(buffer, view, range); } else { await InvokeBelowInputPriority(() => { // This operation needs to happen on UI thread because it needs to access textView.Selection. selection = TryGetCodeRefactoringSelection(buffer, view, range); }).ConfigureAwait(false); } if (!selection.HasValue) { // this is here to fail test and see why it is failed. Trace.WriteLine("given range is not current"); return false; } return await Task.Run( () => provider._codeRefactoringService.HasRefactoringsAsync( document, selection.Value, cancellationToken), cancellationToken).ConfigureAwait(false); } return false; }
private ImmutableArray<SuggestedActionSet> GetRefactorings( IDocumentSupportsFeatureService supportsFeatureService, ISuggestedActionCategorySet requestedActionCategories, Workspace workspace, Document document, SnapshotSpan range, CancellationToken cancellationToken) { this.AssertIsForeground(); if (workspace.Options.GetOption(EditorComponentOnOffOptions.CodeRefactorings) && _owner._codeRefactoringService != null && supportsFeatureService.SupportsRefactorings(document) && requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.Refactoring)) { // Get the selection while on the UI thread. var selection = TryGetCodeRefactoringSelection(_subjectBuffer, _textView, range); if (!selection.HasValue) { // this is here to fail test and see why it is failed. Trace.WriteLine("given range is not current"); return ImmutableArray<SuggestedActionSet>.Empty; } // It may seem strange that we kick off a task, but then immediately 'Wait' on // it. However, it's deliberate. We want to make sure that the code runs on // the background so that no one takes an accidently dependency on running on // the UI thread. var refactorings = Task.Run( () => _owner._codeRefactoringService.GetRefactoringsAsync( document, selection.Value, cancellationToken), cancellationToken).WaitAndGetResult(cancellationToken); var filteredRefactorings = FilterOnUIThread(refactorings, workspace); return filteredRefactorings.SelectAsArray(r => OrganizeRefactorings(workspace, r)); } return ImmutableArray<SuggestedActionSet>.Empty; }
private IEnumerable<SuggestedActionSet> GetRefactorings( ISuggestedActionCategorySet requestedActionCategories, Document document, ITextSnapshot snapshot, Workspace workspace, IOptionService optionService, CancellationToken cancellationToken) { // For Dev14 Preview, we also want to show refactorings in the CodeFix list when users press Ctrl+. if (requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.Refactoring) || requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.CodeFix)) { var refactoringsOn = optionService.GetOption(EditorComponentOnOffOptions.CodeRefactorings); if (!refactoringsOn) { return null; } // Get the selection while on the UI thread. var selection = GetCodeRefactoringSelection(snapshot); if (!selection.HasValue) { // this is here to fail test and see why it is failed. System.Diagnostics.Trace.WriteLine("given range is not current"); return null; } var refactorings = Task.Run( async () => await _owner._codeRefactoringService.GetRefactoringsAsync(document, selection.Value, cancellationToken).ConfigureAwait(false), cancellationToken).WaitAndGetResult(cancellationToken); return refactorings.Select(r => OrganizeRefactorings(workspace, r)); } return null; }
public async Task<bool> HasSuggestedActionsAsync(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { var view = _textView; var buffer = _subjectBuffer; var provider = _owner; if (view == null || buffer == null || provider == null) { return false; } using (var asyncToken = provider._listener.BeginAsyncOperation("HasSuggesetedActionsAsync")) { var result = await HasSuggesetedActionCoreAsync(view, buffer, provider._codeFixService, range, cancellationToken).ConfigureAwait(false); if (!result.HasValue) { return false; } if (result.Value.HasFix) { Logger.Log(FunctionId.SuggestedActions_HasSuggestedActionsAsync); return true; } if (result.Value.PartialResult) { // reset solution version number so that we can raise suggested action changed event Volatile.Write(ref _lastSolutionVersionReported, InvalidSolutionVersion); return false; } return false; } }