Skip to main content

Language Server Protocol para Synesis v1.1

Project description

Synesis LSP

Real-time validation and language features for Synesis v1.1 files.

A Language Server Protocol (LSP) implementation that provides diagnostics and editor features for Synesis projects in VSCode and other compatible editors.

License: MIT Python 3.10+

Overview

Synesis LSP is a protocol adapter: it does not re-implement parsing or semantics. All validation is delegated to the Synesis compiler, and the server focuses on translating compiler output into LSP diagnostics and features.

Features

  • Real-time syntax and semantic validation (template rules, REQUIRED/OPTIONAL, BUNDLE, ARITY)
  • Pedagogical diagnostics with clear explanations
  • Automatic discovery of templates and bibliography
  • Fuzzy matching for missing bibrefs
  • Full support for .syn, .synp, .synt, .syno
  • Semantic tokens for syntax highlighting
  • Document symbols (SOURCE/ITEM/ONTOLOGY)
  • Hover, completion, and inlay hints
  • Go-to-definition and rename (bibrefs and codes)
  • Relation graph generation (Mermaid)

Requirements

  • Python 3.10+
  • Synesis compiler installed

Installation

From PyPI

pip install synesis
pip install synesis-lsp

From Source

git clone https://github.com/synesis-lang/synesis.git
git clone https://github.com/synesis-lang/synesis-lsp.git

pip install -e synesis
pip install -e synesis-lsp

Usage

Standalone Server

python -m synesis_lsp

The server communicates via STDIO.

VSCode

The Synesis Explorer extension manages the LSP server automatically.

Synesis Workspace Requirements

For full semantic validation, the workspace should contain:

  • A project file *.synp (required)
  • A template *.synt referenced by the .synp
  • Bibliography *.bib, annotations *.syn, and ontologies *.syno as needed

Notes:

  • Multiple .synt files may exist, but the only valid one is the template referenced by .synp.
  • Without a .synp, the LSP provides only syntax validation and grammar keywords.

Project Structure

synesis-lsp/
├── synesis_lsp/           # Python package (server)
│   ├── __init__.py
│   ├── __main__.py        # Entry point (python -m synesis_lsp)
│   ├── server.py          # LSP server (pygls)
│   ├── converters.py      # ValidationError → LSP Diagnostic
│   ├── cache.py           # Workspace cache
│   ├── semantic_tokens.py # Semantic tokens
│   ├── symbols.py         # Document symbols
│   ├── hover.py           # Hover provider
│   ├── definition.py      # Go-to-definition
│   ├── completion.py      # Autocomplete
│   ├── inlay_hints.py     # Inlay hints
│   ├── explorer_requests.py # Custom explorer requests
│   ├── graph.py           # Relation graph (Mermaid)
│   ├── signature_help.py  # Signature help
│   └── rename.py          # Rename provider
├── tests/                 # Test suite
├── pyproject.toml         # Package configuration
├── INTERFACES.md          # Compiler ↔ LSP contracts
├── CHANGELOG.md           # Release history
├── LICENSE                # MIT License
└── README.md              # This file

Tests

pip install -e ".[dev]"
pytest tests/
pytest --cov=synesis_lsp tests/

Development Notes

  • This LSP is a protocol adapter; do not implement parsing/semantics here.
  • All validation must use synesis.lsp_adapter.validate_single_file.
  • Always convert SourceLocation (1-based) to LSP Range (0-based).
  • If you change error/result contracts, update INTERFACES.md and converters.py.
  • Keep the server resilient: exceptions must become diagnostics, never crashes.

Architecture

┌─────────────┐
│   VSCode    │  (Editor)
└──────┬──────┘
       │ LSP Protocol (JSON-RPC via STDIO)
       ▼
┌─────────────────────────────────┐
│   synesis_lsp.server.py         │  (Python Server)
├─────────────────────────────────┤
│ • Handlers: did_open, did_change│
│ • Converters: Error → Diagnostic│
│ • Providers: tokens, symbols,   │
│   hover, completion, definition,│
│   inlay, signature, rename      │
│ • Commands: loadProject, stats, │
│   explorer, relation graph      │
└──────┬──────────────────────────┘
       │ imports
       ▼
┌─────────────────────────────────┐
│   synesis.lsp_adapter           │  (Compiler Adapter)
├─────────────────────────────────┤
│ • validate_single_file()        │
│ • Context discovery             │
└──────┬──────────────────────────┘
       │ uses
       ▼
┌─────────────────────────────────┐
│   synesis.compiler              │  (Compiler)
├─────────────────────────────────┤
│ • Lark Parser (LALR)            │
│ • SemanticValidator             │
│ • ValidationResult              │
└─────────────────────────────────┘

Advanced Features

  • Custom commands: synesis/loadProject, synesis/getProjectStats, synesis/getReferences, synesis/getCodes, synesis/getRelations, synesis/getRelationGraph
  • Cross-file features (hover, definition, completion, rename, graph) depend on the workspace cache loaded via synesis/loadProject

Troubleshooting

Error: "Package 'synesis' not found"

pip install synesis

LSP does not validate after editing

  1. Check logs: Output → Synesis LSP in VSCode
  2. Reload window: Ctrl+Shift+P → "Reload Window"
  3. Ensure the .synp references the correct template and bibliography
  4. Look for log messages like: Projeto Synesis carregado, Template carregado, Bibliografia carregada

Incorrect diagnostics

The LSP uses the compiler output. If a diagnostic is wrong:

  1. Test with CLI: synesis check arquivo.syn
  2. If CLI also reports it, the bug is in the compiler
  3. Report in the compiler issue tracker

License

MIT License - Synesis Project

Contributing

Contributions are welcome. Please follow the code conventions and add tests for new features.

References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

synesis_lsp-0.14.25.tar.gz (81.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

synesis_lsp-0.14.25-py3-none-any.whl (76.1 kB view details)

Uploaded Python 3

File details

Details for the file synesis_lsp-0.14.25.tar.gz.

File metadata

  • Download URL: synesis_lsp-0.14.25.tar.gz
  • Upload date:
  • Size: 81.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for synesis_lsp-0.14.25.tar.gz
Algorithm Hash digest
SHA256 bef0d6b8ce1c7ecf88148fdf08946e91f90959d9fe01b46df264988d237389f0
MD5 ced62a47c4892f21563d64a566d95190
BLAKE2b-256 da089c1f6f25c31923a169a6e6b06cf9850306d4ed0a0352140d1032d2ecd2bd

See more details on using hashes here.

File details

Details for the file synesis_lsp-0.14.25-py3-none-any.whl.

File metadata

  • Download URL: synesis_lsp-0.14.25-py3-none-any.whl
  • Upload date:
  • Size: 76.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for synesis_lsp-0.14.25-py3-none-any.whl
Algorithm Hash digest
SHA256 b253c17fe88b690e70ba6a021e258e657d6b8b6d3a63acf2890e5e5beb1bee27
MD5 8c724eb6d79014d3ba61e18c6d7e90ae
BLAKE2b-256 ec25605de07784acde2bb4fc4fbdc42b1978d4eba0a7e59d2b9aa1d6a0cf8471

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page