bestgopher
bestgopher
> This is how it behaves on my end. > > Screen.Recording.2024-08-18.115030.mp4 It looks like the rust-formatter's behavior. I reproduced it only with rust file(.rs file). You could turn off...
@JunkuiZhang https://github.com/user-attachments/assets/c6be104d-6e0f-4918-b504-d73ab53e8fbf
> Great, can we test this? > > https://github.com/zed-industries/zed/blob/10a996cbc40498f58a91fe1a2433bd81ea3c0218/crates/editor/src/editor_tests.rs#L6119 > > has some formatting tests, presumably we can add another one nearby? Done, please take a look.
> test_document_format_during_save Hi, I have a question: Whether `editor.update(cx, |editor, cx| editor.set_text("", cx));` can clean the file?
> It does clean the text, in the file, so not sure what do you mean. ```rust editor.update(cx, |editor, cx| editor.set_text("", cx)); assert!(cx.read(|cx| editor.is_dirty(cx))); let save = editor .update(cx, |editor,...
> Ok(Some(vec![lsp::TextEdit::new( > + lsp::Range::new(lsp::Position::new(0, 0), lsp::Position::new(u32::MAX, 0)), > + "".to_string(), > + )])) If the end of Range were changed to `lsp::Position::new(0, 0)`, it will be failed.
My original idea is: First, clear the file. Then, mock the lsp return an empty string ``(`Ok(Some(vec![lsp::TextEdit::new(lsp::Range::new(lsp::Position::new(0, 0), lsp::Position::new(0, 0)),"".to_string())]))`). Because the file is empty, `ensure_final_newline` is called and returns...
@SomeoneToIgnore Thanks for your comment and advice. I have wrote another testcase, and it looks good to me.
> There's more than that, isn't it? My comment from [#16423 (comment)](https://github.com/zed-industries/zed/pull/16423#issuecomment-2296640464) pretty much states we should close this PR and use a proper approach. > > Also, I did...
As you can see, Here are two ways to insert '\n': `rust-lsp` and `ensure_final_newline_on_save`. Your video shows that you tested it with *.rs file and the '\n' inserted by lsp....