Skip to content

Exactprint-based import list modification introduces extra newline when there is at least one newline between the module header and the topmost import #1274

Closed
@konn

Description

@konn

As found in PR #1264, it seems that exactprint-based import list modification seems to introduce an extra newline in certain situation.
Bisecting it in the master branch, this behaviour is first introduced in eb557b3.

Steps to reproduce

  1. Checkout eb557b3 and build ghcide the binary and make sure your LSP client will use it as a language server executable.

  2. Save the following as Lib.hs:

    module Lib where
    
    import Data.Vector ()
    
    theFun = fromList

    Make sure there is at least one newline between the module header and the import declaration; otherwise this bug won't occur.

  3. Open Lib.hs and wait for the module to be loaded.

  4. Apply Add fromList to Data.Vector code action.

Expected behaviour

fromList is added to the import list, without any modification to the lines except for import list itself, resulting in:

module Lib where

import Data.Vector (fromList)

theFun = fromList

Actual behaviour

An extra newline added between the module header and the import declaration:

module Lib where


import Data.Vector (fromList)

theFun = fromList

Note that there are two blank lines in-between instead of just one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: ghcidetype: bugSomething isn't right: doesn't work as intended, documentation is missing/outdated, etc..

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions