public override Methods GetMethods(int line, int col, string name) { AstNode node = _templateNode.GetNodeAt(line + 1, col + 1); if (node is NVSelector) { NVClassNode classNode = ((NVClassNode)((NVSelector)node).GetParentType()); if (classNode == null) { return(null); } List <NVMethodNode> overloadedMethods = new List <NVMethodNode>(); foreach (NVMethodNode methodNode in classNode.Methods) { if (methodNode.Name == ((NVSelector)node).Name) { overloadedMethods.Add(methodNode); } } if (overloadedMethods.Count > 0) { return(new NVelocityMethods(overloadedMethods)); } } return(null); }
public List <NVClassNode> GetViewComponents() { List <string> assemblies = GetAssembliesInBinaryDirectory(); List <NVClassNode> types = new List <NVClassNode>(); foreach (string assemblyFileName in assemblies) { if (!IsIgnored(assemblyFileName)) { AssemblyDefinition assemblyDefinition = AssemblyFactory.GetAssembly(assemblyFileName); TypeDefinitionCollection typeDefs = assemblyDefinition.MainModule.Types; foreach (TypeDefinition type in typeDefs) { if (type.Name != "<Module>" && !type.IsAbstract && type.BaseType != null && TypeInherits(typeDefs, type, ViewComponentTypeName)) { NVClassNode classNode = new NVClassNode(type.Name, type.FullName); classNode.ClassPurpose = NVClassNodePurpose.ViewComponent; classNode.AssemblyFileName = assemblyFileName; types.Add(classNode); } } } } return(types); }
public List <NVClassNode> GetHelpers() { List <string> assemblies = GetAssembliesInBinaryDirectory(); List <NVClassNode> types = new List <NVClassNode>(); foreach (string assemblyFileName in assemblies) { if (!IsIgnored(assemblyFileName)) { AssemblyDefinition assemblyDefinition = AssemblyFactory.GetAssembly(assemblyFileName); TypeDefinitionCollection typeDefs = assemblyDefinition.MainModule.Types; foreach (TypeDefinition type in typeDefs) { if (type.Name != "<Module>" && !type.IsAbstract && type.BaseType != null && TypeInherits(typeDefs, type, AbstractHelperTypeName)) { NVClassNode classNode = new NVClassNode(type.Name, type.FullName); classNode.ClassPurpose = NVClassNodePurpose.Helper; classNode.AssemblyFileName = assemblyFileName; foreach (MethodDefinition method in type.Methods) { // Properties have the special name IL flag so ignore get_ and set_ methods if ((method.Attributes & MethodAttributes.Public) == MethodAttributes.Public && method.SemanticsAttributes != MethodSemanticsAttributes.Getter && method.SemanticsAttributes != MethodSemanticsAttributes.Setter) { NVMethodNode methodNode = new NVMethodNode(method.Name, new NVClassNode( method.ReturnType.ReturnType.Name, method.ReturnType.ReturnType.FullName)); List <NVParameterNode> parameters = new List <NVParameterNode>(); foreach (ParameterDefinition parameter in method.Parameters) { parameters.Add(new NVParameterNode( parameter.Name, new NVClassNode(parameter.ParameterType.Name, parameter.ParameterType.FullName), parameter.Sequence)); } methodNode.Parameters = parameters; classNode.AddMethod(methodNode); } } types.Add(classNode); } } } } return(types); }
public override string GetDescription(int index) { string description = string.Empty; NVIdNode idNode = _declarations[index].IdNode; if (idNode is NVClassNode) { NVClassNode classNode = (NVClassNode)idNode; XmlDocumentationProvider documentationProvider = new XmlDocumentationProvider(classNode.AssemblyFileName); string classSummary = documentationProvider.GetTypeDocumentation(classNode.FullName); if (!string.IsNullOrEmpty(classSummary)) { description = string.Format("class {0}\n{1}", classNode.FullName, classSummary); } else { description = string.Format("class {0}", classNode.FullName); } } else if (idNode is NVLocalNode) { NVClassNode classNode = (NVClassNode)idNode.Type; if (classNode != null) { XmlDocumentationProvider documentationProvider = new XmlDocumentationProvider(classNode.AssemblyFileName); description = documentationProvider.GetTypeDocumentation(classNode.FullName); } } else if (idNode is NVMethodNode) { NVClassNode classNode = (NVClassNode)((NVMethodNode)idNode).Parent; if (classNode != null) { XmlDocumentationProvider documentationProvider = new XmlDocumentationProvider(classNode.AssemblyFileName); description = documentationProvider.GetMethodDocumentation(classNode.FullName, idNode.Name); } } // Return the documentation or an error message if (!string.IsNullOrEmpty(description)) { return(description); } return(string.Format("Could not retrieve documentation for AST node '{0}' (because it is not supported).", idNode != null ? idNode.GetType().Name : "")); }
/// <summary> /// Returns information about the specified parameter on the specified method signature. /// </summary> /// <param name="index">An index into the list of method signatures.</param> /// <param name="parameter">An index into the parameter list of the specified method signature.</param> /// <param name="name">Returns the name of the parameter.</param> /// <param name="display">Returns the parameter name and type formatted for display.</param> /// <param name="description">Returns a string containing a description of the parameter.</param> public override void GetParameterInfo(int index, int parameter, out string name, out string display, out string description) { NVMethodNode methodNode = _methodNodes[index]; NVParameterNode parameterNode = methodNode.Parameters[parameter]; NVClassNode classNode = (NVClassNode)methodNode.Parent; name = parameterNode.Name; display = string.Format("{0} {1}", parameterNode.Type.Name, parameterNode.Name); // Retrieve XML documentation XmlDocumentationProvider documentationProvider = new XmlDocumentationProvider(classNode.AssemblyFileName); description = documentationProvider.GetParameterDocumentation( classNode.FullName, methodNode.Name, parameterNode.Name); if (string.IsNullOrEmpty(description)) { description = string.Format("Could not retrieve documentation for parameter '{0}'.", parameterNode.Name); } }
public override Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason) { // If the intellisense parse reason was called before the template could be parsed if (_templateNode == null) { return(null); } AstNode astNode = _templateNode.GetNodeAt(line + 1, col + 1); if (astNode == null) { Debug.Fail("Null AstNode when attempting to provide IntelliSense in NVelocityAuthoringScope."); return(null); } NVelocityDeclarations declarations = new NVelocityDeclarations(); if (astNode is NVDesignator) { List <NVLocalNode> localNodes = _templateNode.GetLocalNodesFromScope(line, col); localNodes.Sort(new Comparison <NVLocalNode>( delegate(NVLocalNode x, NVLocalNode y) { return(x.Name.CompareTo(y.Name)); })); foreach (NVLocalNode localNode in localNodes) { declarations.Add(new NVelocityDeclaration(localNode.Name, localNode, IntelliSenseIcon.Variable)); } } else if (astNode is NVSelector) { NVTypeNode typeNode = ((NVSelector)astNode).GetParentType(); if (typeNode is NVClassNode) { NVClassNode classNode = (NVClassNode)typeNode; Dictionary <string, NVMethodNode> uniqueMethods = new Dictionary <string, NVMethodNode>(); foreach (NVMethodNode methodNode in classNode.Methods) { if (!uniqueMethods.ContainsKey(methodNode.Name)) { uniqueMethods.Add(methodNode.Name, methodNode); } } List <NVMethodNode> uniqueMethodsList = new List <NVMethodNode>(); foreach (KeyValuePair <string, NVMethodNode> pair in uniqueMethods) { uniqueMethodsList.Add(pair.Value); } uniqueMethodsList.Sort(new Comparison <NVMethodNode>( delegate(NVMethodNode x, NVMethodNode y) { return(x.Name.CompareTo(y.Name)); })); foreach (NVMethodNode methodNode in uniqueMethodsList) { declarations.Add(new NVelocityDeclaration(methodNode.Name, methodNode, IntelliSenseIcon.Method)); } } else { if (typeNode == null) { declarations.Add(new NVelocityDeclaration("Error: TypeNode is null", null, IntelliSenseIcon.Error)); } else { declarations.Add(new NVelocityDeclaration("Error: Unsupported type for NVSelector " + typeNode.GetType().Name, null, IntelliSenseIcon.Error)); } } } else if (astNode is NVDirective) { NVDirective nvDirective = (NVDirective)astNode; if ((col + 1) - astNode.Position.StartPos == 1) { // TODO: change the if expression so that it checks if the col is between the # and ( // because you can bring up the intellisense list in the middle of the identifier // and it should display the list of the directives instead of the view components. List <string> directivesList = new List <string>(); directivesList.AddRange(new string[] { "if", "elseif", "else", "end", "foreach", "set", "stop", "component", "blockcomponent", "literal", "macro" }); directivesList.Sort(); foreach (string directive in directivesList) { declarations.Add(new NVelocityDeclaration(directive, null, IntelliSenseIcon.Macro)); } } else if (nvDirective.Name == "component" || nvDirective.Name == "blockcomponent") { List <NVClassNode> viewComponents = _templateNode.GetViewComponentsFromScope(); viewComponents.Sort(new Comparison <NVClassNode>( delegate(NVClassNode x, NVClassNode y) { return(x.Name.CompareTo(y.Name)); })); foreach (NVClassNode classNode in viewComponents) { declarations.Add(new NVelocityDeclaration(classNode.Name, classNode, IntelliSenseIcon.Class)); } } } else if (astNode is XmlElement) { string xhtmlSchemaFileName = GetXhtmlSchemaFileName(); if (string.IsNullOrEmpty(xhtmlSchemaFileName)) { Debug.Fail("Could not find XHTML schema."); return(declarations); } XhtmlSchemaProvider xhtmlSchemaProvider = new XhtmlSchemaProvider(xhtmlSchemaFileName); XmlElement xmlElement = (XmlElement)astNode; if (string.IsNullOrEmpty(xmlElement.Name)) { if (xmlElement.Parent != null) { if (!xmlElement.Parent.IsSelfClosing && !xmlElement.IsComplete && !xmlElement.Parent.IsComplete) { declarations.Add(new NVelocityDeclaration(string.Format("/{0}>", xmlElement.Parent.Name), null, IntelliSenseIcon.XmlElement)); } } foreach (string xhtmlElement in xhtmlSchemaProvider.GetElements()) { declarations.Add(new NVelocityDeclaration(xhtmlElement, null, IntelliSenseIcon.XmlElement)); } } else { // Retrieve attributes List <string> xhtmlAttributes = xhtmlSchemaProvider.GetAttributes(xmlElement.Name); // Remove attributes that are already used foreach (AstNode attribute in xmlElement.Attributes) { if (attribute is XmlAttribute) { XmlAttribute xmlAttribute = (XmlAttribute)attribute; if (xhtmlAttributes.Contains(xmlAttribute.Name)) { xhtmlAttributes.Remove(xmlAttribute.Name); } } } // Add the declarations for the attributes to show foreach (string xhtmlAttribute in xhtmlAttributes) { declarations.Add(new NVelocityDeclaration(xhtmlAttribute, null, IntelliSenseIcon.XmlAttribute)); } } } else { declarations.Add(new NVelocityDeclaration("Error: Context unknown, type is " + astNode.GetType().Name, null, IntelliSenseIcon.Error)); } return(declarations); }