-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for textDocument/findReferences, implement support for Cont…
…ext.IncludeDeclaration (#199) * Add tests for "textDocument/references" handler * Respect Context.IncludeDeclaration in handler for "textDocument/findReferences" * Update CHANGELOG.md * Fix an issue in Windows tests .. by reverting #189 (will fix later) * another attempt at it
- Loading branch information
1 parent
437146e
commit aab7156
Showing
10 changed files
with
131 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
module CSharpLanguageServer.Tests.ReferenceTests | ||
|
||
open NUnit.Framework | ||
open Ionide.LanguageServerProtocol.Types | ||
|
||
open CSharpLanguageServer.Tests.Tooling | ||
|
||
[<TestCase>] | ||
let testReferenceWorks() = | ||
use client = setupServerClient defaultClientProfile "TestData/testReferenceWorks" | ||
client.StartAndWaitForSolutionLoad() | ||
|
||
use classFile = client.Open("Project/Class.cs") | ||
|
||
// | ||
// try references request at empty line line 1 -- should return 0 results | ||
// | ||
let referenceParams0: ReferenceParams = | ||
{ TextDocument = { Uri = classFile.Uri } | ||
Position = { Line = 0u; Character = 0u } | ||
WorkDoneToken = None | ||
PartialResultToken = None | ||
Context = { IncludeDeclaration = false } | ||
} | ||
|
||
let locations0: Location[] option = classFile.Request("textDocument/references", referenceParams0) | ||
Assert.IsTrue(locations0.IsNone) | ||
|
||
// | ||
// try references request at MethodA declaration on line 2 | ||
// | ||
let referenceParams1: ReferenceParams = | ||
{ TextDocument = { Uri = classFile.Uri } | ||
Position = { Line = 2u; Character = 16u } | ||
WorkDoneToken = None | ||
PartialResultToken = None | ||
Context = { IncludeDeclaration = false } | ||
} | ||
|
||
let locations1: Location[] option = classFile.Request("textDocument/references", referenceParams1) | ||
|
||
let expectedLocations1: Location array = | ||
[| | ||
{ Uri = classFile.Uri | ||
Range = { | ||
Start = { Line = 8u; Character = 8u } | ||
End = { Line = 8u; Character = 15u } | ||
} | ||
} | ||
|] | ||
|
||
Assert.AreEqual(expectedLocations1, locations1.Value) | ||
|
||
// | ||
// try references request at MethodA declaration on line 2 | ||
// (with IncludeDeclaration=true) | ||
// | ||
let referenceParams2: ReferenceParams = | ||
{ TextDocument = { Uri = classFile.Uri } | ||
Position = { Line = 2u; Character = 16u } | ||
WorkDoneToken = None | ||
PartialResultToken = None | ||
Context = { IncludeDeclaration = true } | ||
} | ||
|
||
let locations2: Location[] option = classFile.Request("textDocument/references", referenceParams2) | ||
|
||
let expectedLocations2: Location array = | ||
[| | ||
{ Uri = classFile.Uri | ||
Range = { | ||
Start = { Line = 2u; Character = 16u } | ||
End = { Line = 2u; Character = 23u } | ||
} | ||
} | ||
|
||
{ Uri = classFile.Uri | ||
Range = { | ||
Start = { Line = 8u; Character = 8u } | ||
End = { Line = 8u; Character = 15u } | ||
} | ||
} | ||
|] | ||
|
||
Assert.AreEqual(expectedLocations2, locations2.Value) |
11 changes: 11 additions & 0 deletions
11
tests/CSharpLanguageServer.Tests/TestData/testReferenceWorks/Project/Class.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Class | ||
{ | ||
public void MethodA(string arg) | ||
{ | ||
} | ||
|
||
public void MethodB(string arg) | ||
{ | ||
MethodA(arg); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
tests/CSharpLanguageServer.Tests/TestData/testReferenceWorks/Project/Project.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters