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

code-action: TOC improvements #22

Merged
merged 18 commits into from
Aug 25, 2022

Conversation

keynmol
Copy link
Contributor

@keynmol keynmol commented Jun 10, 2022

Closes #19

  1. Double indent links in TOC - otherwise they're not rendered as nested lists at all
  2. Enable YAML frontmatter parsing, and propagate it into the document index
  3. Add logic to decide an insertion point for TOC - under yaml front matter, at document beginning, under the single h1 title
  4. Refactor and extract code action logic away from Server
  5. Add helpers and tests to actually assert on the document contents after inserting TOC

TODO

  • Tests that iteratively invoking code action does not add any more newlines (this is premonition - I'm pretty sure it's broken now :-/)

Otherwise they're not interpreted as nested lists
and not rendered correctly in, say, HTML
For example, after YAML frontmatter, after first title

Additionally, correctly render TOCs that start from a heading of
size different to 1
Marksman/Server.fs Outdated Show resolved Hide resolved
Marksman/Server.fs Outdated Show resolved Hide resolved
Marksman/Server.fs Outdated Show resolved Hide resolved
Marksman/Toc.fs Outdated Show resolved Hide resolved
@keynmol keynmol marked this pull request as ready for review June 10, 2022 17:44
Marksman/Cst.fs Outdated Show resolved Hide resolved
Marksman/Index.fs Outdated Show resolved Hide resolved
Marksman/Cst.fs Outdated Show resolved Hide resolved
Marksman/Server.fs Outdated Show resolved Hide resolved
Marksman/Text.fs Outdated Show resolved Hide resolved
Marksman/Toc.fs Outdated Show resolved Hide resolved
Marksman/Toc.fs Outdated Show resolved Hide resolved
Marksman/Toc.fs Outdated Show resolved Hide resolved
Tests/Helpers.fs Outdated Show resolved Hide resolved
Tests/TocTests.fs Outdated Show resolved Hide resolved
@artempyanykh artempyanykh changed the title Toc improvements code-action: TOC improvements Aug 14, 2022
@artempyanykh
Copy link
Owner

@keynmol I checked out locally to try things out. I think something got lost during rebase, as all this insertion logic from CodeActions.fs is not wired into Server.fs and is used only inside tests.

@keynmol
Copy link
Contributor Author

keynmol commented Aug 25, 2022

@artempyanykh This should be ready for review/another manual test

@artempyanykh
Copy link
Owner

@keynmol could you rebase on the latest main please?

@keynmol
Copy link
Contributor Author

keynmol commented Aug 25, 2022

Done

@artempyanykh
Copy link
Owner

image

Copy link
Owner

@artempyanykh artempyanykh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pushing this through! I left a few comments, but nothing critical.

Marksman/CodeActions.fs Outdated Show resolved Hide resolved
Marksman/CodeActions.fs Outdated Show resolved Hide resolved
>> Log.addContext "text" rendered
)

let isEmpty lineNumber = document.text.LineContent(lineNumber).Trim().Length.Equals(0)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Lenth.Equals(0) -> IsEmpty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type 'String' does not define the field, constructor or member 'IsEmpty'

Do I need to open anything or bribe someone to get it?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System.String.IsNullOrEmpty. This is a bit ridiculous though. We should add an extension method to String at some point.

Marksman/CodeActions.fs Outdated Show resolved Hide resolved
Marksman/Cst.fs Outdated Show resolved Hide resolved
Marksman/Cst.fs Outdated Show resolved Hide resolved
Marksman/Server.fs Outdated Show resolved Hide resolved
Marksman/Toc.fs Outdated Show resolved Hide resolved

let modifiedText = applyDocumentAction doc action

let expected =
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'm not sure whether it'll be better in this case, but you could try snapshot tests here to avoid manually typing all these expected doc contents.

@keynmol
Copy link
Contributor Author

keynmol commented Aug 25, 2022

@artempyanykh
Copy link
Owner

Awesome! I did a bit of testing and it worked great. There was just one case where TOC ate a new line
2022-08-25 20 14 58

LMK if you'd like to merge as is or fix the issue.

@keynmol
Copy link
Contributor Author

keynmol commented Aug 25, 2022

I'd rather merge as is (as long as it doesn't lines repeatedly), and then add this case to the tests with some other testing infra improvements

@artempyanykh
Copy link
Owner

image

@artempyanykh artempyanykh merged commit b441131 into artempyanykh:main Aug 25, 2022
@keynmol keynmol deleted the toc-improvements branch August 25, 2022 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generate TOC improvements
2 participants