Skip to content

Commit

Permalink
Centralise definitions of well-known element paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
tintoy committed Oct 15, 2017
1 parent ce31988 commit 62f5be0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ namespace MSBuildProjectTools.LanguageServer.CompletionProviders
public class PackageReferenceCompletion
: CompletionProvider
{
/// <summary>
/// A relative path representing an ItemGroup element.
/// </summary>
static readonly XSPath ItemGroupElementPath = XSPath.Parse("ItemGroup");

/// <summary>
/// Create a new <see cref="PackageReferenceCompletion"/>.
/// </summary>
Expand Down Expand Up @@ -87,7 +82,7 @@ public PackageReferenceCompletion(ILogger logger)
completions.AddRange(packageCompletions);
}
}
else if (location.CanCompleteElement(out XSElement replaceElement, parentPath: ItemGroupElementPath))
else if (location.CanCompleteElement(out XSElement replaceElement, parentPath: WellKnownElementPaths.ItemGroup))
{
if (replaceElement != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ namespace MSBuildProjectTools.LanguageServer.CompletionProviders
public class PropertyElementCompletion
: CompletionProvider
{
/// <summary>
/// A relative path representing a PropertyGroup element.
/// </summary>
static readonly XSPath PropertyGroupElementPath = XSPath.Parse("PropertyGroup");

/// <summary>
/// Create a new <see cref="PropertyElementCompletion"/>.
/// </summary>
Expand Down Expand Up @@ -71,7 +66,7 @@ public PropertyElementCompletion(ILogger logger)
using (await projectDocument.Lock.ReaderLockAsync())
{
XSElement replaceElement;
if (!location.CanCompleteElement(out replaceElement, parentPath: PropertyGroupElementPath))
if (!location.CanCompleteElement(out replaceElement, parentPath: WellKnownElementPaths.PropertyGroup))
{
Log.Verbose("Not offering any completions for {XmlLocation:l} (not a direct child of a 'PropertyGroup' element).", location);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ namespace MSBuildProjectTools.LanguageServer.CompletionProviders
public class TopLevelElementCompletion
: CompletionProvider
{
/// <summary>
/// A path representing the root ("Project") element.
/// </summary>
static readonly XSPath ProjectElementPath = XSPath.Parse("/Project");

/// <summary>
/// Create a new <see cref="TopLevelElementCompletion"/>.
/// </summary>
Expand Down Expand Up @@ -71,7 +66,7 @@ public TopLevelElementCompletion(ILogger logger)
using (await projectDocument.Lock.ReaderLockAsync())
{
XSElement replaceElement;
if (!location.CanCompleteElement(out replaceElement, parentPath: ProjectElementPath))
if (!location.CanCompleteElement(out replaceElement, parentPath: WellKnownElementPaths.Project))
{
Log.Verbose("Not offering any completions for {XmlLocation:l} (not a direct child of the 'Project' element).", location);

Expand Down
23 changes: 23 additions & 0 deletions src/LanguageServer.SemanticModel.MSBuild/WellKnownElementPaths.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace MSBuildProjectTools.LanguageServer.SemanticModel
{
/// <summary>
/// <see cref="XSPath"/>s representing well-known elements in MSBuild projects.
/// </summary>
public static class WellKnownElementPaths
{
/// <summary>
/// The absolute path of the root "Project" element.
/// </summary>
public static XSPath Project = XSPath.Parse("/Project");

/// <summary>
/// The relative path that represents a "PropertyGroup" element (static or dynamic).
/// </summary>
public static readonly XSPath PropertyGroup = XSPath.Parse("PropertyGroup");

/// <summary>
/// The relative path that represents a "ItemGroup" element (static or dynamic).
/// </summary>
public static readonly XSPath ItemGroup = XSPath.Parse("ItemGroup");
}
}

0 comments on commit 62f5be0

Please sign in to comment.