LSP Integration
Fresh has native support for the Language Server Protocol (LSP), providing features like:
- Real-time diagnostics: See errors and warnings in your code as you type.
- Code completion: Get intelligent code completion suggestions.
- Go-to-definition: Quickly jump to the definition of a symbol.
Configuring LSP for a New Language
To add LSP support for a language, you need to configure two sections in your ~/.config/fresh/config.json:
languages: Define the file extensions for the languagelsp: Configure the language server command
For example, to add C# support:
{
"languages": {
"csharp": {
"extensions": ["cs"],
"grammar": "c_sharp",
"comment_prefix": "//",
"auto_indent": true
}
},
"lsp": {
"csharp": {
"command": "/path/to/csharp-language-server",
"args": [],
"enabled": true
}
}
}The language name (e.g., "csharp") must match in both sections. Fresh includes built-in language definitions for Rust, JavaScript, TypeScript, and Python, but you can add any language by configuring it in your config file.
Configuring Language Detection via Settings UI
You can also configure language detection using the Settings UI instead of editing config.json directly:
- Open Settings: Press
Ctrl+,or use the command palette (Ctrl+P) and search for "Settings" - Navigate to Languages: Go to the Languages section
- Add or Edit a Language: Click on an existing language to edit it, or add a new one
- Configure Detection: Set the following fields:
- Extensions: File extensions that should use this language (e.g.,
csfor C#,rsfor 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)
- Extensions: File extensions that should use this language (e.g.,
Example: Adding Shell Script Detection for Dotfiles
To make Fresh recognize .bashrc, .zshrc, and similar files as shell scripts:
- Open Settings (
Ctrl+,) - Go to Languages → bash (or create a new
bashentry) - Add filenames:
.bashrc,.zshrc,.bash_profile,.profile - The grammar should be set to
Bourne Again Shell (bash)or similar
Fresh checks filenames first, then extensions, allowing dotfiles without traditional extensions to get proper syntax highlighting.