iquiw / company-ghc

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

============================== Company GHC |travis| |melpa|

.. contents:: Table of Contents .. sectnum::

Overview

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

Installation

Depends

Optional Dependency

Setup from MELPA_

  1. Install from MELPA_

    | :kbd:M-x package-install RET company-ghc RET

  2. Add company-ghc to company-backends after loading company-mode and ghc-mod

    .. code:: emacs-lisp

    (add-to-list 'company-backends 'company-ghc)

Setup from Git

  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

    .. code:: emacs-lisp

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

Feature

Completion

The following completions are available.

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

    .. image:: images/pragma.png :alt: Completion for pragma

  2. Language extensions. (ghc-language-extensions)

    .. image:: images/language.png :alt: Completion for language extensions

  3. GHC option flags. (ghc-options-flags)

    .. image:: images/option.png :alt: Completion for GHC options

  4. Import module names. (ghc-modules-names)

    .. image:: images/module.png :alt: Completion for import modules

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

    .. image:: images/impspec.png :alt: Completion for import specs

  6. Qualified imported keywords.

    .. image:: images/qualified.png :alt: Completion for qualified imported keywords

  7. Keywords from imported modules.

    .. image:: images/keyword.png :alt: Completion for keywords of imported modules

Show type info in minibuffer

Show module name as annotation

Display Hoogle document as doc-buffer

Locate source

Special completion command

  1. In-module completion (:kbd: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.

    .. image:: images/in-module.png :alt: In-module completion

  2. Hoogle search completion (:kbd: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).

    .. image:: images/hoogle-search.png :alt: 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).

Note

Diagnostic

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

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 :kbd: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.

License

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