Skip to content

fix: make code actions follow formatter tag spacing#1089

Open
lewis6991 wants to merge 1 commit into
EmmyLuaLs:mainfrom
lewis6991:fix/format-insert-space
Open

fix: make code actions follow formatter tag spacing#1089
lewis6991 wants to merge 1 commit into
EmmyLuaLs:mainfrom
lewis6991:fix/format-insert-space

Conversation

@lewis6991
Copy link
Copy Markdown
Collaborator

@lewis6991 lewis6991 commented May 18, 2026

Problem

codeAction.insertSpace is currently a boolean defaulting to false, so generated diagnostic comments cannot follow the formatter configured EmmyLua tag spacing.

Solution

Make codeAction.insertSpace optional. When omitted, generated diagnostic comments resolve the formatter config for the current file and use emmy_doc.space_between_tag_columns. Explicit codeAction.insertSpace still overrides the formatter setting.

Update the generated schema and config docs.

@github-actions
Copy link
Copy Markdown

Code Review Summary

✅ Overall Assessment

This PR introduces a new format.insertSpace configuration option that controls whether the built-in formatter adds a space between --- and annotation tags, while making codeAction.insertSpace fall back to this new setting when not explicitly configured. The changes are well-structured and include proper tests.

🔍 Issues Found

1. Potential Breaking Change for Existing Users

  • Location: schema.json, code_action.rs
  • Issue: Changing codeAction.insertSpace default from false to null changes behavior for users who don't explicitly set this option. Previously, no space was added by default; now it falls back to format.insertSpace (which defaults to false), so behavior remains the same. However, if a user upgrades and their formatter configuration changes, the code action behavior could unexpectedly change.
  • Recommendation: Consider adding a migration note in the changelog or documentation.

2. Inconsistent Fallback Logic

  • Location: build_disable_code.rs line 283
  • Issue: The fallback chain is codeAction.insertSpace -> format.insertSpace -> false. If a user explicitly sets format.insertSpace = null, it will fall back to false. This is fine, but the logic could be clearer.
  • Recommendation: Consider using unwrap_or with a more explicit default:
    fn code_action_insert_space(emmyrc: &Emmyrc) -> bool {
        emmyrc.code_action.insert_space
            .or(emmyrc.format.insert_space)
            .unwrap_or(false)
    }

3. Missing Test for Null Fallback

  • Location: build_disable_code.rs tests
  • Issue: The test only covers cases where both values are Some. Missing test for when both are None (should return false).
  • Recommendation: Add test case:
    #[test]
    fn both_null_defaults_to_false() {
        let emmyrc = Emmyrc::default();
        assert!(!code_action_insert_space(&emmyrc));
    }

4. Documentation Ambiguity

  • Location: emmyrc_json_EN.md line 471
  • Issue: The description "Override format.insertSpace when inserting @diagnostic disable-next-line" is unclear about the fallback behavior. It sounds like it always overrides, but actually it only overrides when explicitly set.
  • Recommendation: Clarify: "When set, overrides format.insertSpace for @diagnostic disable-next-line insertion. When omitted, follows format.insertSpace."

✅ Positive Aspects

  • Good test coverage for both code action and formatter behavior
  • Clear separation of concerns between code action and formatting configuration
  • Proper use of Option<bool> to distinguish between "not set" and explicit false
  • Updated documentation in both Chinese and English
  • Schema updated to reflect new configuration options

📋 Summary

The changes are well-implemented and address a real user need. The main concerns are minor documentation clarity and test completeness. No security vulnerabilities or critical bugs were found.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new format.insertSpace configuration option and updates codeAction.insertSpace to be optional, allowing it to fall back to the global formatting setting. The built-in formatter now utilizes this configuration to determine whether to keep a space between --- and annotation tags. Additionally, the JSON schema and documentation have been updated to reflect these changes, and unit tests were added to ensure correct fallback logic and formatting behavior. I have no feedback to provide.

@CppCXY
Copy link
Copy Markdown
Member

CppCXY commented May 18, 2026

What is the difference between this option and space_between_tag_columns? Maybe my name isn't very appropriate, but it should be for this function.

Edit: I reviewed the code again. If this configuration option is placed here, it seems it cannot be used with the external formatter, so is it really appropriate?

@lewis6991 lewis6991 force-pushed the fix/format-insert-space branch from 16d2540 to 00a060c Compare May 18, 2026 11:16
@lewis6991 lewis6991 changed the title fix: add formatter annotation spacing config fix: make code actions follow formatter tag spacing May 18, 2026
@lewis6991
Copy link
Copy Markdown
Collaborator Author

You're right, sorry. I didn't look closely enough at what already existed.

format.insertSpace was just duplicating emmy_doc.space_between_tag_columns, and your external formatter point is valid too: that option would not have affected external formatter output.

I've revised the PR to remove the new formatter option. The remaining change only makes codeAction.insertSpace optional; when it is omitted, code actions now fall back to the existing resolved formatter config for the file, emmy_doc.space_between_tag_columns.

@lewis6991 lewis6991 force-pushed the fix/format-insert-space branch from 00a060c to ef0bd2a Compare May 18, 2026 11:24
Make codeAction.insertSpace optional so generated diagnostic comments use the existing formatter tag spacing config unless explicitly overridden.

Assisted-by: Codex
@lewis6991 lewis6991 force-pushed the fix/format-insert-space branch from ef0bd2a to 9c1da2a Compare May 18, 2026 11:40
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