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

Formatter incorrectly indents object literals #184

Closed
Cirieno opened this issue Jul 21, 2022 · 1 comment · Fixed by #260
Closed

Formatter incorrectly indents object literals #184

Cirieno opened this issue Jul 21, 2022 · 1 comment · Fixed by #260
Assignees
Labels
bug something isn't working formatter code formatter issues

Comments

@Cirieno
Copy link

Cirieno commented Jul 21, 2022

This may be a very niche situation / edge case due to a way that I have found you can create object literals in a relatively compact but easily readable form (coming from a javascript/JSON background, comma-placement notwithstanding), in which case feel free to wontfix. But I'll describe it anyway...

On Format Document, the formatter indents the first object correctly (one tab), but after that goes wild with the tabs and double-indents the second object (3 tabs), triple indents the third object (4 tabs). It also pulls the last line of the object back in by one tab, so it's in line with its definition. From the end of the function as exampled below to the end of the file the formatter keeps the 4-tabs as the new left margin! And the one super-indented line "useToast" isn't a typo, it does get pushed in one more tab.

Unformatted code

[... AUTORUN SECTION etc]
global __Settings := {}
populateGlobalVars()
return

populateGlobalVars(){
	__Settings.app := {0:0
		, name: "[...]"
		, author: { name: "[...]", email: "[...]", company: "[...]" }
		, build: { version: "[...]", date: "[...]", repo: "[...]" } }

	__Settings.app.tray := {0:0
		, title: __Settings.app.name
		, traytip: "[=" . __Settings.app.name . "]"
		, icon: { location: (A_IsCompiled ? A_ScriptName : "icons\cog-wheel-3.ico"), index: -0 }
		, useToast: getIniVal("Tray\useToast", true)
		, msgTimeout: 2000 }

	__Settings.app.environment := {0:0
		, company: getIniVal("Environment\company", __Settings.app.author.company)
		, computerName: A_ComputerName
		, user: A_UserName
		, domain: getAppEnvironmentDomain() }

	__Settings.app.debugging := {0:0
		, enabledOnInit: getIniVal("AppDebugging\enabled", !A_IsCompiled)
		, activeOnInit: getIniVal("AppDebugging\active", !A_IsCompiled)
		, notifyUser: getIniVal("AppDebugging\notify", true)
		, menuLabel: "Debugging mode" }
	__Settings.app.debugging.enabled := (__Settings.app.debugging.activeOnInit ? true : __Settings.app.debugging.enabledOnInit)
	__Settings.app.debugging.active := (__Settings.app.debugging.enabled && __Settings.app.debugging.activeOnInit)
}

Expected formatted output

(Same as above)

Actual formatted output

populateGlobalVars(){
	__Settings.app := {0:0
		, name: "[...]"
		, author: { name: "[...]", email: "[...]", company: "[...]" }
		, build: { version: "[...]", date: "[...]", repo: "[...]" } }

			__Settings.app.tray := {0:0
				, title: __Settings.app.name
				, traytip: "[=" . __Settings.app.name . "]"
				, icon: { location: (A_IsCompiled ? A_ScriptName : "icons\cog-wheel-3.ico"), index: -0 }
					, useToast: getIniVal("Tray\useToast", true)
				, msgTimeout: 2000 }

				__Settings.app.environment := {0:0
					, company: getIniVal("Environment\company", __Settings.app.author.company)
					, computerName: A_ComputerName
					, user: A_UserName
				, domain: getAppEnvironmentDomain() }

				__Settings.app.debugging := {0:0
					, enabledOnInit: getIniVal("AppDebugging\enabled", !A_IsCompiled)
					, activeOnInit: getIniVal("AppDebugging\active", !A_IsCompiled)
					, notifyUser: getIniVal("AppDebugging\notify", true)
				, menuLabel: "Debugging mode" }
				__Settings.app.debugging.enabled := (__Settings.app.debugging.activeOnInit ? true : __Settings.app.debugging.enabledOnInit)
				__Settings.app.debugging.active := (__Settings.app.debugging.enabled && __Settings.app.debugging.activeOnInit)
				}
@Cirieno Cirieno added bug something isn't working formatter code formatter issues labels Jul 21, 2022
@mark-wiemer
Copy link
Collaborator

Hey @Cirieno , thanks for opening this bug. Are you able to provide a slightly smaller object with values like foo and bar so that we can more easily debug the problem? It's pretty clear, but a short 5-10 line snippet would work wonders to make sure we're all on the same page :)

@mark-wiemer mark-wiemer added this to the Backlog milestone Jul 28, 2022
@mark-wiemer mark-wiemer removed this from the Backlog milestone Oct 15, 2022
mark-wiemer pushed a commit that referenced this issue Nov 15, 2022
mark-wiemer added a commit that referenced this issue Nov 22, 2022
## 3.1.0 - 2022-11-21 🦃

Compiler:

-   New compiler options in settings: Choose base file, file icon, and "use [MPRESS](https://www.autohotkey.com/mpress/mpress_web.htm)"
-   Add "Compiler GUI" command in context menu to use the AHK GUI when compiling

Snippets:

-   Update snippets for AHK 1.1.35.00 and fix broken `InStr()` snippet ([#263](#263))

Grammar: Fix `#Requires` not being recognized ([#268](#268))

Editor: New AHK file icon (green square with white H)

Debugger: Minor debugger improvements

Formatter: Close the following bugs:

    -   Formatter incorrectly indents object literals ([#184](#184), [#222](#222))
    -   Nested one command code flow control ([#255](#255))

Miscellaneous:

-   Extension should start up faster
@mark-wiemer mark-wiemer mentioned this issue Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something isn't working formatter code formatter issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants