Skip to content
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

Don't remap line mappings in Razor files #2460

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/OmniSharp.Roslyn.CSharp/Helpers/LocationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ public static QuickFix GetQuickFix(this Location location, OmniSharpWorkspace wo
if (!location.IsInSource)
throw new Exception("Location is not in the source tree");

var lineSpan = Path.GetExtension(location.SourceTree.FilePath).Equals(".cake", StringComparison.OrdinalIgnoreCase)
? location.GetLineSpan()
: location.GetMappedLineSpan();
var lineSpan = location.GetLineSpan();

var documents = workspace.GetDocuments(lineSpan.Path);
var sourceText = GetSourceText(location, documents, lineSpan.HasMappedPath);
Expand All @@ -39,9 +37,9 @@ public static QuickFix GetQuickFix(this Location location, OmniSharpWorkspace wo
Text = text.Trim(),
FileName = fileName,
Line = lineSpan.StartLinePosition.Line,
Column = lineSpan.HasMappedPath ? 0 : lineSpan.StartLinePosition.Character, // when a #line directive maps into a separate file, assume columns (0,0)
Column = lineSpan.StartLinePosition.Character,
EndLine = lineSpan.EndLinePosition.Line,
EndColumn = lineSpan.HasMappedPath ? 0 : lineSpan.EndLinePosition.Character,
EndColumn = lineSpan.EndLinePosition.Character,
Projects = documents.Select(document => document.Project.Name).ToArray(),
GeneratedFileInfo = generatedInfo
};
Expand Down
26 changes: 9 additions & 17 deletions tests/OmniSharp.Lsp.Tests/ReferencesHandlerFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public FooConsumer()
[Theory]
[InlineData(9)]
[InlineData(100)]
public async Task CanFindReferencesWithLineMapping(int mappingLine)
public async Task FindReferencesWithLineMappingReturnsRegularPosition(int mappingLine)
{
var code = @"
public class Foo
Expand Down Expand Up @@ -162,17 +162,13 @@ public FooConsumer()
Assert.Equal("dummy.cs", regularResult.Uri);
Assert.Equal("dummy.cs", mappedResult.Uri);

// Assert.Equal("public void bar() { }", regularResult.Text);
// Assert.Equal(expectedMappingText, mappedResult.Text);

Assert.Equal(3, regularResult.Range.Start.Line);
Assert.Equal(mappingLine - 1, mappedResult.Range.Start.Line);
Assert.Equal(11, mappedResult.Range.Start.Line);

// regular result has regular postition
// regular + mapped results have regular postition
Assert.Equal(32, regularResult.Range.Start.Character);
Assert.Equal(35, regularResult.Range.End.Character);

// mapped result has column 0,0
Assert.Equal(34, mappedResult.Range.Start.Character);
Assert.Equal(37, mappedResult.Range.End.Character);
}
Expand All @@ -181,7 +177,7 @@ public FooConsumer()
[InlineData(1, true)] // everything correct
[InlineData(100, true)] // file exists in workspace but mapping incorrect
[InlineData(1, false)] // file doesn't exist in workspace but mapping correct
public async Task CanFindReferencesWithLineMappingAcrossFiles(int mappingLine,
public async Task FindReferencesWithLineMappingAcrossFilesReturnsRegularPosition(int mappingLine,
bool mappedFileExistsInWorkspace)
{
var testFiles = new List<TestFile>()
Expand Down Expand Up @@ -216,21 +212,17 @@ public FooConsumer()
var mappedResult = usages.ElementAt(1);

Assert.EndsWith("a.cs", regularResult.Uri.Path);
Assert.EndsWith("b.cs", mappedResult.Uri.Path);
Assert.EndsWith("a.cs", mappedResult.Uri.Path);

Assert.Equal(3, regularResult.Range.Start.Line);
Assert.Equal(mappingLine - 1, mappedResult.Range.Start.Line);

// Assert.Equal("public void bar() { }", regularResult.Text);
// Assert.Equal(expectedMappingText, mappedResult.Text);
Assert.Equal(11, mappedResult.Range.Start.Line);

// regular result has regular postition
// regular + mapped results have regular postition
Assert.Equal(32, regularResult.Range.Start.Character);
Assert.Equal(35, regularResult.Range.End.Character);

// mapped result has column 0,0
Assert.Equal(0, mappedResult.Range.Start.Character);
Assert.Equal(0, mappedResult.Range.End.Character);
Assert.Equal(34, mappedResult.Range.Start.Character);
Assert.Equal(37, mappedResult.Range.End.Character);
}

[Fact]
Expand Down