Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 130 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ the list itself is subject to change.
- [ ] Type of local binding on hover
- Formatting
- [x] [Runic](https://github.com/fredrikekre/Runic.jl) integration
- [ ] [JuliaFormatter](https://github.com/domluna/JuliaFormatter.jl) integration
- [ ] Make formatting backend configurable
- [x] [JuliaFormatter](https://github.com/domluna/JuliaFormatter.jl) integration
- [x] Make formatting backend configurable
- Rename
- [x] Local binding
- [ ] Global binding
Expand Down Expand Up @@ -273,21 +273,32 @@ responsive.
debounce = 2.0 # Wait 2 seconds after typing stops before analyzing
```

#### `[formatter.runic] executable`
#### `formatter`

- Type: string (path)
- Default: `"runic"` (or `"runic.bat"` on Windows)
- Type: string or table
- Default: `"Runic"`

Configures the formatter backend for document and range formatting. Accepts
either a preset formatter name or a custom formatter configuration.

Path to the [Runic](https://github.com/fredrikekre/Runic.jl) formatter
executable. If not specified, JETLS looks for `runic` in your `PATH` (typically
`~/.julia/bin/runic`). Used for document formatting (triggered via editor
format command).
Preset options:
- `"Runic"` (default): Uses [Runic.jl](https://github.com/fredrikekre/Runic.jl)
- `"JuliaFormatter"`: Uses [JuliaFormatter.jl](https://github.com/domluna/JuliaFormatter.jl)

Examples:
```toml
[formatter.runic]
executable = "/custom/path/to/runic"
# Use JuliaFormatter preset
formatter = "JuliaFormatter"

# Or use custom formatter (both fields optional)
[formatter.custom]
executable = "/path/to/custom-formatter"
executable_range = "/path/to/custom-range-formatter"
```

See [Formatting](#formatting) for detailed configuration instructions and setup
requirements.

#### `[testrunner] executable`

- Type: string (path)
Expand All @@ -305,7 +316,7 @@ executable = "/custom/path/to/testrunner"

See [TestRunner integration](#testrunner-integration) for setup instructions.

### How to configure
### How to configure JETLS

#### Method 1: Project-specific configuration file

Expand All @@ -321,6 +332,9 @@ debounce = 2.0

[testrunner]
executable = "/custom/path/to/testrunner"

# Use JuliaFormatter instead of Runic
formatter = "JuliaFormatter"
```

#### Method 2: Editor configuration via LSP
Expand All @@ -341,7 +355,8 @@ Configure JETLS in VSCode's settings.json file with `jetls-client.jetlsSettings`
},
"testrunner": {
"executable": "/custom/path/to/testrunner"
}
},
"formatter": "JuliaFormatter"
}
}
```
Expand All @@ -366,7 +381,8 @@ Configure JETLS in Zed's settings.json file with the `lsp.JETLS.settings` sectio
},
"testrunner": {
"executable": "/custom/path/to/testrunner"
}
},
"formatter": "JuliaFormatter"
}
}
}
Expand All @@ -386,6 +402,104 @@ The `.JETLSConfig.toml` file takes precedence, since it provides a
**client-agnostic** way to configure JETLS that works consistently across
all editors.

## Formatting

JETLS provides document formatting support through integration with external
formatting tools. By default, [Runic.jl](https://github.com/fredrikekre/Runic.jl)
is used, but you can configure alternative formatters or use custom formatting
executables.

### Features

- **Document formatting**: Format entire Julia files
- **Range formatting**: Format selected code regions (Runic and custom
formatters only)
- **Progress notifications**: Visual feedback during formatting operations
for clients that support work done progress

### Prerequisites

JETLS supports preset formatters as well as custom formatting executables.
For preset formatters, install your preferred formatter and ensure it's
available in your system `PATH`:
- [Runic](https://github.com/fredrikekre/Runic.jl) (default):
```bash
julia -e 'using Pkg; Pkg.Apps.add("Runic")'
```
- [JuliaFormatter](https://github.com/domluna/JuliaFormatter.jl):
```bash
julia -e 'using Pkg; Pkg.Apps.add("JuliaFormatter")'
```

Note that you need to manually make `~/.julia/bin` available on the `PATH`
environment for the formatter executables to be accessible.
See <https://pkgdocs.julialang.org/dev/apps/> for the details.

For custom formatters, no installation is required—simply configure the path
to your executable in `.JETLSConfig.toml` (see the [custom formatter](#custom-formatter) section below).

### Formatter configuration

Configure the formatter using either a `.JETLSConfig.toml` file in your project
root or via LSP configuration (see [How to configure JETLS](#how-to-configure-jetls)
for details). The configuration supports three options:

#### Preset `"Runic"` (default)

```toml
formatter = "Runic"
```

In this case, JETLS will look for the `runic` executable and use it to perform formatting.

This is the default setting and doesn't require explicit configuration.
Runic supports both document and range formatting.

#### Preset `"JuliaFormatter"`

```toml
formatter = "JuliaFormatter"
```

In this case, JETLS will look for the `jlfmt` executable and use it to perform formatting.

If a [`.JuliaFormatter.toml` configuration](https://domluna.github.io/JuliaFormatter.jl/dev/config/)
file is found in your project, `jlfmt` will use those settings.
Otherwise, it uses default settings with formatting options provided by the
editor client (such as tab size) when available.

> [!WARNING]
> Note that JuliaFormatter currently, as of v2.2.0, only supports full document
> formatting, not range formatting.

#### Custom formatter

```toml
[formatter.custom]
executable = "/path/to/custom-formatter"
executable_range = "/path/to/custom-range-formatter"
```

Custom formatters should accept Julia code via stdin and output formatted
code to stdout, following the same interface as `runic`:
- `executable`: Command for full document formatting. The formatter should
read the entire Julia source code from stdin, format it completely, and
write the formatted result to stdout. The exit code should be 0 on success.
- `executable_range`: Command for range formatting. The formatter should
accept a `--lines=START:END` argument to format only the specified line
range. It should read the entire document code from stdin and write the
_entire document code_ to stdout with only the specified region formatted.
The rest of the document must remain unchanged.

### Troubleshooting

If you see an error about the formatter not being found:
1. Ensure you've installed the formatter as described above
2. Check that the formatter executable is in your system `PATH` by running
`which runic` or `which jlfmt`
3. For custom formatters, verify the executable path specified in your settings
4. Restart your editor to ensure it picks up the updated `PATH` or configuration

## TestRunner integration

JETLS integrates with [TestRunner.jl](https://github.com/aviatesk/TestRunner.jl)
Expand Down Expand Up @@ -520,9 +634,9 @@ for more details.

If you see an error about `testrunner` not being found:
1. Ensure you've installed TestRunner.jl as described above
2. Check that `testrunner` is in your system PATH by running `which testrunner`:
2. Check that `testrunner` is in your system `PATH` by running `which testrunner`:
otherwise you may need to add `~/.julia/bin` to `PATH`
3. Restart your editor to ensure it picks up the updated PATH
3. Restart your editor to ensure it picks up the updated `PATH`

Test execution requires that your file is saved and matches the on-disk version.
If you see a message asking you to save the file first, make sure to save your
Expand Down
48 changes: 33 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,39 @@
}
}
},
"formatter": {
"oneOf": [
{
"type": "string",
"enum": [
"Runic",
"JuliaFormatter"
],
"default": "Runic",
"description": "Preset formatter to use. 'Runic' (default) or 'JuliaFormatter'."
},
{
"type": "object",
"properties": {
"custom": {
"type": "object",
"properties": {
"executable": {
"type": "string",
"description": "Path to custom formatter executable for document formatting. The formatter should read Julia code from stdin and output formatted code to stdout. Optional."
},
"executable_range": {
"type": "string",
"description": "Path to custom formatter executable for range formatting. Should accept --lines=START:END argument. Optional."
}
}
}
}
}
],
"default": "Runic",
"markdownDescription": "Formatter configuration. Can be a preset name ('Runic' or 'JuliaFormatter') or a custom formatter object. See [Formatting](https://github.com/aviatesk/JETLS.jl#formatting) for details."
},
"testrunner": {
"type": "object",
"properties": {
Expand All @@ -106,21 +139,6 @@
"description": "Path to the TestRunner.jl executable. If empty, uses 'testrunner' from PATH."
}
}
},
"formatter": {
"type": "object",
"properties": {
"runic": {
"type": "object",
"properties": {
"executable": {
"type": "string",
"default": "",
"description": "Path to the Runic formatter executable. If empty, uses 'runic' from PATH."
}
}
}
}
}
}
}
Expand Down
Loading
Loading