Skip to content

Incorrect indentation / fontification after metadata forms #61

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

Closed
yuhan0 opened this issue Mar 6, 2025 · 6 comments · Fixed by #68
Closed

Incorrect indentation / fontification after metadata forms #61

yuhan0 opened this issue Mar 6, 2025 · 6 comments · Fixed by #68
Labels
bug Something isn't working

Comments

@yuhan0
Copy link
Contributor

yuhan0 commented Mar 6, 2025

Expected:

Metadata forms ^:foo / ^{:foo 123} should not affect indentation of the following forms

[a b [c ^:foo
      d
      e]]

Actual:

;; with clojure-ts-indent-style = 'semantic
[a b [c ^:foo
        d
      e]]

;; with clojure-ts-indent-style = 'fixed
[a b [c ^:foo
d
      e]]

Some font-locking of the following form also appears to be affected:

Image


Typing a closing delimiter with Paredit (paredit-close-curly) can also cause the point to jump to the wrong position:

;;   ↓with point here, type "}"
[a ^{ } (b) c]
;;     |   |     
;;     |   actual
;;     expected
@bbatsov bbatsov added the bug Something isn't working label Mar 6, 2025
@bbatsov
Copy link
Member

bbatsov commented Mar 6, 2025

Likely the metadata is not considered in the existing TS queries. I'll take a look when I can.

@yuhan0
Copy link
Contributor Author

yuhan0 commented Mar 6, 2025

(The Paredit navigation issue is probably related to #62, and not directly to this)

@rrudakov
Copy link
Contributor

Some font-locking of the following form also appears to be affected:

This should be fixed by #66

@rrudakov
Copy link
Contributor

Regarding indentation, I can fix that, but I'm not sure if it will be correct. The value with metadata is a single node, it looks like this in the syntax tree:

(sym_lit
    meta: 
     (meta_lit marker: ^
      value: (kwd_lit marker: : name: (kwd_name)))
    name: (sym_name))

And it seems logical to me that metadata and value are aligned vertically (there is a rule defined in the code specifically for that).

(def x
  [a b [c ^:foo
          d
        e]])

Are there any guidelines about this indentation?

@yuhan0
Copy link
Contributor Author

yuhan0 commented Mar 27, 2025

That might be more logical, but other formatters like cljfmt / zprint / standard-clojure-style don't behave this way, so it's probably better to follow the status quo. This situation turns out to be fairly common once you consider type hints and metadata on def / defonce / ns symbols:
https://github.com/clojure/clojure/blob/fb22fd778a272b034684a4ee94509552b46ee8a9/src/clj/clojure/core.clj#L5892
https://github.com/clojure/clojure/blob/fb22fd778a272b034684a4ee94509552b46ee8a9/src/clj/clojure/string.clj#L324

@rrudakov
Copy link
Contributor

Thanks for the examples @yuhan0. I've also found some issues with syntax highlighting related to metadata presence. I'll create a PR with all fixes soon.

rrudakov added a commit to rrudakov/clojure-ts-mode that referenced this issue Mar 28, 2025
…tadata

- Collection elements (except of lists) are properly indented.
- Body of special forms when the entire form has metadata is properly indented.
- Additionally fix syntax highlighting of special forms when the entire form has metadata.
rrudakov added a commit to rrudakov/clojure-ts-mode that referenced this issue Mar 28, 2025
…tadata

- Collection elements (except of lists) are properly indented.
- Body of special forms when the entire form has metadata is properly indented.
- Additionally fix syntax highlighting of special forms when the entire form has metadata.
rrudakov added a commit to rrudakov/clojure-ts-mode that referenced this issue Apr 3, 2025
…tadata

- Collection elements (except of lists) are properly indented.
- Body of special forms when the entire form has metadata is properly indented.
- Additionally fix syntax highlighting of special forms when the entire form has metadata.
rrudakov added a commit to rrudakov/clojure-ts-mode that referenced this issue Apr 3, 2025
…tadata

- Collection elements (except of lists) are properly indented.
- Body of special forms when the entire form has metadata is properly indented.
- Additionally fix syntax highlighting of special forms when the entire form has metadata.
bbatsov pushed a commit that referenced this issue Apr 3, 2025
- Collection elements (except of lists) are properly indented.
- Body of special forms when the entire form has metadata is properly indented.
- Additionally fix syntax highlighting of special forms when the entire form has metadata.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants