Giter Site home page Giter Site logo

company-ghc's Introduction

Company GHC travis melpa

Company-mode completion back-end for haskell-mode via ghc-mod.
It runs when the major mode is derived from haskell-mode.
  • cl-lib

  • company-mode

  • ghc-mod

    In order to make company-ghc work, ghc-comp-init needs to be called once. It is called by ghc-init, so if you follow ghc-mod manual, there is nothing else to do about it. Otherwise (if you don't want to call ghc-init), ensure ghc-comp-init is called before using company-ghc.

  • hoogle command and its database (hoogle data) for doc-buffer support and hoogle search completion.

2.3   Setup from MELPA

  1. Install from MELPA

    M-x package-install RET company-ghc RET
  2. Add company-ghc to company-backends after loading company-mode and ghc-mod

    (add-to-list 'company-backends 'company-ghc)
  1. Install from Git:

    git clone https://github.com/iquiw/company-ghc.git
    
  2. Add company-ghc to company-backends after loading company-mode and ghc-mod

    (add-to-list 'load-path "/path/to/company-ghc")
    (add-to-list 'company-backends 'company-ghc)

The following completions are available.

  1. Pragma names. (ghc-pragma-names)

    Completion for pragma
  2. Language extensions. (ghc-language-extensions)

    Completion for language extensions
  3. GHC option flags. (ghc-options-flags)

    Completion for GHC options
  4. Import module names. (ghc-modules-names)

    Completion for import modules
  5. Variables and functions in import spec. (ghc-module-keyword)

    Completion for import specs
  6. Qualified imported keywords.

    Completion for qualified imported keywords
  7. Keywords from imported modules.

    Completion for keywords of imported modules
  • Type info of completion candidate is displayed in minibuffer, given by ghc-modi browse -d.

    Only when ghc-modi browse -d does not provide type info, company-ghc-show-info (t, oneline or nomodule) is used to determine how type info given by ghc-modi info is displayed.

    Default value of company-ghc-show-info is nil since when ghc-modi info is called, ghc-mod pops up error if the current buffer contains error.

    Show info in minibuffer (``nomodule``)
  • Module name is displayed as completion annotation if company-ghc-show-module is non-nil (default) as in the above images.
  • If hoogle is installed and its database is prepared, then pressing displays hoogle searched documentation in the doc-buffer.

    Display documentation in docbuffer
  • When a function in the local project is selected as completion candidate, pressing C-w (company-show-location) shows its source. It uses information from ghc-mod info, and works only when company-ghc-show-info is non-nil.
  1. In-module completion (M-x company-ghc-complete-in-module)

    It takes a module name in minibuffer, and provides candidates from keywords defined in the specified module. You can use this as an alternative to :browse command of GHCi.

    In-module completion
  2. Hoogle search completion (M-x company-ghc-complete-by-hoogle)

    It takes a query text in minibuffer, and provide candidates from hoogle search results. For example, candidates is like the following if the query is (a -> b) -> (f a -> f b).

    Hoogle search completion

    If you want to get more search results at a time, increase the value of company-ghc-hoogle-search-limit (default 20).

  • Currently, company-ghc treats all symbols as completion prefix unless it starts from line beginning. This means other back-ends after company-ghc have no chance to provide completion candidates in haskell-mode.

    As of now, if you want to use other back-ends with company-ghc, use grouped back-end like below.

    (add-to-list 'company-backends '(company-ghc :with company-dabbrev-code))
  • company-ghc add automatic scan module function to local after-save-hook. It might cause serious problem if there is a bug in it. If you have any trouble at save, turn off autoscan by M-x company-ghc-turn-off-autoscan.

    If customized variable company-ghc-autoscan is nil, autoscan won't be added to local after-save-hook.

    If scan module is not performed in the buffer, completion by company-ghc does not work properly. scan module can be invoked by M-x company-ghc-scan-modules.

  • company-ghc does not try to browse keywords in a module if the module failed to be browsed once.

    If you want company-ghc to browse failed modules again, use M-x company-ghc-clear-failed-cache.

    To make all modules browsed again, use M-x company-ghc-clear-all-cache.

There are some cases that completion by company-ghc does not work. If there is something wrong, run M-x company-ghc-diagnose, which shows diagnostic info like the following:

* company-ghc backend found: company-ghc
* automatic scan module is enabled
* ghc-boot process has been done

Module                                  Alias               Candidates
-------------------------------------------------------------------------------
Data.Maybe                              -                        12
Data.Map                                M                        111
Data.Attoparsec.ByteString.Char8        -                        76
Control.Applicative                     -                        22
Prelude                                 -                        212

The first item shows if company-ghc is added to company-backends or not.

The second item shows if company-ghc auto scan is enabled or not.

The third item shows if ghc-boot has been processed properly.

The table shows rows of imported module in the current buffer, its qualified import alias and number of candidates in the module.

If company-ghc-autoscan is non-nil but company-ghc auto scan is disabled, it is possibly initialization step of company-ghc is not performed by some reason. Check company-ghc configuration. For workaround, run M-x company-ghc-turn-on-autoscan manually.

If ghc-boot process has not been done or failed to run, check ghc-mod configuration (Ref. ghc-mod manual) or whether ghc-mod boot command from shell or command prompt succeeds in the project directory.

If some module is not in the table, it is possibly bug of company-ghc.

Number of candidates is nil initially, and gets filled when completion for the corresponding module is performed. If number of candidates is 0 or nil after completion, it might be problem related to ghc-mod. Try again with setting ghc-debug to t and see if there is any error in *GHC Debug* buffer.

Licensed under the GPL 3+ license.

company-ghc's People

Contributors

iquiw avatar luntain avatar purcell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

company-ghc's Issues

Symbol's value as variable is void: company-backends

Hi there, I am trying to set up company-ghc in Aquamacs and I get this error/warning when starting up aquamacs. Does anyone know what am I missing? Thanks.

Warning (initialization): An error occurred while loading `/Users/yoelusa/.emacs':

Symbol's value as variable is void: company-backends

To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file.  Start Emacs with
the `--debug-init' option to view a complete error backtrace.

I have this configuration on ``~/.emacs`

;; Melpa
(require 'package)
(add-to-list 'package-archives 
         '("melpa" . "http://melpa-stable.milkbox.net/packages/"))
(package-initialize)

(autoload 'ghc-init "ghc" nil t)
(autoload 'ghc-debug "ghc" nil t)
(autoload 'company-mode "company" nil t)

(add-hook 'haskell-mode-hook (lambda () (ghc-init)))

(add-hook 'after-init-hook 'global-company-mode)
(add-to-list 'company-backends 'company-ghc)

The company-ghc-diagnostic-info cmd shows this

* company-ghc backend not found
* automatic scan module is disabled.
  You need to run either 'M-x company-ghc-turn-on-autoscan' once
  or 'M-x company-ghc-scan-modules' when it is necessary.
* ghc-boot process has been done

Module                  Alias           Candidates
-------------------------------------------------------------------------------

The ghc-debug cmd shows this

...
Version: all versions must be the same.
      ghc.el version 0
     ghc-mod version 4.1.6 compiled by GHC 7.8.3
    ghc-modi version 4.1.6 compiled by GHC 7.8.3
    The Glorious Glasgow Haskell Compilation System, version 7.8.3
...

Integrate with company-flx

Citing from the the tool's site [1]:

Company-flex only works with the company-capf backend. Most sources use this backend, with the exception of the more advanced sources. Most backends should be re-written in terms of completion-at-point-functions eventually, although it's going to take a while.

Is it possible that company-ghc use capf?

[1] https://github.com/PythonNut/company-flx

company-ghc-turn-on-autoscan not detected

Hi,
company-ghc-diagnose shows no items when invoked first and suggests:

* company-ghc backend found: company-ghc
* automatic scan module is disabled.
  You need to run either 'M-x company-ghc-turn-on-autoscan' once
  or 'M-x company-ghc-scan-modules' when it is necessary.
* ghc-boot process has been done

However, :f1 v company-ghc-autoscan gives:

company-ghc-autoscan is a variable defined in `company-ghc.el'.
Its value is t

After manually invoking company-ghc-scan-modules, company-ghc-diagnose shows found modules and candidates.

Emacs 24.5.1 on Arch, current company-ghc from gitHub

br,
vlatko

ghc-boot process seems to have failed

Hi,

I'm trying to get company-ghc to work, but without success. The diagnostic reports:

* company-ghc backend found: company-ghc
* automatic scan module is enabled
* ghc-boot process seems to have failed

Module                                  Alias               Candidates
-------------------------------------------------------------------------------
Prelude                                 -                        0

So I applied the recommendations:

  • ghc-mod is properly installed apparently (eg. I can do completion on inst and it goes to instance)
  • ghc-mod boot on the command line does work and gives a huge list of identifiers
  • running with ghc-debug mode does not seem to reveal any issue. Here is the GHC Debug buffer:
% ghc-mod root
/Users/etanter/Develop/Haskell
% boot
% check /Users/etanter/Develop/Haskell/Arboles.hs
% check /Users/etanter/Develop/Haskell/Arboles.hs

I find it strange that it says boot above and not ghc-mode boot. Could it be the problem? if so, where to fix that?
If not, any idea? Something I can do to dig into the matter?

thanks!

Interactive-Haskell hangs

Hi there,
I'm not sure if this is exactly company-ghc's fault but I don't know where else to go, so feel free to point me somewhere else if needed :)
I'm working on the scheme48hours and interactive haskell hangs on me when I start a scheme repl from within the cabal repl. I have to kill ghc and then I either see this in Messages

Company: An error occurred in auto-begin
Wrong type argument: stringp, nil

or I get 1k lines of completions shown in the haskell process log. Either way I have to kill ghc and emacs starts responding only afterwards.

Steps to reproduce (on my machine at least):

  • open Main.hs in Emacs
  • C-c C-l to load the file in the REPL
  • runRepl to start the scheme repl
  • type a letter or two and wait for the completion to kick in (and that's when it hangs)

In case you really go down testing this and want the code I have then here it is, the current master [0fc2d53] is the one you should clone.

To make the listing full, here are my versions:

  • ghc - 7.8.3
  • emacs - 24.4.1
  • emacs packages - updated as of yesterday
  • ghc-mod - 5.2.1.1

completion of symbols in current module when not compiling?

This might be an edge case, and might also be doable by other means, but I was hoping you'd be able to help - when my current module isn't compilable, I lose the ability to complete identifiers from the current module. This is a bit jarring. Might it be possible to have a fallback mode where the tokenised words are used as completion sources when ghc-mod fails to parse the file? Can I achieve this goal by some other company-mode plugin?

Show type info in annotation

Is there any reason to not showing type info in completion annotation? Similar to company-ghc-show-module but company-ghc-show-type-info
It could be very useful.

nil and 0 candidates

Hi!

I've been unable to successfully use company-ghci. Running
company-ghc-diagnose shows nil and 0 completions:

company-ghc backend found: company-ghc
automatic scan module is enabled

Module                                  Alias               Candidates
-------------------------------------------------------------------------------
Seraph.Types                            -                        nil
Debug.Trace                             -                        nil
MVC                                     -                        nil
Data.Set                                S                        nil
Data.Maybe                              -                        0
Data.Map                                M                        nil
Control.Monad.Writer.Strict             -                        nil
Control.Monad.State.Strict              -                        nil
Control.Lens                            -                        nil
Prelude                                 -                        0

Before you invite me to RTFM, I have read the troubleshooting steps on
this: M-: (setq ghc-debug t) and then M-x ghc-debug. Nothing jumps
out me as erroneous:

% ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.8.3
% ghc-mod version
ghc-mod version 5.0.1 compiled by GHC 7.8.3
% ghc-modi version
ghc-modi version 5.0.1 compiled by GHC 7.8.3

I'm using flycheck-haskell and haskell-mode. I'm happy to provide any
additional details you find necessary and thankk you in advance for
any help you can provide with debugging.

haskell-interacative-mode conflicts with company-mode

I am not sure if I should raise this issue somewhere else, but company-mode seems to conflict with haskell-interactive-mode.

To reproduce:

  1. (setq debug-on-error t)
  2. First enter haskell-mode, type something, company is working fine
  3. Then run command haskell-process-load-or-reload, and enter haskell-interactive-mode
  4. Back to haskell-mode, in the beginning of line ,type something, debugger window pops out.

The abridged error message in my case is below:

Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
haskell-interactive-at-prompt()
haskell-interactive-mode-completion-at-point-function()
completion--capf-wrapper(haskell-interactive-mode-completion-at-point-function optimist)
run-hook-wrapped(completion--capf-wrapper haskell-interactive-mode-completion-at-point-function optimist)
company--capf-data()
company-capf(prefix)
#[0 "\n\203 ...
company--begin-new()
company--perform()
#0 "\300 \207" [company--perform] 1 "\n\n(fn)"
funcall(#[0 "\300 \207" [company--perform] 1 "\n\n(fn)"])
company-auto-begin()
company-idle-begin(# #<window 3 on Main.hs> 2490 3405)
apply(company-idle-begin (# #<window 3 on Main.hs> 2490 3405))
byte-code("r\301�\302H�\303H"\210)\301\207" [timer apply 5 6] 4)
timer-event-handler([t 21441 4252 273797 nil company-idle-begin (# #<window 3 on Main.hs> 2490 3405) nil 0])
read-event(nil t 3)
sit-for(3)
flyspell-check-word-p()
byte-code("\306� ...
flyspell-post-command-hook()

Integrate company-ghc into ghc-mod

Hey,

this looks really awesome, adding a company backend for ghc-mod has been on my TODO list for ages now, looks like you did it better than I could have if i tried ;) I'm one of the maintainers of ghc-mod and I was wondering if you might want this to be merged into ghc-mod itself? We're about to do some major elisp code cleanup so this might be just the right time to do it if you want to.

company-ghc backend not found

I am a new emacs user trying to get along with spacemacs. I have ghc-mod installed. When I run company-ghc-diagnose, I see this output:

* company-ghc backend not found
* automatic scan module is disabled.
  You need to run either 'M-x company-ghc-turn-on-autoscan' once
  or 'M-x company-ghc-scan-modules' when it is necessary.
* ghc-boot process has not been done

I am hoping some documentation can be added to the Diagnostic section of the README for a next step to resolve this issue.

No autocompletion candidates for symbols in current file

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 :)

Unwanted "Visit tags table (default TAGS)"

I keep getting the "Visit tags table (default TAGS)" dialog whenever company-ghc tries to do code completion.

I had a search and found this for company mode https://github.com/company-mode/company-mode/issues/333

The followiing is the result of M-x describe-variable completion-at-point-function

completion-at-point-functions's value is (haskell-completions-completion-at-point t)

Local in buffer Main.hs; global value is 
(tags-completion-at-point-function)

I have ghc-mod 5.5.0.0 installed with stack. What do I have to do to stop this behaviour ?

[Question] Constantly "Loading symbols for XX ..."

Hi,
company-ghc is constantly Loading symbols for XX ... while I type. Always the same modules (below).

company-ghc-diagnose:

* company-ghc backend found: (company-ghc :with company-dabbrev-code)
* automatic scan module is enabled
* ghc-boot process has been done

Module                  Alias           Candidates
-------------------------------------------------------------------------------
Types.Plan              -            nil
Types.MobNet                -            nil
Types.Invoice               -            nil
Types.Event             -            nil
StdImports              -            1250
MobNets.Extract             -            nil
Prelude                 -            212

diagnose shows several modules with nil for candidates. Is it my config?

br,
vlatko

company-ghc backend found: company-ghc but ghc-boot process has not been done

* company-ghc backend found: company-ghc
* automatic scan module is enabled
* ghc-boot process has not been done

Module                                  Alias               Candidates
-------------------------------------------------------------------------------
Prelude                                 -                        nil

As the diag above, though company-ghc is added to backend, ghc-boot process cannot been done. What should I do?

My config:

(add-to-list 'company-backends 'company-ghc)
(set-company-backend! 'haskell-mode
  'company-ghc)
  (add-hook 'haskell-mode-hook 'eglot-ensure)

company-ghc shadows other back-ends

As I was playing with company-ghc, it seems to block other back-ends, e.g. company-dabbrev-code because now company-mode won't complete symbol names as shown in the below screenshot.
screen shot 2014-06-24 at 5 31 10 pm

nil candidates without any other errors

Upon running company-ghc-diagnose all modules get loaded, but no candidates appear, and ghc-mod reports no errors either:

no candidates on company-ghc

Further investigation shows that ghc-mod browse can see the symbols exported without problems:

browse works from terminal

On a side-note, ghc-mod boot shows all modules but very few names compared to what ghc-mod browse does. However, none of those functions show up as candidates in the diagnose!

You can use the repository https://github.com/kerscher/preliminaries to try to reproduce.
The library is not on Hackage, yet.

Direct communication with ghc-modi

Currently, company-ghc borrows ghc-mod variables and modifies them by adding text properties.
It is not polite.
I would like to change it by communicating with ghc-modi directly via ghc-sync-process.

Once after ghc-modi supports "-d" and "-o" options like ghc-mod, we can remove call of ghc-get-info and add operators into candidates.

One down side is we may have duplicate set of keywords in ghc-mod and company-ghc.

Company gives “Wrong type argument” error message

If I’m typing a word, and the Company-Mode completions pop-up appears,
and the active completion back-end is company-ghc, the completions
pop-up appears to be properly populated, but it disappears soon after
appearing, and the following error message is logged:

Company: An error occurred in post-command
Company: Front-end company-echo-metadata-frontend error "Company: Back-end company-ghc error "Wrong type argument: stringp, nil" with args (meta putChar)" on command post-command

company-ghc-diagnose’s output seems fine:

* company-ghc backend found: company-ghc
* automatic scan module is enabled
* ghc-boot process has been done

Module                                  Alias               Candidates
-------------------------------------------------------------------------------
Prelude                                 -                        212

Operator in candidates

Since ghc-modi browse now supports -o option to browse operators, it can be achieved.

Fuzzy match for module names

I'd like to be able to type something like C.M.Re and get Control.Monad.Reader. Or rather, C.M and have Control.Monad show up in the completion list.

If I understood the code correctly, this requires us not to use all-completions.

emacs sluggishness due to slow completion with ghc-mod

In spacemacs with stack (I don't know if this is related to how ghc-mod integrates stack), the completion will be unbearably slow as soon as the import list is too big (~ 25 items).

Is there any known trick to avoid the problem (apart from disabling company-ghc) at that point ?

Thanks for your help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.