/// <summary> /// Get hover content for an <see cref="MSBuildUnusedProperty"/>. /// </summary> /// <param name="unusedProperty"> /// The <see cref="MSBuildUnusedProperty"/>. /// </param> /// <returns> /// The content, or <c>null</c> if no content is provided. /// </returns> public MarkedStringContainer UnusedProperty(MSBuildUnusedProperty unusedProperty) { if (unusedProperty == null) { throw new ArgumentNullException(nameof(unusedProperty)); } List <MarkedString> content = new List <MarkedString>(); if (unusedProperty.Element.HasParentPath(WellKnownElementPaths.DynamicPropertyGroup)) { content.Add( $"Dynamic Property: `{unusedProperty.Name}`" ); content.Add( "(properties declared in targets are only evaluated when building the project)" ); } else { content.Add( $"Unused Property: `{unusedProperty.Name}` (condition is false)" ); } string propertyHelp = MSBuildSchemaHelp.ForProperty(unusedProperty.Name); if (propertyHelp != null) { content.Add(propertyHelp); } content.Add( $"Value would have been: `{unusedProperty.Value}`" ); string helpLink = MSBuildSchemaHelp.HelpLinkForProperty(unusedProperty.Name); if (!String.IsNullOrWhiteSpace(helpLink)) { content.Add( $"[Help]({helpLink})" ); } return(new MarkedStringContainer(content)); }
/// <summary> /// Get hover content for an <see cref="MSBuildProperty"/>. /// </summary> /// <param name="property"> /// The <see cref="MSBuildProperty"/>. /// </param> /// <returns> /// The content, or <c>null</c> if no content is provided. /// </returns> public MarkedStringContainer Property(MSBuildProperty property) { if (property == null) { throw new ArgumentNullException(nameof(property)); } List <MarkedString> content = new List <MarkedString> { $"Property: `{property.Name}`" }; string propertyHelp = MSBuildSchemaHelp.ForProperty(property.Name); if (propertyHelp != null) { content.Add(propertyHelp); } if (property.IsOverridden) { // BUG: This is the location of the *overridden* property, not the *overriding* property. // We'll need to build a lookup by recursively following ProjectProperty.Predecessor. Position overridingDeclarationPosition = property.DeclaringXml.Location.ToNative(); StringBuilder overrideDescription = new StringBuilder(); string declarationFile = property.DeclaringXml.Location.File; if (declarationFile != property.Property.Xml.Location.File) { Uri declarationDocumentUri = VSCodeDocumentUri.FromFileSystemPath(declarationFile); overrideDescription.AppendLine( $"Value overridden at {overridingDeclarationPosition} in [{Path.GetFileName(declarationFile)}]({declarationDocumentUri})." ); } else { overrideDescription.AppendLine($"Value overridden at {overridingDeclarationPosition} in this file."); } overrideDescription.AppendLine(); overrideDescription.AppendLine(); overrideDescription.AppendLine( $"Unused value: `{property.DeclaringXml.Value}`" ); overrideDescription.AppendLine(); overrideDescription.AppendLine( $"Actual value: `{property.Value}`" ); content.Add(overrideDescription.ToString()); } else { content.Add($"Value: `{property.Value}`"); } string helpLink = MSBuildSchemaHelp.HelpLinkForProperty(property.Name); if (!String.IsNullOrWhiteSpace(helpLink)) { content.Add( $"[Help]({helpLink})" ); } return(new MarkedStringContainer(content)); }