Help us understand the problem. What is going on with this article?

SublimeREPLにstackのサポートを追加する

More than 3 years have passed since last update.

SublimeREPLはSublime Textにインタプリタを設定するプラグインです。GHCiをエディタ上に呼び出し、編集中のモジュールを手軽にデバッグ/テストできるようにします。このプラグインは現時点でstackをサポートしていませんが、非公式にとりあえず設定できたので紹介します。

デフォルトではGHCiはghciコマンドで呼ばれるよう設定されています(Packages\SublimeREPL\config\Haskell\Main.sublime-menu)。

"command": "repl_open", 
"caption": "Haskell",
"id": "repl_haskell",
"mnemonic": "h",
"args":
{
    "type": "sublime_haskell",
    "encoding": "utf8",
    "cmd": ["ghci"],  ← ここやで
    "cwd": "$file_path",
    "external_id": "haskell",
    "syntax": "Packages/Haskell/Haskell.tmLanguage"
}

stackパッケージ内で全てのモジュール/依存パッケージをロードしつつGHCiを呼び出すには、このコマンドをstack ghciに変更します。パッケージされていないモジュールの場合はstack exec ghciに変更します。手動で変更するのは面倒なので、Haskellの項目を分割し、エディタ上で選択できるようにしました。

[
     {
        "id": "tools",
        "children":
        [{
            "caption": "SublimeREPL",
            "mnemonic": "r",
            "id": "SublimeREPL",
            "children":
            [{
                "caption": "Haskell",
                "id": "Haskell",
                "children":
                [
                    {
                        "command": "repl_open", 
                        "caption": "Haskell",
                        "id": "repl_haskell",
                        "mnemonic": "h",
                        "args":
                        {
                            "type": "sublime_haskell",
                            "encoding": "utf8",
                            "cmd": ["stack", "exec", "ghci"],
                            "cwd": "$file_path",
                            "external_id": "haskell",
                            "syntax": "Packages/Haskell/Haskell.tmLanguage"
                        }
                    },
                    {
                        "command": "repl_open", 
                        "caption": "Haskell - project",
                        "id": "repl_haskell",
                        "mnemonic": "h",
                        "args":
                        {
                            "type": "sublime_haskell",
                            "encoding": "utf8",
                            "cmd": ["stack", "ghci"],
                            "cwd": "$file_path",
                            "external_id": "haskell",
                            "syntax": "Packages/Haskell/Haskell.tmLanguage"
                        }
                    }
                ]
            }]
        }]
    }
]

設定ファイルをこの内容で上書きすれば、メニューでhaskellhaskell - projectが選べるようになります。前者ではstack exec ghciが、後者ではstack ghciが呼ばれます。

ちなみにFluentREPLというプラグインは、選択中のモジュールが保存されるたびにインタプリタにそれをロードし直させる機能をSublimeREPLに追加します。非常に便利です。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした