Skip to content

Make conform respect config.vim.lsp.formatOnSave and config.vim.lsp.mappings.toggleFormatOnSave - #768

Closed
venkyr77 wants to merge 1 commit into
NotAShelf:mainfrom
venkyr77:conform-format-on-save-fix
Closed

Make conform respect config.vim.lsp.formatOnSave and config.vim.lsp.mappings.toggleFormatOnSave#768
venkyr77 wants to merge 1 commit into
NotAShelf:mainfrom
venkyr77:conform-format-on-save-fix

Conversation

@venkyr77

Copy link
Copy Markdown
Contributor

Update of PR #764

The current defaults(link1, link2)from conform config is not respecting the top level config we have for formatOnSave - vim.lsp.formatOnSave. Also, config.vim.lsp.mappings.toggleFormatOnSave has no impact.

From conform docs

-- If this is set, Conform will run the formatter on save.
-- It will pass the table to conform.format().
-- This can also be a function that returns the table
-- If this is set, Conform will run the formatter asynchronously after save.
-- It will pass the table to conform.format().
-- This can also be a function that returns the table.

these need to be set to null (or nil in lua) when config.vim.lsp.formatOnSave is false

This PR fixes conform config to respect config.vim.lsp.formatOnSave

Testing:

Tested my changes by changing the nvf url to the branch from my fork

nvf.url = "github:venkyr77/nvf/conform-format-on-save-fix";

with config.vim.lsp.formatOnSave = false; conform is not auto formatting the file

with config.vim.lsp.formatOnSave = true;

formatOnSaveTrue

with config.vim.lsp.formatOnSave = true; and using the mapping for config.vim.lsp.mappings.toggleFormatOnSave

toggleFormatOnSave

Sanity Checking

  • I have updated the changelog as per my changes
  • I have tested, and self-reviewed my code
  • My changes fit guidelines found in hacking nvf
  • Style and consistency
    • I ran Alejandra to format my code (nix fmt)
    • My code conforms to the editorconfig configuration of the project
    • My changes are consistent with the rest of the codebase
  • If new changes are particularly complex:
    • My code includes comments in particularly complex areas
    • I have added a section in the manual
    • (For breaking changes) I have included a migration guide
  • Package(s) built:
    • .#nix (default package)
    • .#maximal
    • .#docs-html (manual, must build)
    • .#docs-linkcheck (optional, please build if adding links)
  • Tested on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin

Add a 👍 reaction to pull requests you find important.

github-actions Bot pushed a commit that referenced this pull request Mar 31, 2025
@github-actions

github-actions Bot commented Mar 31, 2025

Copy link
Copy Markdown

🚀 Live preview deployed from 79993c7

View it here:

Debug Information

Triggered by: horriblename

HEAD at: conform-format-on-save-fix

Reruns: 848

@venkyr77

Copy link
Copy Markdown
Contributor Author

@horriblename, fixes #764 (comment)

Comment on lines +75 to +76
else
return ${toLuaObject defaultFormatAfterSaveOpts}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

nit: no else return

Comment on lines +45 to +46
else
return ${toLuaObject defaultFormatOnSaveOpts}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

nit: no else return

if the changes look good, I can make a fast followup

Comment thread modules/plugins/formatter/conform-nvim/conform-nvim.nix Outdated
Comment thread modules/plugins/lsp/config.nix Outdated
@venkyr77
venkyr77 force-pushed the conform-format-on-save-fix branch 2 times, most recently from 943b343 to 7eec1d2 Compare April 2, 2025 08:18
github-actions Bot pushed a commit that referenced this pull request Apr 2, 2025
@venkyr77
venkyr77 requested a review from horriblename April 2, 2025 17:18

@horriblename horriblename 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 other than some documentation stuff

in
mkOption {
type = nullOr (either attrs luaInline);
default =

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.

add a defaultText that says something like "enabled with LSP format as fallback, respecting vim.lsp.formatOnSave and vim.lsp.mappings.toggleFormatOnSave"

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.

also: use lib.options.literalMD in the defaultText

Comment thread modules/plugins/formatter/conform-nvim/conform-nvim.nix Outdated
type = nullOr (either attrs luaInline);
default =
mkLuaInline
# lua

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
# lua

Please don't do this. I understand it's easier to handle the code with syntax highlighting, but we don't inject syntax anywhere else in the source tree and Alejandra results in horrible formatting when you specific a language.

Easier if we provide injections for mkLuaInline, CC @horriblename

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.

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.

fwiw, I find flaw in both approaches. Ours require custom query rules for each option we want to support which is tedious, and theirs enforce a style of coding that is usually not in line with official language guidelines just to support a feature in a text editor plugin not everyone uses

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Please don't do this

removed

end
'';
description = ''
Table or function(lualinline) that will be passed to `conform.format()`. If this

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
Table or function(lualinline) that will be passed to `conform.format()`. If this
Table or function(lualinline) that will be passed to `conform.format()`. If this

Is this a function that takes luainline as an argument?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is this a function that takes luainline as an argument?

it can take both

a table or a function that returns table

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Okay, I'm mostly confused about the role of the paranthesis in the description. Does it indicate function arguments?

I think it's better to clarify the wording to state the types properly.

Suggested change
Table or function(lualinline) that will be passed to `conform.format()`. If this
Attribute set or or a Lua function that will be passed to `conform.format()`.

Or similar.

Comment thread modules/plugins/formatter/conform-nvim/conform-nvim.nix Outdated
Comment thread modules/plugins/formatter/conform-nvim/conform-nvim.nix Outdated
Comment thread modules/plugins/formatter/conform-nvim/conform-nvim.nix Outdated
@venkyr77
venkyr77 force-pushed the conform-format-on-save-fix branch from 7eec1d2 to 0ffd832 Compare April 4, 2025 23:21
github-actions Bot pushed a commit that referenced this pull request Apr 4, 2025
@venkyr77

venkyr77 commented Apr 4, 2025

Copy link
Copy Markdown
Contributor Author

@venkyr77

venkyr77 commented Apr 4, 2025

Copy link
Copy Markdown
Contributor Author

@NotAShelf NotAShelf left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Two small notes on the documentation. I have nothing further to nit (for once)

Perhaps a changelog entry would also go very well with the spirit of this change?

end
'';
description = ''
Table or function(lualinline) that will be passed to `conform.format()`. If this

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Okay, I'm mostly confused about the role of the paranthesis in the description. Does it indicate function arguments?

I think it's better to clarify the wording to state the types properly.

Suggested change
Table or function(lualinline) that will be passed to `conform.format()`. If this
Attribute set or or a Lua function that will be passed to `conform.format()`.

Or similar.

Comment on lines +68 to +69
Table or function(luainline) that will be passed to `conform.format()`. If this
is set, Conform will run the formatter asynchronously after save.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Same as my previous comment.

in
mkOption {
type = nullOr (either attrs luaInline);
default = mkLuaInline ''

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.

add defaultText please

something like

defaultText = literalMD "enabled, with fallback to LSP formatting that respects `vim.lsp.formatOnSave` and `vim.lsp.mappingd.toggleFormatSave`" 

@horriblename

Copy link
Copy Markdown
Collaborator

superseded by #891

@github-actions

Copy link
Copy Markdown

✅ Preview has been deleted successfully!

github-actions Bot pushed a commit that referenced this pull request May 13, 2025
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.

3 participants