
    PL
jg                        U d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	  ej
        d          Zdaded<   d	a ej                    ZddZddZddZg dZdS )u?  Language Server Protocol (LSP) integration for Hermes Agent.

Hermes runs full language servers (pyright, gopls, rust-analyzer,
typescript-language-server, etc.) as subprocesses and pipes their
``textDocument/publishDiagnostics`` output into the post-write lint
delta filter used by ``write_file`` and ``patch``.

LSP is **gated on git workspace detection** — if the agent's cwd is
inside a git repository, LSP runs against that workspace; otherwise the
file_operations layer falls back to its existing in-process syntax
checks.  This keeps users on user-home cwd's (e.g. Telegram gateway
chats) from spawning daemons they don't need.

Public API:

    from agent.lsp import get_service

    svc = get_service()
    if svc and svc.enabled_for(path):
        await svc.touch_file(path)
        diags = svc.diagnostics_for(path)

The bulk of the wiring is internal — most callers only need the layer
in :func:`tools.file_operations.FileOperations._check_lint_delta`,
which is already wired (see that module).

Architecture is documented in ``website/docs/user-guide/features/lsp.md``.
    )annotationsN)Optional)
LSPServicez	agent.lspOptional[LSPService]_serviceFreturnc                    t           "t                                           rt           ndS t          5  t           .t                                           rt           ndcddd           S t          j                    a t
          st          j        t                     daddd           n# 1 swxY w Y   t            t                                           rt           ndS )a  Return the process-wide LSP service singleton, or None when disabled.

    The service is created lazily on first call.  ``None`` is returned
    when LSP is disabled in config, when no workspace can be detected,
    or when the platform doesn't support subprocess-based LSP servers.

    On first creation, registers an :mod:`atexit` handler that tears
    down spawned language servers on Python exit so a long-running
    CLI or gateway session doesn't leak pyright/gopls/etc. processes
    when it terminates.
    NT)	r   	is_active_service_lockr   create_from_config_atexit_registeredatexitregister_atexit_shutdown     6/home/kuhnn/.hermes/hermes-agent/agent/lsp/__init__.pyget_servicer   -   s    #--//9xxT9	 & &'1133=88& & & & & & & & 022! 	& O,---!%!& & & & & & & & & & & & & & &" !,1C1C1E1E,88DPs   )B('5B((B,/B,Nonec                     t           5  t          } daddd           n# 1 swxY w Y   | J	 |                                  dS # t          $ r&}t                              d|           Y d}~dS d}~ww xY wdS )z~Tear down the LSP service if one was started.

    Safe to call multiple times; safe to call when no service was created.
    NzLSP shutdown error: %s)r   r   shutdown	Exceptionloggerdebug)svces     r   shutdown_servicer   P   s     
                 	6LLNNNNN 	6 	6 	6LL11555555555	6 s#   
""A 
A2A--A2c                     	 t                       dS # t          $ r&} t                              d|            Y d} ~ dS d} ~ ww xY w)u   atexit-registered wrapper.  Logs at debug because by the time
    atexit fires the user has already seen the agent's final output —
    a noisy shutdown line on top of that is just clutter.zatexit LSP shutdown failed: %sN)r   r   r   r   )r   s    r   r   r   `   s_    : : : :5q999999999:s    
A=A)r   r   r   )r   r   )r   r   )__doc__
__future__r   r   logging	threadingtypingr   agent.lsp.managerr   	getLoggerr   r   __annotations__r   Lockr   r   r   r   __all__r   r   r   <module>r)      s     8 # " " " " "             ( ( ( ( ( (		;	'	'!% % % % % 	   Q  Q  Q  QF6 6 6 6 : : : : <
;
;r   