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

[question] Would it be possible to put the opening brackets on a new line but have no new line after it whilst maintaining indentation? #639

Open
ItsCubeTime opened this issue Jun 11, 2021 · 7 comments
Labels
alignment additional whitespace for alignment enhancement New feature or request indentation Indentation is incorrect whitespace missing or incorrect space around token

Comments

@ItsCubeTime
Copy link

So this is my desired formatting:

image

And so I tried setting:

  "lineEnds": {
    "leftCurly": "before",

See the whole file: https://pastebin.com/ikDkw5Tk

Which resulted in loss of indentation:
image

Is there any setting that might help bringing the indentation back here? Prefferably I would want 3 spaces after the opening bracket & 4 extra spaces for indentation where theres no preceeding bracket on the same line.

Thanks in advance :)

@AlexHaxe AlexHaxe added alignment additional whitespace for alignment enhancement New feature or request indentation Indentation is incorrect whitespace missing or incorrect space around token labels Jun 11, 2021
@ItsCubeTime
Copy link
Author

ItsCubeTime commented Jun 11, 2021

I assume those labels means a no. So if thats the case, would adding something like this:

  "indentation": {
    "character": "    ",
    "trailingWhitespace": false,
    "indentationAfterLeftCurly": true,
    "characterUsedForIndentationAfterLeftCurly": "   ",
    "indentBeforeLeftCurly": true
  },

seem like a decent solution? And if I were to make a PR for it, would it be likely to get merged into master (or would it just be considered unnecessary bloat)?

(and if it does sound good, I would appreciate if somebody could pinpoint to some nice places in the code base for adding these features)

@AlexHaxe
Copy link
Member

that's the first time I've seen such a code style.

and no, it's not available out of the box.
making formatter support it requires changes to indentation and whitespace / alignment logic, because even if indentation worked the way you wanted, it would still have no effect on whitespace after left curly. so both need to be addressed.

as to a PR, I'm not opposed to it, since I don't think I'll find the time to work on it myself.
however I don't think your new configuration values will be necessary, because "leftCurly": "before" should probably already indent the way you intend. as for the alignment that should be "tabWidth" - 1 or a tab depending on whether indentation is done with spaces or tabs.

for starters there is Indenter class which does all of the indentation calculation. just as a heads up: it's probably the most complicated part of formatter.
for alignment there is no dedicated Mark* class, the little bit of alignment that formatter does is done by matrix wrapping code.

make sure you run unittests after changing, because the smallest change will typically make a lot of testcases fail. so finding the right change might take quite some time.

good luck!

@ItsCubeTime
Copy link
Author

ItsCubeTime commented Jun 11, 2021

as for the alignment that should be "tabWidth" - 1 or a tab depending on whether indentation is done with spaces or tabs.

Could you elaborate a bit on this? Is tabWidth an integer var in the code or are you intending this to be an alternative to my configuration suggestions?

that's the first time I've seen such a code style.

Thats because I came up with it myself :) I like it because it aligns the brackets vertically (like all-man-case) whilst being just as compact K&R styles

However after googling some it turns out theres however a name & wikipedia section for it, which explains the same advantages as I originally saw with it :P :
image

@AlexHaxe
Copy link
Member

Could you elaborate a bit on this? Is tabWidth an integer var in the code or are you intending this to be an alternative to my configuration suggestions?

tabWidth is a configuration setting under indentation section. it's used to tell formatter how many spaces are supposed to be in a tab (which of course depends on your editor's settings, but formatter needs to know what you think it is).

However after googling some it turns out theres however a name & wikipedia section for it, which explains the same advantages as I originally saw with it :P :

it also says, that it's inventor is not using it anymore

@ItsCubeTime
Copy link
Author

So I tried building all the targets, however Im a little confused. First off it doesnt seem to wanna build the C++ target and secondly, I cant quite find the directory that the other targets supposedly gets built into (looking to build for debugging). The "build" directory remains with only a hxml file after building

PS C:\Users\Oliver\Downloads\haxe-formatter-master\haxe-formatter-master> Haxe -cp Build --run Build
haxelib path: 
building run.js (0.98791360855102539)
haxelib path: 
building runBrowser.js (0.61609745025634766)
haxelib path: 
building run.n (0.61399531364440918)
haxelib path: 
building Cli.jar (0.61277437210083008)
haxelib path: 
building JSON schema (0.609966516494751)
PS C:\Users\Oliver\Downloads\haxe-formatter-master\haxe-formatter-master> haxe buildCpp.hxml
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkFieldDef.hx:8: characters 47-55 : Pattern variables must be lower-case
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkFieldDef.hx:8: characters 47-55 : Variable KwdFinal must appear exactly once in each sub-pattern
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkTypedefBody.hx:49: characters 14-22 : Pattern variables must be lower-case
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkFinal.hx:46: characters 15-23 : Pattern variables must be lower-case
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkStatement.hx:217: characters 13-21 : Pattern variables must be lower-case
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkClass.hx:56: characters 46-57 : Pattern variables must be lower-case
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkClass.hx:56: characters 46-57 : Variable KwdOverload must appear exactly once in each sub-pattern
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkStatement.hx:219: lines 219-227 : Warning : This case is unused
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkStatement.hx:228: lines 228-229 : Warning : This case is unused
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkStatement.hx:230: lines 230-231 : Warning : This case is unused
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkStatement.hx:232: lines 232-233 : Warning : This case is unused
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkStatement.hx:234: characters 9-38 : Warning : This pattern is unused
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkStatement.hx:236: lines 236-237 : Warning : This case is unused
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkStatement.hx:238: lines 238-239 : Warning : This case is unused
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkStatement.hx:240: lines 240-243 : Warning : This case is unused
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkStatement.hx:244: lines 244-245 : Warning : This case is unused
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkStatement.hx:246: lines 246-247 : Warning : This case is unused
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkStatement.hx:248: lines 248-249 : Warning : This case is unused
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkStatement.hx:250: lines 250-254 : Warning : This case is unused
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkStatement.hx:255: characters 9-21 : Warning : This pattern is unused
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkStatement.hx:265: lines 265-269 : Warning : This case is unused
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkStatement.hx:270: lines 270-274 : Warning : This case is unused
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/utils/TokenTreeCheckUtils.hx:170: characters 13-21 : Pattern variables must be lower-case
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/utils/TokenTreeCheckUtils.hx:398: characters 15-23 : Pattern variables must be lower-case
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/utils/TokenTreeCheckUtils.hx:898: characters 47-55 : Pattern variables must be lower-case
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/utils/TokenTreeCheckUtils.hx:898: characters 47-55 : Variable KwdFinal must appear exactly once in each sub-pattern
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkInterface.hx:36: characters 14-22 : Pattern variables must be lower-case
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkAbstract.hx:51: characters 14-22 : Pattern variables must be lower-case
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkFile.hx:31: characters 134-145 : Pattern variables must be lower-case
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/walk/WalkFile.hx:31: characters 134-145 : Variable KwdOverload must appear exactly once in each sub-pattern
src/formatter/marker/Indenter.hx:560: characters 14-22 : Pattern variables must be lower-case
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/utils/FieldUtils.hx:48: characters 15-23 : Pattern variables must be lower-case
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/utils/FieldUtils.hx:14: characters 26-34 : Pattern variables must be lower-case
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/utils/FieldUtils.hx:14: characters 26-34 : Variable KwdFinal must appear exactly once in each sub-pattern
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/utils/FieldUtils.hx:68: characters 42-50 : Pattern variables must be lower-case
C:\HaxeToolkit\haxe\lib\tokentree/1,1,1/src/tokentree/utils/FieldUtils.hx:68: characters 42-50 : Pattern variables are not allowed in .match patterns
src/formatter/marker/MarkEmptyLines.hx:777: characters 14-22 : Pattern variables must be lower-case
src/formatter/marker/MarkEmptyLines.hx:320: characters 14-22 : Pattern variables must be lower-case
src/formatter/marker/MarkEmptyLines.hx:987: characters 15-23 : Pattern variables must be lower-case
src/formatter/marker/MarkLineEnds.hx:375: characters 14-22 : Pattern variables must be lower-case
src/formatter/marker/MarkLineEnds.hx:375: characters 14-22 : Variable KwdFinal must appear exactly once in each sub-pattern

@ItsCubeTime
Copy link
Author

Also is this the VSCode extension that youre using for debugging? https://github.com/vshaxe/vshaxe-debug-tools/blob/master/images/visualizer.gif

I cant seem to find it on the VS Code market place. Is it bundled in the regular "Haxe", "Haxe language support" extension or do I really need to clone the github repo just for a binary install?

@AlexHaxe
Copy link
Member

formatter uses lix for dependency management. so you need to run

npm i
npx lix download
npx haxe build.hxml

or npx haxe buildCpp.hxml, npx haxe test.hxml, etc.

as to the vshaxe debug tools extension: it's not on the marketplace you need to install it manually (see instructions in it's readme)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
alignment additional whitespace for alignment enhancement New feature or request indentation Indentation is incorrect whitespace missing or incorrect space around token
Projects
None yet
Development

No branches or pull requests

2 participants