IDE Support
Fun provides excellent IDE support through a VS Code extension and Language Server Protocol (LSP) implementation.
Table of Contents
VS Code Extension
The Fun VS Code extension provides a complete development environment for the Fun programming language.
Features
- Syntax Highlighting: Color-coded syntax for Fun code
- IntelliSense: Code completion and suggestions
- Error Reporting: Real-time syntax and type error detection
- Hover Information: Type information on hover
- Go to Definition: Navigate to function and variable definitions
- Symbol Search: Find symbols across your codebase
Extension Structure
vscode/
├── client/ # VS Code extension client
│ ├── src/
│ │ └── extension.ts # Main extension code
│ ├── package.json # Extension manifest
│ └── tsconfig.json # TypeScript configuration
├── package.json # Workspace configuration
└── README.md # Extension documentation
Language Server Protocol
The Fun LSP server provides language intelligence features that work with any LSP-compatible editor.
LSP Features
- Syntax Analysis: Parse and validate Fun code
- Type Checking: Real-time type inference and error detection
- Code Completion: Suggest functions, variables, and types
- Hover Information: Display type information and documentation
- Error Diagnostics: Report syntax and type errors
- Symbol Information: Provide symbol details and locations
Starting the LSP Server
# Start LSP server directly
./fun lsp
# The server runs on stdio and communicates with the client
Features
Syntax Highlighting
The extension provides syntax highlighting for:
- Keywords:
when,is,else,import,from - Operators:
+,-,==,-> - Literals: Numbers, strings, booleans
- Functions: Lambda expressions, function calls
- Types: Type annotations, type constructors
- Comments: Single-line comments with
#
IntelliSense
Code Completion
# Type to see suggestions
inc = \x -> x + 1
inc( # Shows parameter hints
Hover Information
# Hover over functions to see types
inc = \x -> x + 1
# Hover over 'inc' shows: Lam<Int, Int>
# Hover over variables
name = "Alice"
# Hover over 'name' shows: Str
Go to Definition
# Right-click on function name
import math from `./math`
math.inc(5) # Go to definition of 'inc' in math.fun
Error Reporting
Syntax Errors
# Missing semicolon
when x == 0 is
True -> 1
False -> 2 # Error: missing semicolon
# Invalid syntax
inc = \x -> x + # Error: incomplete expression
Type Errors
# Type mismatch
inc = \x -> x + 1
inc(5, 3) # Error: too many arguments
# Undefined variable
result = undefined_var # Error: undefined variable
Import Errors
# Missing module
import missing from `./missing` # Error: module not found
# Invalid import path
import lib from `invalid/path` # Error: cannot read module
Installation
Building the Extension
- Build the Fun executable:
go build - Open the extension directory:
cd vscode code . # Opens VS Code in the extension directory - Install dependencies:
npm install - Run the extension:
- Press
F5in VS Code - This opens a new Extension Development Host window
- Open a
.funfile to test the extension
- Press
Installing in VS Code
- Package the extension:
cd vscode vsce package - Install the extension:
- In VS Code, go to Extensions (Ctrl+Shift+X)
- Click “Install from VSIX…”
- Select the generated
.vsixfile
Manual Installation
- Copy the extension:
cp -r vscode ~/.vscode/extensions/fun-language - Restart VS Code:
- Close and reopen VS Code
- The extension should be available
Configuration
Extension Settings
Add these settings to your VS Code settings:
{
"fun.languageServerPath": "/path/to/your/fun",
"fun.enableTypeChecking": true,
"fun.showTypeInformation": true,
"fun.enableCompletion": true
}
Language Configuration
The extension includes language configuration for:
- File associations:
.funfiles are recognized as Fun code - Comments:
#for single-line comments - Brackets: Automatic bracket matching
- Indentation: Smart indentation for Fun syntax
Keybindings
Default keybindings:
Ctrl+Space: Trigger suggestionsF12: Go to definitionShift+F12: Find all referencesCtrl+Shift+O: Go to symbol in file
Troubleshooting
Common Issues
Extension Not Loading
# Check if the Fun executable is built
ls -la fun
# Verify the extension path in settings
# Make sure fun.languageServerPath points to the correct executable
LSP Server Not Starting
# Test the LSP server manually
./fun lsp
# Check for error messages
# Common issues:
# - Executable not found
# - Permission denied
# - Missing dependencies
No Syntax Highlighting
- Check file association:
- Make sure
.funfiles are associated with Fun language - Right-click on a
.funfile → “Open With” → “Fun”
- Make sure
- Reload the extension:
- Press
Ctrl+Shift+P - Type “Developer: Reload Window”
- Press
No IntelliSense
- Check LSP connection:
- Open Output panel (View → Output)
- Select “Fun Language Server” from dropdown
- Look for connection errors
- Verify file structure:
- Make sure your
.funfiles are valid - Check for syntax errors that might prevent analysis
- Make sure your
Debug Mode
Enable debug mode for detailed logging:
{
"fun.debug": true,
"fun.trace": "verbose"
}
Manual LSP Testing
Test the LSP server manually:
# Start server
./fun lsp
# In another terminal, send LSP messages
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"processId":123,"rootUri":"file:///tmp","capabilities":{}}}' | ./fun lsp
Advanced Configuration
Custom LSP Settings
Configure LSP features:
{
"fun.lsp": {
"completion": {
"triggerCharacters": [".", "("]
},
"hover": {
"enabled": true
},
"diagnostics": {
"enabled": true,
"delay": 1000
}
}
}
Workspace Settings
Project-specific settings in .vscode/settings.json:
{
"fun.languageServerPath": "./fun",
"fun.workspaceRoot": ".",
"fun.includePaths": ["./src", "./lib"]
}
Extension Development
For developers working on the extension:
# Install development dependencies
cd vscode
npm install
# Run tests
npm test
# Build extension
npm run compile
# Package for distribution
vsce package
Best Practices
File Organization
project/
├── src/
│ ├── main.fun
│ ├── math.fun
│ └── utils.fun
├── .vscode/
│ └── settings.json
└── fun # Executable
Extension Usage
- Use type annotations for better IntelliSense
- Organize code in modules for better navigation
- Use consistent naming for better completion
- Enable error reporting to catch issues early
Performance Tips
- Keep files small for faster analysis
- Use modules to organize large codebases
- Avoid circular dependencies that slow down analysis
- Use type annotations to reduce inference time
The IDE support provides a professional development experience for Fun programming, with features comparable to mainstream programming languages.