Skip to content

Transparent Compiler: completion misses symbols from previous files the checked file doesn't depend on #21000

Description

@DedSec256

With the Transparent Compiler, completion in a file doesn't offer symbols from previous files the file doesn't reference yet. The Background Compiler offers them, so this is a regression for anyone switching to the Transparent Compiler.

Repro

File 1:

module Ns1.Ns2.M
let i = 1

File 2, completion at the caret:

namespace Ns1.Ns2

{caret}

Through FCS:

[<Theory>]
[<InlineData(false)>]
[<InlineData(true)>]
let ``Unreferenced symbol from a previous file`` useTransparentCompiler =
    let checker = FSharpChecker.Create(useTransparentCompiler = useTransparentCompiler)

    let file1 = """
module Ns1.Ns2.M
let i = 1
"""

    let file2 = """
namespace Ns1.Ns2

{caret}
"""

    let context = Checker.getCompletionContext file2
    let options = createProjectOptions [ file1; file2 ] []

    let parseResults, checkAnswer =
        checker.ParseAndCheckFileInProject(options.SourceFiles[1], 0, SourceText.ofString context.Source, options)
        |> Async.RunSynchronouslyImmediate

    match checkAnswer with
    | FSharpCheckFileAnswer.Aborted -> failwith "Type checking was aborted"
    | FSharpCheckFileAnswer.Succeeded checkResults ->
        checkResults.GetCodeCompletionSuggestions(context, parseResults, FSharpCodeCompletionOptions.Default)
        |> assertHasItemWithNames [ "M" ]

Expected

M is offered, as with useTransparentCompiler = false.

Actual

M is not offered.

Cause

The Transparent Compiler checks a file against only the files the dependency graph says it depends on. File 2 doesn't reference anything from file 1 yet, so it has no dependency on it. Its name resolution environment, which completion offers symbols from, then lacks M. The Background Compiler checks a file against every file before it.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions