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

support formatting options #112

Closed
dannypsnl opened this issue Jul 12, 2023 · 9 comments · Fixed by #119
Closed

support formatting options #112

dannypsnl opened this issue Jul 12, 2023 · 9 comments · Fixed by #119

Comments

@dannypsnl
Copy link
Contributor

Link: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#formattingOptions

interface FormattingOptions {
	/**
	 * Size of a tab in spaces.
	 */
	tabSize: uinteger

	/**
	 * Prefer spaces over tabs.
	 */
	insertSpaces: boolean;

	/**
	 * Trim trailing whitespace on a line.
	 *
	 * @since 3.15.0
	 */
	trimTrailingWhitespace?: boolean;

	/**
	 * Insert a newline character at the end of the file if one does not exist.
	 *
	 * @since 3.15.0
	 */
	insertFinalNewline?: boolean;

	/**
	 * Trim all newlines after the final newline at the end of the file.
	 *
	 * @since 3.15.0
	 */
	trimFinalNewlines?: boolean;

	/**
	 * Signature for further properties.
	 */
	[key: string]: boolean | integer | string;
}
@6cdh
Copy link
Contributor

6cdh commented Jul 12, 2023

I don't know if someone uses tab for indentation. I always use "convert tab to spaces" personally.
We can respect these arguments:

  • trimTrailingWhitespace
  • insertFinalNewline
  • trimFinalNewlines

@jryans
Copy link
Contributor

jryans commented Jul 12, 2023

I also don't use tabs and always convert to spaces... The Racket style guide also says don't use tabs. (Perhaps someone still uses tabs anyway, but I'm guessing that's quite rare in the Racket ecosystem.)

@6cdh
Copy link
Contributor

6cdh commented Jul 17, 2023

I now understand the purpose of tabSize and insertSpaces. The formatting function always uses space indentation.
If someone use tab indentation in editor, it will look weird.

Based on the Racket style guide, maybe we can replace all tabs with spaces before formatting?

@dannypsnl
Copy link
Contributor Author

Yes, that would be great due to the style

@6cdh
Copy link
Contributor

6cdh commented Jul 17, 2023

So we ignore the options tabSize and insertSpaces, and always use replace tabs with spaces instead?

@dannypsnl
Copy link
Contributor Author

Yes, at least we can make a that first, if anyone wants different behavior, then make the implementation be the default setup & provides others

@6cdh
Copy link
Contributor

6cdh commented Jul 25, 2023

No, It's not easy to do.

The formatting function works for a range of lines.

For example, it need to format from line start to line end (exclusive).

Then if line start - 1 uses tab indentation, line start will always get wrong indent from compute-racket-amount-to-indent which calls racket-amount-to-indent as it doesn't know the tab size.

We cannot make racket-amount-to-indent to know the really tab size, as it seems hardcoded the tab size to 8.

@dannypsnl
Copy link
Contributor Author

If we replace \t with 8 spaces of line first?

@6cdh
Copy link
Contributor

6cdh commented Jul 25, 2023

Good suggestion! It feels dirty but it works.

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 a pull request may close this issue.

3 participants