AstroNvim / astrocommunity

A community repository of common plugin specifications
https://astronvim.github.io/astrocommunity/
GNU General Public License v3.0
1.22k stars 243 forks source link

Inconsistent formatting with markdown codeblocks vs native file #1256

Open cavanaug opened 3 weeks ago

cavanaug commented 3 weeks ago

Checklist

Neovim version (nvim -v)

NVIM v0.10.2 Build type: Release LuaJIT 2.1.1727870382

Operating system/version

debian linux

Terminal/GUI

windows terminal

Describe the bug

Im seeing inconsistent formatting for json files vs json codeblocks in markdown. When editing a standard json file, I get things appropriately mapped with my editorconfig settings of

[*.json]
indent_style = space
indent_size = 4

[*.yaml]
indent_style = space
indent_size = 2

So everything when I run an lsp format is properly formatting with 4 spaces.

But if I bring the same exact json content into a markdown codeblock wrapped with a json type and I do an lsp format I get the same data but it is expanded with tabs, not spaces. This makes it awkward when I check in a file and it is viewed in Github preview, the tabs are then expanded out to 8 spaces and it looks awful.

yaml ironically works identically for formatting a native file or within a code block. That is the behavior I would expect for json as well.

Steps to Reproduce

Load a vanilla astrovim with the included community.lua file

utilize any small json file, and compare its formatting between a native file and the same content in a markdown json codeblock

Expected behavior

I would expect the same formatting (ie. spaces) that I see when editing a json file natively

Screenshots

No response

Additional Context

-- AstroCommunity: import any community modules here -- We import this file in lazy_setup.lua before the plugins/ folder. -- This guarantees that the specs are processed before any user plugins.

---@type LazySpec return { "AstroNvim/astrocommunity", { import = "astrocommunity.pack.lua" }, { import = "astrocommunity.pack.markdown" }, { import = "astrocommunity.pack.json" }, { import = "astrocommunity.pack.yaml" }, -- import/override with your plugins folder }

Minimal configuration

-- save as repro.lua
-- run with nvim -u repro.lua
-- DO NOT change the paths
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "runtime", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  -- stylua: ignore
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable", lazypath })
end
vim.opt.rtp:prepend(vim.env.LAZY or lazypath)

-- install plugins
local plugins = {
  { "AstroNvim/AstroNvim", import = "astronvim.plugins" },
  { "AstroNvim/astrocommunity" },

  -- add any other plugins/customizations here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

-- ONLY THING IS THE community.lua file I listed in additional context
Uzaaft commented 3 weeks ago

@cavanaug Use the issue template properly and fill in the minimal config.

Uzaaft commented 3 weeks ago

I dont think this can be attributed as a bug in the pack, or just a limitation to the upstream plugins that the pack is using. The Json lsp isnt running when editing a markdown file, so its seems like its either markdown-oxide, or perhaps treesitter(Dont see how but just leaving this here) thats formatting the buffer and the code blocks.

azdanov commented 1 week ago

Does Prettier format markdown code blocks?