private CodeFunction GetSelectedFunction(Document activeDocument) { var textSelection = (TextSelection)activeDocument.Selection; if (textSelection == null) { return(null); } var codeModel = activeDocument.ProjectItem.FileCodeModel; if (codeModel == null) { return(null); } return(VsxHelper.TryGetCodeElementFromActivePoint(codeModel, textSelection) as CodeFunction); }