Skip to content

Commit

Permalink
docs(website): new guide for editors (#652)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored Nov 2, 2023
1 parent 950556b commit a7c9d32
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 2 deletions.
10 changes: 9 additions & 1 deletion website/astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ export default defineConfig({
variant: "note",
},
},
{
label: "Integrate Biome in your editor",
link: "/guides/integrate-in-editor",
badge: {
text: "New",
variant: "note",
},
},
],
},
{
Expand Down Expand Up @@ -222,7 +230,7 @@ export default defineConfig({
{ label: "Language support", link: "/internals/language-support" },
{
label: "Architecture",
link: "/internals/architecture"
link: "/internals/architecture",
},
{ label: "Credits", link: "/internals/credits" },
{ label: "Versioning", link: "/internals/versioning" },
Expand Down
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@biomejs/website",
"private": true,
"scripts": {
"start": "astro dev --open",
"start": "astro dev",
"format": "cargo biome-cli-dev format --write .",
"tsc": "tsc --skipLibCheck",
"check": "cargo biome-cli-dev check ./",
Expand Down
82 changes: 82 additions & 0 deletions website/src/content/docs/guides/integrate-in-editor.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
title: Integrate Biome in your editor
description: Learn how you can integrate Biome with editors and IDEs
---

## LSP first-class support

Biome has [LSP](https://microsoft.github.io/language-server-protocol/) first-class support. If your editor does implement LSP, then the integration of Biome should be seamless.

Biome has a command called `lsp-proxy`. When executed, Biome will spawn two processes:
- a [daemon](/internals/architecture#daemon) that does execute the requested operations;
- a server that functions as a proxy between the requests of the client - the editor - and the server - the daemon;

If your editor is able to interact with a server and send [JSON-RPC](https://www.jsonrpc.org/) request, you only need to configure the editor run that command.

You can check how the [`neo-vim biome plugin`](https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/server_configurations/biome.lua) does it.

## Use `stdin`

If your editor doesn't support LSP, you use directly the binary `biome` and call it using [standard input](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).

The following commands can be called via standard input:
- [`format`](/reference/cli/#biome-format)
- [`lint`](/reference/cli/#biome-lint)
- [`check`](/reference/cli/#biome-check)

Biome will return the new output (or the original output if changes haven't occurred) to [standard output](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) and the diagnostics to [standard error](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)).

When you used `stdin`, you must pass the `--stdin-file-path` option. The file `path` **doesn't need to exist** in your file system, it can be any name. **What's important** is to provide the correct file extension, so Biome knows **how to treat** your file.

It's the editor's responsibility to locate the resolve the path of the binary and then call it when it's needed. The binaries are shipped to npm based on the architectures and OS that we support:

- `@biomejs/cli-darwin-arm64`
- `@biomejs/cli-darwin-x64`
- `@biomejs/cli-linux-arm64`
- `@biomejs/cli-linux-x64`
- `@biomejs/cli-win32-arm64`
- `@biomejs/cli-win32-x64`

The binary name is `biome` or `biome.exe`, and it can be found in the root directory of the library, e.g.: `@biomejs/cli-darwin-arm64/biome`, `@biomejs/cli-win32-x64/biome.exe`.

### Use the daemon with the binary

Using the binary via CLI is very efficient, although you won't be able to provide [logs](#daemon-logs) to your users. The CLI allows you to bootstrap a daemon and then use the CLI commands through the daemon itself.

If order to do so, you first need to start a daemon process with the [`start`](/reference/cli#biome-start) command:

```shell
biome start
```
Then, every command needs to add the `--use-server` options, e.g.:

```shell
echo "console.log('')" | biome format --use-server --stdin-file-path=dummy.js
```

:::note
If you decide to use the daemon, you're also responsible to restart/kill the process with the [`stop`](/reference/cli#biome-stop) command, to avoid having ghost processes.
:::

:::caution
Operations via the daemon are significantly slower than the CLI itself, so it's advised to run operations only on single files.
:::

## Daemon logs

The Biome daemon saves logs in your file system. Logs are store in a folder called `biome-logs`. You can fine this folder in the temporary directory of your operating system.

From Windows, using a powershell:
```shell
$env:TEMP
```

From Linux/macOS, using a terminal:

```shell
echo $TMPDIR
```

The log files are rotated on an hourly basis.


0 comments on commit a7c9d32

Please sign in to comment.