Hippocamplus My Second Memory

Workflow Description Language (WDL) in Emacs

I recently started working with WDL files. The Broad Institute recommends using Sublime and the syntax highlighter that they provide. They also provide a syntax highlighter for Vim. As Denis Loginov mentioned, they are working on an LSP implementation for WDL that could be used by tools to get syntax validation.

I looked first for a solution in Emacs, my go-to editor. Luckily there was already a WDL mode available that I just slightly improved. I also made a polymode to complement it and configured lsp-mode to use the WDL implementation. All packages are available through MELPA as wdl-mode, poly-wdl, lsp-mode.

Other useful commands include (setq-default indent-tabs-mode nil) and the whitespace-mode to ensure consistent indents (see the WDL section of my Emacs page).

wdl-mode

The wdl-mode package provides syntax highlighting and indentation. It was developed by Xiaowei Zhan.

I noticed that the indentation was not triggered in the presence of space(s) after the character that should trigger it ({, <<<, }, >>>). Maybe this space is not supposed to be there in the first place. Still, some the files I was working with (or some of TOPMed’s workflows) had those sometimes. I think it’s worth catching those, so I modified the package. It’s now a PR in the main repo. If it’s not merged and part of the next version on MELPA, it could always be modified locally (e.g. in the .emacs.d/elpa/wdl-mode*/wdl-mode.el).

poly-wdl

Starting from existing polymodes, I wrote one for WDL. The goal was to automatically switch to “shell mode” in the command chunks, mostly to get the appropriate indentation. The poly-wdl package is now in MELPA and I’m glad I got to contribute to MELPA even if just with a simple and field-specific package.

Language Server Protocol

There is an LSP implementation for WDL that can be used by Emacs to provide syntax validation and (some) auto-completion. It’s still under active development but it seems to work well already.

To use it in Emacs, the python package providing the server needs to be installed first and Emacs’ lsp-mode needs to be configured:

  • Install the LSP server for WDL: pip install wdl-lsp (or pip3).
  • Install packages through MELPA: lsp-mode, lsp-ui and company-lsp.
  • Add to .emacs file:
(require 'lsp-mode)
(add-to-list 'lsp-language-id-configuration '(wdl-mode . "wdl"))
(defgroup lsp-wdl nil
  "LSP support for WDL."
  :group 'lsp-mode
  :link '(url-link "https://github.com/broadinstitute/wdl-ide"))
(defcustom lsp-wdl-server-command "wdl-lsp"
  "Command to start wdl-lsp."
  :group 'lsp-wdl
  :risky t
  :type 'file)
(lsp-register-client
 (make-lsp-client :new-connection (lsp-stdio-connection
                                   (lambda () lsp-wdl-server-command))
                  :major-modes '(wdl-mode)
                  :priority -1
                  :server-id 'wdl))
(add-hook 'wdl-mode-hook #'lsp)
;; Syntax validation interface
(require 'lsp-ui)
(add-hook 'lsp-mode-hook 'lsp-ui-mode)
(setq lsp-ui-sideline-enable nil)
;; To get some auto-completion
(require 'company-lsp)
(push 'company-lsp company-backends)

Note: The first time a file is opened, the package will ask what is the root of the project. I use the folder that contains the WDL file because I don’t think project structures are integrated at this point. This can be changed at any time using M-x lsp-workspace-folders-remove and M-x lsp-workspace-folders-add.

Screenshots

As an example, here is part of a TOPMed workflow for read alignment available here.

I removed empty lines and some comments to make it more compact.


Syntax validation (error message at the bottom)


Auto-completion