Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support formating a section of markdown #132

Open
4 tasks done
LokiMidgard opened this issue Sep 9, 2024 · 4 comments
Open
4 tasks done

Support formating a section of markdown #132

LokiMidgard opened this issue Sep 9, 2024 · 4 comments
Labels
🤞 phase/open Post is being triaged manually 🧒 semver/minor This is backwards-compatible change 🦋 type/enhancement This is great to have

Comments

@LokiMidgard
Copy link

Initial checklist

Problem

VSCode has a format section command this is currently not supported by this extension.

If supported this allows

  • Selecting a part of text and only format that
  • allows editor.formatOnSaveMode with modificationsIfAvailable to only format modified lienes (if I understood correctly)
  • allows formatting while typing (I think this also need to define what characters trigger formating)

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 to file, to allow formatting on save, without the benefit of formating only changed text.

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Sep 9, 2024
@remcohaszing
Copy link
Member

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

@remcohaszing remcohaszing added 🦋 type/enhancement This is great to have 🧒 semver/minor This is backwards-compatible change labels Sep 13, 2024
@wooorm
Copy link
Member

wooorm commented Sep 13, 2024

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.

@LokiMidgard
Copy link
Author

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…

@remcohaszing
Copy link
Member

remcohaszing commented Sep 13, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤞 phase/open Post is being triaged manually 🧒 semver/minor This is backwards-compatible change 🦋 type/enhancement This is great to have
Development

No branches or pull requests

3 participants