Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: Add intelliJ plugin #33

Merged
merged 17 commits into from
Feb 4, 2025
Merged

feat: Add intelliJ plugin #33

merged 17 commits into from
Feb 4, 2025

Conversation

wsutina
Copy link
Collaborator

@wsutina wsutina commented Jan 31, 2025

📝 Description

Implement an IntelliJ plugin as a lightweight wrapper around the existing ktfmt call, ensuring it uses the same configuration as the CLI for consistency across tools.

⬇️ In Scope

  • Add IntelliJ IDEA plugin implementation.
  • Set up a pipeline to publish the plugin to the IntelliJ Marketplace.

🔜 Follow-up PRs

  • Add configuration options for enabling the plugin and integrating it with a script for formatting.
  • Update the README with installation and usage details.
  • Add a GitHub Action to automate IntelliJ version updates.

@wsutina wsutina changed the title Add intelliJ plugin wip: Add intelliJ plugin Jan 31, 2025
@mmollaverdi mmollaverdi force-pushed the swipawiwat/idea-plugin branch from 998843b to 0df6c91 Compare February 2, 2025 23:57
@mmollaverdi mmollaverdi force-pushed the swipawiwat/idea-plugin branch from 0df6c91 to ca3a0cf Compare February 3, 2025 00:53
@mmollaverdi
Copy link
Collaborator

mmollaverdi commented Feb 4, 2025

Replace cash-server check

Will add a config for this in a follow-up PR.

@@ -19,6 +19,14 @@ jobs:
os: [ ubuntu-latest ]
runs-on: ${{ matrix.os }}
steps:
# Free disk space to avoid running into "No space left on device" errors
# when downloading multiple versions of IntelliJ for plugin verification
- name: Maximize Build Space
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, the GH workflow fails with a disk space error. This just removes a whole bunch of packages which are not needed for our repository's CI.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might need this for publish step too

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did it c6d4934

./gradlew idea-plugin:patchPluginXml
./gradlew idea-plugin:publishPlugin
env:
JETBRAINS_TOKEN: ${{ secrets.JETBRAINS_PLUGIN_TOKEN }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added this secret, but need to test the publishing when this is merged.

/** Returns formatted content or null if the file is already formatted. */
private fun formatFile(file: PsiFile): String? {
var formattedContent = ""
val config = FormattingConfigs.forStdStreams(file.virtualFile.inputStream) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced the bin/kotlin-format call with using the kotlin-format lib here, but will bring back the former behind some form of configuration in a future PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's the case, we can call Ktfmt().format(request.documentText) directly which speed up everything (because we no longer need to open the file).

@@ -46,14 +56,18 @@ internal class TriggerFormatter(private val formatter: Formatter) {
}

companion object {
sealed class FormattingResult(private val compareOrder: Int, val fileName: String) : Comparable<FormattingResult> {
data class FormattingResults(val results: SortedSet<FormattingResult>, val charsProcessed: Long)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

charsProcessed was being extracted from the formatter instance and that meant the formatter needed to be returned from the formatForConfig method. I created this results class instead to hold all we need to return.

data class FormattingResults(val results: SortedSet<FormattingResult>, val charsProcessed: Long)

sealed class FormattingResult(private val compareOrder: Int, val fileName: String) :
Comparable<FormattingResult> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting.

@mmollaverdi mmollaverdi marked this pull request as ready for review February 4, 2025 04:23
@mmollaverdi mmollaverdi changed the title wip: Add intelliJ plugin Add the first version of intelliJ plugin Feb 4, 2025
@wsutina wsutina changed the title Add the first version of intelliJ plugin feat: Add intelliJ plugin Feb 4, 2025
@wsutina wsutina enabled auto-merge (squash) February 4, 2025 06:42
@wsutina wsutina merged commit 154cf24 into main Feb 4, 2025
1 check passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants