Skip to content
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

vim: Fix comma insertion for newline in JSON #19801

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kurtbuilds
Copy link
Contributor

Closes #18509

I tried to create a test case for this but ran into blocks. Neovim doesn't appear to do this (IntelliJ does), so I couldn't use the NeovimTestCase. I tried using VimTestCase:

#[gpui::test]
    async fn test_comma_insertion(cx: &mut gpui::TestAppContext) {
        // Neovim doesn't do this, so use a Zed-only test
        let mut cx = VimTestContext::new(cx, true).await;
        let doc = r#"{
  "foo": "bar",
  "baz": "qux"ˇ
}"#;
        // cx.set_state(doc, Mode::Normal);
        cx.update_buffer(|b, cx| {
            b.set_text(doc, cx);
            let mut config = LanguageConfig::default();
            config.insert_trailing_commas = true;
            config.tab_size = Some(2.try_into().unwrap());
            b.set_language(Some(std::sync::Arc::new(Language::new(config, None))), cx);
        });
        // cx.set_neovim_option("filetype=json").await;
        let expected = r#"{
  "foo": "bar",
  "baz": "qux",
  ˇ
}"#;
        // cx.set_state(doc, Mode::Normal);
        cx.simulate_keystroke("o");
        assert_eq!(cx.display_text(), expected);

but it doesn't seem to execute the newline action with the cx.simulate_keystroke("o"); line.

Release Notes:

  • Zed will insert commas when creating newlines in Vim for JSON/JSONC documents

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Oct 27, 2024
@kurtbuilds kurtbuilds changed the title fix comma insertion for vim newline in json Fix comma insertion for vim newline in json Oct 27, 2024
@maxdeviant maxdeviant changed the title Fix comma insertion for vim newline in json vim: Fix comma insertion for newline in JSON Oct 28, 2024
@ConradIrwin
Copy link
Member

@kurtbuilds you might need to make sure you're in normal mode.

That said, I think we should build this primarily in the editor::Newline handler rather than just for o in normal mode

@kurtbuilds
Copy link
Contributor Author

That makes sense. I'll take another stab at it this weekend :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The user has signed the Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

insert comma when creating newline in JSON
2 participants