samhh / dotfiles

Configuring the universe with Nix.
49 stars 2 forks source link

Snippets #407

Closed samhh closed 9 months ago

samhh commented 9 months ago

https://github.com/samhh/dotfiles/issues/404#issuecomment-1741815595 now that Helix has multi-LSP. NB without native snippets support in Helix yet there's no tabstops beyond the first param.

samhh commented 9 months ago

This gives me a hash mismatch:

diff --git a/flake.lock b/flake.lock
index d3d7143..6dcf0c2 100644
--- a/flake.lock
+++ b/flake.lock
@@ -107,9 +107,30 @@
         "agenix": "agenix",
         "home-manager": "home-manager_2",
         "nixpkgs": "nixpkgs",
+        "snippets-ls": "snippets-ls",
         "tshm-plugin": "tshm-plugin"
       }
     },
+    "snippets-ls": {
+      "inputs": {
+        "nixpkgs": [
+          "nixpkgs"
+        ]
+      },
+      "locked": {
+        "lastModified": 1701388659,
+        "narHash": "sha256-6N7oUpqpuyxcmTf6cQf6j1O6aRR32lnaIJClK23lAtQ=",
+        "owner": "quantonganh",
+        "repo": "snippets-ls",
+        "rev": "fba98d15bdfe686acbaf90674b4893dacce6efd1",
+        "type": "github"
+      },
+      "original": {
+        "owner": "quantonganh",
+        "repo": "snippets-ls",
+        "type": "github"
+      }
+    },
     "tshm-plugin": {
       "flake": false,
       "locked": {
diff --git a/flake.nix b/flake.nix
index 383ae92..c70343b 100644
--- a/flake.nix
+++ b/flake.nix
@@ -15,18 +15,26 @@

       nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";

+      snippets-ls = {
+        url = "github:quantonganh/snippets-ls";
+        inputs.nixpkgs.follows = "nixpkgs";
+      };
+
       tshm-plugin = {
         url = "https://registry.yarnpkg.com/typescript-tshm-plugin/-/typescript-tshm-plugin-0.1.0.tgz";
         flake = false;
       };
     };

-  outputs = { self, agenix, home-manager, nixpkgs, tshm-plugin }:
+  outputs = { self, agenix, home-manager, nixpkgs, snippets-ls, tshm-plugin }:
     let
       system = "aarch64-darwin";
       overlays = with nixpkgs.lib; [
         (const (const self.packages.${system}))
-        (const (const { agenix = agenix.packages.${system}.default; }))
+        (const (const {
+          agenix = agenix.packages.${system}.default;
+          snippets-ls = snippets-ls.packages.${system}.snippets-ls;
+        }))
       ];
       pkgs = import nixpkgs { inherit system overlays; };
     in
diff --git a/home/editor.nix b/home/editor.nix
index 15b3d80..70ea8ef 100644
--- a/home/editor.nix
+++ b/home/editor.nix
@@ -1,5 +1,15 @@
 { lib, pkgs, ... }:

+let tsSnippets = pkgs.writeText "snippets-ls-ts" (builtins.toJSON {
+  sum = {
+    prefix = "sum";
+    body = [
+      "type \${1:MyUnion} = Sum.Member<'\${2:MyVariant}', \${3:string}>;"
+      "const $1 = Sum.create<$1>();"
+    ];
+  };
+});
+in
 {
   programs.helix = {
     enable = true;
@@ -58,6 +68,11 @@
           ];
         };

+        snippets-ls = {
+          command = "snippets-ls";
+          args = [ "-config" tsSnippets ];
+        };
+
         efm = {
           command = "efm-langserver";
           config.documentFormatting = true;
@@ -77,6 +92,8 @@
               name = "efm";
               only-features = [ "format" ];
             }
+
+            "snippets-ls"
           ];
         }
       ];
@@ -93,6 +110,7 @@
       rust-analyzer
       # Needed for rust-analyzer.
       rustc
+      snippets-ls
       nodePackages.typescript-language-server
       nodePackages.vscode-langservers-extracted
     ];
samhh commented 9 months ago

https://github.com/samhh/dotfiles/commit/e436bc79e36f6b389c4e2a7e804b929423aaa7be