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

Formating a *.erl file will cause error #223

Closed
tan-wei opened this issue Dec 15, 2021 · 8 comments
Closed

Formating a *.erl file will cause error #223

tan-wei opened this issue Dec 15, 2021 · 8 comments

Comments

@tan-wei
Copy link

tan-wei commented Dec 15, 2021

Version:

  • vscode_erlang: latest
  • OS: Windows
  • Erlang: V12.1.5

This message will be printed:

=ERROR REPORT==== 15-Dec-2021::08:16:58.526000 ===
LSP handler error error:undef while executing lsp_handlers:textDocument_formatting(_, #{options =>
                                                                                            #{insertSpaces =>
                                                                                                  true,
                                                                                              tabSize =>
                                                                                                  4},
                                                                                        textDocument =>
                                                                                            #{uri =>
                                                                                                  <<"file:///d%3A/DemoProjects/ErlangLearning/drop.erl">>}}), stacktrace:[{erl_tidy,
                                                                                                                                                                           file,
                                                                                                                                                                           ["c:/Users/WINTER~1/AppData/Local/Temp/25KJVDVJNTDR0.erl",
                                                                                                                                                                            [{backups,
                                                                                                                                                                              false},
                                                                                                                                                                             {idem,
                                                                                                                                                                              true}]],
                                                                                                                                                                           []},
                                                                                                                                                                          {lsp_handlers,
                                                                                                                                                                           textDocument_formatting,
                                                                                                                                                                           2,
                                                                                                                                                                           [{file,
                                                                                                                                                                             "src/lsp_handlers.erl"},
                                                                                                                                                                            {line,
                                                                                                                                                                             158}]},
                                                                                                                                                                          {gen_lsp_server,
                                                                                                                                                                           safeApply,
                                                                                                                                                                           3,
                                                                                                                                                                           [{file,
                                                                                                                                                                             "src/gen_lsp_server.erl"},
                                                       `                                                                                                                     {line,
                                                                                                                                                                             26}]},
                                                                                                                                                                          {gen_lsp_server,
                                                                                                                                                                           do_contents,
                                                                                                                                                                           2,
                                                                                                                                                                           [{file,
                                                                                                                                                                             "src/gen_lsp_server.erl"},
                                                                                                                                                                            {line,
                                                                                                                                                                             104}]}]

@pgourlain
Copy link
Owner

Hi Tan,

Can you provide "drop.erl", in order to reproduce it on my laptop.

thanks.

@tan-wei
Copy link
Author

tan-wei commented Dec 16, 2021

No problem. The code here is from book Introducing Erlang published by O'Reilly:

-module(drop).

-export([fall_velocity/2]).

fall_velocity(Planemo, Distance) when Distance >= 0 ->
    case Planemo of
        earth ->
            math:sqrt(2 * 9.8 * Distance);
        moon ->
            math:sqrt(2 * 1.6 * Distance);
        mars ->
            math:sqrt(2 * 3.71 * Distance)  % no closing period!
    end.

Quite an easy code with rebar.config in the project:

{plugins, [rebar3_format]}.

I'm quite new in Erlang, so maybe there is something wrong with my project settings. But I can't find further information in the repo, so I open an issue here to ask whether is my own problem.

Thanks for such a great project and quick reply.

@tan-wei
Copy link
Author

tan-wei commented Dec 16, 2021

Manual command works with formatter now:

rebar3 format --files ./drop.erl

@wojteksurowka
Copy link
Contributor

Fixed by #224

@tan-wei
Copy link
Author

tan-wei commented Jan 2, 2022

Thanks. Waiting for the PR is merged.

@tan-wei
Copy link
Author

tan-wei commented Jan 3, 2022

I can confirm that the issue should be closed. Thanks!

@tan-wei tan-wei closed this as completed Jan 3, 2022
@tan-wei tan-wei reopened this Jan 4, 2022
@tan-wei
Copy link
Author

tan-wei commented Jan 4, 2022

A strange phenomenon. I create a new file records.hrl which comes from book Introducing Erlang:

-record(planemo, {name, gravity, diameter, distance_from_sun}).
-record(tower, {location, height=20, planemo=earth, name}).

After I save with formatting it, the file becomes empty. It seems elfmt clear it all. But if I use manual command:

rebar3 format --files ./records.hrl

It will correctly format the file (see spaces around =):

-record(planemo, {name, gravity, diameter, distance_from_sun}).
-record(tower, {location, height = 20, planemo = earth, name}).

Is it special case for elfmt to process *.hrl files?

wojteksurowka pushed a commit to wojteksurowka/vscode_erlang that referenced this issue Feb 2, 2022
@tan-wei
Copy link
Author

tan-wei commented Mar 29, 2022

Solved. Thanks!

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

3 participants