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

Add comment provider #1095

Merged
merged 11 commits into from
Jul 12, 2023
Merged

Add comment provider #1095

merged 11 commits into from
Jul 12, 2023

Conversation

Lotes
Copy link
Contributor

@Lotes Lotes commented Jun 26, 2023

  • serializes to $comment property

  • comes with default multiline comments

  • replaces consumption of comments in documentation provider by a comment provider call

  • one thing that bothers me is that comments can get duplicated (I guess)

A ::= B c
B ::= a b

For file:

/** comment */
a b c
  • because then $comment(A) == $comment(B) == '/** comment */'
  • @msujew what do you think? Can we live with this or should we filter out the comment for upper nodes when a lower node already has the comment?

@Lotes Lotes marked this pull request as ready for review June 27, 2023 07:03
@Lotes Lotes requested a review from msujew June 27, 2023 07:47
Copy link
Contributor

@spoenemann spoenemann left a comment

Choose a reason for hiding this comment

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

@Lotes could you describe the main use cases for this, besides the documentation provider?

@msujew
Copy link
Member

msujew commented Jun 29, 2023

@spoenemann There are two relevant design changes in here:

  1. Adopters of Langium can choose to override the getComment method to change how other services derive the comment from a given AST node. Right now, all services use findCommentNode, which isn't overridable.
  2. Since we lose the CST during serialization, we also lose all semantically relevant comments. You could argue that comments should never be semantically relevant, but this is not the case for Langium. For example, what if I want to generate interface definitions similar to TSDoc from a serialized version of my AST? We need the AST comment for that, which is exactly what the serializer change in this PR accomplishes.

@msujew
Copy link
Member

msujew commented Jun 29, 2023

what do you think? Can we live with this or should we filter out the comment for upper nodes when a lower node already has the comment?

We can live with that, since filtering it out might be potentially destructive.

Copy link
Contributor

@spoenemann spoenemann left a comment

Choose a reason for hiding this comment

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

Ok, makes sense.

packages/langium/src/documentation/comment-provider.ts Outdated Show resolved Hide resolved
@Lotes Lotes requested a review from msujew July 10, 2023 08:49
Copy link
Member

@msujew msujew left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks 👍

One minor comment, see below.

packages/langium/src/serializer/json-serializer.ts Outdated Show resolved Hide resolved
Co-authored-by: Mark Sujew <mark.sujew@typefox.io>
@Lotes Lotes merged commit 1584fac into main Jul 12, 2023
@Lotes Lotes deleted the lotes/comment-provider branch July 12, 2023 06:50
@spoenemann spoenemann added this to the v2.0.0 milestone Jul 19, 2023
spoenemann pushed a commit that referenced this pull request Aug 15, 2023
* Implement a CommentProvider
* Fix tests
* Add documentation and replace comment consuming in documentation provider
* Make comment retrieval pretty

Co-authored-by: Mark Sujew <mark.sujew@typefox.io>

---------

Co-authored-by: Mark Sujew <mark.sujew@typefox.io>
@msujew msujew mentioned this pull request Jan 8, 2024
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.

3 participants