Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect completion text when using DuplicateRecordFields #682

Closed
expipiplus1 opened this issue Dec 17, 2020 · 14 comments · Fixed by #1360
Closed

Incorrect completion text when using DuplicateRecordFields #682

expipiplus1 opened this issue Dec 17, 2020 · 14 comments · Fixed by #1360
Labels
component: plugins type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@expipiplus1
Copy link
Contributor

Your environment

Output of haskell-language-server --probe-tools or haskell-language-server-wrapper --probe-tools:

❯ haskell-language-server --probe-tools
haskell-language-server version: 0.7.0.0 (GHC: 8.10.2) (PATH: /nix/store/r7bgp8sh4hm7x4r7nz3y3if9n74hv5zx-haskell-language-server-0.7.0.0/bin/haskell-language-server)
Tool versions found on the $PATH
cabal:          3.2.0.0
stack:          Not found
ghc:            8.10.2

Which lsp-client do you use:

This happens with nvim/coc and vscode

Steps to reproduce

In Foo.hs:

{-# language DuplicateRecordFields #-}
module Foo
  where

newtype Foo = Foo { member :: () }
newtype Bar = Bar { member :: () }

in Bar.hs:

module Bar where

import Foo

foo = memb
  • Trigger a completion for memb
  • Observe that member is suggested twice (not useful)
  • Accept either one of the suggestions for member
  • Observe that the text :member:Foo is inserted instead of member

I suppose that this is some incorrect demangling of the $sel:Foo:member names that GHC uses.

image

@jneira jneira added type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. component: plugins labels Dec 17, 2020
@jneira
Copy link
Member

jneira commented Dec 17, 2020

As #680 and #681 i would fix the new completion plugin about to be added with #670

@expipiplus1
Copy link
Contributor Author

expipiplus1 commented Dec 17, 2020

This patch to ghcide fixes things:

diff --git a/src/Development/IDE/Plugin/Completions/Logic.hs b/src/Development/IDE/Plugin/Completions/Logic.hs
index f91a3f7..19f5a78 100644
--- a/src/Development/IDE/Plugin/Completions/Logic.hs
+++ b/src/Development/IDE/Plugin/Completions/Logic.hs
@@ -647,7 +647,7 @@ openingBacktick line prefixModule prefixText Position { _character }
 -- don't want in the autocompleted symbols
 stripAutoGenerated :: CompItem -> CompItem
 stripAutoGenerated ci =
-    ci {label = stripPrefix (label ci)}
+    ci {label = stripPrefix (label ci), insertText = stripPrefix (insertText ci)}
     {- When e.g. DuplicateRecordFields is enabled, compiler generates
     names like "$sel:accessor:One" and "$sel:accessor:Two" to disambiguate record selectors
     https://ghc.haskell.org/trac/ghc/wiki/Records/OverloadedRecordFields/DuplicateRecordFields#Implementation

This does sadly break the record completion snippet though.

I'm not sure what caused this regression, but the recent change nearby is 36a2f0027e73a756d10eb72b2dc36a1711c6802f. @gdevanla what are your thoughts?

@jneira
Copy link
Member

jneira commented Dec 17, 2020

@expipiplus1 if #685 fixes it too, i hope it keeps record completion snippet ok

@gdevanla
Copy link
Contributor

@expipiplus1 It breaks the record completion snippet, since the completion snippets that are values in insertText also have : in them. I think we need to address this issue while constructing CompItem.

@gdevanla
Copy link
Contributor

I think this fixes it. But, we need to make sure it does not break any other cases:

diff --git a/src/Development/IDE/Plugin/Completions/Logic.hs b/src/Development/IDE/Plugin/Completions/Logic.hs
index 42f91ad..ab52074 100644
--- a/src/Development/IDE/Plugin/Completions/Logic.hs
+++ b/src/Development/IDE/Plugin/Completions/Logic.hs
@@ -191,7 +191,7 @@ mkNameCompItem origName origMod thingType isInfix docs !imp = CI{..}
     insertText = case isInfix of
             Nothing -> case getArgText <$> thingType of
                             Nothing -> label
-                            Just argText -> label <> " " <> argText
+                            Just argText -> (stripPrefix label) <> " " <> argText
             Just LeftSide -> label <> "`"

@expipiplus1 Do you plan on working on this fix?

@expipiplus1
Copy link
Contributor Author

I think this fixes it. But, we need to make sure it does not break any other cases:

...

Checking this out now, surely it leaves things less broken than they are currently; and isn't that what tests are for :D

@expipiplus1 Do you plan on working on this fix?

Not sure I can spare the cycles at this busy time of year I'm afraid, also there seems to be other work going on in similar places at the moment.

@gdevanla
Copy link
Contributor

Ok. Thanks. I can work on a quick fix on this issue.

@gdevanla
Copy link
Contributor

@expipiplus1 One other question on your initial comment:

Observe that member is suggested twice (not useful)

I am curious why you did not find this useful. Each of the entries are qualified with respective record declarations as you see here.

cczz

@expipiplus1
Copy link
Contributor Author

Ah, It's because I don't display that information and forgot that that might be the default, so I just see a bunch of repeated lines with the same purpose (to insert cczz)

Ok. Thanks. I can work on a quick fix on this issue.

Thanks! FWIW the patch you posted earlier is working very well.

@gdevanla
Copy link
Contributor

gdevanla commented Jan 4, 2021

I think this issue is fixed and can be closed.

@expipiplus1
Copy link
Contributor Author

Thanks!

@jneira
Copy link
Member

jneira commented Jan 4, 2021

@gdevanla @expipiplus1 thanks for confirming it, closing!

@jneira jneira closed this as completed Jan 4, 2021
@yan-sh
Copy link

yan-sh commented Feb 12, 2021

This problem still exists(

@jneira
Copy link
Member

jneira commented Feb 12, 2021

Ugh, we have to revise this then, a regression test would be definitely needed
//cc @gdevanla

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: plugins type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants