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

Incorrect W0017 warning #23

Open
dszoboszlay opened this issue Apr 21, 2024 · 10 comments
Open

Incorrect W0017 warning #23

dszoboszlay opened this issue Apr 21, 2024 · 10 comments
Assignees
Labels
bug Something isn't working prio-high

Comments

@dszoboszlay
Copy link

Describe the bug

A fully qualified function call to the current module incorrectly triggers a W0017 (function is undefined) warning.

Furthermore, the doc page of the warning has an incorrect title. It says Unused Function while it should be Undefined Function.

To Reproduce**

Type this into VS Code:

-module(elp_w0017).
-export([loop/0]).

loop() ->
  timer:sleep(1000),
  ?MODULE:loop().

Expected behavior

There shouldn't be any warnings reported in this module.

Actual behavior

The last line is marked with W0017.

Context

  • ELP Version (output of elp version): elp 1.1.0+build-2024-04-17
  • Editor used: VS Code with v0.21.0 extension
@dszoboszlay dszoboszlay added the bug Something isn't working label Apr 21, 2024
@alanz alanz self-assigned this Apr 22, 2024
@alanz
Copy link
Member

alanz commented Apr 22, 2024

I am unable to reproduce the warning. I tried pasting your code into an existing valid erlang project, into an empty directory, and creating a test for it. None of these showed the problem.

And I will update the docs, thanks.

Please provide more specific instructions to re-create the error.

@dszoboszlay
Copy link
Author

Hmm... It doesn't always work for me either. I have created this file as /home/dszoboszlay/elp_w0017.erl. If I close VS Code and type code elp_w0017.erl in a shell then first of all VS Code loads the file in restricted mode, but once I say I trust the authors, I get the error.

However, if I close the file in VS Code and then open the file again, I don't get the error any more.

Closing VS Code and typing code elp_w0017.erl again can reproduce the error.

Quite confusing, to be honest.

facebook-github-bot pushed a commit that referenced this issue Apr 22, 2024
Summary:
Address #23
- Fix reported documentation error
- Add test to confirm the normal operation for the provided repro case

Reviewed By: robertoaloi

Differential Revision: D56413056

fbshipit-source-id: eaaea7279c5661135ce03d7444535c4088ef58b0
@alanz
Copy link
Member

alanz commented Apr 22, 2024

I tested it by making ~/fff and putting the file in there.

I am not prepared to give VS Code trust access to my entire home directory.

@dszoboszlay
Copy link
Author

I don't think the directory would matter. I was initially suspecting that a space in the path could have been relevant, but it isn't.

I think what's important is that elp has to be started by VS Code directly for that file. So once elp is running, closing and reopening the file will not trigger the bug. But this may also be some race condition that depends on e.g. number of CPU cores in my machine and what other plugins VS Code is trying to start up in parallel. Is there a way to make elp log what is it doing? Currently it doesn't log anything for me. So it's hard to figure out what's the difference between the first and second opening of the file.

@alanz
Copy link
Member

alanz commented Apr 22, 2024

It logs to stderr by default, which VS Code shows in the output pane.

Screenshot 2024-04-22 at 11 42 22

@alanz
Copy link
Member

alanz commented Apr 22, 2024

And I am looking into why we cant set the log level, and why our config settings show up a "Example configuration".
There is plenty of opportunity for people to improve the extension code, it is not high priority for us, as we have a custom internal one.

@dszoboszlay
Copy link
Author

For me elp doesn't log anything (even if I redirect it to a file, I only get an empty file) and this output doesn't show up.

But I see this in the Extension Host output (when log level is set to trace):

2024-04-22 13:16:29.122 [info] ExtensionService#_doActivateExtension erlang-language-platform.erlang-language-platform, startup: false, activationEvent: 'onLanguage:erlang'
2024-04-22 13:16:29.122 [trace] ExtensionService#loadCommonJSModule file:///home/dszoboszlay/.vscode/extensions/erlang-language-platform.erlang-language-platform-0.21.0-linux-x64/client/out/extension
2024-04-22 13:16:29.123 [trace] ExtensionService#loadExtensionContext erlang-language-platform.erlang-language-platform
2024-04-22 13:16:29.164 [trace] ExtensionService#_callActivateOptional erlang-language-platform.erlang-language-platform
2024-04-22 13:16:29.171 [trace] [vscode.git] INVOKE provider 'Q=>Q.provideLinks(p.URI.revive(V),X)'
2024-04-22 13:16:29.172 [trace] [vscode.git] provider DONE after 1ms
2024-04-22 13:16:29.195 [trace] [erlang-language-platform.erlang-language-platform] INVOKE provider 'Q=>Q.provideDocumentSymbols(p.URI.revive(V),X)'
2024-04-22 13:16:29.195 [trace] [erlang-language-platform.erlang-language-platform] INVOKE provider 'we=>we.provideCodeActions(p.URI.revive(V),X,Q,ge)'
2024-04-22 13:16:29.199 [trace] [erlang-language-platform.erlang-language-platform] INVOKE provider 'ge=>ge.provideInlayHints(p.URI.revive(V),X,Q)'
2024-04-22 13:16:29.347 [trace] [erlang-language-platform.erlang-language-platform] INVOKE provider 'ge=>ge.provideDocumentRangeSemanticTokens(p.URI.revive(V),X,Q)'
2024-04-22 13:16:29.392 [trace] [erlang-language-platform.erlang-language-platform] provider DONE after 197ms
2024-04-22 13:16:29.392 [trace] [erlang-language-platform.erlang-language-platform] provider DONE after 197ms
2024-04-22 13:16:29.392 [trace] [InlayHints] NO inlay hints from 'erlang-language-platform.erlang-language-platform' for range {"startLineNumber":1,"startColumn":1,"endLineNumber":7,"endColumn":1}
2024-04-22 13:16:29.392 [trace] [erlang-language-platform.erlang-language-platform] provider DONE after 193ms
2024-04-22 13:16:29.392 [trace] [erlang-language-platform.erlang-language-platform] provider DONE after 45ms
2024-04-22 13:16:29.495 [trace] [erlang-language-platform.erlang-language-platform] INVOKE provider 'Q=>Q.provideDocumentSymbols(p.URI.revive(V),X)'
2024-04-22 13:16:29.496 [trace] [erlang-language-platform.erlang-language-platform] provider DONE after 1ms
2024-04-22 13:16:29.496 [trace] [erlang-language-platform.erlang-language-platform] INVOKE provider 'ge=>ge.provideFoldingRanges(p.URI.revive(V),X,Q)'
2024-04-22 13:16:29.497 [trace] [erlang-language-platform.erlang-language-platform] provider DONE after 1ms
2024-04-22 13:16:29.571 [trace] [erlang-language-platform.erlang-language-platform] INVOKE provider 'Q=>Q.provideCodeLenses(p.URI.revive(V),X)'
2024-04-22 13:16:29.571 [trace] [eamodio.gitlens] INVOKE provider 'Q=>Q.provideCodeLenses(p.URI.revive(V),X)'
2024-04-22 13:16:29.572 [trace] [eamodio.gitlens] provider DONE after 1ms
2024-04-22 13:16:29.572 [trace] [vscode.merge-conflict] INVOKE provider 'Q=>Q.provideCodeLenses(p.URI.revive(V),X)'
2024-04-22 13:16:29.572 [trace] [erlang-language-platform.erlang-language-platform] provider DONE after 1ms
2024-04-22 13:16:29.573 [trace] ExtHostCommands#executeCommand setContext
2024-04-22 13:16:29.573 [trace] ExtHostCommands#executeCommand _setContext
2024-04-22 13:16:29.574 [trace] [vscode.merge-conflict] provider DONE after 2ms
2024-04-22 13:16:29.640 [trace] [DiagnosticCollection] change many (extension, owner, uris) erlang-language-platform.erlang-language-platform _generated_diagnostic_collection_name_#3 [[{"$mid":1,"external":"file:///home/dszoboszlay/A1/B%202/elp_w0017.erl","path":"/home/dszoboszlay/A1/B 2/elp_w0017.erl","scheme":"file"},[{"startLineNumber":6,"startColumn":3,"endLineNumber":6,"endColumn":17,"message":"Function 'elp_w0017:loop/0' is undefined.","source":"elp","code":{"value":"W0017","target":{"$mid":1,"path":"/erlang-language-platform/docs/erlang-error-index/w/W0017","scheme":"https","authority":"whatsapp.github.io"}},"severity":4,"modelVersionId":1}]]]

@alanz
Copy link
Member

alanz commented Apr 22, 2024

You need to select Erlang Language Platform in the top right selector box of the Output pane, as in my example.

And I have a new release coming that lets you set logging in more detail

@robertoaloi
Copy link
Contributor

@dszoboszlay I cannot reproduce this either. Did you manage to get the logging working, so we can have a look at what's happening for you?

@robertoaloi
Copy link
Contributor

@alanz @dszoboszlay

I was too fast. I can indeed reproduce this. Here are the steps.

  • Add the above file to a new folder (e.g. /tmp/something)
  • Open VS Code (/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code)
  • Trust the newly created folder (Workspaces: Manage workspace trust -> Add /tmp/something
  • Open the folder (File -> Open folder... -> /tmp/something)
  • Navigate to elp_w00017.erl, the only file in the folder
  • ELP starts correctly
  • Switch to the CLI, open the same file (/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code /tmp/something/elp_w0017.erl)
  • A bunch of warnings and errors appear, ELP crashes

Reason:

no value set for SourceRootQuery(SourceRootId(38))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working prio-high
Projects
None yet
Development

No branches or pull requests

3 participants