Skip to content

Commit

Permalink
Do not return nulls when getting documents by path
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeRobich committed Sep 8, 2021
1 parent 4f7ed0f commit f930f33
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/OmniSharp.Roslyn.CSharp/Helpers/LocationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public static QuickFix GetQuickFix(this Location location, OmniSharpWorkspace wo
? location.GetLineSpan()
: location.GetMappedLineSpan();

var documents = workspace.GetDocuments(lineSpan.Path);
var sourceText = GetSourceText(location, documents, lineSpan.HasMappedPath);
var text = GetLineText(location, sourceText, lineSpan.StartLinePosition.Line);

var fileName = Path.IsPathRooted(lineSpan.Path)
? lineSpan.Path
// when a #line directive maps into a separate file using a relative path, get the full path relative to the folder containing the source tree
: Path.GetFullPath(Path.Combine(Path.GetDirectoryName(location.SourceTree.FilePath), lineSpan.Path));

var documents = workspace.GetDocuments(fileName);
var sourceText = GetSourceText(location, documents, lineSpan.HasMappedPath);
var text = GetLineText(location, sourceText, lineSpan.StartLinePosition.Line);

return new QuickFix
{
Text = text.Trim(),
Expand Down
7 changes: 4 additions & 3 deletions src/OmniSharp.Roslyn/OmniSharpWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ public OmniSharpWorkspace(HostServicesAggregator aggregator, ILoggerFactory logg

private void OnDirectoryRemoved(string path, FileChangeType changeType)
{
if(changeType == FileChangeType.DirectoryDelete)
if (changeType == FileChangeType.DirectoryDelete)
{
var docs = CurrentSolution.Projects.SelectMany(x => x.Documents)
.Where(x => x.FilePath.StartsWith(path + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase));

foreach(var doc in docs)
foreach (var doc in docs)
{
OnDocumentRemoved(doc.Id);
}
Expand Down Expand Up @@ -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>();
}

public Document GetDocument(string filePath)
Expand Down

0 comments on commit f930f33

Please sign in to comment.