Skip to content

Commit 8a31344

Browse files
committed
Remove unnecessary local method
1 parent 499eff3 commit 8a31344

File tree

1 file changed

+31
-35
lines changed

1 file changed

+31
-35
lines changed

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/RazorProjectService.cs

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -59,49 +59,45 @@ private async Task AddDocumentToMiscProjectNeedsLocksAsync(string filePath, Canc
5959

6060
_logger.LogDebug($"Adding {filePath} to the miscellaneous files project, because we don't have project info (yet?)");
6161
var miscFilesProject = await _snapshotResolver.GetMiscellaneousProjectAsync(cancellationToken).ConfigureAwait(false);
62-
await AddDocumentToProjectAsync(miscFilesProject, textDocumentPath, cancellationToken).ConfigureAwait(false);
6362

64-
async Task AddDocumentToProjectAsync(IProjectSnapshot projectSnapshot, string textDocumentPath, CancellationToken cancellationToken)
63+
if (miscFilesProject.GetDocument(FilePathNormalizer.Normalize(textDocumentPath)) is not null)
6564
{
66-
if (projectSnapshot.GetDocument(FilePathNormalizer.Normalize(textDocumentPath)) is not null)
67-
{
68-
// Document already added. This usually occurs when VSCode has already pre-initialized
69-
// open documents and then we try to manually add all known razor documents.
70-
return;
71-
}
65+
// Document already added. This usually occurs when VSCode has already pre-initialized
66+
// open documents and then we try to manually add all known razor documents.
67+
return;
68+
}
7269

73-
var targetFilePath = textDocumentPath;
74-
var projectDirectory = FilePathNormalizer.GetNormalizedDirectoryName(projectSnapshot.FilePath);
75-
if (targetFilePath.StartsWith(projectDirectory, FilePathComparison.Instance))
76-
{
77-
// Make relative
78-
targetFilePath = textDocumentPath[projectDirectory.Length..];
79-
}
70+
var targetFilePath = textDocumentPath;
71+
var projectDirectory = FilePathNormalizer.GetNormalizedDirectoryName(miscFilesProject.FilePath);
72+
if (targetFilePath.StartsWith(projectDirectory, FilePathComparison.Instance))
73+
{
74+
// Make relative
75+
targetFilePath = textDocumentPath[projectDirectory.Length..];
76+
}
8077

81-
// Representing all of our host documents with a re-normalized target path to workaround GetRelatedDocument limitations.
82-
var normalizedTargetFilePath = targetFilePath.Replace('/', '\\').TrimStart('\\');
78+
// Representing all of our host documents with a re-normalized target path to workaround GetRelatedDocument limitations.
79+
var normalizedTargetFilePath = targetFilePath.Replace('/', '\\').TrimStart('\\');
8380

84-
var hostDocument = new HostDocument(textDocumentPath, normalizedTargetFilePath);
85-
var textLoader = _remoteTextLoaderFactory.Create(textDocumentPath);
81+
var hostDocument = new HostDocument(textDocumentPath, normalizedTargetFilePath);
82+
var textLoader = _remoteTextLoaderFactory.Create(textDocumentPath);
8683

87-
_logger.LogInformation($"Adding document '{filePath}' to project '{projectSnapshot.Key}'.");
84+
_logger.LogInformation($"Adding document '{filePath}' to project '{miscFilesProject.Key}'.");
8885

89-
await _projectManager
90-
.UpdateAsync(
91-
static (updater, state) => updater.DocumentAdded(state.key, state.hostDocument, state.textLoader),
92-
state: (key: projectSnapshot.Key, hostDocument, textLoader),
93-
cancellationToken)
94-
.ConfigureAwait(false);
86+
await _projectManager
87+
.UpdateAsync(
88+
static (updater, state) => updater.DocumentAdded(state.key, state.hostDocument, state.textLoader),
89+
state: (key: miscFilesProject.Key, hostDocument, textLoader),
90+
cancellationToken)
91+
.ConfigureAwait(false);
9592

96-
// Adding a document to a project could also happen because a target was added to a project, or we're moving a document
97-
// from Misc Project to a real one, and means the newly added document could actually already be open.
98-
// If it is, we need to make sure we start generating it so we're ready to handle requests that could start coming in.
99-
if (_projectManager.IsDocumentOpen(textDocumentPath) &&
100-
_projectManager.TryGetLoadedProject(projectSnapshot.Key, out var project) &&
101-
project.GetDocument(textDocumentPath) is { } document)
102-
{
103-
_ = document.GetGeneratedOutputAsync();
104-
}
93+
// Adding a document to a project could also happen because a target was added to a project, or we're moving a document
94+
// from Misc Project to a real one, and means the newly added document could actually already be open.
95+
// If it is, we need to make sure we start generating it so we're ready to handle requests that could start coming in.
96+
if (_projectManager.IsDocumentOpen(textDocumentPath) &&
97+
_projectManager.TryGetLoadedProject(miscFilesProject.Key, out var project) &&
98+
project.GetDocument(textDocumentPath) is { } document)
99+
{
100+
_ = document.GetGeneratedOutputAsync();
105101
}
106102
}
107103

0 commit comments

Comments
 (0)