@@ -16,7 +16,8 @@ open Helpers.Expecto.ShadowedTimeouts
1616open System.IO
1717
1818module private CodeLens =
19- let examples = Path.Combine(__ SOURCE_ DIRECTORY__, " TestCases" , " CodeLensProjectTests" )
19+ let examples =
20+ Path.Combine(__ SOURCE_ DIRECTORY__, " TestCases" , " CodeLensProjectTests" )
2021
2122 module CodeLensPositionStaysAccurate =
2223 let dir = examples </> " CodeLens_position_stays_accurate"
@@ -64,164 +65,181 @@ module private CodeLens =
6465
6566
6667let projectBasedTests state =
67- testList " ProjectBased" [
68- serverTestList ( " CodeLensPositionStaysAccurate" ) state defaultConfigDto ( Some CodeLens.CodeLensPositionStaysAccurate.dir) ( fun server -> [
69-
70- testCaseAsync " can show codelens after adding newlines to code"
71- <| ( asyncResult {
72- let program = CodeLens.CodeLensPositionStaysAccurate.programFile
73- let! ( doc , _diags ) = Server.openDocument program server
74-
75- let! unresolved = CodeLens.getLenses doc
76- let! resolved = CodeLens.getResolvedLenses doc unresolved
77-
78- let references =
79- resolved
80- |> List.filter ( fun lens -> lens.Command |> Option.exists ( fun c -> c.Title.EndsWith " References" ))
81- |> List.sortBy ( fun lens -> lens.Range.Start.Line)
82-
83- Expect.hasLength references 2 " should have a reference lens"
84-
85- let lens1 = references.[ 0 ]
86- let lens1Range : Range = {
87- Start = { Line = 1 u; Character = 6 u }
88- End = { Line = 1 u; Character = 20 u }
89- }
90-
91- Expect.equal lens1.Range lens1Range " Lens 1 should be at 1:6-1:20"
92-
93- let lens2 = references.[ 1 ]
94- let lens2Range : Range = {
95- Start = { Line = 3 u; Character = 6 u }
96- End = { Line = 3 u; Character = 25 u }
97- }
98-
99- Expect.equal lens2.Range lens2Range " Lens 2 should be at 3:6-3:25"
100-
101- do ! doc.Server.Server.TextDocumentDidChange({
102- TextDocument = doc.VersionedTextDocumentIdentifier
103- ContentChanges = [| U2.C1 {
104- Range = { Start = { Line = 2 u; Character = 0 u }; End = { Line = 2 u; Character = 0 u }; }
105- RangeLength = None
106- Text = " \n\n "
107- } |]
108- })
68+ testList
69+ " ProjectBased"
70+ [ serverTestList
71+ ( " CodeLensPositionStaysAccurate" )
72+ state
73+ defaultConfigDto
74+ ( Some CodeLens.CodeLensPositionStaysAccurate.dir)
75+ ( fun server ->
76+ [
77+
78+ testCaseAsync " can show codelens after adding newlines to code"
79+ <| ( asyncResult {
80+ let program = CodeLens.CodeLensPositionStaysAccurate.programFile
81+ let! ( doc , _diags ) = Server.openDocument program server
82+
83+ let! unresolved = CodeLens.getLenses doc
84+ let! resolved = CodeLens.getResolvedLenses doc unresolved
85+
86+ let references =
87+ resolved
88+ |> List.filter ( fun lens -> lens.Command |> Option.exists ( fun c -> c.Title.EndsWith " References" ))
89+ |> List.sortBy ( fun lens -> lens.Range.Start.Line)
90+
91+ Expect.hasLength references 2 " should have a reference lens"
92+
93+ let lens1 = references.[ 0 ]
94+
95+ let lens1Range : Range =
96+ { Start = { Line = 1 u; Character = 6 u }
97+ End = { Line = 1 u; Character = 20 u } }
98+
99+ Expect.equal lens1.Range lens1Range " Lens 1 should be at 1:6-1:20"
100+
101+ let lens2 = references.[ 1 ]
109102
110- let! nextLens = CodeLens.getLenses doc
111- let! resolvedNextLens = CodeLens.getResolvedLenses doc nextLens
103+ let lens2Range : Range =
104+ { Start = { Line = 3 u; Character = 6 u }
105+ End = { Line = 3 u; Character = 25 u } }
112106
113- let references =
114- resolvedNextLens
115- |> List.filter ( fun lens -> lens.Command |> Option.exists ( fun c -> c.Title.EndsWith " References" ))
116- |> List.sortBy ( fun lens -> lens.Range.Start.Line)
107+ Expect.equal lens2.Range lens2Range " Lens 2 should be at 3:6-3:25"
117108
118- let lens1 = references.[ 0 ]
119- let lens1Range : Range = {
120- Start = { Line = 1 u; Character = 6 u }
121- End = { Line = 1 u; Character = 20 u }
122- }
109+ do !
110+ doc.Server.Server.TextDocumentDidChange(
111+ { TextDocument = doc.VersionedTextDocumentIdentifier
112+ ContentChanges =
113+ [| U2.C1
114+ { Range =
115+ { Start = { Line = 2 u; Character = 0 u }
116+ End = { Line = 2 u; Character = 0 u } }
117+ RangeLength = None
118+ Text = " \n\n " } |] }
119+ )
123120
124- Expect.equal lens1.Range lens1Range " Lens 1 should be at 1:6-1:20"
121+ let! nextLens = CodeLens.getLenses doc
122+ let! resolvedNextLens = CodeLens.getResolvedLenses doc nextLens
125123
126- let lens2 = references.[ 1 ]
127- let lens2Range : Range = {
128- Start = { Line = 5 u; Character = 6 u }
129- End = { Line = 5 u; Character = 25 u }
130- }
124+ let references =
125+ resolvedNextLens
126+ |> List.filter ( fun lens -> lens.Command |> Option.exists ( fun c -> c.Title.EndsWith " References" ))
127+ |> List.sortBy ( fun lens -> lens.Range.Start.Line)
131128
132- Expect.equal lens2.Range lens2Range " Lens 2 should be at 5:6-5:25 "
129+ let lens1 = references .[ 0 ]
133130
134- return ()
135- }
136- |> AsyncResult.foldResult id ( fun e -> failtest $ " {e} " ))
131+ let lens1Range : Range =
132+ { Start = { Line = 1 u ; Character = 6 u }
133+ End = { Line = 1 u ; Character = 20 u } }
137134
138- ]
139- )
140- ]
135+ Expect.equal lens1.Range lens1Range " Lens 1 should be at 1:6-1:20"
136+
137+ let lens2 = references.[ 1 ]
138+
139+ let lens2Range : Range =
140+ { Start = { Line = 5 u; Character = 6 u }
141+ End = { Line = 5 u; Character = 25 u } }
142+
143+ Expect.equal lens2.Range lens2Range " Lens 2 should be at 5:6-5:25"
144+
145+ return ()
146+ }
147+ |> AsyncResult.foldResult id ( fun e -> failtest $" {e}" ))
148+
149+ ]) ]
141150
142151let tests state =
143152
144- testList ( nameof CodeLens) [
145- projectBasedTests state
146- serverTestList " scriptTests" state defaultConfigDto None ( fun server ->
147- [ testCaseAsync " can show codelens for type annotation"
148- <| CodeLens.check server """
153+ testList
154+ ( nameof CodeLens)
155+ [ projectBasedTests state
156+ serverTestList " scriptTests" state defaultConfigDto None ( fun server ->
157+ [ testCaseAsync " can show codelens for type annotation"
158+ <| CodeLens.check server """
149159 module X =
150160 $0let func x = x + 1$0
151- """ ( fun ( _doc , lenses , _unresolved , _resolved ) -> async {
152- Expect.hasLength lenses 2 " should have a type lens and a reference lens"
153- let typeLens = lenses[ 0 ]
154- Expect.equal typeLens.Command.Value.Title " int -> int" " first lens should be a type hint of int to int"
155- Expect.isNone typeLens.Command.Value.Arguments " No data required for type lenses"
156- Expect.equal typeLens.Command.Value.Command " " " No command for type lenses" })
157-
158- testCaseAsync " can show codelens for 0 reference count"
159- <| CodeLens.check server """
161+ """ ( fun ( _doc , lenses , _unresolved , _resolved ) ->
162+ async {
163+ Expect.hasLength lenses 2 " should have a type lens and a reference lens"
164+ let typeLens = lenses[ 0 ]
165+ Expect.equal typeLens.Command.Value.Title " int -> int" " first lens should be a type hint of int to int"
166+ Expect.isNone typeLens.Command.Value.Arguments " No data required for type lenses"
167+ Expect.equal typeLens.Command.Value.Command " " " No command for type lenses"
168+ })
169+
170+ testCaseAsync " can show codelens for 0 reference count"
171+ <| CodeLens.check server """
160172 module X =
161173 $0let func x = x + 1$0
162- """ ( fun ( _doc , lenses , _unresolved , _resolved ) -> async {
163- Expect.hasLength lenses 2 " should have a type lens and a reference lens"
164- let referenceLens = lenses[ 1 ]
165-
166- let emptyCommand =
167- Some
168- { Title = " 0 References"
169- Arguments = None
170- Command = " " }
171-
172- Expect.equal referenceLens.Command emptyCommand " There should be no command or args for zero references" })
173- testCaseAsync " can show codelens for multi reference count"
174- <| CodeLens.check server """
174+ """ ( fun ( _doc , lenses , _unresolved , _resolved ) ->
175+ async {
176+ Expect.hasLength lenses 2 " should have a type lens and a reference lens"
177+ let referenceLens = lenses[ 1 ]
178+
179+ let emptyCommand =
180+ Some
181+ { Title = " 0 References"
182+ Arguments = None
183+ Command = " " }
184+
185+ Expect.equal referenceLens.Command emptyCommand " There should be no command or args for zero references"
186+ })
187+ testCaseAsync " can show codelens for multi reference count"
188+ <| CodeLens.check server """
175189 module X =
176190 $0let func x = x + 1$0
177191
178192 let doThing () = func 1
179- """ ( fun ( doc , lenses , _unresolved , _resolved ) -> async {
180-
181-
182- Expect.hasLength lenses 2 " should have a type lens and a reference lens"
183- let referenceLens = lenses[ 1 ]
184- Expect.isSome referenceLens.Command " There should be a command for multiple references"
185- let referenceCommand = referenceLens.Command.Value
186- Expect.equal referenceCommand.Title " 1 References" " There should be a title for multiple references"
187-
188- Expect.equal
189- referenceCommand.Command
190- " fsharp.showReferences"
191- " There should be a command for multiple references"
192-
193- Expect.isSome referenceCommand.Arguments " There should be arguments for multiple references"
194- let args = referenceCommand.Arguments.Value
195- Expect.equal args.Length 3 " There should be 2 args"
196-
197- let filePath , triggerPos , referenceRanges =
198- args[ 0 ]. Value< string>(),
199- ( args[ 1 ] :?> JObject) .ToObject< Ionide.LanguageServerProtocol.Types.Position>(),
200- ( args[ 2 ] :?> JArray)
201- |> Seq.map ( fun t -> ( t :?> JObject) .ToObject< Ionide.LanguageServerProtocol.Types.Location>())
202- |> Array.ofSeq
203-
204- Expect.equal filePath doc.Uri " File path should be the doc we're checking"
205- Expect.equal triggerPos { Line = 1 u; Character = 6 u } " Position should be 1:6"
206- Expect.hasLength referenceRanges 1 " There should be 1 reference range for the `func` function"
207-
208- Expect.equal
209- referenceRanges[ 0 ]
210- { Uri = doc.Uri
211- Range =
212- { Start = { Line = 3 u; Character = 19 u }
213- End = { Line = 3 u; Character = 23 u } } }
214- " Reference range should be 0:0" })
215- testCaseAsync " can show reference counts for 1-character identifier"
216- <| CodeLens.check server """
193+ """ ( fun ( doc , lenses , _unresolved , _resolved ) ->
194+ async {
195+
196+
197+ Expect.hasLength lenses 2 " should have a type lens and a reference lens"
198+ let referenceLens = lenses[ 1 ]
199+ Expect.isSome referenceLens.Command " There should be a command for multiple references"
200+ let referenceCommand = referenceLens.Command.Value
201+ Expect.equal referenceCommand.Title " 1 References" " There should be a title for multiple references"
202+
203+ Expect.equal
204+ referenceCommand.Command
205+ " fsharp.showReferences"
206+ " There should be a command for multiple references"
207+
208+ Expect.isSome referenceCommand.Arguments " There should be arguments for multiple references"
209+ let args = referenceCommand.Arguments.Value
210+ Expect.equal args.Length 3 " There should be 2 args"
211+
212+ let filePath , triggerPos , referenceRanges =
213+ args[ 0 ]. Value< string>(),
214+ ( args[ 1 ] :?> JObject) .ToObject< Ionide.LanguageServerProtocol.Types.Position>(),
215+ ( args[ 2 ] :?> JArray)
216+ |> Seq.map ( fun t -> ( t :?> JObject) .ToObject< Ionide.LanguageServerProtocol.Types.Location>())
217+ |> Array.ofSeq
218+
219+ Expect.equal filePath doc.Uri " File path should be the doc we're checking"
220+ Expect.equal triggerPos { Line = 1 u; Character = 6 u } " Position should be 1:6"
221+ Expect.hasLength referenceRanges 1 " There should be 1 reference range for the `func` function"
222+
223+ Expect.equal
224+ referenceRanges[ 0 ]
225+ { Uri = doc.Uri
226+ Range =
227+ { Start = { Line = 3 u; Character = 19 u }
228+ End = { Line = 3 u; Character = 23 u } } }
229+ " Reference range should be 0:0"
230+ })
231+ testCaseAsync " can show reference counts for 1-character identifier"
232+ <| CodeLens.check server """
217233 $0let f () = ""$0
218- """ ( fun ( _doc , lenses , _unresolved , _resolved ) -> async {
219- Expect.hasLength lenses 2 " should have a type lens and a reference lens"
220- let referenceLens = lenses[ 1 ]
221- Expect.isSome referenceLens.Command " There should be a command for multiple references"
222- let referenceCommand = referenceLens.Command.Value
223- Expect.equal referenceCommand.Title " 0 References" " There should be a title for multiple references"
224- Expect.equal referenceCommand.Command " " " There should be no command for multiple references"
225- Expect.isNone referenceCommand.Arguments " There should be arguments for multiple references" }) ])
226-
227- ]
234+ """ ( fun ( _doc , lenses , _unresolved , _resolved ) ->
235+ async {
236+ Expect.hasLength lenses 2 " should have a type lens and a reference lens"
237+ let referenceLens = lenses[ 1 ]
238+ Expect.isSome referenceLens.Command " There should be a command for multiple references"
239+ let referenceCommand = referenceLens.Command.Value
240+ Expect.equal referenceCommand.Title " 0 References" " There should be a title for multiple references"
241+ Expect.equal referenceCommand.Command " " " There should be no command for multiple references"
242+ Expect.isNone referenceCommand.Arguments " There should be arguments for multiple references"
243+ }) ])
244+
245+ ]
0 commit comments