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

Inconsistent formatting of defprotocol with docstring on separate line from method declaration. #1978

Closed
skylize opened this issue Nov 27, 2022 · 6 comments

Comments

@skylize
Copy link
Contributor

skylize commented Nov 27, 2022

  • While typing, the docstring aligns with the parameters.

  • If the cursor is anywhere within the method form, then calva-fmt.formatCurrentForm follows the same rule, and aligns the docsctring to the params.

  • This only applies or gets updated for the single form containing the cursor. Move the cursor inside a different method's form, and run calva-fmt.formatCurrentForm to also format that form as described above, but again not affecting alignment of any other methods.

  • Move the cursor to where it is outside of any method expression and run calva-fmt.formatCurrentForm and a different rule takes over. All the docstrings align to the second character of the respective method name.

  • Same with other format-triggering events (such as paredit.dragSexpForward). So long as the cursor is not within a form that defines a method, all the docstrings align to a +2 character indentation.

; | for cursor

(defprotocol Foo
  (method [_] |"docstring"))

; <Enter>
(defprotocol Foo
  (method [_]
         |"docstring"))

; <calva-fmt.formatCurrentForm>
(defprotocol Foo
  (method [_]
         |"docstring"))

; <move cursor>
(defprotocol Foo
 |(method [_]
          "docstring"))

; <calva-fmt.formatCurrentForm>
(defprotocol Foo
 |(method [_]
    "docstring"))

; <move cursor>
(defprotocol Foo
  (|method [_]
     "docstring"))

; <calva-fmt.formatCurrentForm>
(defprotocol Foo
  (|method [_]
           "docstring"))
@SillyCoon
Copy link
Contributor

@PEZ I think this issue related to #1957, the indenter case seems to be already fixed, I'll take a look on the formatter case

@skylize
Copy link
Contributor Author

skylize commented Jan 10, 2023

I agree this sounds like probably an alternate manifestation of the same issue (though cannot say for sure until one or the other is fixed 😄).

@PEZ
Copy link
Collaborator

PEZ commented Jan 10, 2023

@SillyCoon, I think the formatter case might be solved by adding defprotocol to the format-depth map you introduced in your latest PR.

@SillyCoon
Copy link
Contributor

Yeah, it looks like this. I will create a PR with defprotocol and will move this map to the config

SillyCoon added a commit to SillyCoon/calva that referenced this issue Jan 11, 2023
@SillyCoon
Copy link
Contributor

Hello @PEZ! I think this ticket also was not closed automatically 😢

@bpringe bpringe closed this as completed Feb 7, 2023
@skylize
Copy link
Contributor Author

skylize commented Feb 16, 2023

Thanks @SillyCoon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants