Skip to content

Commit a8139c8

Browse files
committed
fix(language-server): ensure completion list contains terms from other contexts in the same glossary file, even when the first glossary has more than 60 matching terms
1 parent 29e8239 commit a8139c8

20 files changed

+1680265
-1530245
lines changed

src/language-server/Contextive.LanguageServer.Tests/E2e/CompletionTests.fs

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -85,38 +85,6 @@ let tests =
8585
|> List.map testCompletionsWithMultipleGlossaries
8686
|> testList "Test Completions with multiple glossaries"
8787

88-
let testCompletionsWithLargeGlossaries (text: string, position, expectedLength) =
89-
testAsync
90-
$"""Given content '{text}' at position {position} respond with expected completion list count {expectedLength}""" {
91-
92-
let workspaceRelative = Path.Combine("fixtures", "performance")
93-
94-
let config = [ Workspace.optionsBuilder <| workspaceRelative ]
95-
96-
let workspaceBase =
97-
Workspace.workspaceFolderPath workspaceRelative |> _.ToUri().ToString()
98-
99-
use! client = TestClient(config) |> init
100-
101-
let textDocumentUri = Path.Combine(workspaceBase, "test.txt")
102-
103-
let sw = System.Diagnostics.Stopwatch()
104-
105-
sw.Start()
106-
let! result = client |> Completion.getCompletionFromText text textDocumentUri position
107-
sw.Stop()
108-
109-
let completionLabels = Completion.getLabels result
110-
111-
test <@ Seq.length completionLabels = expectedLength @>
112-
test <@ sw.Elapsed < System.TimeSpan.FromSeconds 10 @>
113-
}
114-
115-
[ "", Position(0, 0), 15 * 4 * 15 // 15 terms x 4 variations per term * 15 glossaries
116-
"cake_switch", Position(0, 11), 2 ] // 1 term * 2 variations (we always return at least 2 variations and let the client do further filtering)
117-
|> List.map testCompletionsWithLargeGlossaries
118-
|> testList "Test Completions with large glossaries"
119-
12088
let singleWordCompletion (term, tokenAtPosition: string option, expectedLabel: string) =
12189
testCase $"Completion of \"{term}\" with {tokenAtPosition} at position, returns \"{expectedLabel}\""
12290
<| fun () ->
@@ -284,3 +252,38 @@ let tests =
284252
|> Seq.head
285253

286254
test <@ completionItem.Kind = CompletionItemKind.Reference @> ]
255+
256+
let private testCompletionsWithLargeGlossaries (text: string, position, expectedLength) =
257+
testAsync
258+
$"""Given content '{text}' at position {position} respond with expected completion list count {expectedLength}""" {
259+
260+
let workspaceRelative = Path.Combine("fixtures", "performance")
261+
262+
let config = [ Workspace.optionsBuilder <| workspaceRelative ]
263+
264+
let workspaceBase =
265+
Workspace.workspaceFolderPath workspaceRelative |> _.ToUri().ToString()
266+
267+
use! client = TestClient config |> init
268+
269+
let textDocumentUri = Path.Combine(workspaceBase, "test.txt")
270+
271+
let sw = System.Diagnostics.Stopwatch()
272+
273+
sw.Start()
274+
let! result = client |> Completion.getCompletionFromText text textDocumentUri position
275+
sw.Stop()
276+
277+
let completionLabels = Completion.getLabels result
278+
279+
test <@ Seq.length completionLabels = expectedLength @>
280+
test <@ sw.Elapsed < System.TimeSpan.FromSeconds 5 @>
281+
}
282+
283+
[<Tests>]
284+
let performanceTests =
285+
[ "", Position(0, 0), 60 * 4 * 16 // 15 terms x 4 variations per term * 16 glossaries
286+
"disguised_stinger", Position(0, 11), 2 ] // 1 term * 2 variations (we always return at least 2 variations and let the client do further filtering)
287+
|> List.map testCompletionsWithLargeGlossaries
288+
|> testList "LanguageServer Performance.Test Completions with large glossaries"
289+
|> testSequenced

src/language-server/Contextive.LanguageServer.Tests/E2e/HoverTests.fs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,21 @@ let tests =
241241
test <@ result = null @>
242242
}
243243

244+
]
244245

245-
testAsync $"Hover is within performance limit with many very large glossaries" {
246+
[<Tests>]
247+
let performanceTests =
248+
testSequenced
249+
<| testList
250+
"LanguageServer Performance.Hover"
251+
[ testAsync $"Hover is within performance limit with many very large glossaries" {
246252
let workspaceRelative = Path.Combine("fixtures", "performance")
247253
let config = [ Workspace.optionsBuilder <| workspaceRelative ]
248254

249255
use! client = TestClient config |> init
250256

251257
// Update this if the performance test glossaries in `fixtures/performance` are updated with the `generate_perf_glossaries.fsx` script.
252-
let sampleTerm = "Cake switch thunder"
258+
let sampleTerm = "Disguised stinger mow"
253259

254260
let workspaceBase =
255261
Workspace.workspaceFolderPath workspaceRelative |> _.ToUri().ToString()
@@ -273,11 +279,11 @@ let tests =
273279

274280
let sw = System.Diagnostics.Stopwatch()
275281
sw.Start()
276-
let! hover = client.TextDocument.RequestHover(hoverParams) |> Async.AwaitTask
282+
let! hover = client.TextDocument.RequestHover hoverParams |> Async.AwaitTask
277283
sw.Stop()
278284

279285
test <@ hover.Contents.HasMarkupContent @>
280286
test <@ hover.Contents.MarkupContent.Kind = MarkupKind.Markdown @>
281287
test <@ hover.Contents.MarkupContent.Value.Contains sampleTerm @>
282-
test <@ sw.Elapsed < System.TimeSpan.FromSeconds 6 @>
288+
test <@ sw.Elapsed < System.TimeSpan.FromSeconds 5 @>
283289
} ]

src/language-server/Contextive.LanguageServer.Tests/fixtures/performance/generate_perf_glossaries.fsx

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ open CrypticWizard.RandomWordGenerator
1111
/// <para>The number of terms in each file is set by the constant value `numTermsInFile`.<para>
1212
/// <para>The number of files generated is set by the constant value `numFiles`.</para>
1313
/// </summary>
14-
/// <remarks>If the files are regenerated, be sure to update the example term in the HoverTests.fs file in the `Hover is within performance limit with many very large glossaries` test.</remarks>
14+
/// <remarks>
15+
/// <para>If the files are regenerated, be sure to update the example terms in:</para>
16+
/// <para>the HoverTests.fs file in the `Hover is within performance limit with many very large glossaries` test and
17+
/// <para>the example term in CompletionTests.fs in the `Test Completions with large glossaries` test.</para>
18+
/// </remarks>
1519
1620
[<Literal>]
1721
let numTermsInFile = 10_000
1822

1923
[<Literal>]
20-
let numFiles = 15
24+
let numFiles = 8
2125

2226
let wg = WordGenerator()
2327

@@ -44,26 +48,31 @@ let newPara numSentences sentenceLen =
4448

4549
System.String.Join(System.Environment.NewLine + System.Environment.NewLine, sentences)
4650

51+
let makeTermList (numTerms: int) =
52+
seq { 0..numTerms }
53+
|> Seq.map (fun idx ->
54+
{ Term.Default with
55+
Name = newSentence 3
56+
Definition = newPara 5 8 |> Some })
57+
58+
let makeContext (numTerms: int) =
59+
let terms = makeTermList numTerms
60+
61+
{ Context.Default with
62+
Name = ""
63+
DomainVisionStatement = ""
64+
Terms = terms |> ResizeArray }
65+
4766
let makeFile (numTerms: int) (fileIdx: int) =
4867

4968
printfn "fileIdx: %A" fileIdx
5069

51-
let terms =
52-
seq { 0..numTerms }
53-
|> Seq.map (fun idx ->
54-
{ Term.Default with
55-
Name = newSentence 3
56-
Definition = newPara 5 8 |> Some })
57-
58-
let context =
59-
{ Context.Default with
60-
Name = ""
61-
DomainVisionStatement = ""
62-
Terms = terms |> ResizeArray }
70+
let context1 = makeContext numTerms
71+
let context2 = makeContext numTerms
6372

6473
let gf =
6574
{ GlossaryFile.Default with
66-
Contexts = [| context |] |> ResizeArray }
75+
Contexts = [| context1; context2 |] |> ResizeArray }
6776

6877
System.IO.File.WriteAllText($"perf{fileIdx}.glossary.yml", serialize gf)
6978

0 commit comments

Comments
 (0)