Skip to main content

optics-framework-lsp

A language server and linter for optics-framework test suites.

License Python 3.14+


An optics suite is CSV or YAML files referring to each other by name, and nothing checks that those names line up. This does, across the whole project and across both formats, over LSP while you type or as one command. Its rules come from optics-framework's own readers, so it agrees with the runtime.

Install

uv tool install optics-framework-lsp

Or from a checkout, for development:

uv sync

In an editor

Two packaged clients bundle the server's dependencies, so neither needs the steps above:

Both need a Python 3.12+ interpreter and attach to every *.csv, *.yaml and *.yml in the project without claiming those extensions, so whatever editor you already use for them is untouched. A file that is not a suite gets nothing back.


The linter

optics-lsp lint reports every problem in a suite in one shot. Point it at a project:

$ optics-lsp lint ~/projects/my_project

Line numbers are 1-based, matching your editor's status bar. A whole project takes about 60 ms including process start, because nothing on this path imports any LSP machinery.

The exit code is 0 whenever validation ran, findings or not. Non-zero means the input could not be read at all. Which severities should block a pipeline is your policy, so read status if you want that decision made for you.

JSON, for another program

Add --json for the machine-readable form. A caller holding uploaded files in memory, with nothing on disk, can pipe them in instead and skip the filesystem entirely:

$ echo '{"files": [{"name": "modules.csv", "content": "module_name,module_step\nM,Sleep\n"}]}' \
    | optics-lsp lint

Reading on stdin always answers JSON:

{
  "status": "FAIL",
  "analyzed": { "modules.csv": "modules" },
  "skipped": [],
  "diagnostics": [
    {
      "uri": "modules.csv",
      "severity": "error",
      "code": "keyword-arity",
      "message": "'Sleep' takes 1-1 params, got 0",
      "row": 2,
      "range": { "startLine": 1, "startColumn": 0, "endLine": 2, "endColumn": 0 },
      "source": "optics"
    }
  ]
}

row is 1-based for a person, range is 0-based for an editor. Diagnostics arrive sorted by file then row, so a caller need not re-sort.

Shelling out from Node: pass the arguments as an array with the payload on stdin rather than interpolating either into a shell string, and raise maxBuffer past its 1 MB default.

analyzed and skipped: which files were even looked at

File kind comes from the contents, not the filename: a csv's header row, a yaml's top-level keys. analyzed says what each file became (test_cases, modules, elements, error_definitions, and for a yaml holding several, all of them); skipped lists the files that matched none.

optics ignores those files too, so a skipped file is usually a dataset and fine. But a test_cases file with a typo in its header lands there as well, and would otherwise be indistinguishable from a clean one.

What it reports

Two severities, and the line between them is one question: does optics fail, or does it run and do something you probably didn't mean?

Errors are a name that resolves to nothing, or a call the keyword rejects:

code meaning
module-not-found a test step names a module no file defines
keyword-not-found a module step is neither a keyword nor another module
keyword-arity a keyword got too few or too many params
element-not-found a ${ref} has no element and nothing binds it

Warnings mean it loads, but a row you wrote isn't doing what it looks like:

code meaning
duplicate-module, duplicate-test-case the later definition wins, wherever the files sit
duplicate-element a file repeats an entire element row
duplicate-error-code, duplicate-match-string error definitions merge across files, so these clash
error-definition-incomplete a row missing a column, so it never matches
csv-too-few-columns the reader skips the row
csv-too-many-columns the extra cells are dropped
csv-whitespace-line a row of nothing but separators

YAML is a peer of CSV at run time but a rough one, and every way it goes wrong goes wrong silently — the reader logs and carries on with an empty section, so the run fails somewhere that says nothing about the cause. These are errors:

code meaning
yaml-step-without-variable a step with no ${...}, so its params are swallowed into the keyword name and Sleep 5 looks up sleep_5
yaml-section-key-case test_cases: where the reader looks up Test Cases, so the section loads empty
yaml-section-shape Test Cases or Modules as a mapping rather than a list of single-key mappings, which aborts the run
yaml-step-not-a-string anything else as a step, which aborts the run
yaml-parse-error malformed yaml, which optics reads as an empty file
yaml-error-definitions-unread a warning: error definitions have no yaml form, only csv

The language server

Run with no arguments and it speaks LSP over stdio. Unknown flags are ignored rather than rejected, so a client that insists on passing --stdio needs no special handling.

One workspace folder is one project. Cross-file rules mean a single edit can change diagnostics anywhere in the suite, so the whole folder is revalidated on every change, and the server asks the client to watch **/*.{csv,yaml,yml} so a git checkout is picked up too. Open buffers override what is on disk. Dot folders are never descended into, because a project's .venv holds optics-framework's own sample suites and images, which would invent element and module names the project does not have.

Features

Diagnostics

Everything from the linter section above, live, across the whole project. Because resolution is a project-wide question, defining an element in one file clears the element-not-found in another without touching it.

Completion

Aware of where you are, because in a CSV the column is the context — and in a YAML the section and the depth are.

where the cursor is what is offered
an empty file the four header rows, or the three yaml section keys, since either decides the file's kind
module_step, or a yaml Modules step every keyword and every module in the project, since a step can be either
a param cell what that particular keyword accepts at that position
test_step, module_name modules that already exist, since both columns continue a block
element_name names used somewhere but never defined
any element_id*, or a yaml locator template image filenames found anywhere in the project
test_case existing test cases, plus the lifecycle names (Suite Setup, …) not yet used

In a YAML the section and the indent stand in for the column, and a step's params are the words after the keyword rather than cells of their own. A half-typed multi-word keyword is replaced whole, so Press El completes to Press Element rather than nesting.

Param completion is specific rather than generic. Read Data's second param offers the project's data files; Invoke API's first offers collection.api identifiers parsed out of the project's YAML; Run Loop and Execute Module offer modules, written bare. Params with a documented set of values offer exactly those. direction gives up, down, left, right; rule gives any, all; element_state gives visible, invisible, enabled, disabled. Condition alternates condition and target, so it offers modules in the target slots and modules-or-variables in the others, with ! inversion preserved.

Accepting a param the header does not yet cover widens the header in the same edit, because csv.DictReader drops cells the header does not name and the param would otherwise silently vanish. A YAML has no header to widen.

Hover

A keyword's real signature and the framework's own docstring, which is where the accepted values are actually written:

Press Element(element, repeat='1', offset_x='0', offset_y='0', index='0',
              aoi_x='0', aoi_y='0', aoi_width='100', aoi_height='100', event_name=None)

Press a specified element.

:param element: The element to be pressed (text, xpath or image).
:param repeat: Number of times to repeat the press.
:param index: Index of the element if multiple matches are found.
:param aoi_width: Width percentage of Area of Interest (0-100). Default: 100.

Defaults are rendered as name='value', so what an omitted cell falls back to is visible without reading the source.

Signature help

The keyword's params with the column you are in marked active, retriggering on every comma, which is how you tell param 4 from param 5 in a row of commas.

Goto definition

From a step to the module it runs, or from a ${ref} to the elements it reads. Every ${name} in the cell is offered, not just one: a fallback element is several rows, and so is ${a} == ${b}.

Two details it gets right. A module_step naming something that is also a keyword resolves to the keyword, so a same-named module is not offered, mirroring what the runner does. And Condition's !Name inversion is stripped the same way the runner strips it.

Find references

Every place a name is used across the project, optionally including where it is bound. Works on test cases, modules, elements and error codes, the things the project owns. A keyword belongs to the framework, and an image, data file or API identifier names something outside the CSVs, so neither comes back from here.

Rename

Renames across every file that writes the name, with prepare-rename so the client can reject an invalid position before you start typing. This is the feature that most needs to be project-wide: the runner keys everything by name, so a rename that misses one cell quietly changes what runs instead of failing loudly.

Document symbols

One file's outline: what it defines, and the rows making each one up:

Open App          [Function]  2 steps
    Launch App    [Method]
    Sleep         [Method]    2
Login             [Function]  1 step
    Press Element [Method]    ${btn}
Workspace symbols

Every name the project declares, searchable from anywhere — "Go to Symbol in Workspace" in VS Code, workspace/symbol on the wire. Declarations only: a module's steps and an element's locators belong to the file outline, and repeating them here would bury the handful of names being searched for under every row that mentions them.

kind what it is
Class a test case
Function a module
Variable an element, once, however many locator rows it has
Constant an error code

The match is a case-insensitive substring, and each result carries the kind its file's contents made it (modules, test_cases, …) as the container, since that is the only thing telling a module from a test case of the same name.

Semantic tokens

Highlighting neither grammar can express, because the meaning of a piece of a suite depends on where it sits and on the rest of the project:

token what it marks
keyword the header row, or a yaml's section keys: the names that decide what the file is
class a test case
function a module, wherever it is named
method a step that resolves to a framework keyword
variable ${name}, and an element_name that defines one
string a locator, a data file, an API identifier
enumMember an error code, and a param with a documented set of values
operator the ! that inverts a Condition

A framework keyword also carries the defaultLibrary modifier, so themes colour it apart from a module of the same shape, which they would otherwise draw identically.


AI agents

Both editor clients offer the server over MCP, so an agent can ask it about the whole project rather than only the open files. Automatic in VS Code; Tools | Configure Optics LSP MCP Server in JetBrains IDEs. See editors/code and editors/intellij.

For anything with a shell, optics-lsp lint . --json needs no bridge at all.


The keyword catalog

src/optics_framework_lsp/keywords.py is generated and holds 49 keywords from optics-framework 1.9.3: each one's params, which are required, the defaults, and the framework's own docstring, which is where hover text and the param values come from.

It is compiled in rather than read from your environment. Importing optics_framework.api.* pulls numpy, cv2, pandas and skimage through common.optics_builder, needing a 342 MB install and failing outright if any one of those is broken, leaving a project with no keyword diagnostics at all and no explanation why.

To refresh it for a new optics release:

python scripts/update_catalog.py ~/src/optics-framework
python scripts/update_catalog.py --check    # exits 1 if the committed table is stale

Signatures are read with ast, never imported, which is what lets the script run against a bare checkout or a --no-deps install and makes it usable for diffing two releases. It refuses to run if one of the four API classes gains a base class, since that would mean keywords it cannot see. A test runs --check, so a stale table fails the suite.

Development

uv run pytest tests/ -q

One test needs optics-framework itself and skips without it; point OPTICS_PROBE_VENV at a virtualenv that has it to run that one.

The engine is deliberately protocol-free. validate() returns plain Finding objects and each transport converts at its own boundary: server.py to lsprotocol diagnostics, lint.py to JSON. import lsprotocol.types alone costs ~290 ms, which a long-lived server pays once and a per-call command would pay every time. tests/test_lint.py asserts the lint path imports neither pygls nor lsprotocol, so it stays that way.

License

Apache 2.0.

Release files for optics-framework-lsp 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for optics-framework-lsp 1.2.1
File Size Uploaded
optics_framework_lsp-1.2.1.tar.gz 60.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for optics-framework-lsp 1.2.1
File Interpreter ABI Platform
optics_framework_lsp-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 126.3 kB

Release files / optics_framework_lsp-1.2.1.tar.gz

Download URL optics_framework_lsp-1.2.1.tar.gz
Size 60.6 kB
Tags Source
SHA-256 checksum
How to use checksums
67588a6db34c1e0616e3f62fc7b35e62d17a1a88c10016e428576f48c5d110c9
BLAKE2b-256 checksum
How to use checksums
398ee1a9d38a6d140542659f5d323ad379d42fb48ab34e57e99bb1b87c382d55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 9, 2026.

Transparency log

Release files / optics_framework_lsp-1.2.1-py3-none-any.whl

Download URL optics_framework_lsp-1.2.1-py3-none-any.whl
Size 65.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cfe8bb1c94616196e5ba25741a06508b0bf1d0933e28b829dd2f1466f4f5ba1b
BLAKE2b-256 checksum
How to use checksums
08100e9b48594e407e5164a2b465fb67beae63298deb130da8ec6080f45c12ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 9, 2026.

Transparency log

Release history Release notifications | RSS feed

1.3.0

2 release files

This release

1.2.1 This release

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page