Skip to content

Commit 361a46f

Browse files
Clean up ProjectConfigurationFileChangeEventArgs a bit
1 parent e4c69c8 commit 361a46f

File tree

2 files changed

+13
-25
lines changed

2 files changed

+13
-25
lines changed

SpellingExclusions.dic

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
csharp
22
cshtml
33
csproj
4+
deserializer
45
hresult
56
microsoft
67
vsls

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationFileChangeEventArgs.cs

+12-25
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,20 @@
1212

1313
namespace Microsoft.AspNetCore.Razor.LanguageServer;
1414

15-
internal sealed class ProjectConfigurationFileChangeEventArgs : EventArgs
15+
internal sealed class ProjectConfigurationFileChangeEventArgs(
16+
string configurationFilePath,
17+
RazorFileChangeKind kind,
18+
IRazorProjectInfoDeserializer? projectInfoDeserializer = null) : EventArgs
1619
{
17-
public string ConfigurationFilePath { get; }
18-
public RazorFileChangeKind Kind { get; }
20+
public string ConfigurationFilePath { get; } = configurationFilePath;
21+
public RazorFileChangeKind Kind { get; } = kind;
1922

20-
private readonly IRazorProjectInfoDeserializer _deserializer;
23+
private readonly IRazorProjectInfoDeserializer _deserializer = projectInfoDeserializer ?? RazorProjectInfoDeserializer.Instance;
2124
private RazorProjectInfo? _projectInfo;
22-
private readonly object _gate;
25+
private readonly object _gate = new();
2326
private bool _deserialized;
2427

25-
public ProjectConfigurationFileChangeEventArgs(
26-
string configurationFilePath,
27-
RazorFileChangeKind kind,
28-
IRazorProjectInfoDeserializer? projectInfoDeserializer = null)
29-
{
30-
ConfigurationFilePath = configurationFilePath ?? throw new ArgumentNullException(nameof(configurationFilePath));
31-
Kind = kind;
32-
_deserializer = projectInfoDeserializer ?? RazorProjectInfoDeserializer.Instance;
33-
_gate = new object();
34-
}
35-
36-
public bool TryDeserialize(LanguageServerFeatureOptions languageServerFeatureOptions, [NotNullWhen(true)] out RazorProjectInfo? projectInfo)
28+
public bool TryDeserialize(LanguageServerFeatureOptions options, [NotNullWhen(true)] out RazorProjectInfo? projectInfo)
3729
{
3830
if (Kind == RazorFileChangeKind.Removed)
3931
{
@@ -65,7 +57,7 @@ public bool TryDeserialize(LanguageServerFeatureOptions languageServerFeatureOpt
6557
{
6658
Configuration = deserializedProjectInfo.Configuration with
6759
{
68-
LanguageServerFlags = languageServerFeatureOptions.ToLanguageServerFlags()
60+
LanguageServerFlags = options.ToLanguageServerFlags()
6961
}
7062
};
7163

@@ -79,15 +71,10 @@ public bool TryDeserialize(LanguageServerFeatureOptions languageServerFeatureOpt
7971
return false;
8072
}
8173
}
82-
}
8374

84-
projectInfo = _projectInfo;
85-
if (projectInfo is null)
86-
{
87-
// Deserialization failed
88-
return false;
75+
projectInfo = _projectInfo;
8976
}
9077

91-
return true;
78+
return projectInfo is not null;
9279
}
9380
}

0 commit comments

Comments
 (0)