Skip to content

Added the formatting support#34

Open
Suyog241005 wants to merge 4 commits into
hyperjump-io:mainfrom
Suyog241005:feat/Implement-auto-formatting
Open

Added the formatting support#34
Suyog241005 wants to merge 4 commits into
hyperjump-io:mainfrom
Suyog241005:feat/Implement-auto-formatting

Conversation

@Suyog241005

@Suyog241005 Suyog241005 commented Jun 27, 2026

Copy link
Copy Markdown

Fixes

Fixes #25

Description

This PR implements auto-formatting (onDocumentFormatting) for JSON files using the existing jsonc-parser dependency.

Changes

  • Registered documentFormattingProvider: true inside the server capabilities.
  • Added a new Formatting feature module that maps the editor's formatting options (tabSize, insertSpaces) to jsonc.format.
  • Added comprehensive unit tests for spaces, tabs, CRLF preservation, and invalid JSON error handling.

@Suyog241005

Copy link
Copy Markdown
Author

Hey @jdesrosiers, opened the PR for the formatting support! Let me know if the changes look good to you.

Comment thread language-server/src/features/Formatting.ts Outdated
Comment thread language-server/src/features/Formatting.ts Outdated
Comment thread language-server/src/features/Formatting.ts Outdated

@jdesrosiers jdesrosiers left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good so far. I left a few notes. Please also include onDocumentRangeFormatting.

There's also onDocumentOnTypeFormatting, but I think that's a separate concern. I'm not entirely sure what that one is for.

Comment thread language-server/src/features/Formatting.ts Outdated
Comment thread language-server/src/features/Formatting.ts Outdated
Comment thread language-server/src/features/Formatting.test.ts
Comment thread language-server/src/features/Formatting.test.ts Outdated
@Suyog241005

Suyog241005 commented Jun 28, 2026

Copy link
Copy Markdown
Author

Looks good so far. I left a few notes. Please also include onDocumentRangeFormatting.

There's also onDocumentOnTypeFormatting, but I think that's a separate concern. I'm not entirely sure what that one is for.

onDocumentOnTypeFormatting is used for formatting as you type (triggered by specific characters like ; or }), which is standard for programming languages but not necessary for JSON files since editors already handle JSON indentation naturally.

I will include onDocumentRangeFormatting as requested.

@Suyog241005 Suyog241005 requested a review from jdesrosiers June 28, 2026 23:55

@srivastava-diya srivastava-diya left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

hey @Suyog241005 could you please have a look at why the tests are failing on windows. thanks!

@Suyog241005

Copy link
Copy Markdown
Author

hey @Suyog241005 could you please have a look at why the tests are failing on windows. thanks!

Yeah, the tests were failing on Windows CI because I wasn't using EOL from node:os in the test file. I've updated the tests to use EOL so they are fully cross-platform now

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.

feat: Implement formatting (onDocumentFormatting)

3 participants