LoginSignup
0

More than 5 years have passed since last update.

Flycheck でインポートパスを追加する(D言語版).

Posted at

みなさん Flycheck 使ってますか?
Flycheck を使うと自動的に構文チェックをしてくれるので大変便利な上,モジュールのインポートパス等も標準的なディレクトリ構成の場合にはそれっぽく扱ってくれます.

が,モジュールとディレクトリ構成が異なっている場合にはインポートパスをうまく扱えません.

例えば,

hoge.d: hoge モジュール
fuga.d: tm_tn.fuga モジュール

のようなパッケージ構成かつ,

hoge.d
src/tm_tn/fuga.d

のようなディレクトリ構成になっている場合,

fuga.d に以下のように module 宣言があれば,Flycheck はそれをうまく考慮してくれます.

fuga.d
module tm_tn.fuga;

一方,hoge.d 内に以下のように書いても,Flycheck は標準では src をインポートパスとして考慮してくれません.

hoge.d
import tm_tn.fuga;

これでは困る場合があるので,なんとかしてみました.
以下を emacs.el に追加してください.

emacs.el
(require 'flycheck)

(flycheck-def-option-var flycheck-d-custom-import-paths nil d-dmd
  "A list of additional import paths."
  :type '(repeat :tag "Additional paths"
          (string :tag "import path"))
  :safe #'flycheck-string-list-p
  :package-version '(flycheck . "0.14"))

(put 'd-dmd :flycheck-command
     (append (flycheck-checker-command 'd-dmd)
             '((option-list "-I" flycheck-d-custom-import-paths s-prepend))))

あとは hoge.d の先頭か末尾に以下を書いておけばいい感じにインポートパスを見てくれます.

hoge.d
// Local variables:
// flycheck-d-custom-import-paths: ("src")
// End:

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0