FsAutoComplete icon indicating copy to clipboard operation
FsAutoComplete copied to clipboard

Inconsistency in generated `open` location between Code Completion and Code Fix

Open Booksbaum opened this issue 4 years ago • 3 comments

Inconsistency in generated open location between Code Completion and Code Fix

When completing (Ctrl+Space) a type in an unopened Namespace, its open gets automatically generated. Alternatively the open can be generated via Code Fix (Ctrl+.) on a type in unopened namespace.

But currently these open get generated at different locations:

  • Code Completion: Nearest possible place (-> nearest module)
  • Code fix: Top level (-> root module)

Example:

module Root

module Nested =

  let foo () =
    Regex
  //     ^ cursor is here

open locations:

  • Code Completion:
    module Root
    
    module Nested =
      open System.Text.RegularExpressions 
    
      let foo () =
        Regex
    
  • Code fix:
    module Root
    open System.Text.RegularExpressions 
    
    module Nested =
    
      let foo () =
        Regex
    

These two should have same behaviour.

  • Default: probably Nearest (like it's currently with code completion)
  • Probably introduce a setting for default location
  • Choice for Code Fix (-> two open XXXX fixes with different open locations)
    • Default location (based on setting) should have higher priority in list (come before other location)

Additional by baronfel (https://github.com/fsharp/FsAutoComplete/pull/788#issuecomment-857000143):

Regarding your note, I've noticed that myself and haven't yet come to a decision on how to handle it. I think it's safest to go to Nearest by default, but I do agree that we could easily make it an option for the user for the codefix. For code completion I think a user setting would be the correct way to go, which we would just need to add to the config DTO and flow down into other layers as appropriate.

Booksbaum avatar Jun 08 '21 18:06 Booksbaum

Closing as #788 (released in 0.46.2) fixed this.

baronfel avatar Jun 13 '21 16:06 baronfel

#788 "just" fixes some cases where opens from Code Completions are inserted into invalid places (and such producing compiler errors).

But the basic behaviour of both wasn't changed: Code Completion still opens in nearest location, Code Fix in top level
-> this issue isn't solved

Booksbaum avatar Jun 13 '21 17:06 Booksbaum

Oh of course, this was the issue you added specifically to address that inconsistency.

baronfel avatar Jun 13 '21 17:06 baronfel