Riderの設定をGithubで完全同期できるようにした
TL; DR
Jetbrainsエディタの設定をGithubと同期できるSetting Repositoryというプラグインがある。しかしこのSetting Repository はデフォルトでは中途半端なGithub同期しかしないので、Jetbrains Riderの設定を完全に同期できるようにした。
環境
Windows10 Jetbrains Rider 2018.2
経緯
下記のエントリーのようにJetbrains Riderが起動しなくなった。
kitsune-no-yomeiri.hatenadiary.jp
一応この問題は解決したのだが、その解決方法が「今までにいろいろ作ってきた設定やプラグインをすべて消して再インストール」することだった。
この解決方法はいままで作ってきた『数年継ぎ足した秘伝のタレ』を捨てるようなもので、泣く泣く実行せざるを得なかった。だって設定とかキーマッピングとかって自分が使いやすいようにちまちま育てていくもんなんですよ...。それ全部削除ってめっちゃつらい...。
なので、同じことが起こらないように『数年継ぎ足した秘伝のタレ』をGithubにpushして、Riderがぶっ壊れても設定を復元できるような仕組みを模索できたのでエントリーとして残す。
設定をGithubと同期するJetbrains謹製プラグインは一応はある
Supports sharing settings between installations of IntelliJ Platform based products used by the same developer (or team) on different computers.
Synchronization is performed automatically after successful completion of "Update Project" or "Push" actions. Also you can do sync using VCS -> Sync Settings.
(訳: 開発者が複数のPC間でもしくはチーム間でJetbrainsのエディタを使うときに役に立つよ!GithubにPushするなりしたら設定が同期されるよ!)
ということで試したが、結論から言うとこれだけでは設定は部分的にしか同期されない。後述するが、完全に同期するには自作の.DotSettingsファイルをここに追加して、ここの.DotSettingsファイルを使用するよう設定する必要がある。
(以下の記事を参考にしてSetting Repositoryの設定ができる。)
マクロやキーマッピングやカラースキームは同期されるが、Live Templateやコード規則は同期されない。特にLive Templateは自作できたりするし、使用頻度もかなり高い。カスタムしたLive Templateが同期しないのはちょっといただけない。
Settings repositoryの詳細を調べた
ということで同期されているディレクトリの詳細をgit bashで見てみた。
- Setting RepositoryがGithubと同期するのはデフォルトではWindows10であれば
~/.Rider2018.2/config/settingsRepository/repository
以下のディレクトリのようだ。
$ pwd /c/Users/xxx/.Rider2018.2/config/settingsRepository/repository
# ここの内部構造を見てみる ~/.Rider2018.2/config/settingsRepository/repository (master) $ pwd;find . | sort | sed '1d;s/^\x;s/\/\([^/]*\)$/|--\1/;s/\/[^/|]*/| /g' /c/Users/xxx/.Rider2018.2/config/settingsRepository/repository |--.git | |--_windows | |--git.xml | |--keymap.xml | |--laf.xml |--codestyles | |--Default.xml |--colors.scheme.xml |--debugger.xml |--editor.codeinsight.xml |--ide.general.xml |--JetbrainsRider.DotSettings //自分で作成した.DotSettingsファイル(後述) |--keymaps | |--Default copy.xml |--macros.xml |--terminal.xml |--ui.lnf.xml |--vsts_settings.xml
このディレクトリを見る限り、デバッガ、マクロ、ターミナル、キーマップ、カラースキーマらへんの設定はGithubと同期してるっぽい。
他のJetbrainsのエディタでは~/.<product ><version>/config
以下にLive Templateのディレクトリ(templates
)が作られるようだが、Jetbrains Riderでは作られていない模様。
参考: IntelliJ IDEA 2018.2では%HOMEPATH%\.<product><version>\config\templates
ディレクトリが自動で作られる
www.jetbrains.com
...
ふむ。
じゃあ、Jetbrains RiderのLive Templateの情報はどこに保存されているのだろう。
RiderのLive Templateの情報は.DotSettingsファイルに保存されている
もろもろ調べていたら
C:\Users\xxx\.Rider2018.2\config\resharper-host\GlobalSettingsStorage.DotSettings
というファイルの中にLiveTemplatesという文言があった。
# C:\Users\xxx\.Rider2018.2\config\resharper-host\GlobalSettingsStorage.DotSettings <s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=2A7799E642B6AF499EA6D709A1546A87/@KeyIndexDefined">True</s:Boolean> <s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=2A7799E642B6AF499EA6D709A1546A87/Applicability/=Live/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=2A7799E642B6AF499EA6D709A1546A87/Reformat/@EntryValue">True</s:Boolean>
このファイルが怪しい...。でも.DotSettingsファイルってなんだろう...。
.DotSettings is 何
JetBrains Rider 2018.2 Help Layer-Based Settings
Reshaper 2018.2 help Managing and Sharing ReSharper Settings
Out of the box, ReSharper comes with the default set of preferences, which are based on conventions and best practices in the .NET world. These default settings are hard-coded in the product and you can always reset to the defaults if necessary. If you change any settings, your change is saved in a settings layer and ReSharper applies it overriding the corresponding default setting. Initially, ReSharper suggests three layers, in which you can save your preferences: This computer, Solution team-shared, and Solution personal.
ここらへんを見てみると.DotSettingsは.NET界隈の設定ファイルのようで、レイヤーで設定を塗り替えて管理することができるがみたいだ。この引用はReshaperのドキュメントから引っ張ってきた。.NETの設定管理方法(?)をReshaperが採用しており、RiderはReshaperをもとに開発されている。だからRiderには~/.Rider2018.2/config/
以下にtemplates/
がなく、いろんな設定をReshaperと同様に.DotSettingsで管理しているのだと思われる。
Jetbrains Riderでは複数の.DotSettingsが存在しており、基本的に3つのレイヤーで分けられている。そしてレイヤーの優先順位でどう設定をされるかが決まるようだ。
.DotSettingsの3つのレイヤー構成
デフォルトで三種類の.DotSettingsファイルが存在する。
① <SolutionName>.sln.DotSettings.user
Solutionファイルの個人の設定を決める
② <SolutionName>.sln.DotSettings
Solutionファイルのチーム間設定を決める
③ ~\.Rider2018.2\config\resharper-host\GlobalSettingsStorage.DotSettings
今触っているPCのグローバルな設定を決める.DotSettings
(上記3つのレイヤー以外にも追加できる)
.DotSettingsの適用順位
まず、
ベースとして③のGlobalSettingsStorage.DotSettings
の設定が適用される
↓
次にチームでの設定として② <SolutionName>.sln.DotSettings
で上書きされ、
↓
最後に①の <SolutionName>.sln.DotSettings.user
の設定で塗り替えられる
なので、自分だけの設定を割当てたいなら
① Solutionファイルの個人の設定を決める<SolutionName>.DotSettings.user
に任意の.DotSettingsを指定してやればいい。
この.DotSettingsをGithubで同期できればLive Templateは保存される。
- Setting RepositoryがGithubと同期するディレクトリは
~/.Rider2018.2/config/settingsRepository/repository
以下であり、(Windows10)
また、
- 自分だけの設定を割当てたいなら上記①の
<SolutionName>.DotSettings.user
に任意の.DotSettingsを指定してやればいい。
なので、
~/.Rider2018.2/config/settingsRepository/repository
以下にMyJetbrainsRiderSetting.DotSettings
なりを作成し、上記①の<SolutionName>.DotSettings.user
にMyJetbrainsRiderSetting.DotSettings
を設定してやれば
Githubに同期されるため、Githubに自作のLive Templateやその他の設定を残すことができる。
改めて先程のSetting Repositoryの中身を見てみる。
$ pwd /c/Users/xxx/.Rider2018.2/config/settingsRepository/repository # ここの内部構造を見てみる ~/.Rider2018.2/config/settingsRepository/repository (master) $ pwd;find . | sort | sed '1d;s/^\x;s/\/\([^/]*\)$/|--\1/;s/\/[^/|]*/| /g' /c/Users/xxx/.Rider2018.2/config/settingsRepository/repository |--.git | |--_windows | |--git.xml | |--keymap.xml | |--laf.xml |--codestyles | |--Default.xml |--colors.scheme.xml |--debugger.xml |--editor.codeinsight.xml |--ide.general.xml |--JetbrainsRider.DotSettings //自分で作成した.DotSettingsファイル(ここに作る) |--keymaps | |--Default copy.xml |--macros.xml |--terminal.xml |--ui.lnf.xml |--vsts_settings.xml
長くなってきたので、細かい手順は別の記事にします。