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
wrong indentation with jsx #1019
Comments
|
I was going to open a separate issue, but piggybacking here since this is my issue. Treesitter JSX indentation is a work in progress. With TS indentation enabled, opening a new line (indentation should be directly under the Then opening up a curly brace is really weird, goes all the way to the first column: If I disable TS indentation but still have Treesitter for highlighting, I get these incorrect results (first open newline then add in curly brace): If I use Polyglot instead, and disable Treesitter, the indentation works correctly: I tried @kyazdani42 If testing needed in future, I would be happy to help. Cheers. |
|
Question. Is is possible to use Treesitter for highlighting and Polyglot for indentation? I assume not, but that's kind of what I want whilst Treesitter indentation settles down. |
|
Answering my own question after discussion in this Reddit thread. No it is not possible to use Polyglot JSX indentation with Treesitter. Polyglot uses vim-jsx-pretty for indentation. And that indentation mechanism uses Vim's tradition syntax subsystem.....which Treesitter explicitly disables. So vim-jsx-pretty indentation will not work whilst Treesitter is in effect. It is a similar situation with Tim Pope's endwise plugin does not work with Treesitter because syntax is disabled. The solution will be maturation (better Treesitter indentation) and ecosystem (new Treesitter-aware plugins). Early adopter pains. |
|
@bluz71 when you're fine with having tree-sitter and syntax running, you can enable them both. There's also an option that nvim-treesitter does not active syntax. |
|
Interesting. My understanding is that Treesitter by default disables syntax (which makes sense to me). How do I tell Treesitter not to disable |
|
Just use You can experiment with the effect of this setting, by running |
|
Very interesting. It may well solve my issue. I will experiment with it tomorrow. I appreciate the tip. |
|
hi, i have to update my branch but it should fix this indentation issue. |
|
When the branch is ready, let us know, I would like to test it. |
|
This configuration works well for me: local treesitter = require'nvim-treesitter.configs'
treesitter.setup {
ensure_installed = {
'c', 'cpp', 'dart', 'go', 'html', 'java', 'javascript', 'python', 'ruby',
'rust', 'typescript'
},
highlight = {
enable = true,
additional_vim_regex_highlighting = true
},
indent = {
enable = false
}
}
I get Treesitter highlighting and Polyglot indenting. This is ideal until Treesitter indentation is sorted out, maybe sooner than later via @kyazdani42 branch. I am pleased. Many thanks. |
|
@kyazdani42's #1020 PR is a massive improvement. I just did some quick tests and it works great for my simple JavaScript + JSX code. Fantastic. Note, I am sure there are still some more wrinkles to iron out, but this is a very big improvement. I no longer need to use |
Do you get jxs indenting correctly?, if so, do you have enabled |
|
I spoke too soon.
However, tags within tags are still wonky. Apologies for stating all was working well. I do very little JSX so my test was very quick, too quick. Request indent settings are:
If doing JSX the following settings are probably better for now (aka use vim-jsx-pretty indents via local treesitter = require'nvim-treesitter.configs'
treesitter.setup {
ensure_installed = "maintained",
highlight = {
enable = true,
additional_vim_regex_highlighting = true
},
indent = {
enable = false
}
} |
|
i do a lot of jsx and haven't noticed wonkiness yet, but i'm still thinking about this indent algorithm, because it's quite hard to do unfortunately due to languages having very specific edge cases. I'd consider indent still WIP. |
|
Ok, I have done a heap of testing with Treesitter and JSX; hours of testing. Treesitter JSX indent is not wonky by itself, in fact it works quite well. My apologies. Even disabling Polyglot languages, like the following, is not enough: let g:polyglot_disabled = ['javascript']The above For example, this works quite well ( let g:polyglot_disabled = ['javascript']
Plug 'sheerun/vim-polyglot', { 'tag': 'v4.16.0' }The Treesitter teams needs to be aware the vim-polyglot can badly mess up Treesitter indents. Treesitter will be blamed, but Polyglot is doing the mess up (somehow, which I don't understand). I am almost of the opinion that the Neovim Treesitter team tell users not to install or use vim-polyglot at all. I think I am eventually going to stop using Polyglot. For now I will stick with the Cheers. |
|
For me it wasn't working because filetype was set to |
I'm still having the same problem, indentation on javascriptreact files doesn't indent properly when working with tags, but on javascript filetypes the do work well. |
@kyazdani42 I'm still having this issue on latest nvim-treesitter, trying setting the filetype of the file to An example of the cursor would be: return (
<Col>
<Row>
| <----------- cursor goes here
</Col> |
|
indentation is still not perfect. I'm really busy lately so haven't had the time to check nvim-treesitter related issues, because my other plugin got a lot of traction and with work and summer ... I'll take a look at indentation if nobody does it first, but when i'll have some time, so that might not be soon i'm afraid :/ |
|
Just curious if this is still possibly fixed as the issue is closed. Currently the indent still doesn't work as expected. @kyazdani42 Is this still on your roadmap to do? Thank you for your work! |
|
its not on my roadmap atm, i dont have quite the time :/ |
|
I wouldn't mind poking at this if you could point me in the right direction @kyazdani42. I use nvim + treesitter for tsx development daily and this has annoyed me for a while so I'm motivated to give it a shot :) |
|
At the moment, indent doesn't support injected languages. |
|
any update on this? |
|
Hi, I'm not sure if there was a regression at some point, but I'm still getting the bug where adding a "{" in the middle of a JSX block sets the indent to 0. const Testo = () => {
return <div>
{/* adding a newline sets the indentation to here */}
{
|<-- typing a "{" moves the bracket back to here
</div>
};Interestingly, when I print out the node type in while node do
print(node:type())
" ...
endI get the following output: Looks kinda similar to #2516, but I'm not sure. EDIT: Okay, I don't know if it's related, but setting |
|
Wondering if there is any update on this issue? It still happening to me. |
|
@sahibalejandro I would recommend to set up a test case for your issue and make it fail our CI. If you poke a bit around with |
|
@theHamsta the filetype is Thanks for the hint tho! |
|
Javascript should contain the Jsx queries. So there are some Js queries that cause wrong indentation |
|
After doing more tests, indentation on
<SomeComponent>
<div>
<div>
Something here... (new line)
| <-- cursor jumps here
</div>
</div>
</SomeComponent>
if (someValidation) {
| <-- cursor jumps here
}
<div>
<div>
<span>hello world</span>
| <-- cursor jumps here
</div>
</div>I don't have enough knowledge to write test files in Worth to mention that I tested it with a clean Neovim |
|
I've just made the transition from Polyglot to Treesitter, and can confirm that I'm running into at least some variation of this problem. I can recreate indentation problems with a minimum setup of only treesitter, confirming that I do have the Creating a new line from within a function specified outside the This problem seems to be exacerbated once plugins are added that take into account the ESLint file etc, and the new line indentation is way off. In summary, I'm seeing the same as sahibalejandro for the conditional statements, but it's slightly different for the other scenarios they've specified. Changing the file type doesn't seem to make any changes for me. I'm using Nvim 0.7 with the latest treesitter version. |
|
same issue here :( pretty annoying Also, the embedded html code in the .jsx file are not highlighted. |








Describe the bug
I have wrong indentation when hit enter/new line in only in jsx tags
To Reproduce
Output of
:checkhealth nvim_treesitterhealth#nvim_treesitter#check
Installation
tree-sitterfound 0.18.3(parser generator, used for :TSInstallFromGrammar)gitexecutable found.ccexecutable found.Parser/Features H L F I
Legend: H[ighlight], L[ocals], F[olds], I[ndents]
*) multiple parsers found, only one will be used
x) errors found in the query, try to run :TSUpdate {lang}
Output of
nvim --versionNVIM v0.5.0-dev+1144-gd38508d88
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/cc -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home//repos/neovim/build/config -I/home//repos/neovim/src -I/home//repos/neovim/.deps/usr/include -I/usr/include -I/home//repos/neovim/build/src/nvim/auto -I/home//repos/neovim/build/include
Compiled by root
Features: +acl +iconv +tui
See ":help feature-compile"
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/usr/local/share/nvim"
Run :checkhealth for more info
The text was updated successfully, but these errors were encountered: