Skip to content

Commit 3c0c2b7

Browse files
committed
feat: add Nix development flake with Neovim config
1 parent a6d664d commit 3c0c2b7

21 files changed

+683
-7
lines changed

.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.git
2+
Dockerfile
3+
.dockerignore

Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM nixos/nix
2+
RUN nix-channel --update
3+
COPY ./nix/nix.conf /etc/nix/nix.conf
4+
RUN mkdir /templ
5+
COPY . /templ
6+
WORKDIR /templ
7+
RUN nix develop --impure --command printf "Build complete\n"
8+
COPY ./nix/.config /root/.config
9+
# Open port for templ LSP HTTP debugging
10+
EXPOSE 7474
11+
CMD nix develop --impure

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,14 @@ To add extensive debug information, you can include additional args to the LSP,
645645
646646
## Tasks
647647
648+
### nix-develop
649+
650+
Run a Nix shell that contains everything required to build templ.
651+
652+
```sh
653+
nix develop --impure
654+
```
655+
648656
### build
649657
650658
Build a local version.
@@ -743,6 +751,22 @@ Directory: docs
743751
npm run build
744752
```
745753
754+
### docker-build
755+
756+
Build a Docker container with a full development environment and Neovim setup for testing the LSP.
757+
758+
```
759+
docker build -t templ:latest .
760+
```
761+
762+
### docker-run
763+
764+
Run a Docker development container in the current directory.
765+
766+
```
767+
docker run -p 7474:7474 -v `pwd`:/templ -it --rm templ:latest
768+
```
769+
746770
# Code signing
747771
748772
The binaries are created by me and signed by my GPG key. You can verify with my key https://adrianhesketh.com/a-h.gpg

cmd/templ/lspcmd/proxy/documentcontents.go

+4
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ func (d *Document) String() string {
146146
return strings.Join(d.Lines, "\n")
147147
}
148148

149+
func (d *Document) Replace(with string) {
150+
d.Lines = strings.Split(with, "\n")
151+
}
152+
149153
func (d *Document) Apply(r *lsp.Range, with string) {
150154
withLines := strings.Split(with, "\n")
151155
d.normalize(r)

cmd/templ/lspcmd/proxy/server.go

+1
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ func (p *Server) Formatting(ctx context.Context, params *lsp.DocumentFormattingP
631631
},
632632
NewText: w.String(),
633633
})
634+
d.Replace(w.String())
634635
return
635636
}
636637

docs/docs/syntax-and-usage/for.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
sidebar_position: 4
3+
---
4+
5+
# For loops
6+
7+
templ supports iterating over slices, arrays and channels etc. using the for loop:
8+
9+
```templ
10+
templ listNames(items []Item) {
11+
<ul>
12+
for _, item := range items {
13+
<li>{ item.Name }</li>
14+
}
15+
</ul>
16+
}
17+
```
18+
19+
```html
20+
<ul>
21+
<li>A</li>
22+
<li>B</li>
23+
<li>C</li>
24+
</ul>
25+
```

docs/docs/syntax-and-usage/loops.md

-7
This file was deleted.

flake.lock

+225
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
inputs = {
3+
flake-utils.url = "github:numtide/flake-utils";
4+
nixpkgs.url = "nixpkgs/nixos-22.11";
5+
xc = {
6+
url = "github:joerdav/xc";
7+
inputs.nixpkgs.follows = "nixpkgs";
8+
};
9+
go = {
10+
url = "github:a-h/nix-golang";
11+
inputs.nixpkgs.follows = "nixpkgs";
12+
};
13+
neovim-nightly-overlay = {
14+
url = "github:nix-community/neovim-nightly-overlay";
15+
inputs.nixpkgs.follows = "nixpkgs";
16+
# Neovim 0.9.0
17+
inputs.neovim-flake.url = "github:neovim/neovim?dir=contrib&rev=040f1459849ab05b04f6bb1e77b3def16b4c2f2b";
18+
};
19+
};
20+
21+
outputs = { self, flake-utils, nixpkgs, xc, go, neovim-nightly-overlay }:
22+
flake-utils.lib.eachDefaultSystem (system:
23+
let
24+
pkgsDefault = import nixpkgs { overlays = [ neovim-nightly-overlay.overlay ]; };
25+
pkgs = import nixpkgs {
26+
inherit system; overlays = [
27+
(self: super: {
28+
xc = xc.packages.${system}.xc;
29+
neovim = import ./nix/nvim.nix { pkgs = pkgsDefault; };
30+
go = go.packages.${system}.go_1_20_3;
31+
gopls = pkgs.callPackage ./nix/gopls.nix { };
32+
templ = pkgs.callPackage ./nix/templ.nix {
33+
go = self.go;
34+
xc = self.xc;
35+
};
36+
nerdfonts = (pkgsDefault.nerdfonts.override { fonts = [ "IBMPlexMono" ]; });
37+
})
38+
];
39+
};
40+
shell = pkgs.mkShell {
41+
packages = [
42+
pkgs.asciinema
43+
pkgs.git
44+
pkgs.go
45+
pkgs.gopls
46+
pkgs.gotools
47+
pkgs.ibm-plex
48+
pkgs.neovim
49+
pkgs.nerdfonts
50+
pkgs.ripgrep
51+
pkgs.silver-searcher
52+
pkgs.templ
53+
pkgs.tmux
54+
pkgs.wget
55+
pkgs.xc
56+
pkgs.zip
57+
];
58+
};
59+
in
60+
{
61+
devShells = {
62+
default = shell;
63+
};
64+
}
65+
);
66+
}

0 commit comments

Comments
 (0)