GNU TeXmacsUser manualReferenceAboutEnglish
Adding a feature or a provider of program code

A feature of program code is a question which a provider answers for the code at the cursor: which blocks fold here, what is the outline, where is the definition of this name. The core asks it (

code-features.scm

), a command of

progs/code

uses the answer, and tree-sitter and the language servers give it from their adapters. Neither the command nor the core knows which provider answers, nor whether a provider is part of the build.

1.The features and their answers

A provider is a procedure of no argument, called with the cursor where the feature is asked for, and a predicate of no argument, which tells whether it can answer there (cheap: it is called for the menus). Its answer, or #f (and '()) when it has none, which lets the next provider answer:

'fold-ranges

The blocks around the cursor which may fold, as a list of (first last) (rows of the lines of the code).

'fold-all-ranges

All the blocks which Fold all blocks folds, as above.

'outline

The entries (level kind name detail path) of the code, in their order: path is where the cursor goes, the names are in Cork.

'definition

Goes to the definition of the name at the cursor; #t when it did.

'syntax-errors

The items (severity start end message) of the code at the cursor (severity: 'error, 'warning or 'info; start, end: paths).

'server-diagnostics

No answer is used: a provider which is available means that a server gives the diagnostics of the code, and the syntax errors are not shown there.

'completion-context

Where the cursor is: 'code, 'string or 'comment.

'local-names

The names of the code (its definitions), which ⇥ completes where no server follows the code.

2.A provider

(code-provider-set! 'outline 'syntax 20
  (lambda () (and (syntax-cursor-language) #t))
  syntax-outline-at-cursor)

gives the feature 'outline a provider named 'syntax of rank 20: the providers are asked by rank, the lowest first (the servers have 10, tree-sitter 20, because a server sees the other files of a project). The preference code:outline chooses one by its name instead (auto, the default, by rank; off, none). code-provider-remove! takes a provider away, and code-available-providers tells which ones can answer at the cursor.

The providers of a feature which may be left out of a build are set in its adapter (

ts-code.scm

,

lsp-code.scm

). A new adapter goes into the list code-adapters of

code-features.scm

, with a glue routine which only a build with the feature has: the adapter is loaded the first time a feature is asked for, if that routine is defined and its file is there. The adapter may use the modules of its feature directly; nothing else may (a module which needs the functions of the syntax tree loads

code-syntax.scm

).

3.A feature

  1. The command, in a module of progs/code, asks the feature with code-ask and says so when no provider answers (set-message); code-available? tells whether it can be offered at the cursor.

  2. The command is defined lazily in

    init-texmacs.scm

    (lazy-define), and has an entry in focus-extra-menu of

    code-menu.scm

    and a key in

    prog-kbd.scm

    , if it is for all code.

  3. The providers which can answer register themselves in their adapters.

  4. The suite code (

    code-test.scm

    ) tests the command with providers of its own (names other than those of the adapters, ranks below theirs), which it removes at the end: it runs in every build. It ignores the preferences of the user (code-ignore-preferences!); a test never writes them.

  5. src/docs/code-features.md

    and the pages of this chapter say what the feature is, and the manual what the user sees (editing program code).

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".