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

utils.getElmVersion returns empty version #518

Closed
jlocans opened this issue Feb 12, 2021 · 15 comments
Closed

utils.getElmVersion returns empty version #518

jlocans opened this issue Feb 12, 2021 · 15 comments

Comments

@jlocans
Copy link

jlocans commented Feb 12, 2021

Expected Behavior

Extension should work (look for Elm packages in right directory)
utils.getElmVersion should return Elm version that is installed. 0.19.1 in this case.

Current Behavior

UPDATED: Found that utils.getElmVersion is returning empty value instead of version.


Opening the elm-spa-example project. The only thing that seems to work is syntax highlighting.
One of the first errors in output is
Error: ENOENT: no such file or directory, open 'C:\Users\janis\AppData\Roaming\elm\packages\NoRedInk\elm-json-decode-pipeline\1.0.0\elm.json'
The file is actually located in
C:\Users\janis\AppData\Roaming\elm\0.19.1\packages\NoRedInk\elm-json-decode-pipeline\1.0.0\elm.json
See the 0.19.1 version part.

The weird thing is that it worked the first time I installed it (moments before I reinstalled it). Basically I installed the extension. It worked. Then noticed numbers next to elm files in file explorer and was wondering if that is extension feature or vscode feature (which I had just updated as well) as I couldn't understand what they meant. Fastest way to check from where the features comes? Uninstall extension. Uninstalled it, numbers were gone. Ok, so that is extensions feature. Installed it back and it doesn't work any more.

Then I found the ENOENT error and that I had two version folders inside AppData\Roaming\elm\packages\ - 0.19.0 and 0.19.1.
Uninstalled both Elm versions.
Deleted elm-spa-example project
Deleted elm folder in AppData\Roaming
Installed Elm 0.19.1
Cloned project again and built it, but the path is still as AppData\Roaming\elm\0.19.1\packages

Possible Solution

No solution, but seems that extensions is looking for packages in the wrong directory.

Your Environment

  • Version used: v2.0.3

vscode info:
Version: 1.53.1 (system setup)
Commit: 5d424b828ada08e1eb9f95d6cb41120234ef57c7
Date: 2021-02-08T23:29:42.785Z
Electron: 11.2.1
Chrome: 87.0.4280.141
Node.js: 12.18.3 EDIT: Updated to v14.15.5
V8: 8.7.220.31-electron.0
OS: Windows_NT x64 10.0.17134

Full log

[Info  - 7:49:48 PM] Loading Elm tree-sitter syntax from c:\Users\janis\.vscode\extensions\elmtooling.elm-ls-vscode-2.0.3\server\out\tree-sitter-elm.wasm
[Info  - 7:49:48 PM] Found 1 elm.json files for workspace f:/dev/elm-spa-example
[Info  - 7:49:48 PM] Found 1 unique elmWorkspaces for workspace f:/dev/elm-spa-example
[Info  - 7:49:48 PM] Starting language server for folder: file:///f%3A/dev/elm-spa-example
[Info  - 7:49:48 PM] Elm version  detected.
[Info  - 7:49:48 PM] Reading elm.json from f:/dev/elm-spa-example/elm.json
[Error - 7:49:49 PM] Error parsing files for f:/dev/elm-spa-example/elm.json:
Error: ENOENT: no such file or directory, open 'C:\Users\janis\AppData\Roaming\elm\packages\NoRedInk\elm-json-decode-pipeline\1.0.0\elm.json'
[Error - 7:49:49 PM] Notification handler 'textDocument/didOpen' failed with message: Cannot read property 'getTree' of undefined
[Error - 7:49:49 PM] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Cannot read property 'getTree' of undefined
  Code: -32603 
[Error - 7:49:49 PM] Request textDocument/codeAction failed.
  Message: Request textDocument/codeAction failed with message: Cannot read property 'getTree' of undefined
  Code: -32603 
[Error - 7:49:49 PM] Request textDocument/foldingRange failed.
  Message: Request textDocument/foldingRange failed with message: Cannot read property 'getTree' of undefined
  Code: -32603 
[Error - 7:49:49 PM] TypeError: Cannot read property 'getTree' of undefined delayed processing of request
[Error - 7:49:49 PM] Request textDocument/codeLens failed.
  Message: Request textDocument/codeLens failed with message: Cannot read property 'getTree' of undefined
  Code: -32603 
[Error - 7:53:14 PM] Request textDocument/codeAction failed.
  Message: Request textDocument/codeAction failed with message: Cannot read property 'getTree' of undefined
  Code: -32603 
[Error - 7:53:15 PM] Notification handler 'textDocument/didSave' failed with message: Cannot read property 'getTree' of undefined
@razzeee razzeee transferred this issue from elm-tooling/elm-language-client-vscode Feb 12, 2021
@razzeee
Copy link
Member

razzeee commented Feb 12, 2021

Something is weird with your elm executable, can you run elm --version?

[Info  - 7:49:48 PM] Elm version  detected.

this usually shows the version in between

@jlocans
Copy link
Author

jlocans commented Feb 12, 2021

Yes, just noticed as well.
Elm is at 0.19.1

Trying to see if I can debug it. Cloned elm-language-client-vscode and trying to figure out what to do after running the project.

@razzeee
Copy link
Member

razzeee commented Feb 12, 2021

This is the code, if you haven't found it already https://github.com/elm-tooling/elm-language-server/blob/master/src/elmWorkspace.ts#L333

@jlocans
Copy link
Author

jlocans commented Feb 12, 2021

OK, figured out that I have to open the project from the vscode instance that opens when debugging, dooh. But for some reason the breakpoint I set becomes unbound once debugging.
I'll try to get this running and see if I can get something helpful.

@razzeee
Copy link
Member

razzeee commented Feb 12, 2021

You need to attach to the port 5010 (there is a debug config), you need to be in an elm file for the server to spin up, but it's hard to attach early enough.

@jlocans
Copy link
Author

jlocans commented Feb 12, 2021

Server does spin up. Debugger listening on ws://127.0.0.1:5010/b65cc304-4d87-4cc7-9cdd-31e3edf233ec
Added console log and can see that as well, but can't debug.
By default it listened on 6010. Changed to 5010, but with no success.

I'm not very familiar with node js development. Do I have to attach debugger manually?
The way it works now, is that when I start debugging, the spa project is opened with elm file selected and I can see debug messages in output.
Updated node to v14.15.5 hoping for some magic.

@jlocans jlocans changed the title Looking for packages in wrong directory utils.getElmVersion returns empty version Feb 12, 2021
@razzeee
Copy link
Member

razzeee commented Feb 12, 2021

You only have to attach a debugger cause we're running a client, which you will debug automatically, but also a server, which is a remote process.

I'm sorry it should be port 6010, said that from memory

@jlocans
Copy link
Author

jlocans commented Feb 12, 2021

Got to the point where the elm --version command is executed and it looks good to me.
image
Makes me think it's my machine specific issue.

@razzeee razzeee added this to the 2.1 milestone Feb 12, 2021
@razzeee
Copy link
Member

razzeee commented Feb 12, 2021

That's before it returns, what's the actual return?

@jlocans
Copy link
Author

jlocans commented Feb 12, 2021

{
  command: "elm --version",
  exitCode: 0,
  stdout: "",
  stderr: "",
  failed: false,
  timedOut: false,
  isCanceled: false,
  killed: false,
}

@razzeee
Copy link
Member

razzeee commented Feb 12, 2021

So now the question is, why stdout is empty. How did you install elm? Might be worth to try to reinstall.

@jlocans
Copy link
Author

jlocans commented Feb 12, 2021

Installed it from https://github.com/elm/compiler/releases/download/0.19.1/installer-for-windows.exe

I had 0.19.0 before.
Installed 0.19.1
Uninstalled 0.19.0
Uninstalled 0.19.1
Installed 0.19.1 again
for whatever reason uninstalled Installed 0.19.1 again and deleted elm folder in AppData\Roaming
Installed 0.19.1 again.

Running elm --version from any terminal (cmd, powershell, bash) returns 0.19.1
And as mentioned, it worked the first time I installed the extension. Strange.

@jlocans
Copy link
Author

jlocans commented Feb 13, 2021

I think I found the issue.
execa.sync is not executing elm command. Instead it is opening elm.js file inside spa project.
If I change the value of cwd to a path that isn't elm project then it works fine.
Or if I rename elm.js to something else then it works fine.

Made a small snippet to test this.

import execa from "execa";

const cwd = 'f:\\dev\\elm-spa-example';
const input = undefined;
const preferLocal = true;
const stripFinalNewLine = false;

function exec(cmd, args) {
  try {
    return execa.sync(cmd, args, {
      cwd,
      input,
      preferLocal,
      stripFinalNewLine
    });
  }
  catch (exc) {
    return exc;
  }
}

const res = exec('elm', ['--version']);
console.log(res);

vscode actually opens the elm.js file when running this.
Changing const res = exec('elm', ['--version']); to const res = exec('elm.exe', ['--version']); also works, but that's only for windows of course.

Do we actually need the cwd parameter in this case? Without it it would work fine. If I set cwd to undefined in snippet it works fine, but not in server. Basically I call execa.sync with the exact same parameters in snippet and server, and get different results in this case.

Goods news for me is that I can work around this by making change in the make command and rename or move elm.js

@razzeee
Copy link
Member

razzeee commented Feb 13, 2021

Right, I always recommend to not use elm.js as windows finds this confusing evancz/guide.elm-lang.org#244

Still, this is a new place to show this problem, as we just recently had to introduce that elm --version call

@jlocans
Copy link
Author

jlocans commented Feb 13, 2021

Yeah, I was just following the spa project instructions.
Thanks for your help @razzeee

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