Open smoothdeveloper opened 3 years ago
Another case:
[<AutoOpen>] // will insert after the attribute
module Foo2 =
// would prefer here if "Always place open statements at the top level" is unchecked
let a () =
let t = Task.Factory.StartNew(fun () -> 1) // use the code fix on Task
()
Currently
Here it introduces open ...
on a new line just after the attribute making the code invalid.
Given the settings, I'd prefer open ...
to land on a new line just above let a () =
@vzarytovskii/@cartermp do you know if there are tests for this code fix, is it easy to add one for each cases?
This seems like a bug in the tryfindinsertioncontext routine here: https://github.com/dotnet/fsharp/blob/8b361cfc6eecbccfb2dc625faa7ff66e7e621be5/src/fsharp/service/ServiceAssemblyContent.fs#L994
It's complicated code unfortunately. I'm not sure if it's under test. We have decent testing for the analysis part, but not the insertion part.
Okay this still reproduces the "Always place open statements at the top level" off.
Fixed partially as of now - the code fix doesn't break the code anymore but the location of the inserted code is still not precise.
In indented context, the open namespace code fix puts the declaration at wrong indentation level.
It doesn't always affect the code, but when there are type extensions, it breaks it.
Related information
VS2019 16.8