haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.71k stars 368 forks source link

Adding imports adds an extra comma #2958

Closed cdsmith closed 2 years ago

cdsmith commented 2 years ago

It is legal in Haskell to write an import list like this:

import Foo
  ( a,
    b,
    c,
  )

Note the trailing comma. In particular, Ormolu formats files this way. However, if I have an import list formatted this way, and ask HLS to add an import (for example, from the quick-actions list, or otherwise auto-importing something), I get this

import Foo
  ( a,
    b,
    c,, newImport
  )

Note the double comma at the end. Of course, this is a syntax error.

michaelpj commented 2 years ago

I bet this is related to https://github.com/haskell/haskell-language-server/issues/2399, in that something is not using exactprint. If we're using exactprint I wouldn't expect this kind of bug.

kokobd commented 2 years ago

I'm going to take a look at this.