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

Indentation not correct when in block #27

Open
randomizedthinking opened this issue May 19, 2017 · 11 comments
Open

Indentation not correct when in block #27

randomizedthinking opened this issue May 19, 2017 · 11 comments
Labels

Comments

@randomizedthinking
Copy link

randomizedthinking commented May 19, 2017

The indentation of the powershell script is not correct when in braces blocks. For instance, the following lines are correct:

Write-Host "line 1"
Write-Host "line 2"

While, if they are inside a pair of braces, when use = to indent the code block, the outcome becomes:

If ($value -gt 0)
{
    Write-Host "line 1"
        Write-Host "line 2"
}
@ghost
Copy link

ghost commented Jun 15, 2017

I can't confirm that. Indentation works fine for me.

Are your Vim settings correct? The file ps1.vim in \indent\ sets the smartindent. Try enabling/disabling the Vim's indent options to isolate the problem.

@heaths
Copy link
Collaborator

heaths commented Jun 15, 2017

I couldn't repro this either.

@anthony-geoghegan
Copy link
Contributor

anthony-geoghegan commented Jun 17, 2017

I think the OP may be referring to the indentation when = is used to filter lines. If this is the case, I was able to reproduce this behaviour. Personally, I rarely use this feature so I’ve never had to look into it – and both equalprg and indentexpr are kept to their default values (blank).

@randomizedthinking
Copy link
Author

Thanks @anthony-geoghegan. The original post is also edited to make the point clearer.

@heaths heaths added the bug label Jun 19, 2017
@heaths
Copy link
Collaborator

heaths commented Jun 19, 2017

If someone knows how to fix this and wants to submit a PR, I'm happy to merge if scenario testing passes.

@fretep
Copy link

fretep commented Oct 31, 2017

@heaths you mention scenario testing, are there unit tests we can populate with failing scenarios? If not, would you accept a PR for some unit tests perhaps utilizing Vader?

#18 (closed, not pulled) does not have this specific issue.

However, both smartindent used by this project and #18 have other issues like not working with herestrings, block comments, breaking on lines after a closing brace (i.e. the line after a param block), getting confused with backslashes in strings and other issues.

Unfortunately, I'm not all that familiar with the way the indent code works, but I'd be happy to have a crack to see how far I can get, but I'd be happier if we had a test of tests that people agreed on that I could chip away at getting to passing.

@sethcenterbar
Copy link

Idk if this is still being worked on, but I'm having the same issue as OP.

@heaths
Copy link
Collaborator

heaths commented Jun 8, 2018

@fretep, we do not have tests currently but Vader at a glance seems fine. I just meant for someone to go through the broken scenario and make sure it works, and make sure - at least with basic testing - nothing regressed. I test out the PRs before merging typically, but it's good to test at both ends. The person who submitted #18 closed the issue themselves since it didn't work as expected in scenarios they tested.

@sethcenterbar, we will happily accept PRs to fix this behavior.

@nsartor
Copy link

nsartor commented Jun 14, 2019

Not a a great solution, but if you add a semicolon to the end of each powershell line, then gg=G (indent whole file) works as expected.

So in the example by @randomizedthinking you would need to change it to this:

If ($value -gt 0)
{
    Write-Host "line 1";
    Write-Host "line 2";
}

Definitely not ideal, but it works.

@xeyownt
Copy link

xeyownt commented Feb 23, 2022

I also had a similar problem, which is that automatic indentation of the closing brace was bad when typing (I'm using auto-pairs also, which inserts these automatically).

And I confirm this is due to having equalprg set globally in .vimrc file.

Removing that line fixed the issue for me. I rather set that according to filetype now.

@sisrfeng
Copy link

I had similar problem and removing set smartindent in indent/ps1.vim solved it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants