feat: YAML LSP (/yaml endpoint) + IAC source catalog enrichment
- Add yaml-language-server (Node.js) to Dockerfile stage 3 - Add YAML_LSP_PORT=2090 env var (Dockerfile + ilsp.nomad) - Start yaml-language-server in background thread (_serve_yaml_lsp) - Expose /yaml WebSocket endpoint (same WS→TCP proxy as /python and /bicep) - Load iac_source_catalog.json alongside bicep_modules_catalog.json - Enrich param_completion_items() with descriptions + required flag from IAC source - Required params sorted first (sortText 0_lru_param_0_...) and marked with * - detail field shows * prefix for required params - Update /health to report iac_source_modules + yaml_lsp fields - Rewrite EDITOR_SETUP.md: WebSocket URLs, YAML schemas config for all editors (Helix, Neovim, PyCharm, VS Code) with azure-pipelines + gitea actions schemas - All 35 tests pass
This commit is contained in:
@@ -29,6 +29,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
PYTHON_LSP_PORT = int(os.getenv("PYTHON_LSP_PORT", "2087"))
|
||||
BICEP_LSP_PORT = int(os.getenv("BICEP_LSP_PORT", "2088"))
|
||||
YAML_LSP_PORT = int(os.getenv("YAML_LSP_PORT", "2090"))
|
||||
HTTP_PORT = int(os.getenv("HTTP_PORT", "8000"))
|
||||
|
||||
_CHUNK = 65536
|
||||
@@ -45,6 +46,20 @@ def _serve_python_lsp(port: int) -> None:
|
||||
logger.warning("pylsp exited (code %s) — restarting", proc.returncode)
|
||||
|
||||
|
||||
def _serve_yaml_lsp(port: int) -> None:
|
||||
"""Start yaml-language-server in TCP socket mode; restart on unexpected exit."""
|
||||
import shutil
|
||||
yaml_ls = shutil.which("yaml-language-server")
|
||||
if not yaml_ls:
|
||||
logger.warning("yaml-language-server not found — /yaml completions disabled")
|
||||
return
|
||||
while True:
|
||||
proc = subprocess.Popen([yaml_ls, f"--socket={port}"])
|
||||
logger.info("yaml-language-server listening on localhost:%d PID=%d", port, proc.pid)
|
||||
proc.wait()
|
||||
logger.warning("yaml-language-server exited (code %s) — restarting", proc.returncode)
|
||||
|
||||
|
||||
async def _pipe(reader: asyncio.StreamReader, writer) -> None:
|
||||
"""Pipe bytes from reader to writer until EOF."""
|
||||
try:
|
||||
@@ -109,10 +124,13 @@ async def _build_app() -> web.Application:
|
||||
app = web.Application()
|
||||
|
||||
async def health(_: web.Request) -> web.Response:
|
||||
import shutil
|
||||
return web.json_response({
|
||||
"status": "ok",
|
||||
"pypi_packages": len(PypiCatalog._packages),
|
||||
"bicep_modules": len(BicepModuleCatalog._modules),
|
||||
"iac_source_modules": len(BicepModuleCatalog._iac),
|
||||
"yaml_lsp": bool(shutil.which("yaml-language-server")),
|
||||
})
|
||||
|
||||
async def reload(_: web.Request) -> web.Response:
|
||||
@@ -132,10 +150,14 @@ async def _build_app() -> web.Application:
|
||||
async def bicep_ws(request: web.Request) -> web.WebSocketResponse:
|
||||
return await _ws_proxy(request, "127.0.0.1", BICEP_LSP_PORT)
|
||||
|
||||
async def yaml_ws(request: web.Request) -> web.WebSocketResponse:
|
||||
return await _ws_proxy(request, "127.0.0.1", YAML_LSP_PORT)
|
||||
|
||||
app.router.add_get("/health", health)
|
||||
app.router.add_post("/reload", reload)
|
||||
app.router.add_get("/python", python_ws)
|
||||
app.router.add_get("/bicep", bicep_ws)
|
||||
app.router.add_get("/yaml", yaml_ws)
|
||||
return app
|
||||
|
||||
|
||||
@@ -152,13 +174,17 @@ async def main_async() -> None:
|
||||
# LSP servers run internally on localhost — not exposed outside the container
|
||||
threading.Thread(target=_serve_python_lsp, args=(PYTHON_LSP_PORT,), daemon=True).start()
|
||||
threading.Thread(target=serve_bicep, args=(BICEP_LSP_PORT,), daemon=True).start()
|
||||
threading.Thread(target=_serve_yaml_lsp, args=(YAML_LSP_PORT,), daemon=True).start()
|
||||
|
||||
app = await _build_app()
|
||||
runner = web.AppRunner(app)
|
||||
await runner.setup()
|
||||
site = web.TCPSite(runner, "0.0.0.0", HTTP_PORT)
|
||||
await site.start()
|
||||
logger.info("iLSP HTTP on http://0.0.0.0:%d (ws://.../python ws://.../bicep)", HTTP_PORT)
|
||||
logger.info(
|
||||
"iLSP HTTP on http://0.0.0.0:%d (ws://.../python ws://.../bicep ws://.../yaml)",
|
||||
HTTP_PORT,
|
||||
)
|
||||
|
||||
await asyncio.Event().wait()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user