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

cue fmt indents top-level comments #722

Closed
cueckoo opened this issue Jul 3, 2021 · 5 comments
Closed

cue fmt indents top-level comments #722

cueckoo opened this issue Jul 3, 2021 · 5 comments
Assignees
Labels
fmt Related to formatting functionality. NeedsInvestigation

Comments

@cueckoo
Copy link
Collaborator

cueckoo commented Jul 3, 2021

Originally opened by @bbkane in cuelang/cue#722

What version of CUE are you using (cue version)?

$ cue version
cue version 0.3.0-beta.3 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

$ cat fields.cue
// comment
hello: "world"
$ cue fmt

What did you expect to see?

$ cat fields.cue
// comment
hello: "world"

What did you see instead?

$ cat fields.cue
	// comment
hello: "world"
@cueckoo cueckoo added fmt Related to formatting functionality. NeedsInvestigation labels Jul 3, 2021
@cueckoo cueckoo added this to the v0.4.x milestone Jul 3, 2021
@rogpeppe
Copy link
Member

This also applies to cue export --out cue FWIW.
This testscript fails:

exec cue export --out cue c.cue
cmp stdout want.cue
-- c.cue --
// Comment
foo: 1
-- want.cue --
// Comment
foo: 1

@mpvl
Copy link
Member

mpvl commented May 17, 2022

@rogpeppe cue export uses the format package for the output, just like fmt.

@FogDong
Copy link

FogDong commented May 17, 2022

I've fixed a similar issue in #1704, and I'd like to work on this issue :) @mpvl

@mpvl mpvl added the Discuss Requires maintainer discussion label May 18, 2022
@mvdan mvdan removed the Discuss Requires maintainer discussion label Apr 10, 2023
@myitcv myitcv modified the milestones: v0.4.x, fmt-redesign Apr 27, 2023
@myitcv myitcv added the zGarden label Jun 15, 2023
@myitcv myitcv removed the zGarden label Aug 18, 2023
@rudifa
Copy link
Contributor

rudifa commented Nov 18, 2023

Elaborating from testscript above by @rogpeppe, this shows similarities and differences between fmt, def and export --out cue.

Are any of these differences intended?

# show the`cue export` handling of comments: run with `testscript -continue 722-4.txtar
force-verbose
env CUEDO_FMT_DEBUGSTR=1
exec cue version

# 3 commands have the same behavior with c.cue
# they preserve the comment but indent it

exec cat c.cue

#A ------------------------------------
exec cue export --out cue c.cue
cmp stdout want.cue         ### fail - indents

#B ------------------------------------
exec cue def c.cue
cmp stdout want.cue         ### fail - indents

#C ------------------------------------
exec cue fmt c.cue          ### fmt is the last because it modifies c.cue in place
cmp c.cue want.cue          ### fail - indents

# 2 commands have the same behavior with 722-2.cue
# they drop the comment

#D ------------------------------------
exec cue export --out cue 722-2.cue
cmp stdout 722-2.cue                    ### fail - drops comment and newline

#E ------------------------------------
exec cue def 722-2.cue
cmp stdout 722-2.cue                    ### fail - drops comment and newline

# cue fmt preserves all unchanged

#F ------------------------------------
exec cue fmt 722-2.cue  ### fmt is the last because it modifies 722-2.cue in place
cmp 722-2.cue 722-2-want-maybe.cue      ### pass - unchanged

# files -------------------------------

-- c.cue --
// Comment
foo: 1
-- want.cue --
// Comment
foo: 1
-- 722-2.cue --
// comment

hello: "world"
-- 722-2-want-maybe.cue --
// comment

hello: "world"
-- end --

@mvdan mvdan removed this from the fmt-redesign milestone Mar 19, 2024
@jpluscplusm
Copy link
Collaborator

This also affects the playground: https://cuelang.org/play/?id=G3wjR5M0KCi#w=function&i=cue&f=eval&o=cue

I've just started filling out the set of preloadable examples for the playground, and almost every single one of them will need leading comments, explaining what's about to be demonstrated. This bug will give a less than great impression of the playground to newcomers, IMHO!!

cueckoo pushed a commit to cue-lang/cuelang.org that referenced this issue Mar 28, 2024
This adds a small set of representative examples to the playground,
replacing the current invalid examples.

They are placed in an indicative structure, with the "Introduction"
category being intended to hold examples for the user who landed on the
playground before reading any other part of the site, and the "Tour"
category showing a couple of CUE examples taken directly from the
on-page CUE in docs/tour/.

The Tour category isn't expanded to include all the docs examples, yet,
as both cue-lang/cue#2995 and cue-lang/cue#2900 need resolving to let us
avoid spending a *lot* of time on manual content syncing.

Formatting notes for as&when the examples are expanded, and if their
generation is automated:

- Because cue-lang/cue#722 also strikes the playground ("top-level
  comments are indented") when the playground's default of "cue eval" is
  selected, care has been taken to make sure that comments are used that
  don't trigger this bug (as it looks pretty poor for predefined
  examples to have this problem). Some relevant information:
  - only the first comment presented at the top of the "eval" output is
    affected
  - it doesn't affect comments which aren't included in the output, such
    as introductory comments which are separated by a blank line from
    the first field emitted
  - it doesn't affect fields with a struct or list value
  - it only affects single-line comments
  - it can affect a comment that's not the first line of the source, if
    it's attached to any definition of the first field that's present in
    the emitted output

- Including  links from tour-derived examples back to the relevant tour
  page feels like a win, but they need to be split over two comment
  lines or the end of the URL disappears from view. This also has the
  nice effect of pushing the URL to the second line of the editor, which
  makes the "Follow link (ctrl+click)" mouseover popup *not* get
  visually truncated by the top edge of the editor pane.

Preview-Path: /play
Signed-off-by: Jonathan Matthews <[email protected]>
Change-Id: I374ee591f767bea3a0e07f29ce7825468661f42f
cueckoo pushed a commit to cue-lang/cuelang.org-trybot that referenced this issue Mar 28, 2024
This adds a small set of representative examples to the playground,
replacing the current invalid examples.

They are placed in an indicative structure, with the "Introduction"
category being intended to hold examples for the user who landed on the
playground before reading any other part of the site, and the "Tour"
category showing a couple of CUE examples taken directly from the
on-page CUE in docs/tour/.

The Tour category isn't expanded to include all the docs examples, yet,
as both cue-lang/cue#2995 and cue-lang/cue#2900 need resolving to let us
avoid spending a *lot* of time on manual content syncing.

Formatting notes for as&when the examples are expanded, and if their
generation is automated:

- Because cue-lang/cue#722 also strikes the playground ("top-level
  comments are indented") when the playground's default of "cue eval" is
  selected, care has been taken to make sure that comments are used that
  don't trigger this bug (as it looks pretty poor for predefined
  examples to have this problem). Some relevant information:
  - only the first comment presented at the top of the "eval" output is
    affected
  - it doesn't affect comments which aren't included in the output, such
    as introductory comments which are separated by a blank line from
    the first field emitted
  - it doesn't affect fields with a struct or list value
  - it only affects single-line comments
  - it can affect a comment that's not the first line of the source, if
    it's attached to any definition of the first field that's present in
    the emitted output

- Including  links from tour-derived examples back to the relevant tour
  page feels like a win, but they need to be split over two comment
  lines or the end of the URL disappears from view. This also has the
  nice effect of pushing the URL to the second line of the editor, which
  makes the "Follow link (ctrl+click)" mouseover popup *not* get
  visually truncated by the top edge of the editor pane.

Preview-Path: /play
Signed-off-by: Jonathan Matthews <[email protected]>
Change-Id: I374ee591f767bea3a0e07f29ce7825468661f42f
Dispatch-Trailer: {"type":"trybot","CL":1188421,"patchset":2,"ref":"refs/changes/21/1188421/2","targetBranch":"master"}
cueckoo pushed a commit to cue-lang/cuelang.org that referenced this issue Mar 28, 2024
This adds a small set of representative examples to the playground,
replacing the current invalid examples.

They are placed in an indicative structure, with the "Introduction"
category being intended to hold examples for the user who landed on the
playground before reading any other part of the site, and the "Tour"
category showing a couple of CUE examples taken directly from the
on-page CUE in docs/tour/.

The Tour category isn't expanded to include all the docs examples, yet,
as both cue-lang/cue#2995 and cue-lang/cue#2900 need resolving to let us
avoid spending a *lot* of time on manual content syncing.

Formatting notes for as&when the examples are expanded, and if their
generation is automated:

- Because cue-lang/cue#722 also strikes the playground ("top-level
  comments are indented") when the playground's default of "cue eval" is
  selected, care has been taken to make sure that comments are used that
  don't trigger this bug (as it looks pretty poor for predefined
  examples to have this problem). Some relevant information:
  - only the first comment presented at the top of the "eval" output is
    affected
  - it doesn't affect comments which aren't included in the output, such
    as introductory comments which are separated by a blank line from
    the first field emitted
  - it doesn't affect fields with a struct or list value
  - it only affects single-line comments
  - it can affect a comment that's not the first line of the source, if
    it's attached to any definition of the first field that's present in
    the emitted output

- Including links from tour-derived examples back to the relevant tour
  page feels like a win, but they need to be split over two comment
  lines or the end of the URL disappears from view. This also has the
  nice effect of pushing the URL to the second line of the editor, which
  makes the "Follow link (ctrl+click)" mouseover popup *not* get
  visually truncated by the top edge of the editor pane.

Preview-Path: /play
Signed-off-by: Jonathan Matthews <[email protected]>
Change-Id: I374ee591f767bea3a0e07f29ce7825468661f42f
cueckoo pushed a commit to cue-lang/cuelang.org-trybot that referenced this issue Mar 28, 2024
This adds a small set of representative examples to the playground,
replacing the current invalid examples.

They are placed in an indicative structure, with the "Introduction"
category being intended to hold examples for the user who landed on the
playground before reading any other part of the site, and the "Tour"
category showing a couple of CUE examples taken directly from the
on-page CUE in docs/tour/.

The Tour category isn't expanded to include all the docs examples, yet,
as both cue-lang/cue#2995 and cue-lang/cue#2900 need resolving to let us
avoid spending a *lot* of time on manual content syncing.

Formatting notes for as&when the examples are expanded, and if their
generation is automated:

- Because cue-lang/cue#722 also strikes the playground ("top-level
  comments are indented") when the playground's default of "cue eval" is
  selected, care has been taken to make sure that comments are used that
  don't trigger this bug (as it looks pretty poor for predefined
  examples to have this problem). Some relevant information:
  - only the first comment presented at the top of the "eval" output is
    affected
  - it doesn't affect comments which aren't included in the output, such
    as introductory comments which are separated by a blank line from
    the first field emitted
  - it doesn't affect fields with a struct or list value
  - it only affects single-line comments
  - it can affect a comment that's not the first line of the source, if
    it's attached to any definition of the first field that's present in
    the emitted output

- Including links from tour-derived examples back to the relevant tour
  page feels like a win, but they need to be split over two comment
  lines or the end of the URL disappears from view. This also has the
  nice effect of pushing the URL to the second line of the editor, which
  makes the "Follow link (ctrl+click)" mouseover popup *not* get
  visually truncated by the top edge of the editor pane.

Preview-Path: /play
Signed-off-by: Jonathan Matthews <[email protected]>
Change-Id: I374ee591f767bea3a0e07f29ce7825468661f42f
Dispatch-Trailer: {"type":"trybot","CL":1188421,"patchset":3,"ref":"refs/changes/21/1188421/3","targetBranch":"master"}
cueckoo pushed a commit to cue-lang/cuelang.org that referenced this issue Mar 28, 2024
This adds a small set of representative examples to the playground,
replacing the current invalid examples.

They are placed in an indicative structure, with the "Introduction"
category being intended to hold examples for the user who landed on the
playground before reading any other part of the site, and the "Tour"
category showing a couple of CUE examples taken directly from the
on-page CUE in docs/tour/.

The Tour category isn't expanded to include all the docs examples, yet,
as both cue-lang/cue#2995 and cue-lang/cue#2900 need resolving to let us
avoid spending a *lot* of time on manual content syncing.

Formatting notes for as&when the examples are expanded, and if their
generation is automated:

- Because cue-lang/cue#722 also strikes the playground ("top-level
  comments are indented") when the playground's default of "cue eval" is
  selected, care has been taken to make sure that comments are used that
  don't trigger this bug (as it looks pretty poor for predefined
  examples to have this problem). Some relevant information:
  - only the first comment presented at the top of the "eval" output is
    affected
  - it doesn't affect comments which aren't included in the output, such
    as introductory comments which are separated by a blank line from
    the first field emitted
  - it doesn't affect fields with a struct or list value
  - it only affects single-line comments
  - it can affect a comment that's not the first line of the source, if
    it's attached to any definition of the first field that's present in
    the emitted output

- Including links from tour-derived examples back to the relevant tour
  page feels like a win, but they need to be split over two comment
  lines or the end of the URL disappears from view. This also has the
  nice effect of pushing the URL to the second line of the editor, which
  makes the "Follow link (ctrl+click)" mouseover popup *not* get
  visually truncated by the top edge of the editor pane.

For cue-lang/docs-and-content#92

Preview-Path: /play
Signed-off-by: Jonathan Matthews <[email protected]>
Change-Id: I374ee591f767bea3a0e07f29ce7825468661f42f
cueckoo pushed a commit to cue-lang/cuelang.org-trybot that referenced this issue Mar 28, 2024
This adds a small set of representative examples to the playground,
replacing the current invalid examples.

They are placed in an indicative structure, with the "Introduction"
category being intended to hold examples for the user who landed on the
playground before reading any other part of the site, and the "Tour"
category showing a couple of CUE examples taken directly from the
on-page CUE in docs/tour/.

The Tour category isn't expanded to include all the docs examples, yet,
as both cue-lang/cue#2995 and cue-lang/cue#2900 need resolving to let us
avoid spending a *lot* of time on manual content syncing.

Formatting notes for as&when the examples are expanded, and if their
generation is automated:

- Because cue-lang/cue#722 also strikes the playground ("top-level
  comments are indented") when the playground's default of "cue eval" is
  selected, care has been taken to make sure that comments are used that
  don't trigger this bug (as it looks pretty poor for predefined
  examples to have this problem). Some relevant information:
  - only the first comment presented at the top of the "eval" output is
    affected
  - it doesn't affect comments which aren't included in the output, such
    as introductory comments which are separated by a blank line from
    the first field emitted
  - it doesn't affect fields with a struct or list value
  - it only affects single-line comments
  - it can affect a comment that's not the first line of the source, if
    it's attached to any definition of the first field that's present in
    the emitted output

- Including links from tour-derived examples back to the relevant tour
  page feels like a win, but they need to be split over two comment
  lines or the end of the URL disappears from view. This also has the
  nice effect of pushing the URL to the second line of the editor, which
  makes the "Follow link (ctrl+click)" mouseover popup *not* get
  visually truncated by the top edge of the editor pane.

For cue-lang/docs-and-content#92

Preview-Path: /play
Signed-off-by: Jonathan Matthews <[email protected]>
Change-Id: I374ee591f767bea3a0e07f29ce7825468661f42f
Dispatch-Trailer: {"type":"trybot","CL":1188421,"patchset":4,"ref":"refs/changes/21/1188421/4","targetBranch":"master"}
cueckoo pushed a commit to cue-lang/cuelang.org that referenced this issue Mar 28, 2024
This adds a small set of representative examples to the playground,
replacing the current invalid examples.

They are placed in an indicative structure, with the "Introduction"
category being intended to hold examples for the user who landed on the
playground before reading any other part of the site, and the "Tour"
category showing a couple of CUE examples taken directly from the
on-page CUE in docs/tour/.

The Tour category isn't expanded to include all the docs examples, yet,
as both cue-lang/cue#2995 and cue-lang/cue#2900 need resolving to let us
avoid spending a *lot* of time on manual content syncing.

Formatting notes for as&when the examples are expanded, and if their
generation is automated:

- Because cue-lang/cue#722 also strikes the playground ("top-level
  comments are indented") when the playground's default of "cue eval" is
  selected, care has been taken to make sure that comments are used that
  don't trigger this bug (as it looks pretty poor for predefined
  examples to have this problem). Some relevant information:
  - only the first comment presented at the top of the "eval" output is
    affected
  - it doesn't affect comments which aren't included in the output, such
    as introductory comments which are separated by a blank line from
    the first field emitted
  - it doesn't affect fields with a struct or list value
  - it only affects single-line comments
  - it can affect a comment that's not the first line of the source, if
    it's attached to any definition of the first field that's present in
    the emitted output

- Including links from tour-derived examples back to the relevant tour
  page feels like a win, but they need to be split over two comment
  lines or the end of the URL disappears from view. This also has the
  nice effect of pushing the URL to the second line of the editor, which
  makes the "Follow link (ctrl+click)" mouseover popup *not* get
  visually truncated by the top edge of the editor pane.

For cue-lang/docs-and-content#92

Preview-Path: /play
Signed-off-by: Jonathan Matthews <[email protected]>
Change-Id: I374ee591f767bea3a0e07f29ce7825468661f42f
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cuelang.org/+/1188421
Reviewed-by: Paul Jolly <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
@mvdan mvdan self-assigned this Jun 11, 2024
cueckoo pushed a commit to cue-lang/cuelang.org-trybot that referenced this issue Jul 24, 2024
This removes several uses of "```" to format code on the page, and
replaces them with "{{{with code ...}}}". This benefits us by increasing
automated "cue fmt" coverage of the examples on the site, and by
engaging syntax highlighting without manual language markers.

Some examples of "```" remain, such as where an environment variable is
being demonstrated; or inside the language guide and spec, which aren't
being updated on the master branch currently.

One example in the modules reference triggers cue-lang/cue#722, and ends
up with a leading comment being incorrectly indented; this error is
allowed to exist as the issue is fixed, and the page will soon fix
itself when the site is updated to use CUE v0.10.0 or later.

One page (list-no-duplicates) loses the highlighting of specific lines
in some examples. This is acceptable in light of the changes anticipated
by cue-lang/docs-and-content#171, which are likely to result in this
page being completely rewritten or subsumed into another howto guide.

Preview-Path: /docs/howto/list-no-duplicates/
Preview-Path: /docs/introduction/
Preview-Path: /docs/reference/modules/
Signed-off-by: Jonathan Matthews <[email protected]>
Change-Id: I1a15a52ddf979ad6ee44bc8950d5e67892bfeb2f
Dispatch-Trailer: {"type":"trybot","CL":1198345,"patchset":1,"ref":"refs/changes/45/1198345/1","targetBranch":"master"}
cueckoo pushed a commit to cue-lang/cuelang.org-trybot that referenced this issue Jul 24, 2024
This removes several uses of "```" to format code on the page, and
replaces them with "{{{with code ...}}}". This benefits us by increasing
automated "cue fmt" coverage of the examples on the site, and by
engaging syntax highlighting without manual language markers.

Some examples of "```" remain, such as where an environment variable is
being demonstrated; or inside the language guide and spec, which aren't
being updated on the master branch currently.

One example in the modules reference triggers cue-lang/cue#722, and ends
up with a leading comment being incorrectly indented; this error is
allowed to exist as the issue is fixed, and the page will soon fix
itself when the site is updated to use CUE v0.10.0 or later.

One page (list-no-duplicates) loses the highlighting of specific lines
in some examples. This is acceptable in light of the changes anticipated
by cue-lang/docs-and-content#171, which are likely to result in this
page being completely rewritten or subsumed into another howto guide.

Preview-Path: /docs/howto/list-no-duplicates/
Preview-Path: /docs/introduction/
Preview-Path: /docs/reference/modules/
Signed-off-by: Jonathan Matthews <[email protected]>
Change-Id: I1a15a52ddf979ad6ee44bc8950d5e67892bfeb2f
Dispatch-Trailer: {"type":"trybot","CL":1198345,"patchset":2,"ref":"refs/changes/45/1198345/2","targetBranch":"master"}
cueckoo pushed a commit to cue-lang/cuelang.org-trybot that referenced this issue Jul 26, 2024
This removes several uses of "```" to format code on the page, and
replaces them with "{{{with code ...}}}". This benefits us by increasing
automated "cue fmt" coverage of the examples on the site, and by
engaging syntax highlighting without manual language markers.

Some examples of "```" remain, such as where an environment variable is
being demonstrated; or inside the language guide and spec, which aren't
being updated on the master branch currently.

One example in the modules reference triggers cue-lang/cue#722, and ends
up with a leading comment being incorrectly indented; this issue is
fixed, and the example will have its #nofmt removed after the site is
updated to use CUE v0.10.0 or later.

One page (list-no-duplicates) loses the highlighting of specific lines
in some examples. This is acceptable in light of the changes anticipated
by cue-lang/docs-and-content#171, which are likely to result in this
page being completely rewritten or subsumed into another howto guide.

Preview-Path: /docs/howto/list-no-duplicates/
Preview-Path: /docs/introduction/
Preview-Path: /docs/reference/modules/
Signed-off-by: Jonathan Matthews <[email protected]>
Change-Id: I1a15a52ddf979ad6ee44bc8950d5e67892bfeb2f
Dispatch-Trailer: {"type":"trybot","CL":1198345,"patchset":3,"ref":"refs/changes/45/1198345/3","targetBranch":"master"}
cueckoo pushed a commit to cue-lang/cuelang.org that referenced this issue Jul 26, 2024
This removes several uses of "```" to format code on the page, and
replaces them with "{{{with code ...}}}". This benefits us by increasing
automated "cue fmt" coverage of the examples on the site, and by
engaging syntax highlighting without manual language markers.

Some examples of "```" remain, such as where an environment variable is
being demonstrated; or inside the language guide and spec, which aren't
being updated on the master branch currently.

One example in the modules reference triggers cue-lang/cue#722, and ends
up with a leading comment being incorrectly indented; this issue is
fixed, and the example will have its #nofmt removed after the site is
updated to use CUE v0.10.0 or later.

One page (list-no-duplicates) loses the highlighting of specific lines
in some examples. This is acceptable in light of the changes anticipated
by cue-lang/docs-and-content#171, which are likely to result in this
page being completely rewritten or subsumed into another howto guide.

Preview-Path: /docs/howto/list-no-duplicates/
Preview-Path: /docs/introduction/
Preview-Path: /docs/reference/modules/
Signed-off-by: Jonathan Matthews <[email protected]>
Change-Id: I1a15a52ddf979ad6ee44bc8950d5e67892bfeb2f
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cuelang.org/+/1198345
Reviewed-by: Daniel Martí <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fmt Related to formatting functionality. NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

8 participants