LoginSignup
0
0

More than 1 year has passed since last update.

jsonでスニペットを書かなくて良いようにした

Posted at

はじめに

Nimの勉強に、ultisnipで使われている記法(を簡略化したもの)で定義したスニペットファイルを、LSP形式のjsonファイルに変換するプログラムを書きました。

snip2json

導入

一応binディレクトリにバイナリを置いていますが、linux以外では自前ビルドしてください。クロスコンパイル試したんですが上手くいかなかったので。。。
公式からインストールして

nim c -d:release snip2json.nim

でコンパイル出来ます。

使い方

非常にシンプルで、指定のディレクトリ以下にある全てのファイルを変換して出力します。デフォルトだとsnip/以下のファイルをjson/以下に出力します。

 .
└──  snip
   └──  test.snip

これが

 .
├──  json
│  └──  test.json
└──  snip
   └──  test.snip

こう。拡張子は見てないです。

中身はこんなふうに変換されます。

test.snip
snippet test
hello! $1
endsnippet

snippet test2
hello! ${1:name}

by
endsnippet
test.json
{
  "test": {
    "prefix": [
      "test"
    ],
    "body": [
      "hello! $1"
    ]
  },
  "test2": {
    "prefix": [
      "test2"
    ],
    "body": [
      "hello! ${1:name}",
      "",
      "by"
    ]
  }
}

おわり

自分で使うには十分な機能になりました。json書きづらいんですよね。

0
0
0

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
0