Open LokiMidgard opened 1 month ago
The remark language server can’t support range formatting, because remark doesn’t support formatting text ranges. Personally I’m not very interested in this feature, but I would be willing to implement this if unified and remark support it. I don’t really understand how this should work or if this is even possible with the current architecture.
cc @wooorm @ChristianMurphy
Can’t work? Footnote definitions, regular definitions, could be anywhere else.
What if the current selection looks like it starts with frontmatter, even though it isn’t at the start of the document?
What if you select something that looks like “blocks” but is inline, and try to format it? Say, asd |# qwe|
.
It seems very difficult. I don’t really see the use.
I'm not 100% sure, but If I understand it correctly, the rangeformating request will provide the whole file and a range that should be formated. So the complete document is available for parsing.
It should just return text edits, for the selected text. So without looking a the current implementation, if there are several edits on the whole file they could be filtered to just return those in the range. Assuming they do not depend o another.
So there should be no problem misinterpreting inline text for blogs or something as frontmatter that isn't.
But it still looks like this is the wrong repo for this issue…
I’m ok with tracking this here. If this feature appears upstream, it eventually needs to end up here.
Currently the whole file is parsed and reformatted when formatting. This is one big edit. It’s possible to calculate text diffs and convert those to formatting ranges. This is done for example in unified-consistency
and eslint-plugin-prettier
. The problem is that these changes don’t have any context, only plain text diffs. The result can be invalid. I trust a human to apply them, but not an automation.
Initial checklist
Problem
VSCode has a
format section
command this is currently not supported by this extension.If supported this allows
editor.formatOnSaveMode
withmodificationsIfAvailable
to only format modified lienes (if I understood correctly)Solution
It is said in the vscode extensions docs that the extension need to respond to the
textDocument/rangeFormatting
request.Alternatives
For
formatOnSave
the mode can be set tofile
, to allow formatting on save, without the benefit of formating only changed text.