WhatsApp / erlang-language-platform

Erlang Language Platform. LSP server and CLI.
https://whatsapp.github.io/erlang-language-platform/
Apache License 2.0
209 stars 16 forks source link

Incorrect W0017 warning #23

Open dszoboszlay opened 2 months ago

dszoboszlay commented 2 months ago

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

alanz commented 2 months ago

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 commented 2 months ago

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.

alanz commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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

Screenshot 2024-04-22 at 11 42 22
alanz commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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 commented 1 month ago

@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 commented 1 month ago

@alanz @dszoboszlay

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

Reason:

no value set for SourceRootQuery(SourceRootId(38))