This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/layers/+lang/crystal
2021-06-06 22:26:31 +02:00
..
img
config.el crystal: refactor 2021-04-04 12:48:21 +02:00
funcs.el Defer loading of lsp servers up to when the buffer is visible 2021-06-06 22:26:31 +02:00
layers.el Apply GPLv3 terms explicitly to all elisp files 2021-03-25 22:59:32 -04:00
packages.el crystal: refactor 2021-04-04 12:48:21 +02:00
README.org documentation formatting: Tue Nov 10 22:56:00 UTC 2020 2020-11-12 22:38:27 +01:00

crystal layer

/TakeV/spacemacs/media/commit/f3b902a304e1e98eefb60612b76e10e2ff1ebbf7/layers/+lang/crystal/img/crystal.png

Description

This layer provides support for the Crystal language.

Features:

Install

To use this configuration layer, add it to your ~/.spacemacs. You will need to add crystal to the existing dotspacemacs-configuration-layers list in this file.

Configuration

All layer configurations can be done by setting layer variables in your dotfile. No custom user config lines are necessary

Choosing a backend

This layer provides two alternative backends to choose from.

Company-crystal

This is the default choice if nothing is set and no lsp layer is loaded in your dotfile. This mode only provides very limited IDE capabilities. Used best if only small files are edited. To set explicitly set the following in your dotfile:

  (crystal :variables crystal-backend 'company-crystal)

LSP

For proper IDE support this backend should be used. It is based on an external server which will be started automatically by emacs, once a crystal file is opened. The key bindings are the same for all lsp modes so if you are already familiar with one you should be able to work the same in all modes.

To set explicitly do the following in your dotfile:

  (crystal :variables
           crystal-backend 'lsp)

For this to work you will also need to obtain the latest version of the lsp server from here.

NOTE: Key bindings for LSP are defined in the LSP layer. Also it is advisable to have a look at the autocomplete layer for an optimal intellisense config for LSP.

REPL

To be able to connect to inf-crystal, you need to make sure that icr is installed.

Installation instructions can be found on the main page of icr.

Although not in the installation instruction it seems that on macOS you can install it with Homebrew:

  brew install crystal-icr

Ameba

To be able to use ameba.el, you need to make sure that ameba is installed.

Installation instructions can be found on the main page of ameba.

Key bindings

Crystal commands

Key binding Description
SPC m e b play-crystal submit buffer
SPC m e e play-crystal show code in a browser
SPC m e i download play-crystal snippet
SPC m e r play-crystal submit region
SPC m g G jump to definition in other window
SPC m g a jump to matching spec file or back from spec to code file
SPC m g g jump to definition
SPC m t b run crystal spec for the current buffer
SPC m t p run crystal spec for the current project
SPC m u c show context
SPC m u e show macro expansion
SPC m u f format the current buffer
SPC m u i show implementations for given call
SPC m a x run crystal run for the current file

REPL

Start a inferior crystal REPL process with SPC m ' or SPC m s i. Then you can send code to it with the bindings below:

Key binding Description
SPC m ' start inferior REPL process
SPC m s B send buffer and switch to REPL
SPC m s F send function definition and switch to REPL
SPC m s R send region and switch to REPL
SPC m s b send buffer
SPC m s f send function definition
SPC m s i start inferior REPL process
SPC m s r send region
SPC m s s switch to REPL

Ameba

Key binding Description
SPC m u a d Prompts from a directory on which to run Ameba
SPC m u a f Runs Ameba on the current visited file
SPC m u a p Runs Ameba on the entire project