Guide for designing and implementing new LSAP APIs. Use when adding new capabilities to LSAP (definitions, references, rename, etc.) or when asking how to add new features to the LSAP protocol...
Guide for adding new APIs to LSAP. Study existing code as needed.
Three layers:
src/lsap/schema/): Request/Response models (Pydantic), Markdown templatessrc/lsap/capability/): Business logic, LSP orchestrationKey Principles: Agent-cognitive design, Markdown-first output, semantic anchoring via Locate, composed capabilities
Study these before implementing:
src/lsap/schema/definition.py + src/lsap/capability/definition.pysrc/lsap/schema/reference.py + src/lsap/capability/reference.pysrc/lsap/schema/rename.py + src/lsap/capability/rename.pysrc/lsap/schema/symbol.py + src/lsap/capability/symbol.pysrc/lsap/schema/<name>.py)See src/lsap/schema/definition.py for complete example.
Key components:
Request, LocateRequest, or PaginatedRequestResponse or PaginatedResponsemodel_config.json_schema_extra["markdown"]Template basics (see docs/liquid_cheatsheet.md):
{% if items.size == 0 %}...{% endif %}{% for item in items %}...{% endfor %}{{ mode | capitalize }}, {{ path | join: "." }}src/lsap/capability/<name>.py)See src/lsap/capability/definition.py for complete example.
Pattern:
from attrs import define
from .abc import Capability
@define
class MyCapability(Capability[MyRequest, MyResponse]):
async def __call__(self, req: MyRequest) -> MyResponse | None:
# 1. Locate position (if needed)
if not (loc_resp := await self.locate(req)):
return None
# 2. Call LSP operations via ensure_capability()
# 3. Process results (use asyncer.create_task_group for parallelism)
# 4. Return response (or None on failure)
Important: Return None on failure, not empty response.
Add to src/lsap/capability/__init__.py and src/lsap/schema/__init__.py
See tests/test_definition.py for examples. Must test: success case, not found case.
Create schema/<name>.md with usage examples.
See src/lsap/capability/reference.py for complete pattern with PaginationCache and paginate().
from lsap.utils.document import DocumentReader
content = await self.client.read_file(file_path)
reader = DocumentReader(content)
snippet = reader.read(context_range, trim_empty=True)
from lsap.utils.symbol import symbol_at
symbols = await ensure_capability(
self.client, WithRequestDocumentSymbol
).request_document_symbol_list(file_path)
if symbols and (match := symbol_at(symbols, position)):
symbol_path, symbol = match
from lsap.utils.capability import ensure_capability
result = await ensure_capability(
self.client,
WithRequestReferences,
error="Fallback instructions if not supported"
).request_references(file_path, position)
See src/lsap/utils/ for implementations.
Path handling:
client.from_uri(uri) - Returns relative path by defaultclient.from_uri(uri, relative=False) - Returns absolute pathPosition conversion:
Position.from_lsp(lsp_pos) - LSP (0-based) โ LSAP (1-based)lsap_pos.to_lsp() - LSAP (1-based) โ LSP (0-based)Hover content:
clean_hover_content(hover.value) - Removes LSP formatting artifactsFiles to create:
src/lsap/schema/<name>.pysrc/lsap/capability/<name>.pytests/test_<name>.pyschema/<name>.mdFiles to update:
src/lsap/schema/__init__.pysrc/lsap/capability/__init__.pyMust verify:
None on failure (not empty response)ensure_capability() for LSP operationsdocs/locate_design.md - Position resolution patternsdocs/liquid_cheatsheet.md - Template syntaxCONTRIBUTING.md - Development workflow