Skip to content

atomic-ehr/fhirpath-lsp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FHIRPath Language Server Protocol

A comprehensive Language Server Protocol implementation for FHIRPath with VS Code extension support, providing intelligent features for FHIR healthcare data queries.

πŸš€ Features

βœ… Core Language Support (Phase 1)

  • 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

βœ… Intelligence Features (Phase 2)

  • 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

πŸš€ Advanced Features

  • 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

πŸ“ Project Structure

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

πŸ› οΈ Installation & Setup

Prerequisites

  • Bun runtime (recommended) or Node.js 18+
  • VS Code 1.84+

Build from Source

  1. Clone the repository

    git clone https://github.com/atomic-ehr/fhirpath-lsp.git
    cd fhirpath-lsp
  2. Install dependencies

    bun install:all
    # or individually:
    # bun install && cd client && bun install && cd ../server && bun install && cd ../shared && bun install
  3. Build the extension

    bun run build
  4. Run in development

    bun run dev

βš™οΈ Configuration

The FHIRPath LSP server uses a centralized configuration system that supports multiple configuration sources with automatic validation and type safety.

Configuration Sources (in priority order)

  1. Workspace Configuration - .fhirpath-lsp.json in your project root
  2. User Configuration - ~/.fhirpath-lsp/config.json
  3. Environment Variables - FHIRPATH_LSP_* prefixed variables
  4. Runtime Configuration - Dynamic updates via LSP

Example Configuration

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
          }
        ]
      }
    }
  }
}

Environment Variables

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=true

Configuration Validation

The 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.

πŸ› Local Development & Debugging

Development Environment Setup

  1. Open in VS Code

    code .
  2. Install recommended extensions (when prompted)

    • TypeScript and JavaScript Language Features
    • ESLint
    • Prettier

Debugging the Extension

Method 1: Using the Development Script

bun run dev

This builds the extension and opens a new VS Code window with the extension loaded.

Method 2: Using VS Code Debug Configuration

  1. Open the project in VS Code
  2. Go to Run and Debug (Ctrl+Shift+D)
  3. Select "Launch Extension" from the dropdown
  4. 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

Method 3: Manual Debugging Steps

  1. Build the project

    bun run build
  2. Open Command Palette (Ctrl+Shift+P)

  3. Run "Developer: Reload Window" to reload the extension

  4. Open a .fhirpath file to activate the extension

Testing Language Features

  1. Create a test file with .fhirpath extension:

    // 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
    
  2. Test features:

    • Syntax Highlighting: Different colors for keywords, functions, strings
    • Auto-completion: Type Patient. and press Ctrl+Space
    • Hover: Hover over functions like where() or first()
    • Error Detection: Invalid syntax should show red squiggles
    • FHIR Validation: Invalid properties should show warnings

Debugging with Context Data

  1. Add context declaration at the top of your .fhirpath file:

    // @context Patient test/patient-example.json
    Patient.name.given.first()
    
  2. Features with context:

    • Hover shows actual evaluation results
    • More accurate FHIR validation
    • Enhanced completion suggestions

Debugging Server Issues

  1. Enable server tracing in VS Code settings:

    {
      "fhirpath.trace.server": "verbose"
    }
  2. View server logs:

    • Open Output panel (Ctrl+Shift+U)
    • Select FHIRPath Language Server from dropdown
  3. 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

Development Commands

# 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 package

Debugging Configuration Files

The 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

πŸ“Š Performance Metrics

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

πŸ§ͺ Testing

Test Files Available

  • test/basic-test.fhirpath - Basic syntax and functions
  • test/context-test.fhirpath - Context-aware evaluation
  • test/diagnostic-test.fhirpath - Error detection
  • test/multi-expression-test.fhirpath - Multiple expressions
  • test/patient-example.json - Sample FHIR Patient resource
  • test/vital-signs-data.json - Sample observation data

Running Tests

bun run test

πŸ“ˆ Implementation Status

βœ… Phase 1: Foundation (Complete)

  • LSP server structure
  • Parser integration (@atomic-ehr/fhirpath)
  • TextMate grammar for syntax highlighting
  • Diagnostic provider for syntax errors
  • VS Code extension client
  • Document synchronization

βœ… Phase 2: Intelligence (Complete)

  • 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

πŸ”„ Phase 3: Advanced Features (Planned)

  • Code formatting and refactoring
  • Go-to-definition and find references
  • Workspace symbol search
  • Integration with FHIR servers
  • Advanced diagnostics and quick fixes

πŸ—οΈ Architecture

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.

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes following the existing code style
  4. Add tests for new functionality
  5. Ensure all tests pass (bun run test)
  6. Run type checking (bun run typecheck)
  7. Format code (bun run format)
  8. Commit your changes (git commit -m 'Add amazing feature')
  9. Push to the branch (git push origin feature/amazing-feature)
  10. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ”— Related Projects

πŸ“ž Support


Built with ❀️ by the Atomic EHR Team

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors