Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
tintoy committed Apr 1, 2024
1 parent ac20790 commit b42e183
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 32 deletions.
11 changes: 5 additions & 6 deletions src/LanguageServer.Engine/Documents/MasterProjectDocument.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using Microsoft.Build.Exceptions;
using MSBuildProjectTools.LanguageServer.SemanticModel;
using MSBuildProjectTools.LanguageServer.Utilities;
using Serilog;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -10,10 +13,6 @@

namespace MSBuildProjectTools.LanguageServer.Documents
{
using SemanticModel;
using System.Collections.Concurrent;
using Utilities;

/// <summary>
/// Represents the document state for an MSBuild project.
/// </summary>
Expand All @@ -23,7 +22,7 @@ public class MasterProjectDocument
/// <summary>
/// Sub-projects (if any).
/// </summary>
readonly ConcurrentDictionary<Uri, SubProjectDocument> _subProjects = new ConcurrentDictionary<Uri, SubProjectDocument>();
readonly ConcurrentDictionary<Uri, SubProjectDocument> _subProjects = new();

/// <summary>
/// Create a new <see cref="MasterProjectDocument"/>.
Expand Down Expand Up @@ -69,7 +68,7 @@ protected override void Dispose(bool disposing)
/// Add a sub-project.
/// </summary>
/// <param name="documentUri">
/// The sub-project.
/// The sub-project's document URI.
/// </param>
/// <param name="createSubProjectDocument">
/// A factory delegate to create the <see cref="SubProjectDocument"/> if it does not already exist.
Expand Down
7 changes: 6 additions & 1 deletion src/LanguageServer.Engine/Documents/Workspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,12 @@ public async Task<ProjectDocument> GetProjectDocument(Uri documentUri, bool relo
isNewProject = true;
if (MasterProject == null)
return MasterProject = new MasterProjectDocument(this, documentUri, Log);
{
MasterProjectDocument masterProjectDocument = new(this, documentUri, Log);
MasterProject = masterProjectDocument;
return masterProjectDocument;
}
SubProjectDocument subProject = MasterProject.GetOrAddSubProject(documentUri,
() => new SubProjectDocument(this, documentUri, Log, MasterProject)
Expand Down
25 changes: 5 additions & 20 deletions test/LanguageServer.Engine.Tests/MSBuildObjectLocatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,18 @@ namespace MSBuildProjectTools.LanguageServer.Tests
/// <summary>
/// Tests for locating MSBuild objects by position.
/// </summary>
/// <param name="testOutput">
/// The xUnit test output for the current test.
/// </param>
[Collection(MSBuildEngineFixture.CollectionName)]
public class MSBuildObjectLocatorTests
: TestBase, IDisposable
public class MSBuildObjectLocatorTests(ITestOutputHelper testOutput)
: TestBase(testOutput), IDisposable
{
/// <summary>
/// The directory for test files.
/// </summary>
static readonly DirectoryInfo TestDirectory = new DirectoryInfo(Path.GetDirectoryName(
typeof(MSBuildObjectLocatorTests).Assembly.Location
));

/// <summary>
/// The project collection for any projects loaded by the current test.
/// </summary>
ProjectCollection _projectCollection;

/// <summary>
/// Create new <see cref="MSBuildObjectLocatorTests"/>.
/// </summary>
/// <param name="testOutput">
/// The xUnit test output for the current test.
/// </param>
public MSBuildObjectLocatorTests(ITestOutputHelper testOutput)
: base(testOutput)
{
}

/// <summary>
/// Dispose of resources being used by the test.
/// </summary>
Expand Down
20 changes: 15 additions & 5 deletions test/LanguageServer.Engine.Tests/TestProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ public static string GetProjectFile(Type testClassType, params string[] relative

string testDeploymentDirectory = GetTestDeploymentDirectory(testClassType);

string projectFileName = Path.Combine(
string projectFileName = Path.Combine([
testDeploymentDirectory,
Path.Combine(relativePathSegments)
);
.. relativePathSegments
]);
projectFileName = Path.GetFullPath(projectFileName); // Flush out any relative-path issues now, rather than when we are trying to open the file.

return projectFileName;
Expand Down Expand Up @@ -361,7 +361,11 @@ static string GetTestDeploymentDirectory(Type testClassType)
/// <param name="TextPositions">
/// The <see cref="TextPositions"/> for the project text.
/// </param>
public record class TestProjectXml(XmlDocumentSyntax ProjectXml, XmlLocator XmlLocations, TextPositions TextPositions);
public record class TestProjectXml(
XmlDocumentSyntax ProjectXml,
XmlLocator XmlLocations,
TextPositions TextPositions
);

/// <summary>
/// An MSBuild project, loaded for a test.
Expand All @@ -381,6 +385,12 @@ public record class TestProjectXml(XmlDocumentSyntax ProjectXml, XmlLocator XmlL
/// <param name="TextPositions">
/// The <see cref="TextPositions"/> for the project text.
/// </param>
public record class TestProject(Project MSBuildProject, MSBuildObjectLocator ObjectLocations, XmlDocumentSyntax ProjectXml, XmlLocator XmlLocations, TextPositions TextPositions)
public record class TestProject(
Project MSBuildProject,
MSBuildObjectLocator ObjectLocations,
XmlDocumentSyntax ProjectXml,
XmlLocator XmlLocations,
TextPositions TextPositions
)
: TestProjectXml(ProjectXml, XmlLocations, TextPositions);
}

0 comments on commit b42e183

Please sign in to comment.