microsoft / qsharp-compiler

Q# compiler, command line tool, and Q# language server
https://docs.microsoft.com/quantum
MIT License
682 stars 170 forks source link

Code action to open namespace inserts declaration at wrong location when no other opens present #394

Open cgranade opened 4 years ago

cgranade commented 4 years ago

Describe the bug

When using a code action to add a missing open declaration to a source file that does not yet contain any open statements (including Microsoft.Quantum.Intrinsic), the new open declaration is included at the wrong location.

To Reproduce

Start with the following source file:

namespace Microsoft.Quantum.Arrays {

    /// # Summary
    function All<'T> (predicate : ('T -> Bool), array : 'T[]) : Bool {
       return Fold(And, true, Mapped(predicate, array));
    }

}

Select the available code action at And to obtain:

namespace Microsoft.Quantum.Arrays {

    /// # Summary
    open Microsoft.Quantum.Logical;

    function All<'T> (predicate : ('T -> Bool), array : 'T[]) : Bool {
       return Fold(And, true, Mapped(predicate, array));
    }

}

Expected behavior

namespace Microsoft.Quantum.Arrays {
    open Microsoft.Quantum.Logical;

    /// # Summary
    function All<'T> (predicate : ('T -> Bool), array : 'T[]) : Bool {
       return Fold(And, true, Mapped(predicate, array));
    }

}

System information

bettinaheim commented 4 years ago

That's a good candidate for a bug bash...