Crystal-Modeling / tasklist-lang

Langium-based LS for TaskList language implemented in GLSP blueprints. Integrated with GLSP as SourceModel Server for demo purpose
Apache License 2.0
3 stars 1 forks source link

Learn LSP for backward model modification #19

Closed hpopov closed 1 year ago

hpopov commented 1 year ago

Learn LSP capabilities, such as formatting (how LS changes are propagated back to the editor?), code actions (the API used in Sprotty Server to enable graphical editing), and LSP content assist (used in form of a VSCode-like popup to change cross-references)

This is a preliminary task for #20

hpopov commented 1 year ago
hpopov commented 1 year ago

Formatting

Why I cannot use LSP Code actions to create new tasks: because in Code Actions you have no context about existing tasks, which mean, you cannot guarantee, that newly created task will have semantically valid name. The only case is to create tasks with empty name, but I would rather make empty names invalid too (e.g., when I create new task with 'next' Code Action, it creates both a new task and a reference to it from the current one).

I will not be able to use LangiumFormatter (or any other implementation of LSP formatter I guess), because vscode-languageserver-types FormattingOptions do not suggest a possibility of inserting custom symbols (only whitespaces and newlines). However, the possibility is there -- Langium's AbstractFormatter returns an array of VSCode TextEdit, and vscode-languageserver Connection can register a handle for Document Formatting.

It seems, you can push document edit from LS to LSP client, using Workspace ApplyEdit command from server (i.e. Langium) to client (e.g., VSCode Monaco). Moreover, I think that I should not register custom client-to-server command on the LSP side, but instead use LMS API: since:

  1. I will send a request (e.g., add Task (in tasklist language)), which operates model-specific information, that LSP itself shouldn't be aware of.
  2. The request is going to be send by GLSP server, which doesn't actually know it is talking to LS!!! It only uses LMS API. See Langium tutorial on creating custom command for more details.
hpopov commented 1 year ago

I do believe, that Code Actions are invoked programmatically by sending a corresponding action message from LSP client to LS. But since at the moment I decided not to use LSP Code Actions for LMS backward model modification (see Zettelkasten journal for 2023-07-20), I will skip learning them in more depth

hpopov commented 1 year ago

Moved LMS Content Assist discovering into a separate subtask: #26