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

Code formatting isn't working for me with VS Code #122

Open
fgimian opened this issue Nov 8, 2022 · 8 comments
Open

Code formatting isn't working for me with VS Code #122

fgimian opened this issue Nov 8, 2022 · 8 comments

Comments

@fgimian
Copy link

fgimian commented Nov 8, 2022

Hey there, thanks so much for your work on this language server.

I'm using the latest v0.902 with v0.0.15 of the VS Code extension running over Remote SSH to a Ubuntu 22.04 server with Perl 5.36 installed via perlbrew. Everything works as expected except code formatting despite the fact that perltidy is installed and available in $PATH. Running the Format Document command simply does nothing at all.

When I switch to the perltidy extension for formatting, everything works correctly.

I've also attempted to specify my exact location of .perltidyrc and PLS still won't budge, while the perltidy extension I linked above works.

I'm not entirely sure how to troubleshoot this to provide more information. Do you have any suggestions?

Thanks
Fotis

@fgimian
Copy link
Author

fgimian commented Nov 8, 2022

Appears to be the same issue as #50 Adding -nst resolves the problem. Perhaps it may be worth adding to the README @FractalBoy?

I'll close this one then 😄
Fotis

@fgimian fgimian closed this as completed Nov 8, 2022
@FractalBoy
Copy link
Owner

I guess I hadn't considered adding -nst in the code. I can go ahead and do that.

@fgimian
Copy link
Author

fgimian commented Nov 8, 2022

I guess I hadn't considered adding -nst in the code. I can go ahead and do that.

Thank you so much! 😄

@fgimian
Copy link
Author

fgimian commented Nov 8, 2022

Just wanted to re-open this as there seem to be multiple issues (at least for me). The -nst flag is the first. But even after that, PLS doesn't seem to comply to my .perltidyrc.

For example, I increased the indent to 8 for demonstrational purposes:

This is my .perltidyrc:

--perl-best-practices
--indent-columns=8
--continuation-indentation=8
--nostandard-output

My little input file is:

package Greeter;
use 5.036;

our $VERSION = 1.0;

sub get_greeting ($name) {
    return "hi there ${name}";
}

1;

Using the perltidy CLI, I get the expected result:

package Greeter;
use 5.036;

our $VERSION = 1.0;

sub get_greeting ($name) {
        return "hi there ${name}";
}

1;

However, donig this in VS Code with PLS indents to a 2-space indent:

package Greeter;
use 5.036;

our $VERSION = 1.0;

sub get_greeting ($name) {
  return "hi there ${name}";
}

1;

Using the other mentioned extension works as expected 😄

Any ideas?
Fotis

@FractalBoy
Copy link
Owner

What about your VSCode settings? Your tab settings in VSCode are also taken into account when formatting.

@fgimian
Copy link
Author

fgimian commented Nov 8, 2022

What about your VSCode settings? Your tab settings in VSCode are also taken into account when formatting.

Thanks heaps for the reply. I've tried this with an empty VS Code configuration file only containing the pls.perltidy.perltidyrc setting and sadly see the same problem.

However, I did some more digging based on your comment and as you mentioned, PLS will indent completely based on the indent level of the file (which may be auto-detected).

I got this working as follows in my VS Code config:

    "[perl]": {
        "editor.tabSize": 8,
        "editor.detectIndentation": false
    }

However, I'm not sure that PLS should consider the VS Code indent level; after all this is why Perl Tidy exists, to ensure that code conforms to a specific style and this should ideally be fully specified in .perltidyrc IMHO.

What do you think?
Fotis

@fgimian
Copy link
Author

fgimian commented Nov 8, 2022

Just a further thought, the current behaviour will likely cause conflicts with [CodeLayout::RequireTidyCode] in Perl Critic as PLS ultimately may not indent a file based on the .perltidyrc setting; but rather the editor setting.

I'd at least love the option to turn this behaviour off and make .perltidyrc the single point of truth for all formatting 😄

@FractalBoy
Copy link
Owner

FractalBoy commented Nov 8, 2022

While I don't necessarily disagree, I'm not sure there's a "right" answer here. If I were to remove this behavior, there might be someone who is relying on it and files an issue asking me to change it back.

I think I will err on the side of respecting the options that the Language Server Protocol provides.

Edit: I suppose your suggestion (an option) would be the best of both worlds. If you are able, feel free to submit a PR. Otherwise I can get to it when I have time.

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

No branches or pull requests

2 participants