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

Formatting options #24

Open
hifismith opened this issue Oct 27, 2022 · 2 comments
Open

Formatting options #24

hifismith opened this issue Oct 27, 2022 · 2 comments

Comments

@hifismith
Copy link

Sorry if this isn't technically an issue, but I was wondering what everyone was doing for formatting. The only option in VS code for "Document Format As" is Wolfram Language, but that has the following problem:

I would like the indents to be added correctly for new lines, and for my line breaks to be left untouched. But what's going on now is code that starts like this:
image

Ends up like this after shift+opt+F
image

If there's a better place to ask this question (Stack Exchange etc.) please point me there. Thanks

@bostick
Copy link

bostick commented Oct 28, 2022

Probably the best place is opening an issue for the CodeFormatter repo:
https://github.com/WolframResearch/codeformatter

There are various options for the formatter that are exposed as options for the functions in the CodeFormatter` context.

I talk about the CodeFormatter` package in this talk from WTC2020:
Formatting the Wolfram Language (youtube)

There is not yet a convenient way of modifying settings through VSCode, but you can modify settings for the formatter by changing the command for the LSP server and settings various variables.

Here is an example command with line width of Infinity and using the experimental line-breaking method "LineBreakerV2":

"wolfram.command": [
    "`kernel`",
    "-noinit",
    "-noprompt",
    "-nopaclet",
    "-nostartuppaclets",
    "-noicon",
    "-run",
    "Needs[\"LSPServer`\"];CodeFormatter`$DefaultLineWidth=Infinity;CodeFormatter`$DefaultBreakLinesMethod=\"LineBreakerV2\";LSPServer`StartServer[]"
]

LineBreakerV2 tries to do a better job of understanding and using the tree-structure of the code. But there are still issues and it is not yet turned on by default.

Formatter-specific issues can be opened here:
https://github.com/WolframResearch/codeformatter

@hifismith
Copy link
Author

This is really great information, thank you!

The IntelliJ plugin is quadrupling in price, so I thought I'd check in on the VS Code plugin. Formatting is probably my biggest hurdle in switching, so I'll definitely review the links you sent. Btw, thanks for adding the section folding. It's working

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

No branches or pull requests

2 participants