Skip to content

Commit

Permalink
feat: make the formatter path configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
kclejeune authored and jnoortheen committed Oct 12, 2021
1 parent b07688e commit 03c25cb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Adds [nix](https://nixos.org/) language support for VSCode Editor.

* When `Language Server` support is not enabled the following tools are used to
+ Formatting support
- with the help of [nixpkgs-format](https://github.com/nix-community/nixpkgs-fmt)
- with the help of [nixpkgs-format](https://github.com/nix-community/nixpkgs-fmt) or other tools as specified by the `nix.formatterPath` option
+ Error Report
- Using `nix-instantiate` errors reported

Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
"configuration": {
"title": "NixIDE",
"properties": {
"nix.formatterPath": {
"type": "string",
"default": "nixpkgs-fmt",
"description": "Location of the nix formatter command."
},
"nix.serverPath": {
"type": "string",
"default": "rnix-lsp",
Expand Down
4 changes: 4 additions & 0 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export class Config {
return this.cfg.get<T>(path) ?? def_val;
}

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

get serverPath(): string {
return this.get<string>("serverPath", "rnix-lsp");
}
Expand Down
7 changes: 5 additions & 2 deletions src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import {
TextEdit,
} from "vscode";
import { IProcessResult, runInWorkspace } from "./process-runner";
import { config } from "./configuration";

const FORMATTER = "nixpkgs-fmt";
const FORMATTER = config.formatterPath;

/**
* Get text edits to format a range in a document.
Expand All @@ -33,7 +34,9 @@ const getFormatRangeEdits = async (
);
} catch (error) {
if (error instanceof Error) {
await vscode.window.showErrorMessage(`Failed to run ${FORMATTER}: ${error.message}`);
await vscode.window.showErrorMessage(
`Failed to run ${FORMATTER}: ${error.message}`
);
}
// Re-throw the error to make the promise fail
throw error;
Expand Down

0 comments on commit 03c25cb

Please sign in to comment.