fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Felix Leitzvscode: add options for global and user snippets (#3765)24c1a633

master
1.7 KiB71 linesraw
1{ pkgs, ... }:
2
3let
4
5  snippetsDir = if pkgs.stdenv.hostPlatform.isDarwin then
6    "Library/Application Support/Code/User/snippets"
7  else
8    ".config/Code/User/snippets";
9
10  globalSnippetsPath = "${snippetsDir}/global.code-snippets";
11
12  globalSnippetsExpectedContent = pkgs.writeText "global.code-snippet" ''
13    {
14      "fixme": {
15        "body": [
16          "fixme body in global user snippet"
17        ],
18        "description": "Insert a FIXME remark",
19        "prefix": [
20          "fixme"
21        ]
22      }
23    }
24  '';
25
26  haskellSnippetsPath = "${snippetsDir}/haskell.json";
27
28  haskellSnippetsExpectedContent = pkgs.writeText "haskell.json" ''
29    {
30      "impl": {
31        "body": [
32          "impl body in user haskell snippet"
33        ],
34        "description": "Insert an implementation stub",
35        "prefix": [
36          "impl"
37        ]
38      }
39    }
40  '';
41
42in {
43  programs.vscode = {
44    enable = true;
45    package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; };
46    globalSnippets = {
47      fixme = {
48        prefix = [ "fixme" ];
49        body = [ "fixme body in global user snippet" ];
50        description = "Insert a FIXME remark";
51      };
52    };
53    languageSnippets = {
54      haskell = {
55        impl = {
56          prefix = [ "impl" ];
57          body = [ "impl body in user haskell snippet" ];
58          description = "Insert an implementation stub";
59        };
60      };
61    };
62  };
63
64  nmt.script = ''
65    assertFileExists "home-files/${globalSnippetsPath}"
66    assertFileContent "home-files/${globalSnippetsPath}" "${globalSnippetsExpectedContent}"
67
68    assertFileExists "home-files/${haskellSnippetsPath}"
69    assertFileContent "home-files/${haskellSnippetsPath}" "${haskellSnippetsExpectedContent}"
70  '';
71}