> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/sinelaw/fresh/llms.txt
> Use this file to discover all available pages before exploring further.

# Language Server Protocol

> Native LSP support with real-time diagnostics, code completion, and intelligent navigation

Fresh has native support for the Language Server Protocol (LSP), providing powerful code intelligence features across multiple programming languages.

## Core Features

Fresh's LSP integration provides:

<CardGroup cols={3}>
  <Card title="Real-time Diagnostics" icon="triangle-exclamation">
    See errors and warnings in your code as you type
  </Card>

  <Card title="Code Completion" icon="wand-magic-sparkles">
    Get intelligent code completion suggestions
  </Card>

  <Card title="Go-to-Definition" icon="arrow-pointer">
    Quickly jump to the definition of a symbol
  </Card>
</CardGroup>

## Diagnostics Panel

The diagnostics panel provides a centralized view of all errors and warnings in your code.

<Steps>
  <Step title="Open the Panel">
    Open the diagnostics panel with **Show Diagnostics Panel** or **Toggle Diagnostics Panel** from the command palette.
  </Step>

  <Step title="Navigate Issues">
    * **Up/Down**: Scroll the editor to preview each diagnostic's location
    * **Enter**: Jump to the diagnostic and focus the editor
    * **F8**: Jump to next diagnostic without the panel
    * **Shift+F8**: Jump to previous diagnostic
  </Step>
</Steps>

## Code Folding

When the LSP server provides `foldingRange`, fold indicators appear in the gutter. See [Editing — Code Folding](./editing.md#code-folding) for more details.

## Built-in LSP Support

Fresh includes built-in LSP configurations for many languages. Simply install the server and Fresh will use it automatically:

| Language              | LSP Server                 | Install Command                                        |
| --------------------- | -------------------------- | ------------------------------------------------------ |
| Rust                  | rust-analyzer              | `rustup component add rust-analyzer`                   |
| Go                    | gopls                      | `go install golang.org/x/tools/gopls@latest`           |
| TypeScript/JavaScript | typescript-language-server | `npm install -g typescript-language-server typescript` |
| Python                | pylsp                      | `pip install python-lsp-server`                        |
| Java                  | jdtls                      | `brew install jdtls`                                   |
| Zig                   | zls                        | `brew install zls`                                     |
| LaTeX                 | texlab                     | `brew install texlab`                                  |
| Markdown              | marksman                   | `brew install marksman`                                |
| C/C++                 | clangd                     | `brew install llvm`                                    |

## Python LSP Configuration

The default Python server is `pylsp`. Fresh also supports several alternative Python language servers:

<Tabs>
  <Tab title="pyright">
    Recommended for type checking with strong TypeScript-like type analysis.

    ```json theme={null}
    {
      "lsp": {
        "python": {
          "command": "pyright-langserver",
          "args": ["--stdio"],
          "enabled": true
        }
      }
    }
    ```

    <Info>Install: `npm install -g pyright` or `pip install pyright`</Info>
  </Tab>

  <Tab title="basedpyright">
    Enhanced pyright fork with additional features.

    ```json theme={null}
    {
      "lsp": {
        "python": {
          "command": "basedpyright-langserver",
          "args": ["--stdio"],
          "enabled": true
        }
      }
    }
    ```

    <Info>Install: `pip install basedpyright` or `uv pip install basedpyright`</Info>
  </Tab>

  <Tab title="pylsp with plugins">
    pylsp supports various plugins for enhanced functionality:

    ```json theme={null}
    {
      "lsp": {
        "python": {
          "command": "pylsp",
          "args": [],
          "enabled": true,
          "initialization_options": {
            "pylsp": {
              "plugins": {
                "pycodestyle": { "enabled": true },
                "pylint": { "enabled": true }
              }
            }
          }
        }
      }
    }
    ```
  </Tab>
</Tabs>

## Configuring LSP for a New Language

To add LSP support for a language, configure two sections in your `~/.config/fresh/config.json`:

<Steps>
  <Step title="Define the language">
    Add the language to the `languages` section with file extensions:

    ```json theme={null}
    {
      "languages": {
        "csharp": {
          "extensions": ["cs"],
          "grammar": "c_sharp",
          "comment_prefix": "//",
          "auto_indent": true
        }
      }
    }
    ```
  </Step>

  <Step title="Configure the LSP server">
    Add the language server configuration to the `lsp` section:

    ```json theme={null}
    {
      "lsp": {
        "csharp": {
          "command": "/path/to/csharp-language-server",
          "args": [],
          "enabled": true
        }
      }
    }
    ```
  </Step>
</Steps>

<Note>
  The language name (e.g., `"csharp"`) must match in both sections. Fresh includes built-in language definitions for Rust, JavaScript, TypeScript, and Python.
</Note>

## Configuring Language Detection via Settings UI

You can also configure language detection using the Settings UI instead of editing `config.json` directly:

<Steps>
  <Step title="Open Settings">
    Use **Edit → Settings...** or the command palette (`Ctrl+P`) and search for "Settings"
  </Step>

  <Step title="Navigate to Languages">
    Go to the **Languages** section
  </Step>

  <Step title="Add or Edit a Language">
    Click on an existing language to edit it, or add a new one
  </Step>

  <Step title="Configure Detection">
    Set the following fields:

    * **Extensions**: File extensions that should use this language (e.g., `cs` for C#, `rs` for Rust)
    * **Filenames**: Specific filenames without extensions (e.g., `Makefile`, `.bashrc`, `.zshrc`)
    * **Grammar**: The syntax highlighting grammar to use (must match a grammar name from syntect)
  </Step>
</Steps>

### Example: Adding Shell Script Detection for Dotfiles

To make Fresh recognize `.bashrc`, `.zshrc`, and similar files as shell scripts:

<Steps>
  <Step title="Open Settings">
    Open Settings (**Edit → Settings...**)
  </Step>

  <Step title="Configure bash language">
    Go to **Languages → bash** (or create a new `bash` entry)
  </Step>

  <Step title="Add filenames">
    Add filenames: `.bashrc`, `.zshrc`, `.bash_profile`, `.profile`
  </Step>

  <Step title="Set grammar">
    The grammar should be set to `Bourne Again Shell (bash)` or similar
  </Step>
</Steps>

<Info>
  The `filenames` field supports glob patterns like `*.conf`, `*rc`, or `/etc/**/rc.*` for matching files without standard extensions. Fresh checks filenames first, then extensions, allowing dotfiles without traditional extensions to get proper syntax highlighting.
</Info>
