Company-mode completion back-end for haskell-mode via ghc-mod
.. contents:: Table of Contents .. sectnum::
Company-mode_ completion back-end for
ghc-mod. | It runs when the major mode is derived from
In order to make company-ghc work,
ghc-comp-initneeds 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-comp-initis called before using company-ghc.
hoogle_ command and its database (
hoogle data) for doc-buffer support and hoogle search completion.
M-x package-install RET company-ghc RET
.. code:: emacs-lisp
(add-to-list 'company-backends 'company-ghc)
Install from Git::
git clone https://github.com/iquiw/company-ghc.git
.. code:: emacs-lisp
(add-to-list 'load-path "/path/to/company-ghc") (add-to-list 'company-backends 'company-ghc)
The following completions are available.
.. image:: images/pragma.png :alt: Completion for pragma
.. image:: images/language.png :alt: Completion for language extensions
.. image:: images/option.png :alt: Completion for GHC options
.. image:: images/module.png :alt: Completion for import modules
.. image:: images/impspec.png :alt: Completion for import specs
.. image:: images/qualified.png :alt: Completion for qualified imported keywords
.. image:: images/keyword.png :alt: Completion for keywords of imported modules
ghc-modi browse -d.
ghc-modi browse -ddoes not provide type info,
nomodule) is used to determine how type info given by
ghc-modi infois displayed.
Default value of
company-ghc-show-infois nil since when
ghc-modi infois called, ghc-mod pops up error if the current buffer contains error.
.. image:: images/showinfo.png :alt: Show info in minibuffer (
company-ghc-show-moduleis non-nil (default) as in the above images.
hoogle_ is installed and its database is prepared, then pressing :kbd: displays hoogle searched documentation in the doc-buffer.
.. image:: images/doc-buffer.png :alt: Display documentation in docbuffer
company-show-location) shows its source. It uses information from
ghc-mod info, and works only when
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
:browsecommand of GHCi.
.. image:: images/in-module.png :alt: In-module completion
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).
.. image:: images/hoogle-search.png :alt: Hoogle search completion
If you want to get more search results at a time, increase the value of
As of now, if you want to use other back-ends with company-ghc, use grouped back-end like below.
.. code:: emacs-lisp
(add-to-list 'company-backends '(company-ghc :with company-dabbrev-code))
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 :kbd:
If customized variable
company-ghc-autoscanis nil, autoscan won't be added to local
If scan module is not performed in the buffer, completion by company-ghc does not work properly. scan module can be invoked by :kbd:
If you want company-ghc to browse failed modules again, use :kbd:
To make all modules browsed again, use :kbd:
There are some cases that completion by company-ghc does not work. If there is something wrong, run :kbd:
M-x company-ghc-diagnose, which shows diagnostic info like the following::
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-ghcis added to
The second item shows if company-ghc auto scan is enabled or not.
The third item shows if
ghc-boothas 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.
company-ghc-autoscanis non-nil but company-ghc auto scan is disabled, it is possibly initialization step of
company-ghcis not performed by some reason. Check company-ghc configuration. For workaround, run :kbd:
ghc-bootprocess has not been done or failed to run, check ghc-mod configuration (Ref.
ghc-mod manual_) or whether
ghc-mod bootcommand 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
tand see if there is any error in
Licensed under the GPL 3+ license.
.. _company-mode: https://company-mode.github.io/ .. _haskell-mode: https://github.com/haskell/haskell-mode .. _ghc-mod: http://www.mew.org/~kazu/proj/ghc-mod/en/ .. _ghc-mod manual: http://www.mew.org/~kazu/proj/ghc-mod/en/preparation.html .. _haskell-docs: https://github.com/chrisdone/haskell-docs .. _hoogle: https://hackage.haskell.org/package/hoogle .. _MELPA: https://melpa.org/ .. |travis| image:: https://api.travis-ci.org/iquiw/company-ghc.svg?branch=master :target: https://travis-ci.org/iquiw/company-ghc .. |melpa| image:: https://melpa.org/packages/company-ghc-badge.svg :target: https://melpa.org/#/company-ghc