lemminx icon indicating copy to clipboard operation
lemminx copied to clipboard

Send `workspace/applyEdit` to client for auto-close of tags

Open mickaelistria opened this issue 6 years ago • 12 comments

Auto-edits like closing tags as user types should be implemented using the standard workspace/applyEdit command. Basically, the LS would listen to documentChange (so far, so good), and when it is detected that an opening tag was closed (like <hello>, it should send the workspace/applyEdit command to add the </hello> tag at the right location).

mickaelistria avatar Mar 12 '19 18:03 mickaelistria

I think we can probably switch to using workspace/applyEdit easily, but it won't be sent on documentChange for the moment. So far, the whole document is sent to the server (an experimental incremental mode exists but is largely untested), detecting the precise location where a tag needs closing requires a more precise range.

fbricon avatar Mar 12 '19 20:03 fbricon

detecting the precise location where a tag needs closing requires a more precise range.

I think the LS can try to compare the previous document state with the current one on documentChange to sort out the smaller grain change can trigger an auto-edit. But at this point, I guess it's the same difficulty than implementing incremental mode...

mickaelistria avatar Mar 12 '19 20:03 mickaelistria

I'd be more inclined to (ab)use the completion request instead

fbricon avatar Mar 12 '19 20:03 fbricon

That would be already a nice way to provide a good chunk of value.

mickaelistria avatar Mar 12 '19 20:03 mickaelistria

This issue is implemented by https://github.com/NikolasKomonen/lsp4xml/tree/autoCompletionMigration but because the LSP does not allow snippets in applyEdit's it will not be merged.

NikolasKomonen avatar May 21 '19 19:05 NikolasKomonen

This issue is marked as "blocked by LSP", but in reality, isn't it more blocked by lack of support for incremental changes in lsp4xml?

mickaelistria avatar Aug 06 '19 20:08 mickaelistria

@mickaelistria I started working on this issue, but using the applyEdit method didn't allow for selecting the cursor position (using a $0 ) and it always put the cursor at the end of the insert. Overall the experience is not as good as the current implementation I've found.

NikolasKomonen avatar Aug 07 '19 13:08 NikolasKomonen

Ok, so this is https://github.com/Microsoft/language-server-protocol/issues/724 , isn't it?

mickaelistria avatar Aug 07 '19 13:08 mickaelistria

yup, not sure if it's being worked on currently or is just in the backlog. I created a similar issue previously but it's been overridden by microsoft/language-server-protocol#724, which should be the one to follow for any updates.

NikolasKomonen avatar Aug 07 '19 14:08 NikolasKomonen

Wouldn't https://microsoft.github.io/language-server-protocol/specification#textDocument_onTypeFormatting be the right thing to use here? Actually, I'm not sure clients would be expected to change the cursor position.

mickaelistria avatar Aug 08 '19 19:08 mickaelistria

Wouldn't https://microsoft.github.io/language-server-protocol/specification#textDocument_onTypeFormatting be the right thing to use here?

We need to experiment it for XML. But for HTML language server it will require to do the same thing if it works

angelozerr avatar Jun 21 '21 13:06 angelozerr

What is the currently status for this issue?

moabson avatar Jul 02 '21 19:07 moabson