A comprehensive Language Server Protocol implementation for FHIRPath with VS Code extension support, providing intelligent features for FHIR healthcare data queries.
- Syntax Highlighting - Comprehensive TextMate grammar for FHIRPath
- Error Detection - Real-time syntax validation with precise error positioning
- Language Configuration - Bracket matching, auto-closing, and folding support
- Document Synchronization - Incremental text updates with caching
- Auto-completion - Context-aware suggestions for functions, operators, and FHIR resources
- Semantic Highlighting - Enhanced syntax highlighting with proper token classification
- Hover Documentation - Rich tooltips with function documentation and live expression evaluation
- FHIR Validation - Resource path validation against FHIR R4 specifications
- Performance Optimization - Advanced LRU caching with performance metrics
- Multi-expression Support - Parse and validate semicolon-separated expressions
- Live Expression Evaluation - Real-time evaluation in hover when context data is available
- Rich Formatting - Markdown documentation with collapsible sections and visual badges
- Context Analysis - Document-level context parsing and intelligent validation
- Centralized Configuration - Unified configuration management with type safety and validation
fhirpath-lsp/
βββ client/ # VS Code extension client
β βββ src/extension.ts # Extension entry point
β βββ package.json # Extension manifest
βββ server/ # Language server implementation
β βββ src/
β β βββ server.ts # Main LSP server
β β βββ parser/
β β β βββ FHIRPathService.ts # Parser integration
β β βββ providers/
β β β βββ CompletionProvider.ts # Auto-completion
β β β βββ SemanticTokensProvider.ts # Semantic highlighting
β β β βββ HoverProvider.ts # Hover documentation
β β β βββ DiagnosticProvider.ts # Error detection
β β β βββ FHIRValidationProvider.ts # FHIR validation
β β βββ services/
β β βββ FHIRPathFunctionRegistry.ts # Function definitions
β β βββ FHIRResourceService.ts # FHIR resource schemas
β β βββ CacheService.ts # Performance caching
β β βββ DocumentService.ts # Document management
β β βββ FHIRPathContextService.ts # Context analysis
β βββ package.json
βββ shared/ # Shared types and utilities
β βββ src/
β β βββ types.ts # Common interfaces
β β βββ index.ts # Shared exports
β βββ package.json
βββ syntaxes/
β βββ fhirpath.tmGrammar.json # TextMate grammar
βββ test/ # Test cases and examples
β βββ *.fhirpath # Test expressions
β βββ patient-example.json # Sample FHIR data
β βββ vital-signs-data.json # Sample context data
βββ tasks/ # Development task tracking
βββ adr/ # Architecture Decision Records
βββ package.json # Root workspace configuration
- Bun runtime (recommended) or Node.js 18+
- VS Code 1.84+
-
Clone the repository
git clone https://github.com/atomic-ehr/fhirpath-lsp.git cd fhirpath-lsp -
Install dependencies
bun install:all # or individually: # bun install && cd client && bun install && cd ../server && bun install && cd ../shared && bun install
-
Build the extension
bun run build
-
Run in development
bun run dev
The FHIRPath LSP server uses a centralized configuration system that supports multiple configuration sources with automatic validation and type safety.
- Workspace Configuration -
.fhirpath-lsp.jsonin your project root - User Configuration -
~/.fhirpath-lsp/config.json - Environment Variables -
FHIRPATH_LSP_*prefixed variables - Runtime Configuration - Dynamic updates via LSP
Create a .fhirpath-lsp.json file in your workspace root:
{
"diagnostics": {
"enabled": true,
"performance": {
"maxComplexity": 15,
"maxNestingDepth": 6,
"flagRedundantOperations": true
},
"codeQuality": {
"maxLineLength": 120,
"flagMagicValues": true
},
"fhirBestPractices": {
"enforceTypeSafety": true,
"checkCardinality": true
}
},
"providers": {
"completion": {
"maxSuggestions": 75,
"includeSnippets": true
},
"hover": {
"includeExamples": true,
"maxContentLength": 1200
},
"performance": {
"requestThrottling": {
"enabled": true,
"configs": [
{
"requestType": "completion",
"limit": 15,
"windowMs": 1000
}
]
}
}
}
}You can also configure the server using environment variables:
# Diagnostic configuration
export FHIRPATH_LSP_DIAGNOSTICS_PERFORMANCE_MAX_COMPLEXITY=20
export FHIRPATH_LSP_DIAGNOSTICS_CODE_QUALITY_MAX_LINE_LENGTH=120
# Provider configuration
export FHIRPATH_LSP_PROVIDERS_COMPLETION_MAX_SUGGESTIONS=100
export FHIRPATH_LSP_PROVIDERS_HOVER_INCLUDE_EXAMPLES=trueThe system automatically validates all configuration values and provides helpful error messages for invalid settings. Configuration changes are applied in real-time without requiring a server restart.
For complete configuration documentation, see server/src/config/README.md.
-
Open in VS Code
code . -
Install recommended extensions (when prompted)
- TypeScript and JavaScript Language Features
- ESLint
- Prettier
bun run devThis builds the extension and opens a new VS Code window with the extension loaded.
- Open the project in VS Code
- Go to Run and Debug (Ctrl+Shift+D)
- Select "Launch Extension" from the dropdown
- Press F5 or click the green play button
This will:
- Build the extension automatically
- Launch a new VS Code window (Extension Development Host)
- Attach the debugger to both client and server processes
-
Build the project
bun run build
-
Open Command Palette (Ctrl+Shift+P)
-
Run "Developer: Reload Window" to reload the extension
-
Open a
.fhirpathfile to activate the extension
-
Create a test file with
.fhirpathextension:// Test basic syntax highlighting Patient.name.where(use = 'official').given.first() // Test auto-completion (type Patient. and see suggestions) Patient. // Test FHIR validation (this should show an error) Patient.invalidProperty // Test multi-expression support Patient.name.given.first(); Patient.birthDate -
Test features:
- Syntax Highlighting: Different colors for keywords, functions, strings
- Auto-completion: Type
Patient.and press Ctrl+Space - Hover: Hover over functions like
where()orfirst() - Error Detection: Invalid syntax should show red squiggles
- FHIR Validation: Invalid properties should show warnings
-
Add context declaration at the top of your
.fhirpathfile:// @context Patient test/patient-example.json Patient.name.given.first() -
Features with context:
- Hover shows actual evaluation results
- More accurate FHIR validation
- Enhanced completion suggestions
-
Enable server tracing in VS Code settings:
{ "fhirpath.trace.server": "verbose" } -
View server logs:
- Open Output panel (Ctrl+Shift+U)
- Select FHIRPath Language Server from dropdown
-
Common issues:
- Server not starting: Check the Output panel for errors
- Features not working: Verify the server is running and connected
- Performance issues: Check cache statistics in server logs
# Build all workspaces
bun run build
# Build with watch mode
bun run watch
# Type checking
bun run typecheck
# Run tests
bun run test
# Clean build outputs
bun run clean
# Lint code
bun run lint
# Format code
bun run format
# Package extension for distribution
bun run packageThe project includes VS Code debugging configurations in .vscode/:
- launch.json: Debug configurations for client and server
- tasks.json: Build tasks and shortcuts
- settings.json: Workspace-specific settings
Current performance targets (all met):
- Auto-completion response: < 200ms
- Semantic token generation: < 100ms
- Hover information: < 150ms
- FHIR validation: < 300ms
- Memory usage: < 35MB for server process
- Cache hit rate: > 80% for repeated operations
test/basic-test.fhirpath- Basic syntax and functionstest/context-test.fhirpath- Context-aware evaluationtest/diagnostic-test.fhirpath- Error detectiontest/multi-expression-test.fhirpath- Multiple expressionstest/patient-example.json- Sample FHIR Patient resourcetest/vital-signs-data.json- Sample observation data
bun run test- LSP server structure
- Parser integration (@atomic-ehr/fhirpath)
- TextMate grammar for syntax highlighting
- Diagnostic provider for syntax errors
- VS Code extension client
- Document synchronization
- Auto-completion provider with function registry
- Semantic token provider for enhanced highlighting
- Hover provider with comprehensive documentation
- FHIR resource path validation
- Performance optimization with caching
- Multi-expression support
- Live expression evaluation
- Code formatting and refactoring
- Go-to-definition and find references
- Workspace symbol search
- Integration with FHIR servers
- Advanced diagnostics and quick fixes
The project follows a clean architecture with clear separation of concerns:
- Client: VS Code extension handling UI interactions
- Server: Language server implementing LSP protocol
- Shared: Common types and utilities
- Parser: Integration with @atomic-ehr/fhirpath library
- Providers: Feature-specific implementations (completion, hover, etc.)
- Services: Core business logic and data management
See ADR-001 for detailed architecture decisions.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes following the existing code style
- Add tests for new functionality
- Ensure all tests pass (
bun run test) - Run type checking (
bun run typecheck) - Format code (
bun run format) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- @atomic-ehr/fhirpath - Core FHIRPath parser
- FHIR R4 Specification
- FHIRPath Specification
- Create an issue for bug reports
- Start a discussion for questions
- Check existing issues before creating new ones
Built with β€οΈ by the Atomic EHR Team