Skip to content

Commit

Permalink
fix: default to nixfmt formatter (#441)
Browse files Browse the repository at this point in the history
  • Loading branch information
Grraahaam authored Jan 17, 2025
1 parent d82ee30 commit 582c364
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ You can also open the Command Palette (<kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>P</
1. Install the extension
2. Open a Nix file
3. Syntax highlighting should work out of the box.
4. Formatting the code should work if `nixpkgs-fmt` is installed and available on the PATH.
4. Formatting the code should work if [`nixfmt`](https://github.com/NixOS/nixfmt) (or the archived [`nixpkgs-fmt`](https://github.com/nix-community/nixpkgs-fmt)) is installed and available on the `$PATH`.
5. Full language support is available if you have a language server installed and enabled. See [LSP Plugin Support](#lsp-plugin-support) for more information.

## Features 🎯

- [Syntax Highlighting](./images/docs/nix-syntax-highlight.png) support. Also Nix code blocks inside `markdown` files also [highlighted](./images/docs/md-embed-nix.png).
- The basic language integration is supported out of the box using `nixpkgs-fmt` and `nix instantiate`. Syntax Errors are [linted](./images/docs/linting.png) using `nix-instantiate` while Auto-Formatting is handled by `nixpkgs-fmt` by default. Custom formatter can be set by [setting `nix.formatterPath`](#custom-formatter).
- The basic language integration is supported out of the box using `nixfmt` and `nix-instantiate`. Syntax Errors are [linted](./images/docs/linting.png) using `nix-instantiate` while Auto-Formatting is handled by `nixfmt` by default. Custom formatter can be set by [setting `nix.formatterPath`](#custom-formatter).
- The full language support is enabled by [configuring an LSP server](#lsp-plugin-support).
- Snippets are provided for conditional expressions, `let` expressions, `with` expressions, and `rec`ursive sets.
- Path completion support using https://github.com/ChristianKohler/PathIntellisense extension
- Path completion support using [PathIntellisense](https://github.com/ChristianKohler/PathIntellisense) extension

## Settings ⚙️

Expand All @@ -32,7 +32,7 @@ It can be changed by setting `nix.formatterPath` to any command which can accept

```json5
{
"nix.formatterPath": "nixpkgs-fmt" // or "nixfmt" or ["treefmt", "--stdin", "{file}"]
"nix.formatterPath": "nixfmt" // or "nixpkgs-fmt" or ["treefmt", "--stdin", "{file}"]
// or using flakes with `formatter = pkgs.alejandra;`
// "nix.formatterPath": ["nix", "fmt", "--", "--"]
}
Expand All @@ -50,10 +50,12 @@ Full language support can be enabled by using a language server. Generally, any
"nix.serverSettings": { ... }
}
```
Some examples of advanced settings are provided below for [nil](https://github.com/oxalica/nil) and [nixd](https://github.com/nix-community/nixd).
Some examples of advanced settings are provided below for [`nil`](https://github.com/oxalica/nil) and [`nixd`](https://github.com/nix-community/nixd).

* [Nil Advanced Settings](./docs/snippets/advanced-nil-settings.jsonc)
* [Nixd Advanced Settings](./docs/snippets/advanced-nixd-settings.jsonc)
* [`nil` Advanced Settings](./docs/snippets/advanced-nil-settings.jsonc)
* See the [settings documentation](https://github.com/oxalica/nil/blob/main/docs/configuration.md)
* [`nixd` Advanced Settings](./docs/snippets/advanced-nixd-settings.jsonc)
* See the [settings documentation](https://github.com/nix-community/nixd/blob/main/nixd/docs/configuration.md)

## Contributing 💪

Expand Down
4 changes: 3 additions & 1 deletion docs/snippets/advanced-nil-settings.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
// nil configuration documentation :
// https://github.com/oxalica/nil/blob/main/docs/configuration.md
"nix.enableLanguageServer": true,
"nix.serverPath": "nil",
"nix.serverSettings": {
Expand All @@ -7,7 +9,7 @@
"ignored": ["unused_binding", "unused_with"],
},
"formatting": {
"command": ["nixpkgs-fmt"],
"command": ["nixfmt"],
},
},
},
Expand Down
4 changes: 3 additions & 1 deletion docs/snippets/advanced-nixd-settings.jsonc
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
// nixd configuration documentation :
// https://github.com/nix-community/nixd/blob/main/nixd/docs/configuration.md#configuration-overview
"nix.enableLanguageServer": true,
"nix.serverPath": "nixd",
"nix.serverSettings": {
"nixd": {
"formatting": {
"command": ["nixpkgs-fmt"],
"command": ["nixfmt"],
},
"options": {
// By default, this entry will be read from `import <nixpkgs> { }`.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"string",
"array"
],
"default": "nixpkgs-fmt",
"default": "nixfmt",
"description": "Location of the nix formatter command."
},
"nix.serverPath": {
Expand All @@ -86,7 +86,7 @@
"nix.enableLanguageServer": {
"type": "boolean",
"default": false,
"description": "Use LSP instead of nix-instantiate and nixpkgs-fmt."
"description": "Use LSP instead of nix-instantiate and nixfmt."
},
"nix.serverSettings": {
"type": "object",
Expand Down
2 changes: 1 addition & 1 deletion src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class Config {
}

get formatterPath(): string | Array<string> {
return this.get<string>("formatterPath", "nixpkgs-fmt");
return this.get<string>("formatterPath", "nixfmt");
}

get serverPath(): string {
Expand Down

0 comments on commit 582c364

Please sign in to comment.