-
Notifications
You must be signed in to change notification settings - Fork 24
Support IntelliJ 2023.2 #56
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| distributionBase=GRADLE_USER_HOME | ||
| distributionPath=wrapper/dists | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip | ||
| zipStoreBase=GRADLE_USER_HOME | ||
| zipStorePath=wrapper/dists |
18 changes: 18 additions & 0 deletions
18
src/IC-232/kotlin/com/amazon/ion/plugin/intellij/formatting/ASTNodeUtils.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package com.amazon.ion.plugin.intellij.formatting | ||
|
|
||
| import com.amazon.ion.plugin.intellij.utils.filterWhitespace | ||
| import com.intellij.lang.ASTNode | ||
| import org.jetbrains.kotlin.idea.base.psi.getLineNumber | ||
| import org.jetbrains.kotlin.psi.psiUtil.siblings | ||
|
|
||
| /** | ||
| * Determine if a node is on the same line as another node. | ||
| */ | ||
| fun ASTNode.sameLineAs(another: ASTNode) = | ||
| another.psi.getLineNumber(start = true) == this.psi.getLineNumber(start = true) | ||
|
|
||
| /** | ||
| * Return the previous sibling of a node if it exists. | ||
| */ | ||
| fun ASTNode.previousSibling(): ASTNode? = | ||
| siblings(forward = false).filterWhitespace().firstOrNull() | ||
33 changes: 33 additions & 0 deletions
33
src/IC-232/kotlin/com/amazon/ion/plugin/intellij/formatting/IonCodeStyleSettingsProvider.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package com.amazon.ion.plugin.intellij.formatting | ||
|
|
||
| import com.amazon.ion.plugin.intellij.IonLanguage | ||
| import com.intellij.application.options.CodeStyleAbstractConfigurable | ||
| import com.intellij.application.options.CodeStyleAbstractPanel | ||
| import com.intellij.application.options.TabbedLanguageCodeStylePanel | ||
| import com.intellij.openapi.options.Configurable | ||
| import com.intellij.psi.codeStyle.CodeStyleSettings | ||
| import com.intellij.psi.codeStyle.CodeStyleSettingsProvider | ||
|
|
||
| private const val CODE_STYLE_SETTINGS_DISPLAY_NAME = "Ion" | ||
|
|
||
| class IonCodeStyleSettingsProvider : CodeStyleSettingsProvider() { | ||
| override fun getConfigurableDisplayName(): String = CODE_STYLE_SETTINGS_DISPLAY_NAME | ||
|
|
||
| override fun createSettingsPage(settings: CodeStyleSettings, modelSettings: CodeStyleSettings): Configurable = | ||
| CodeStyleConfigurableConfiguration(settings, modelSettings) | ||
| } | ||
|
|
||
| private class CodeStyleConfigurableConfiguration(settings: CodeStyleSettings, modelSettings: CodeStyleSettings) | ||
| : CodeStyleAbstractConfigurable(settings, modelSettings, CODE_STYLE_SETTINGS_DISPLAY_NAME) { | ||
|
|
||
| override fun createPanel(settings: CodeStyleSettings): CodeStyleAbstractPanel = IonCodeStyleMainPanel(currentSettings, settings) | ||
| override fun getHelpTopic(): String? = null | ||
| } | ||
|
|
||
| private class IonCodeStyleMainPanel(currentSettings: CodeStyleSettings, settings: CodeStyleSettings) | ||
| : TabbedLanguageCodeStylePanel(IonLanguage.INSTANCE, currentSettings, settings) { | ||
|
|
||
| override fun initTabs(settings: CodeStyleSettings?) { | ||
| addIndentOptionsTab(settings) | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
34
src/IC-232/kotlin/com/amazon/ion/plugin/intellij/formatting/IonFormattingModelBuilder.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package com.amazon.ion.plugin.intellij.formatting | ||
|
|
||
| import com.amazon.ion.plugin.intellij.formatting.blocks.IonBlockOptions | ||
| import com.amazon.ion.plugin.intellij.formatting.blocks.RootIonBlock | ||
| import com.intellij.formatting.FormattingContext | ||
| import com.intellij.formatting.FormattingModel | ||
| import com.intellij.formatting.FormattingModelBuilder | ||
| import com.intellij.formatting.FormattingModelProvider | ||
|
|
||
| /** | ||
| * Creates the block model for an Ion file. | ||
| * | ||
| * The block model will determine how elements are spaced, indented and aligned. | ||
| */ | ||
| class IonFormattingModelBuilder : FormattingModelBuilder { | ||
| override fun createModel(formattingContext: FormattingContext): FormattingModel { | ||
| val element = formattingContext.psiElement | ||
| val settings = formattingContext.codeStyleSettings | ||
|
|
||
| val rootBlock = RootIonBlock( | ||
| node = element.node, | ||
| options = IonBlockOptions( | ||
| spaceBuilder = IonCodeBlockSpacingProvider(settings), | ||
| codeStyle = settings | ||
| ) | ||
| ) | ||
|
|
||
|
|
||
| return FormattingModelProvider.createFormattingModelForPsiFile( | ||
| element.containingFile, | ||
| rootBlock, settings | ||
| ) | ||
| } | ||
| } |
68 changes: 68 additions & 0 deletions
68
src/IC-232/kotlin/com/amazon/ion/plugin/intellij/formatting/blocks/IonSExpressionBlock.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package com.amazon.ion.plugin.intellij.formatting.blocks | ||
|
|
||
| import com.amazon.ion.plugin.intellij.formatting.previousSibling | ||
| import com.amazon.ion.plugin.intellij.formatting.sameLineAs | ||
| import com.amazon.ion.plugin.intellij.psi.IonTypes | ||
| import com.amazon.ion.plugin.intellij.psi.isOneLiner | ||
| import com.amazon.ion.plugin.intellij.utils.elementIsA | ||
| import com.intellij.lang.ASTNode | ||
| import com.intellij.openapi.diagnostic.debug | ||
| import com.intellij.openapi.diagnostic.logger | ||
| import com.intellij.psi.tree.IElementType | ||
| import org.jetbrains.kotlin.idea.base.psi.getLineNumber | ||
|
|
||
| private val logger = logger<IonSExpressionBlock>() | ||
|
|
||
| class IonSExpressionBlock( | ||
| node: ASTNode, | ||
| formatting: IonBlockFormattingOptions, | ||
| options: IonBlockOptions | ||
| ) : AbstractIonBlock(node, formatting = formatting, options = options) { | ||
|
|
||
| override val childIndentedTypes: Set<IElementType> = setOf( | ||
| IonTypes.VALUE, | ||
| IonTypes.COMMENT | ||
| ) | ||
|
|
||
| override val childContainerTypes: Set<IElementType> = setOf( | ||
| IonTypes.SEXPRESSION_ELEMENTS | ||
| ) | ||
|
|
||
| override val containerWrapperTypes: Set<IElementType> = setOf( | ||
| IonTypes.LPAREN, | ||
| IonTypes.RPAREN | ||
| ) | ||
|
|
||
| override fun buildChildBlockFormatting(child: ASTNode): IonBlockFormattingOptions = | ||
| buildSpecialCaseChildBlockFormatting(child) ?: | ||
| super.buildChildBlockFormatting(child) | ||
|
|
||
| private fun buildSpecialCaseChildBlockFormatting(child: ASTNode): IonBlockFormattingOptions? { | ||
|
|
||
| // Lazy evaluate the previous sibling if needed. | ||
| val previous by lazy { child.previousSibling() } | ||
|
|
||
| /** | ||
| * Check if we are the first comment within the expression, there is a special comment | ||
| * case where we don't want to apply the child alignment to the comment. For example: | ||
| * | ||
| * (join // special case comment which is inline with operator | ||
| * // child comments are inline with inner values | ||
| * anotherValue | ||
| * ) | ||
| */ | ||
| if (child elementIsA IonTypes.COMMENT && previous?.elementType == IonTypes.SEXPRESSION_OPERATOR) { | ||
|
|
||
| logger.debug { "Formatting [${child.psi.getLineNumber()}] - Special case inline expression comment line" } | ||
|
|
||
| val comment = child.psi | ||
| val expressionOperator = previous!! | ||
|
|
||
| if (comment.isOneLiner() && child.sameLineAs(expressionOperator)) { | ||
| return IonBlockFormatting.sameAlignment(this) | ||
| } | ||
| } | ||
|
|
||
| return null | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/IC-232/kotlin/com/amazon/ion/plugin/intellij/psi/PsiElementExtensions.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.amazon.ion.plugin.intellij.psi | ||
|
|
||
| import com.intellij.psi.PsiElement | ||
| import org.jetbrains.kotlin.idea.base.psi.getLineCount | ||
|
|
||
| /** | ||
| * True if the element is all in a single line. | ||
| * | ||
| * Exists for Backwards Compatibility: <= IC-2020.2 | ||
| */ | ||
| fun PsiElement.isOneLiner() = getLineCount() == 1 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(🗺️ PR tour) All the contents in IC-232 are copied from IC-231.