Skip to content

Commit a3573a6

Browse files
committed
document the program-model requests and keyword highlighting
`by/entryPoint`, `by/testItems`, `by/runModules`, `by/buildOutput` and `by/syntaxOutline` arrive over several commits but read as one thing: the questions an editor used to answer by guessing at a layout the build decides. `editor.md` already names `by/alignmentGroups` and `by/dataFlowAt`, so they belong beside those rather than scattered across the commits that added them.
1 parent 02343fc commit a3573a6

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

‎docs/basedpython/features/editor.md‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,46 @@ decided by working out the rewrite, so the actions a `textDocument/codeAction`
366366
reply offers have each been computed to answer it. send `only` to narrow that —
367367
a request that does not ask for `refactor` kinds does no refactoring work at all
368368

369+
## keyword highlighting
370+
371+
`textDocument/documentHighlight` on a keyword answers the keywords that belong
372+
with it rather than the occurrences of a symbol: the `elif`s and `else` of an
373+
`if`, the `except`, `else` and `finally` of a `try`, the `return`s of a `def`.
374+
the pairing is read off the parse tree, so `match = 1` is an assignment and
375+
nothing lights up on it. a position that is not a keyword is answered the way it
376+
always was
377+
378+
## the program model
379+
380+
a run configuration, a test list and a "go to generated file" are all questions
381+
about the project rather than about a position in a file, and each used to be an
382+
editor's own guess at a layout the build decides. the server answers them
383+
instead, from the same reading the transpiler and the checker use:
384+
385+
| request | answers |
386+
| ------------------ | --------------------------------------------------------------------------- |
387+
| `by/entryPoint` | whether a module has a `main`, and the command line the transpiler gives it |
388+
| `by/testItems` | the tests pytest collects from a document, with their node ids |
389+
| `by/runModules` | the modules `by run` can be given, and the one `run.main` names |
390+
| `by/buildOutput` | where a project's build writes, and which output came from which source |
391+
| `by/syntaxOutline` | a document's suites, clause keywords, call statements and string parts |
392+
393+
`by/buildOutput` maps both ways: given a `.by` it names the file the build writes
394+
it to, given a file in the build directory it names the source. the path inside
395+
the build follows the *module* tree, not the directory tree, so a src-layout
396+
project's `src/pkg/main.by` is `build/pkg/main.py` — which is why this is the
397+
build's answer rather than a path an editor can assemble
398+
399+
`by/syntaxOutline` answers one document whole, on every revision the client wants
400+
to serve features from: it is what an editor needs to type in an
401+
indentation-delimited language — which line opens a suite, where a compound
402+
statement ends, what a string literal's escapes and interpolations are, and how
403+
much indentation a triple-quoted string has stripped
404+
405+
`.by` test files are collected under the same names as python ones — `test_*.by`
406+
and `*_test.by` — because a `.by` transpiles to the `.py` of the same stem, and
407+
that is the file pytest sees
408+
369409
## debugger facts
370410

371411
while a program is stopped, an editor knows something no checker does: what the

0 commit comments

Comments
 (0)