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

bug: embedded text detected by treesitter but not formatted by conform #207

Closed
1 task done
thenbe opened this issue Nov 17, 2023 · 2 comments · Fixed by #251
Closed
1 task done

bug: embedded text detected by treesitter but not formatted by conform #207

thenbe opened this issue Nov 17, 2023 · 2 comments · Fixed by #251
Labels
bug Something isn't working P0 Highest priority, will receive attention

Comments

@thenbe
Copy link

thenbe commented Nov 17, 2023

Neovim version (nvim -v)

NVIM v0.9.4 Build type: Release LuaJIT 2.1.1693350652

Operating system/version

  • system: "x86_64-linux" - host os: Linux 6.1.62, NixOS, 23.11 (Tapir), 23.11.20231112.e44462d - multi-user?: yes - sandbox: yes - version: `nix-env (Nix) 2.18.1

Add the debug logs

  • I have set log_level = vim.log.levels.DEBUG and pasted the log contents below.

Log file

Log file: /home/nbe/projects/playground/repro-conform-embed/.repro//state/nvim/conform.log
          13:49:53[INFO] Run prettier on /home/nbe/projects/playground/repro-conform-embed/foo.ts
          13:49:53[DEBUG] Run command: { "prettier", "--stdin-filepath", "/home/nbe/projects/playground/repro-conform-embed/foo.ts" }
          13:49:53[DEBUG] prettier exited with code 0
          13:49:53[INFO] Run injected on /home/nbe/projects/playground/repro-conform-embed/foo.ts

Formatters for this buffer:
prettier ready (html, typescript)
injected ready (typescript)

Other formatters:

Describe the bug

Is it a fair assumption to expect the formatter to work whenever treesitter syntax highlighting is working? If so, then this is a bug.

Steps To Reproduce

  1. Create a foo.ts file with the following contents:

    foo.innerHTML = ` <div>   hello</div>  `;
    
    bar.innerHTML = `
    <div>   world
    </div>
    `;
  2. Observe that treesitter has detected the embedded HTML text. Observe that the embedded HTML text has proper HTML syntax highlighting.

  3. Run :lua require "conform".format()

  4. .

    • ACTUAL: Observe that none of the embedded HTML text is formatted.
    • EXPECTED: Observe that all embedded text is formatted.

Expected Behavior

.

Minimal example file

No response

Minimal init.lua

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "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
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
    {
    "nvim-treesitter/nvim-treesitter",
    build = ":TSUpdate",
    config = function()
      require("nvim-treesitter.configs").setup({
        ensure_installed = { "c", "lua", "typescript", "html" },
        auto_install = true,
        highlight = { enable = true },
      })
    end,
  },
  {
    "stevearc/conform.nvim",
    config = function()
      require("conform").setup({
        log_level = vim.log.levels.DEBUG,
        -- add your config here
        formatters_by_ft = {
          ["typescript"] = { "prettier", "injected" },
          ["html"] = { "prettier" },
        }
      })
    end,
  },
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

Additional context

No response

@thenbe thenbe added the bug Something isn't working label Nov 17, 2023
@thenbe
Copy link
Author

thenbe commented Nov 17, 2023

Extra context:

The query responsible for detecting this particular embedded text is defined here.

Custom injection queries are also affected by this issue. A relevant example (and a possible fix?) can be found here.

@stevearc
Copy link
Owner

I made a change for #205 that partially fixes this. The one remaining pieces is that the injected formatter currently expects the injected language to occupy entire lines. It can't handle an inline injection like you have on the first line of your example file. I'll add support for that when I get time.

@stevearc stevearc added the P0 Highest priority, will receive attention label Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P0 Highest priority, will receive attention
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants