![]() |
Pitfalls of the features of program code | ![]() |
What went wrong while the features of program code were made, and what to keep in mind when they change.
A feature is there when its glue is ((defined? 'tree-sitter-program-language), (defined? 'lsp-start)), not when its Scheme files are: they are installed in every build.
The functions of
ts-edit.scm
are public: once it is loaded, they replace the stubs of
code-syntax-none.scm
in all the modules. A module which :uses it directly loads it in a build without tree-sitter, whose first call then fails (an unbound glue routine): it was so for sessions and program inputs. Use (code code-syntax).
The modules of tree-sitter call its glue when they are loaded: a test suite which :uses them at the start makes every suite fail without tree-sitter.
check-master.scm
loads the modules of the suites treesit and lsp when they run.
Run the suites in the three builds (both features, without tree-sitter, without the servers) after a change of the core: a test which expects what one feature does (the quotes which tree-sitter balances) checks for the feature.
In S7, '() is true: code-ask skips it explicitly, so that an empty answer lets the next provider answer.
In a tm-menu, when greys its entries and assuming hides them: a test of a menu sees the labels of the greyed entries.
An overload of focus-extra-menu ends with (dynamic (former t)), and an overload of a notify- hook calls (former …): the one which is defined last would else replace the others (the entries of sessions and program inputs).
In notify-cursor-moved and notify-buffer-changed, the mode predicates (in-prog?) are those of an environment which is not up to date: decide from what is known of the buffer, or later (delayed).
The state of a line is kept on its highlight observers: an edit of the line forgets it, an edit of another line does not. A line keeps at most 9 nested folds (CODE_FOLD_MAX); code-fold-lines refuses a deeper one.
The mark of the first line of a fold depends on the next line, which is not one of the inputs of its bridge, and is drawn after the end of the line: the part of the window which is drawn again after a change is that of the line as it was. The commands of the folds draw the whole window again once (refresh-window, delayed).
While the document is being modified (the cursor moved into a fold by an edit), tree->path of a line is #f: its update is delayed.
Deleting the first line of a fold at the start of the code leaves hidden lines with no line before them: code-unfold-all and the cursor which comes there show them.
The removal of a highlight leaves an empty place in the list of observers of a line (remove_highlight):
code_lines.cpp
makes the list shorter, else a line folded many times would have a long one, which every typesetting of the line goes through.
An edit of a line removes its layers but keeps its tree: an undo gives it back its text without them. A decoration which is the same as before is given again when the line has none (
lsp-decorate.scm
).
The diagnostics are kept as paths: those of the code blocks of a document are computed again from their lines when the document changes (a paragraph inserted above a block moves them), those of the syntax tree are cleared when the cursor leaves the code.
A code block is known by its tree and its language: a block whose language changes gets a new virtual file, the former one is closed. The virtual files are named after the document with its suffix (two documents notes.tm and notes.html do not share them).
Looking for the code blocks walks the whole document in Scheme: it is done at the first sync of a document and at each save; the other syncs look at the known blocks and the one at the cursor.
The lines of a unit are made again from its blocks at each use at the cursor (lsp-unit-set-roots!), which costs the lines of all the blocks of the language: fine for the documents with code which people write, not for one with thousands of lines of code in blocks. A line of a unit is a line of a block: a range of the server over two blocks is drawn from its start, and an edit which would join or split blocks is not applied.
The tests turn the code blocks on with lsp-blocks-force! and choose the units with lsp-blocks-join-force!, not with the preferences.
The scripts of the Vue GUI (TEXMACS_VUE_SCRIPT) type key std ( as a parenthesis: the keys of the folds are key M-S-9 and key M-S-0. What display* writes there goes to the log of the process.
A fresh home shows the welcome page instead of the file: start from a copy of a home which has been used.