Skip to content

Add optional "organize imports" feature#183

Merged
rvanasa merged 8 commits intomainfrom
organize-imports-2
Mar 10, 2026
Merged

Add optional "organize imports" feature#183
rvanasa merged 8 commits intomainfrom
organize-imports-2

Conversation

@rvanasa
Copy link
Copy Markdown
Contributor

@rvanasa rvanasa commented Mar 6, 2026

Implements "organize imports" similar to what was previously implemented in the VS Code extension. Instead of using a parsed AST, this implementation uses a token tree for more robustness to syntax errors and compatibility across a wider range of compiler versions. This implementation also confirms that all imports are preserved before applying the changes.

Example .prettierrc:

{
    "plugins": ["prettier-plugin-motoko"],
    "motokoOrganizeImports": true
}

@rvanasa rvanasa changed the title Add option to organize imports Add optional "organize imports" feature Mar 6, 2026
Copy link
Copy Markdown

@Kamirus Kamirus left a comment

Choose a reason for hiding this comment

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

Nice work on this feature! Solid safety-first approach (always returning the original tree on failure). I have a few suggestions

Comment thread src/printers/motoko-tt-ast/print.ts Outdated
Comment thread src/printers/motoko-tt-ast/organizeImports.ts Outdated
Comment thread README.md
Comment thread src/printers/motoko-tt-ast/organizeImports.ts Outdated
@rvanasa
Copy link
Copy Markdown
Contributor Author

rvanasa commented Mar 9, 2026

(CI error expected and fixes itself when releasing)

@rvanasa rvanasa merged commit 7c93535 into main Mar 10, 2026
7 checks passed
@rvanasa rvanasa deleted the organize-imports-2 branch March 10, 2026 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants