@@ -34,7 +34,9 @@ import com.tang.intellij.lua.psi.LuaTypes.*
3434 */
3535class LuaFormattingModelBuilder : FormattingModelBuilder {
3636 override fun createModel (element : PsiElement , settings : CodeStyleSettings ): FormattingModel {
37- val ctx = LuaFormatContext (settings, settings.getCustomSettings(LuaCodeStyleSettings ::class .java), createSpaceBuilder(settings))
37+ val commonSettings = settings.getCommonSettings(LuaLanguage .INSTANCE )
38+ val luaSettings = settings.getCustomSettings(LuaCodeStyleSettings ::class .java)
39+ val ctx = LuaFormatContext (commonSettings, luaSettings, createSpaceBuilder(settings))
3840 return FormattingModelProvider .createFormattingModelForPsiFile(element.containingFile,
3941 LuaScriptBlock (element,
4042 Wrap .createWrap(WrapType .NONE , false ),
@@ -46,6 +48,7 @@ class LuaFormattingModelBuilder : FormattingModelBuilder {
4648
4749 private fun createSpaceBuilder (settings : CodeStyleSettings ): SpacingBuilder {
4850 val luaCodeStyleSettings = settings.getCustomSettings(LuaCodeStyleSettings ::class .java)
51+ val commonSettings = settings.getCommonSettings(LuaLanguage .INSTANCE )
4952
5053 return SpacingBuilder (settings, LuaLanguage .INSTANCE )
5154 .before(END ).lineBreakInCode()
@@ -54,8 +57,8 @@ class LuaFormattingModelBuilder : FormattingModelBuilder {
5457 .around(ELSE ).lineBreakInCode()
5558 .before(ELSEIF ).lineBreakInCode()
5659 .after(LOCAL ).spaces(1 ) // local<SPACE>
57- .before(COMMA ).spaces(if (settings .SPACE_BEFORE_COMMA ) 1 else 0 )
58- .after(COMMA ).spaces(if (settings .SPACE_AFTER_COMMA ) 1 else 0 ) // ,<SPACE>
60+ .before(COMMA ).spaces(if (commonSettings .SPACE_BEFORE_COMMA ) 1 else 0 )
61+ .after(COMMA ).spaces(if (commonSettings .SPACE_AFTER_COMMA ) 1 else 0 ) // ,<SPACE>
5962 .between(LCURLY , TABLE_FIELD ).spaces(1 ) // {<SPACE>1, 2 }
6063 .between(TABLE_FIELD , RCURLY ).spaces(1 ) // { 1, 2<SPACE>}
6164 .before(TABLE_FIELD_SEP ).none() // { 1<SPACE>, 2 }
@@ -64,9 +67,9 @@ class LuaFormattingModelBuilder : FormattingModelBuilder {
6467 .afterInside(RPAREN , FUNC_BODY ).lineBreakInCode()
6568 .between(FUNCTION , FUNC_BODY ).none()
6669 .between(FUNCTION , NAME_DEF ).spaces(1 ) // function<SPACE>name()
67- .around(BINARY_OP ).spaces(if (settings .SPACE_AROUND_ASSIGNMENT_OPERATORS ) 1 else 0 )
70+ .around(BINARY_OP ).spaces(if (commonSettings .SPACE_AROUND_ASSIGNMENT_OPERATORS ) 1 else 0 )
6871 .around(UNARY_OP ).none()
69- .around(ASSIGN ).lineBreakOrForceSpace(false , settings .SPACE_AROUND_ASSIGNMENT_OPERATORS ) // = 号两头不能换行
72+ .around(ASSIGN ).lineBreakOrForceSpace(false , commonSettings .SPACE_AROUND_ASSIGNMENT_OPERATORS ) // = 号两头不能换行
7073 .around(LuaSyntaxHighlighter .KEYWORD_TOKENS ).spaces(1 )
7174 .around(LBRACK ).none() // [
7275 .before(RBRACK ).none() // ]
0 commit comments