iquiw / company-ghc

Company-mode completion back-end for haskell-mode via ghc-mod
125 stars 6 forks source link

No autocompletion candidates for symbols in current file #31

Open lengstrom opened 8 years ago

lengstrom commented 8 years ago

Hi,

company-ghc works great for autocompleting candidates in Prelude and other modules I import, but for some reason doesn't autocomplete candidates in the file I'm working in. To make a contrived example, when I have the code:

lastDigit :: Integer -> Integer
lastDigit n = n `mod` 10

When I write "las", there's no completion for lastDigit:

getLastDigit :: Integer -> Integer
getLastDigit n = las...

Is this by design or am I doing something wrong? Thanks in advance for the help, other than with this problem I'm loving company-ghc :)

iquiw commented 8 years ago

It is just not implemented. company-ghc scans module import statements and browse the modules (ghc-modi browse). There is no logic to scan or browse functions in the current file.

company-dabbrev-code with grouped backend can complete identifiers in the current file, thought it does not show the type signature. e.g.

(add-to-list 'company-backends '(company-ghc :with company-dabbrev-code))
lengstrom commented 8 years ago

Awesome thanks a lot!

On Wednesday, July 6, 2016, Iku Iwasa notifications@github.com wrote:

It is just not implemented. company-ghc scans module import statements and browse the modules (ghc-modi browse). There is no logic to scan or browse functions in the current file.

company-dabbrev-code with grouped backend can complete identifiers in the current file, thought it does not show the type signature. e.g.

(add-to-list 'company-backends '(company-ghc :with company-dabbrev-code))

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/iquiw/company-ghc/issues/31#issuecomment-230789172, or mute the thread https://github.com/notifications/unsubscribe/AAucIbAIdGUO6cAoZO-ZP7sBvNHUTZzrks5qS7ulgaJpZM4JFVVV .

freckletonj commented 7 years ago

I would contribute a PR if I had the skills, but I'm a bit new to Haskell. I spent an hour looking for this feature, and would also love if it existed!

The following didn't work for me:

(with-eval-after-load 'company
  ;(setq ghc-debug t)
  (add-to-list 'company-backends '(company-ghc :with company-dabbrev-code)))
infinity0 commented 6 years ago

@freckletonj as you can see from C-h f, with-eval-after-load takes a FILE not a function name. So you want "company" instead of 'company, like this:

  (with-eval-after-load "company"
    (add-to-list 'company-backends '(company-ghc :with company-dabbrev-code)))

Depending on what other things you have, you might want to wrap the whole thing in a (with-eval-after-load "ghc" [as above]) as well. That works for me anyway.