-
Notifications
You must be signed in to change notification settings - Fork 417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not return nulls when getting documents by path #2233
Conversation
cbe330e
to
0ff84ad
Compare
#line default | ||
#line hidden") | ||
#line hidden"), | ||
new TestFile(mappedFilePath, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the mapped file as an additional document will create a valid DocumentId that an be found by file path but does not exist in the Project.Documents.
@@ -144,7 +144,8 @@ public IEnumerable<ProjectId> AddFilesToWorkspace(string folderPath, params Test | |||
Workspace, | |||
Path.Combine(folderPath, "project.csproj"), | |||
new[] { "net472" }, | |||
testFiles.Where(f => f.FileName.EndsWith(".cs", StringComparison.OrdinalIgnoreCase)).ToArray()); | |||
testFiles.Where(f => f.FileName.EndsWith(".cs", StringComparison.OrdinalIgnoreCase)).ToArray(), | |||
testFiles.Where(f => !f.FileName.EndsWith(".cs", StringComparison.OrdinalIgnoreCase) && !f.FileName.EndsWith(".csx", StringComparison.OrdinalIgnoreCase)).ToArray()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All non-C# files will be added as additional documents to the project.
@@ -340,7 +340,8 @@ public IEnumerable<Document> GetDocuments(string filePath) | |||
{ | |||
return CurrentSolution | |||
.GetDocumentIdsWithFilePath(filePath) | |||
.Select(id => CurrentSolution.GetDocument(id)); | |||
.Select(id => CurrentSolution.GetDocument(id)) | |||
.OfType<Document>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the .cshtml files will have valid DocumentIds but not be part of any Project's Documents null can be returned, the OfType
will filter out the null values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, thanks.
do we need to prevent them from being discovered as misc files?
according to the logs here it was additionally discovered as misc file dotnet/vscode-csharp#4746 (comment)
Good point. I had made an assumption they were added as additional documents. I'll add a test which validates the document in misc workspace. |
3818d37
to
dcbef8d
Compare
Resolves #2125
The IEnumerable returned by
workspace.GetDocuments(string filePath)
can containnull
s if the filepath isn't present in any Project.Documents. In this case .cshtml files are not part of the compilation and are AdditionalDocuments in the workspace. The addedOfType<>()
will filter out thenull
values and allow an empty enumerable to be returned.Using the repro provided at https://github.com/jsheely/dotnet6-omni-bug1, we get results instead of an NRE.