Skip to content

API turboframe.ui.lsp

rafageist edited this page Dec 4, 2026 · 4 revisions

turboframe.ui.lsp

Source: turboframe/ui/lsp.py. Generated from the code of TurboFrame 0.3.0 by tools/wiki_api.py.

A language server in the editor: its documents, diagnostics, completions, signatures, hovers, definitions, references and problems.

LspMixin is part of the application (a DesktopApp with turboframe.ui.editing.EditorMixin). It implements the hooks turboframe.ui.editor.CodeEditor looks for on the application (lsp_complete, lsp_document, lsp_signature_changed, lsp_go_to_definition) and follows the editors (after_open, editor_changed, after_save, after_close):

  • a server starts when the first file of its language opens (the status line's spinner says so) and learns of every change; its errors and warnings are drawn in the editor (set_diagnostics) and listed in the Problems window (CM_LSP_PROBLEMS);
  • its completions fill the completion list as you type (or with Ctrl+Space), with the selected one's documentation beside it; a call's signature shows over the line while its arguments are typed;
  • Symbol information (CM_LSP_HOVER) shows its hover under the cursor; Go to definition (CM_LSP_DEFINITION, or Ctrl+click) opens the definition; Find references (CM_LSP_REFERENCES) lists the uses in the References window; Go back (CM_LSP_BACK) returns to where the last jump started; CM_LSP_RESTART starts the servers again.

Several servers can run, one per ServerSpec (the application's LSP_SERVERS, each with its language); lsp_server_for(editor) says which one an editor's file goes to, and the settings' store (lsp_store: load() and save(dict)) can choose a server per language ("lsp": language to a server's name, "auto" or "off") and give a server's command ("lsp_commands"). The other hooks: lsp_session_class (an LspSession subclass), lsp_root(editor), lsp_wants(editor), lsp_trigger(editor, char), lsp_in_call(editor), lsp_quiet_here(editor, line), lsp_no_server_message(editor), lsp_diagnostics_filter(text, items), lsp_clean(text), lsp_normalize(name) and place_lsp_window(window). lsp_command(command, info) runs the commands for the application's run_command; lsp_shutdown() stops every server before the application exits.

The pure parts are exported: completion_result (a server's items as the completion list), signature_layout (a signature as the box shows it, its parameter marked), reference_items and the two windows. It needs pygls (the lsp extra).

Contents

CM_LSP_DEFINITION, CM_LSP_REFERENCES, CM_LSP_HOVER, CM_LSP_BACK, CM_LSP_PROBLEMS, CM_LSP_RESTART, LSP_COMMANDS, AUTO, OFF, KIND, Place, ReferencesWindow, ProblemsWindow, lf_offset, reference_items, signature_layout, completion_result, LspMixin

CM_LSP_DEFINITION

10298

CM_LSP_REFERENCES

10299

CM_LSP_HOVER

10300

CM_LSP_BACK

10301

CM_LSP_PROBLEMS

10302

CM_LSP_RESTART

10303

LSP_COMMANDS

frozenset({10298, 10299, 10300, 10301, 10302, 10303})

AUTO

'auto'

OFF

'off'

KIND

dict (25 entries)

class Place

class Place
Place(path: Path, row: int, column: int)

Where the cursor was, for Go back.

class ReferencesWindow

class ReferencesWindow(LocationsWindow)
ReferencesWindow(number: int = 0)

Where a symbol is used, one row per place: Enter goes there (Go back comes back).

  • activate(index: int) -> None

class ProblemsWindow

class ProblemsWindow(LocationsWindow)
ProblemsWindow(number: int = 0)

The language servers' errors and warnings in the open files.

lf_offset

def lf_offset(text: str, line: int, character: int) -> int

A protocol position as an offset into text with \n newlines (what goto_location takes).

reference_items

def reference_items(root: Path | None, found: list[Location], texts: dict[Path, str]) -> list[MessageItem]

The heading, then a row per place: path:line: the line's text (texts: each file's text).

signature_layout

def signature_layout(found: types.SignatureHelp | None, width: int, *, clean: Callable[[str], str] = <function clean_hover>)

(lines, mark) for the signature box (turboframe.ui.completion.signature_lines), or None (not in a call). The label's white space is collapsed, and the active parameter's span follows it; clean makes the documentation text (turboframe.lsp.clean_hover).

completion_result

def completion_result(items: list[types.CompletionItem], text: str, offset: int, *, prefix: str | None = None, normalize: Callable[[str], str] | None = None, limit: int = 200) -> CompletionResult

The server's items as the completion list at offset in text, filtered by what is typed.

prefix is what the items replace (the name before the cursor by default); an item is kept when its name starts with it, case ignored, or when it does once both pass through normalize (a language's sigils: "$", a namespace's "\"). Snippets become text with the caret in place; the other edits that come with an item (an import line) are kept as offsets. At most limit items, in the server's order.

class LspMixin

class LspMixin

Language servers in the editors, mixed into a DesktopApp with EditorMixin.

LSP_SERVERS are the servers the application knows; lsp_store keeps the user's choices; the hooks below have defaults. LSP_NAME is what a completion replaces (a regular expression ending in $), LSP_SIGILS the characters a name may start with that are not part of it ("$"), LSP_TRIGGERS the characters after which the list opens by itself (when the server says they trigger it).

  • back_places (property): Where Go back returns, the last one last.
  • lsp_settings() -> tuple[dict[str, str], dict[str, list[str]]]: (choice per language, command per server) from lsp_store (empty without one).
  • lsp_root(editor) -> Path | None: The folder a server of editor's file works in: the application's folder, else the file's.
  • lsp_servers_for(language: str | None) -> list[ServerSpec]: The servers of LSP_SERVERS for language.
  • lsp_server_for(editor) -> tuple[ServerSpec, list[str]] | None: Which server editor's file goes to, and its command line; None: none. By default the settings' choice for its language (AUTO: the first of LSP_SERVERS whose command is found).
  • lsp_make_session(server: ServerSpec, command: list[str], root: Path) -> LspSession: A new session of server (lsp_session_class), its callbacks the mixin's.
  • lsp_wants(editor) -> bool: editor's text goes to a server: a file (not untitled) in one of its SMART_LANGUAGES.
  • lsp_trigger(editor, char: str) -> bool: Typing char opens the completion list by itself: one of LSP_TRIGGERS that the server says triggers it.
  • lsp_in_call(editor) -> bool: The cursor is still inside the call the server's signature is about (a language checks its parentheses); True by default: the server's word.
  • lsp_quiet_here(editor, line: str) -> bool: No list opens by itself here (line: the line up to the cursor; a comment or a string, where there are no names to complete); False by default.
  • lsp_no_server_message(editor) -> str: What the user is told (once per language) when no server serves editor's language.
  • lsp_diagnostics_filter(text: str, items: list[types.Diagnostic]) -> list[types.Diagnostic]: The diagnostics kept (diagnostics_in's keep): an application drops the idioms a static analyser misreads. All of them by default.
  • lsp_clean(text: str) -> str: A hover's or a documentation's text as the boxes show it: turboframe.lsp.clean_hover by default (an application also drops its language's open tags).
  • lsp_normalize(name: str) -> str: A name as completion compares it (completion_result's normalize): itself by default.
  • place_lsp_window(window: LocationsWindow) -> None: Put a new References or Problems window on the desktop (an application puts it along the bottom).
  • lsp_session(editor=None) -> LspSession | None: The running session of editor's server (without an editor: the first one running), or None.
  • async lsp_ensure(editor) -> LspSession | None: The running session of editor's server, started if needed (None: no server, it failed, or the application is exiting).
  • async lsp_stop(name: str | None = None) -> None: Stop the server name (every one without a name): a restart, a folder changed, the exit. One still starting ends as soon as it can.
  • async lsp_restart() -> None: Stop the servers and start them again for the editors that want one (new settings, a server stuck).
  • async lsp_shutdown() -> None: The application exits: nothing starts a server again, and every one stops.
  • lsp_changed(window) -> None: window's text changed (or it opened): the server hears of it once the keys pause.
  • lsp_sync(window) -> None
  • lsp_saved(window) -> None
  • lsp_closed(window) -> None
  • after_open(window) -> None
  • editor_changed(window) -> None
  • cursor_moved(window) -> None
  • after_save(window) -> None
  • after_close(window) -> None
  • lsp_working (property): A server is busy with work of its own (indexing).
  • lsp_complete(view, explicit: bool) -> None: Ask the server for completions at the cursor of view (a CodeEditor); shown when they come.
  • lsp_signature_changed(view) -> None: Typed in a call (( or ,), or moved while its signature shows: ask again.
  • lsp_document(view, item: Completion) -> None: The documentation of the selected completion, beside the list.
  • async lsp_hover(window) -> None: Symbol information: what the server knows about the name under the cursor, in a box under it.
  • lsp_go_to_definition(view) -> None: Ctrl+click in an editor: Go to definition.
  • async lsp_definition(window) -> None: Go to definition: where the server says the name under the cursor is defined (Go back returns).
  • async lsp_references(window) -> None: Find references: every use of the name under the cursor, in the References window.
  • remember_place(window=None) -> None: Where the cursor is, for Go back.
  • async go_back() -> None: Go back: to where the last Go to definition, or reference, was taken.
  • problems_window() -> ProblemsWindow | None
  • problem_items() -> list[MessageItem]: A row per diagnostic of the open editors: name:line:column: severity: message.
  • show_problems() -> ProblemsWindow: The Problems window, opened if it is not, on top.
  • lsp_status(editor=None) -> str: For the status line and messages: editor's server (the active editor's), or why there is none.
  • async lsp_command(command: int, info: object = None) -> bool: Run one of LSP_COMMANDS (from a worker): info may be the editor window. False for another command, or one that needs an editor when there is none.

Clone this wiki locally