Skip to main content

Module lsp_helpers

Module lsp_helpers 

Source
Expand description

Phase 5.5.LSP.1 step 2: pure LSP utility helpers, lifted from lattice_ui_tui::app. These functions translate between the editor’s internal byte-indexed shapes and lsp-types’s wire shapes (UTF-16 column positions, hover-content markdown). They depend only on lattice_core::Buffer, lattice_grammar::Position, and lattice_lsp::position – all host-side – so they have no reason to live in the renderer crate.

lattice_ui_tui::app re-exports both names under their original crate::app:: paths so the existing ~18 call sites (App-side LSP request helpers) continue to compile unchanged through the rest of the LSP cluster migration.

Functions§

app_to_lsp_position
Convert an editor-side Position (line + utf-8 byte column) into the LSP-side lattice_lsp::lsp_types::Position (line + utf-16 code- unit column). Returns None when the line index is past the end of the buffer – e.g. cursor on a sentinel row past EOF.
call_hierarchy_to_row
Render one CallHierarchyItem (the caller / callee) as a SymbolRow for the picker. The item’s detail (if any) plus the originating callable’s name ride in container. Phase 5.8.AD.2: hoisted from TUI App.
code_action_kind_glyph
Map an LSP CodeActionKind to a one-char glyph used in the picker margin (🛠, ♻, ↗, etc.). Unknown / custom kinds and bare Command payloads land on ?. Phase 5.8.AD.2.
completion_kind_glyph
5.5.LSP.4: single-character glyph for an LSP CompletionItemKind. Same shape as symbol_kind_glyph but maps the completion-item kind enum (which is wider – snippets, keywords, folders, etc.). Used by the LSP completion picker / insert-completion overlay row marginalia.
cursor_inside_range
Is the editor cursor inside the half-open LSP range? Compares only by (line, character) in LSP utf-16 space because the range is LSP-shape; the host cursor is assumed converted. Phase 5.8.AD.2: hoisted from TUI App.
definition_response_to_locations
5.5.LSP.2: flatten an LSP GotoDefinitionResponse (Scalar / Array / Link) into a uniform Vec<Location>. The Link shape carries richer per-result info (origin selection range used to highlight the symbol the user clicked); we drop it for now and keep the target location only – the App’s jump path is position-only. When 4.2.d’s picker buffer lands the link metadata (e.g., target_selection_range for narrower jump destinations) becomes useful and this function gains a richer sibling.
flatten_document_symbol_response
5.5.LSP.5: flatten an LSP DocumentSymbolResponse into a pre-rendered Vec<SymbolRow>. The legacy Flat(Vec<SymbolInformation>) variant is one row per symbol with no nesting; the modern Nested(Vec<DocumentSymbol>) variant carries children: Vec<DocumentSymbol>, walked depth-first to preserve outline ordering.
flatten_selection_range_chain
4.4.e: flatten an LSP SelectionRange (linked list via parent) into a Vec<Range> ordered innermost-first. Phase 5.8.AD.2: hoisted from TUI App.
hover_contents_to_markdown
prepare_rename_placeholder
Extract a placeholder name from a PrepareRenameResponse, if the server supplied one. Used when the user invoked :rename without a name. Phase 5.8.AD.2.
range_covers
Render an LSP HoverContents payload to a markdown string the renderer’s hover popup pipeline can highlight via the markdown grammar.
signature_help_to_markdown
5.5.LSP.4: render an LSP SignatureHelp payload to a markdown string the popup renderer can display. Picks the active signature (server-supplied active_signature index, default 0) and inlines the active parameter’s documentation when present. Returns the empty string when the response carries no signatures – the caller surfaces “no signature info”.
symbol_information_to_row
5.5.LSP.5: project an LSP SymbolInformation (legacy outline + workspace-symbol shape) into a SymbolRow. Returns None when the location’s URI doesn’t resolve to a path.
symbol_kind_glyph
5.5.LSP.5: single-character glyph for an LSP SymbolKind. Picked to fit a fixed-width column in picker rows so the marginalia column stays aligned. Falls back to ? for kinds we don’t have a specific glyph for.
type_hierarchy_to_row
4.5.b: render one TypeHierarchyItem (a supertype or subtype of the cursor’s type) as a [SymbolRow] for the picker. Same projection as call_hierarchy_to_row because the item shape is identical. Phase 5.8.AD.2.
word_under_cursor
5.5.LSP.2: extract the word-class span straddling cursor on the cursor’s line. Returns None when the cursor is not on a word character – “no symbol under cursor” is preferable to a label that jumps to a different identifier than the user pointed at. Used by the LSP nav / references dispatchers to label the tag-stack entry + the picker title.
workspace_symbol_to_row
5.5.LSP.5: convert a modern (LSP 3.17+) WorkspaceSymbol into a SymbolRow. When the symbol’s location came back as the WorkspaceLocation (URI-only) variant, fires workspaceSymbol/resolve against the originating server to upgrade to a real Location with range. Returns None when the URI doesn’t map to a path; resolve failures fall back to (0, 0) so the row stays navigable.