Repository navigation
API 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_RESTARTstarts 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).
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
10298
10299
10300
10301
10302
10303
frozenset({10298, 10299, 10300, 10301, 10302, 10303})
'auto'
'off'
dict (25 entries)
class Place
Place(path: Path, row: int, column: int)Where the cursor was, for Go back.
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(LocationsWindow)
ProblemsWindow(number: int = 0)The language servers' errors and warnings in the open files.
def lf_offset(text: str, line: int, character: int) -> intA protocol position as an offset into text with \n newlines (what goto_location takes).
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).
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).
def completion_result(items: list[types.CompletionItem], text: str, offset: int, *, prefix: str | None = None, normalize: Callable[[str], str] | None = None, limit: int = 200) -> CompletionResultThe 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 LspMixinLanguage 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)fromlsp_store(empty without one). -
lsp_root(editor) -> Path | None: The folder a server ofeditor's file works in: the application'sfolder, else the file's. -
lsp_servers_for(language: str | None) -> list[ServerSpec]: The servers ofLSP_SERVERSforlanguage. -
lsp_server_for(editor) -> tuple[ServerSpec, list[str]] | None: Which servereditor's file goes to, and its command line; None: none. By default the settings' choice for its language (AUTO: the first ofLSP_SERVERSwhose command is found). -
lsp_make_session(server: ServerSpec, command: list[str], root: Path) -> LspSession: A new session ofserver(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 itsSMART_LANGUAGES. -
lsp_trigger(editor, char: str) -> bool: Typingcharopens the completion list by itself: one ofLSP_TRIGGERSthat 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 serveseditor's language. -
lsp_diagnostics_filter(text: str, items: list[types.Diagnostic]) -> list[types.Diagnostic]: The diagnostics kept (diagnostics_in'skeep): 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_hoverby default (an application also drops its language's open tags). -
lsp_normalize(name: str) -> str: A name as completion compares it (completion_result'snormalize): 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 ofeditor's server (without an editor: the first one running), or None. -
async lsp_ensure(editor) -> LspSession | None: The running session ofeditor'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 servername(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) -> Nonelsp_saved(window) -> Nonelsp_closed(window) -> Noneafter_open(window) -> Noneeditor_changed(window) -> Nonecursor_moved(window) -> Noneafter_save(window) -> Noneafter_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 ofview(aCodeEditor); 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 ofLSP_COMMANDS(from a worker):infomay be the editor window. False for another command, or one that needs an editor when there is none.
TurboFrame · part of Divengine · GPL-3.0-or-later · report an issue
Tutorial
Examples
The desktop
- The Desktop
- Application Mixins
- Windows and Lists
- Dialogs
- Histories
- Progress
- Themes and Colors
- Glyphs
- Settings and Recent Files
- Command Palette
Editing
Tasks
Languages
Running
Reference
Links