private async System.Threading.Tasks.Task DoWorkAsync(string commandName) { if (!(ServiceProvider.GetService(typeof(SComponentModel)) is IComponentModel componentModel)) { return; } if (!(ServiceProvider.GetService(typeof(SVsTextManager)) is IVsTextManager vsTextManager)) { return; } ErrorHandler.ThrowOnFailure(vsTextManager.GetActiveView(1, null, out var activeView)); var editorService = componentModel.GetService <IVsEditorAdaptersFactoryService>(); var textView = editorService.GetWpfTextView(activeView); var caretPosition = textView.Caret.Position; var bufferPosition = caretPosition.BufferPosition; var document = bufferPosition.Snapshot.GetOpenDocumentInCurrentContextWithChanges(); if (document == null) { return; } var position = bufferPosition.Position; var semanticModel = await document.GetSemanticModelAsync(); var selectedSymbol = await GetSymbolUnderCursorAsync(document, semanticModel, position); ITypeSymbol symbolToSerialize; switch (selectedSymbol) { // 'Foo' in `var f = new Foo { ... }`. case IMethodSymbol methodSymbol when methodSymbol.MethodKind == MethodKind.Constructor: symbolToSerialize = methodSymbol.ReceiverType; break; // 'Foo' in `public class Foo { ... }`, `public Foo F { get; set; }`. case ITypeSymbol typeSymbol: symbolToSerialize = typeSymbol; break; default: ShowMessageBox(ServiceProvider, "Invoke this menu on a type name."); return; } // This does the actual magic. var classInfo = new TypeSymbolParser().GetMemberInfoRecursive(symbolToSerialize, semanticModel); ShowOutput(classInfo, commandName); }
private async System.Threading.Tasks.Task DoWorkAsync(string commandName) { var componentModel = ServiceProvider.GetService(typeof(SComponentModel)) as IComponentModel; if (componentModel == null) { return; } var vsTextManager = ServiceProvider.GetService(typeof(SVsTextManager)) as IVsTextManager; if (vsTextManager == null) { return; } IVsTextView activeView; ErrorHandler.ThrowOnFailure(vsTextManager.GetActiveView(1, null, out activeView)); var editorService = componentModel.GetService <IVsEditorAdaptersFactoryService>(); var textView = editorService.GetWpfTextView(activeView); CaretPosition caretPosition = textView.Caret.Position; SnapshotPoint bufferPosition = caretPosition.BufferPosition; var document = bufferPosition.Snapshot.GetOpenDocumentInCurrentContextWithChanges(); if (document == null) { return; } int position = bufferPosition.Position; SemanticModel semanticModel = await document.GetSemanticModelAsync(); ISymbol selectedSymbol = await GetSymbolUnderCursorAsync(document, semanticModel, position); var typeSymbol = selectedSymbol as ITypeSymbol; if (typeSymbol == null) { ShowMessageBox(ServiceProvider, "Invoke this menu on a type name."); return; } // This does the actual magic. var classInfo = new TypeSymbolParser().GetMemberInfoRecursive(typeSymbol, semanticModel); ShowOutput(classInfo, commandName); }