Skip to content

Commit

Permalink
Generate hover content for elements that don't directly correspond to…
Browse files Browse the repository at this point in the history
… MSBuild objects.

#5
  • Loading branch information
tintoy committed Apr 21, 2018
1 parent ce19add commit c009349
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 21 deletions.
62 changes: 44 additions & 18 deletions help/elements.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
{
"PropertyGroup": {
"description": "Contains a set of user-defined `Property` elements.",
"help": "https://docs.microsoft.com/en-us/visualstudio/msbuild/propertygroup-element-msbuild"
"*.Condition": {
"description": "Optional expression evaluated to determine whether the target element should be evaluated",
"help": "https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-conditions"
},
"*.Label": {
"description": "Optional expression. Used to identify or order system and user elements"
},
"Choose": {
"description": "Evaluates child elements to select one set of `ItemGroup` elements and/or `PropertyGroup` elements to evaluate. ",
"help": "https://docs.microsoft.com/en-us/visualstudio/msbuild/choose-element-msbuild"
},
"Import": {
"description": "Imports the contents of one project file into another project file.",
"help": "https://docs.microsoft.com/en-us/visualstudio/msbuild/import-element-msbuild"
},
"Import.MinimumVersion": {
"description": "Optional expression used to specify the minimum SDK version required by the referring import"
},
"Import.Project": {
"description": "Project file to import"
},
"Import.Sdk": {
"description": "Name of the SDK which contains the project file to import"
},
"Import.Version": {
"description": "Optional expression used to specify the version of the SDK referenced by this import"
},
"ImportGroup": {
"description": "Contains a collection of `Import` elements that are grouped under an optional `Condition`.",
"help": "https://docs.microsoft.com/en-us/visualstudio/msbuild/importgroup-element"
},
"Item": {
"description": "Contains a user-defined item and its metadata.",
Expand All @@ -15,13 +42,12 @@
"description": "The `ItemDefinitionGroup` element lets you define a set of `Item` definitions, which are metadata values that are applied to all items in the project, by default.",
"help": "https://docs.microsoft.com/en-us/visualstudio/msbuild/itemdefinitiongroup-element-msbuild"
},
"Choose": {
"description": "Evaluates child elements to select one set of `ItemGroup` elements and/or `PropertyGroup` elements to evaluate. ",
"help": "https://docs.microsoft.com/en-us/visualstudio/msbuild/choose-element-msbuild"
"OnError": {
"description": "Specifies targets to execute in the event of a recoverable error",
"help": "https://docs.microsoft.com/en-us/visualstudio/msbuild/onerror-element-msbuild"
},
"When": {
"description": "Evaluates child `ItemGroup` and/or `PropertyGroup` elements when its `Condition` is true.",
"help": "https://docs.microsoft.com/en-us/visualstudio/msbuild/choose-element-msbuild"
"OnError.ExecuteTargets": {
"description": "Semicolon separated list of targets to execute"
},
"Otherwise": {
"description": "Evaluates child `ItemGroup` and/or `PropertyGroup` elements when none of its sibling `When` elements has a `Condition` that is true.",
Expand All @@ -31,20 +57,20 @@
"description": "Stores task output values in items and properties.",
"help": "https://docs.microsoft.com/en-us/visualstudio/msbuild/output-element-msbuild"
},
"UsingTask": {
"description": "Maps the task that is referenced in a `Task` element to the assembly that contains the task implementation. ",
"help": "https://docs.microsoft.com/en-us/visualstudio/msbuild/usingtask-element-msbuild"
"PropertyGroup": {
"description": "Contains a set of user-defined `Property` elements.",
"help": "https://docs.microsoft.com/en-us/visualstudio/msbuild/propertygroup-element-msbuild"
},
"Target": {
"description": "Contains a set of tasks for MSBuild to execute sequentially.",
"help": "https://docs.microsoft.com/en-us/visualstudio/msbuild/target-element-msbuild"
},
"Import": {
"description": "Imports the contents of one project file into another project file.",
"help": "https://docs.microsoft.com/en-us/visualstudio/msbuild/import-element-msbuild"
"UsingTask": {
"description": "Maps the task that is referenced in a `Task` element to the assembly that contains the task implementation. ",
"help": "https://docs.microsoft.com/en-us/visualstudio/msbuild/usingtask-element-msbuild"
},
"ImportGroup": {
"description": "Contains a collection of `Import` elements that are grouped under an optional `Condition`.",
"help": "https://docs.microsoft.com/en-us/visualstudio/msbuild/importgroup-element"
"When": {
"description": "Evaluates child `ItemGroup` and/or `PropertyGroup` elements when its `Condition` is true.",
"help": "https://docs.microsoft.com/en-us/visualstudio/msbuild/choose-element-msbuild"
}
}
51 changes: 48 additions & 3 deletions src/LanguageServer.Engine/ContentProviders/HoverContentProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,22 @@ public MarkedStringContainer Condition(string elementName, string condition)
return null;

string evaluatedCondition = _projectDocument.MSBuildProject.ExpandString(condition);

return new MarkedStringContainer(

List<MarkedString> content = new List<MarkedString>
{
"Condition",
$"Evaluated: `{evaluatedCondition}`"
);
};

string helpLink = MSBuildSchemaHelp.HelpLinkForElement("*.Condition");
if (!String.IsNullOrWhiteSpace(helpLink))
{
content.Add(
$"[Help]({helpLink})"
);
}

return new MarkedStringContainer(content);
}

/// <summary>
Expand Down Expand Up @@ -625,5 +636,39 @@ public MarkedStringContainer UnresolvedSdkImport(MSBuildUnresolvedSdkImport unre
descriptionContent.ToString()
);
}

/// <summary>
/// Get hover content for an XML element that does not directly correspond to an <see cref="MSBuildObject"/>.
/// </summary>
/// <param name="element">
/// The <see cref="XSElement"/>.
/// </param>
/// <returns>
/// The content, or <c>null</c> if no content is provided.
/// </returns>
public MarkedStringContainer Element(XSElement element)
{
if (element == null)
throw new ArgumentNullException(nameof(element));

string elementDescription = MSBuildSchemaHelp.ForElement(element.Name);
if (String.IsNullOrWhiteSpace(elementDescription))
return null;

List<MarkedString> content = new List<MarkedString>
{
elementDescription
};

string helpLink = MSBuildSchemaHelp.HelpLinkForElement(element.Name);
if (!String.IsNullOrWhiteSpace(helpLink))
{
content.Add(
$"[Help]({helpLink})"
);
}

return new MarkedStringContainer(content);
}
}
}
6 changes: 6 additions & 0 deletions src/LanguageServer.Engine/Handlers/HoverHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ async Task<Hover> OnHover(TextDocumentPositionParams parameters, CancellationTok
{
hoverContent = contentProvider.UnresolvedImport(unresolvedImport);

break;
}
default:
{
hoverContent = contentProvider.Element(element);

break;
}
}
Expand Down

0 comments on commit c009349

Please sign in to comment.