LSP State changes: Adds a PreviewState to maintain all preview state in lsp, corresponding to LanguageState and CompileState.
LanguageState owns an only PreviewState
lsp can start with only PreviewState in future, to achieve minimal LSP, as mentioned in #357.
New command group:
doStartPreview: An internal command, starts a preview session and returns the exporting ports: dataPlanePort and staticServerPort.
doKillPreview: Kill a running preview unconditionally.
scrollPreview: editor informs preview panels to scroll.
New notifications:
tinymist/preview/scrollSource: preview panels informs editor to scroll documents.
tinymist/documentOutline: informs changes of layout-stage document outline (compared with eval-stage document outline)
tinymist/preview/dispose: informs a closed preview session event.
Todo list:
[x] Kill preview actors correctly.
Allow multiple preview instances at the same time.
Left work in future PR.
Respect preview's compile arguments, like typst-preview.inputs or typst-preview.fontPaths.
We have ignored them and added deprecation notes.
[x] Previewing in browser seems to not stop correctly.
Control Plane is removed
Editor -> Control Plane messages are replaced by lsp commands.
Control Plane -> Editor messages are replaced by lsp noptifications.
New State Management
Since tinymist lsp is a long-running service, while typst preview was an one-shot program, we must introduce task/session concept. Client must allocate a task id for each session, and refer to the concrete session by the id in latter requests.
However, to avoid resource leaking, I'm trying to let preview session closed automatically in very nice timing. Compared with new/free API, we use start/kill API.
new/free are hard to use. They are c-style and you may leak some preview sessions easily.
start will create a data plane server. When no any client of the data plane is alive for about 5 seconds (or other time limit), the session will get closed. When the client side preview panel is disposed, client will kill the session as well.
kill is idempotent, you can invoke it for multiple times.
Previous PRs:
364
337
332
323
Implementation notes:
PreviewState
to maintain all preview state in lsp, corresponding toLanguageState
andCompileState
.LanguageState
owns an onlyPreviewState
PreviewState
in future, to achieve minimal LSP, as mentioned in #357.doStartPreview
: An internal command, starts a preview session and returns the exporting ports:dataPlanePort
andstaticServerPort
.doKillPreview
: Kill a running preview unconditionally.scrollPreview
: editor informs preview panels to scroll.tinymist/preview/scrollSource
: preview panels informs editor to scroll documents.tinymist/documentOutline
: informs changes of layout-stage document outline (compared with eval-stage document outline)tinymist/preview/dispose
: informs a closed preview session event.Todo list:
Allow multiple preview instances at the same time.Respect preview's compile arguments, liketypst-preview.inputs
ortypst-preview.fontPaths
.Control Plane is removed
Editor -> Control Plane
messages are replaced by lsp commands.Control Plane -> Editor
messages are replaced by lsp noptifications.New State Management
Since tinymist lsp is a long-running service, while typst preview was an one-shot program, we must introduce task/session concept. Client must allocate a task id for each session, and refer to the concrete session by the id in latter requests.
However, to avoid resource leaking, I'm trying to let preview session closed automatically in very nice timing. Compared with
new
/free
API, we usestart
/kill
API.new
/free
are hard to use. They are c-style and you may leak some preview sessions easily.start
will create a data plane server. When no any client of the data plane is alive for about 5 seconds (or other time limit), the session will get closed. When the client side preview panel is disposed, client will kill the session as well.kill
is idempotent, you can invoke it for multiple times.