Skip to content

Commit 8ac99f8

Browse files
brettfobaronfel
authored andcommitted
change the type of completion item returned for scripts (#7899)
1 parent c0002cc commit 8ac99f8

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

src/fsharp/FSharp.Compiler.Private.Scripting/FSharpScript.fs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,27 @@ type FSharpScript(?captureInput: bool, ?captureOutput: bool, ?additionalArgs: st
4545

4646
member __.ErrorProduced = errorProduced.Publish
4747

48-
member __.Eval(code: string) =
49-
let ch, errors = fsi.EvalInteractionNonThrowing code
48+
member __.Fsi = fsi
49+
50+
member __.Eval(code: string, ?cancellationToken: CancellationToken) =
51+
let cancellationToken = defaultArg cancellationToken CancellationToken.None
52+
let ch, errors = fsi.EvalInteractionNonThrowing(code, cancellationToken)
5053
match ch with
5154
| Choice1Of2 v -> Ok(v), errors
5255
| Choice2Of2 ex -> Error(ex), errors
5356

54-
/// Get the available completion symbols from the code at the specified location.
57+
/// Get the available completion items from the code at the specified location.
5558
///
5659
/// <param name="text">The input text on which completions will be calculated</param>
5760
/// <param name="line">The 1-based line index</param>
5861
/// <param name="column">The 0-based column index</param>
59-
member __.GetCompletionSymbols(text: string, line: int, column: int) =
62+
member __.GetCompletionItems(text: string, line: int, column: int) =
6063
async {
6164
let! parseResults, checkResults, _projectResults = fsi.ParseAndCheckInteraction(text)
6265
let lineText = text.Split('\n').[line - 1]
6366
let partialName = QuickParse.GetPartialLongNameEx(lineText, column - 1)
64-
let! symbolUses = checkResults.GetDeclarationListSymbols(Some parseResults, line, lineText, partialName)
65-
let symbols = symbolUses
66-
|> List.concat
67-
|> List.map (fun s -> s.Symbol)
68-
return symbols
67+
let! declarationListInfos = checkResults.GetDeclarationListInfo(Some parseResults, line, lineText, partialName)
68+
return declarationListInfos.Items
6969
}
7070

7171
interface IDisposable with

tests/FSharp.Compiler.Private.Scripting.UnitTests/CompletionTests.fs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,46 @@ type CompletionTests() =
1616
use script = new FSharpScript()
1717
let lines = [ "let x = 1"
1818
"x." ]
19-
let! completions = script.GetCompletionSymbols(String.Join("\n", lines), 2, 2)
20-
let matchingCompletions = completions |> List.filter (fun s -> s.DisplayName = "CompareTo")
21-
Assert.AreEqual(1, List.length matchingCompletions)
19+
let! completions = script.GetCompletionItems(String.Join("\n", lines), 2, 2)
20+
let matchingCompletions = completions |> Array.filter (fun d -> d.Name = "CompareTo")
21+
Assert.AreEqual(1, matchingCompletions.Length)
2222
} |> Async.StartAsTask :> Task
2323

2424
[<Test>]
2525
member _.``Instance completions from a previous submission``() =
2626
async {
2727
use script = new FSharpScript()
2828
script.Eval("let x = 1") |> ignoreValue
29-
let! completions = script.GetCompletionSymbols("x.", 1, 2)
30-
let matchingCompletions = completions |> List.filter (fun s -> s.DisplayName = "CompareTo")
31-
Assert.AreEqual(1, List.length matchingCompletions)
29+
let! completions = script.GetCompletionItems("x.", 1, 2)
30+
let matchingCompletions = completions |> Array.filter (fun d -> d.Name = "CompareTo")
31+
Assert.AreEqual(1, matchingCompletions.Length)
3232
} |> Async.StartAsTask :> Task
3333

3434
[<Test>]
3535
member _.``Static member completions``() =
3636
async {
3737
use script = new FSharpScript()
38-
let! completions = script.GetCompletionSymbols("System.String.", 1, 14)
39-
let matchingCompletions = completions |> List.filter (fun s -> s.DisplayName = "Join")
40-
Assert.GreaterOrEqual(List.length matchingCompletions, 1)
38+
let! completions = script.GetCompletionItems("System.String.", 1, 14)
39+
let matchingCompletions = completions |> Array.filter (fun d -> d.Name = "Join")
40+
Assert.GreaterOrEqual(matchingCompletions.Length, 1)
4141
} |> Async.StartAsTask :> Task
4242

4343
[<Test>]
4444
member _.``Type completions from namespace``() =
4545
async {
4646
use script = new FSharpScript()
47-
let! completions = script.GetCompletionSymbols("System.", 1, 7)
48-
let matchingCompletions = completions |> List.filter (fun s -> s.DisplayName = "String")
49-
Assert.GreaterOrEqual(List.length matchingCompletions, 1)
47+
let! completions = script.GetCompletionItems("System.", 1, 7)
48+
let matchingCompletions = completions |> Array.filter (fun d -> d.Name = "String")
49+
Assert.GreaterOrEqual(matchingCompletions.Length, 1)
5050
} |> Async.StartAsTask :> Task
5151

5252
[<Test>]
5353
member _.``Namespace completions``() =
5454
async {
5555
use script = new FSharpScript()
56-
let! completions = script.GetCompletionSymbols("System.", 1, 7)
57-
let matchingCompletions = completions |> List.filter (fun s -> s.DisplayName = "Collections")
58-
Assert.AreEqual(1, List.length matchingCompletions)
56+
let! completions = script.GetCompletionItems("System.", 1, 7)
57+
let matchingCompletions = completions |> Array.filter (fun d -> d.Name = "Collections")
58+
Assert.AreEqual(1, matchingCompletions.Length)
5959
} |> Async.StartAsTask :> Task
6060

6161
[<Test>]
@@ -65,7 +65,7 @@ type CompletionTests() =
6565
let lines = [ "open System.Linq"
6666
"let list = new System.Collections.Generic.List<int>()"
6767
"list." ]
68-
let! completions = script.GetCompletionSymbols(String.Join("\n", lines), 3, 5)
69-
let matchingCompletions = completions |> List.filter (fun s -> s.DisplayName = "Select")
70-
Assert.AreEqual(1, List.length matchingCompletions)
68+
let! completions = script.GetCompletionItems(String.Join("\n", lines), 3, 5)
69+
let matchingCompletions = completions |> Array.filter (fun d -> d.Name = "Select")
70+
Assert.AreEqual(1, matchingCompletions.Length)
7171
} |> Async.StartAsTask :> Task

0 commit comments

Comments
 (0)