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

Try to fix indentation for <template> ... </template> #6054

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

NullVoxPopuli
Copy link
Contributor

@NullVoxPopuli NullVoxPopuli commented Feb 6, 2024

Currently, when I press Enter in a

// test.gjs
<template>

</template>

block,
the cursor goes all the way to the left, rather than being indented.

I'm still trying to figure out how to test things locally, so this isn't ready for review or merge.

@clason clason added the indent Issues or PRs about indentation queries or module label Feb 6, 2024
@lucario387
Copy link
Member

Are you sure? I think it's just the filetype being incorrect here.

test.gjs shows javascript.glimmer as the filetype, not glimmer

@NullVoxPopuli
Copy link
Contributor Author

correct -- maybe I need to configure an offset? (I don't know how to do that)
Right now, tree-sitter-glimmer has no idea if it's being used between <template>...</template> or not

@lucario387
Copy link
Member

lucario387 commented Feb 9, 2024

But tree-sitter-glimmer do know though? It's the fact that javascript.glimmer filetypes do not get the automatic vim.bo.indentexpr=v:lua.require('vnim-treesitter').indentexpr()

Consider adding a line of vim.treesitter.language.register("glimmer", {"javascript.glimmer"}) somewhere in your file.

@NullVoxPopuli
Copy link
Contributor Author

NullVoxPopuli commented Feb 9, 2024

I don't think that's correct. tree-sitter-glimmer is for the sub-language within <template> ... </template>, not the whole gjs file.

Injection declared here:

(#set! injection.language "glimmer"))

Consider adding a line of vim.treesitter.language.register("glimmer", {"javascript.glimmer"}) somewhere in your file.

Is this something other language libraries do? (registering themselves?)
Or is this only done to override associations with parsers?

If so, tree-sitter-javascript is the correct parser for gjs.
But maybe I misunderstand what that register command does? how does it relate to the indentexpr? Is that something I should PR to tree-sitter-glimmer?

One thing I've been trying to figure out, is where is the right place to fix indentation of

const Two = <template>|</template>;

(press enter)

const Two = <template>
|</template>;

it should be this instead:

const Two = <template>
  |
</template>;  

something needs to tell the inner syntax (tree-sittter-glimmer) to offset all indentation by an additional $OFFSET_SIZE (whatever that is)


when I created this PR, I didn't notice that I had a conflicting indent plugin installed (conflicting may be a bit strong), but best to test without. I've disabled https://github.com/VidocqH/auto-indent.nvim

@lucario387
Copy link
Member

That's not really because of the indentexpr.
Auto newlining the end template tag is the formatexpr's thing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
indent Issues or PRs about indentation queries or module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants