sui icon indicating copy to clipboard operation
sui copied to clipboard

Sui Move VSCode Language Support Plugin gives false error in Hello World Program, builds fine

Open gordonkoehn opened this issue 1 year ago • 7 comments
trafficstars

Following the standard hello world tutorial yields an error in using the official Move VS Code Plugin gives:

Compilation in test mode requires passing the UnitTest module in the Move stdlib as a dependency

for the module definition hello world.

Yet the hello world package builds fine.

Steps to Reproduce Issue

Following step by step introduction of Move Book/Hello World

e.g.

  1. Standard Setup Sui
  2. Install VSCode Plugin Move v0.0.3

Expected Result

No errors, no warnings.

Actual Result

hello_world.move

Compilation in test mode requires passing the UnitTest module in the Move stdlib as a dependency

What is this test mode?

System Information

  • OS: Mac 14.4.1
  • sui-client 1.24.0

Code

/// The module `hello_world` under named address `hello_world`.
/// The named address is set in the `Move.toml`.
module hello_world::hello_world {
    // Imports the `String` type from the Standard Library
    use std::string::String;

    /// Returns the "Hello, World!" as a `String`.
    public fun hello_world(): String {
        b"Hello, World!".to_string()
    }
}

Screenshot 2024-05-06 at 20 35 25

gordonkoehn avatar May 06 '24 18:05 gordonkoehn

This should not be happening if Sui framework (or just Move stdlib) is correctly specified as a dependency in the Move.toml file.

Context - currently, we need to build all projects in the VSCode plugin in "test mode". In this mode, all test code is included into the project (otherwise, in non-test mode, it is removed during compilation). Perhaps incorrectly, but I consider this a minor inconvenience as Mysten's VSCode plugin is meant for development of Sui smart contracts and any contract beyond the most trivial ones would already require inclusion of Sui framework code as a dependency.

All that being said, I followed the instructions from https://move-book.com/your-first-move/hello-world.html. up to the Compiling the Package chapter and I don't see any errors...

awelc avatar May 06 '24 20:05 awelc

Thank you for your prompt support and the context; I much appreciated it. I've just switched my VS Code Move Extension version to v0.0.2, and the error disappears.

To be clear, it builds perfectly fine; it's just the red underlining / flagging an error by the move language support.

I've attached the compressed folder of my project state. Yet it's probably something with my setup. Let me know if I can supply other setup details to reproduce the behaviour. hello_world.zip

Please feel free to close this issue at your judgment.

gordonkoehn avatar May 07 '24 10:05 gordonkoehn

I tried it on my side with code attached and cannot repro... Let's try a few more things (I am assuming you did not change any options for the VSCode plugin, such as location of the Move analyzer binary, etc.):

  • uninstall Move VSCode plugin
  • quit VSCode
  • remove VSCode extension from the filesystem: remove directory representing the extension (starting with mysten) from the ~/.vscode/extensions/ directory
  • remove Move analyzer binary from ~/.sui/bin/ directory
  • start VSCode
  • install the newest version of the VSCode extension from the marketplace
  • restart VSCode

awelc avatar May 07 '24 17:05 awelc

The issue persists – with the v0.0.3 version of the Move VSCode plugin.

Correct, I did not change any options – default installation via the VSCode GUI. Followed your clean install instructions meticulously, yet the issue appears again.

When I switch to the v0.0.2 version of the Move VSCode plugin, the false positive error disappears.

gordonkoehn avatar May 07 '24 17:05 gordonkoehn

This is really strange and I would like to get to the bottom of this if possible. Could you perhaps restart VSCode and let me know what the extension logs are saying (View->Output menu and then both Move and Move Client options from the drop-down menu on the right-hand side).

Could you also please list the content of the ~/.vscode/extensions directory?

awelc avatar May 07 '24 17:05 awelc

Certainly, here are the outputs as screenshots:

Move Output

Move Output

Move Client

Move Client Output

Move Language Server

  • also found this Move Language Server

Extensions Directory

extensions directory

gordonkoehn avatar May 07 '24 18:05 gordonkoehn

Nothing looks out of ordinary other than perhaps that you seem to also have movebit's extension files in your ~/.vscode/extensions directory. I wonder if this extension is actively installed in your VSCode instance - if it is, perhaps you can uninstall it and then (regardless if it was actively installed or not) remove the movebit-sui-move-analyzer-1.1.6 directory from ~/.vscode/extensions.

Another thing to try (if you are not yet too annoyed with this - and my apologies, I am grasping at straws here...) is to change Sui dependency in hello_world's manifest file to the local one. Please clone Sui to your main directory (unless you already have it there):

cd ~/
git clone https://github.com/MystenLabs/sui.git

And replace Sui dependency in the manifest file with:

Sui = { local = "/Users/gordonkoehn/sui/crates/sui-framework/packages/sui-framework/" }

awelc avatar May 07 '24 18:05 awelc

Good Morning again. No apologies are needed; I am happy to contribute to smoothening the start of the next ones with Sui in VSCode.

  • sui-move-analyzer: I probably did install it when I first searched for a language support plugin. Wasn't sure which was the official one, this one had more downloads. It was disabled the whole time during our debugging. Uninstalled it now and deleted movebit.sui-move-analyzer-1.1.6. I closed VSCode and restarted the Move plugin, but the false postie error persists. Screenshot 2024-05-08 at 10 33 05

  • changing the Sui dependency to local: Cloned as described, edited my .tomlsee below. I closed and reloaded my VSCode. Here is the output of my Output/Move Extension; see below. Error persists. Screenshot 2024-05-08 at 10 33 47

Screenshot 2024-05-08 at 10 36 29

gordonkoehn avatar May 08 '24 08:05 gordonkoehn

I have the same issue with Move extension v0.0.3 Compilation in test mode requires passing the UnitTest module in the Move stdlib as a dependency. I followed the steps above, but the error persists

FlorianMilcendeau avatar May 09 '24 10:05 FlorianMilcendeau

Could you try running sui move test (assuming sui command is on your path) in the hello_world directory and let me know what happens?

awelc avatar May 09 '24 16:05 awelc

Works, perfectly fine.

Screenshot 2024-05-09 at 20 16 33

gordonkoehn avatar May 09 '24 18:05 gordonkoehn

Let's see if you are using move-analyzer binary from the expected location.

  • quit VSCode
  • move Move analyzer binary from ~/.sui/bin/ directory some temporary one
  • start VSCode

You should get a different error now due to missing Move analyzer binary. Please let me know if you did (and restore Move analyzer binary to ~/.sui/bin/)

awelc avatar May 09 '24 19:05 awelc

I closed VSCode, and deleted ~.sui/bin/move-analyzer accidentally, yet it came back upon opening VSCode. No errors thrown upon opening VSCode.

That false positive error persists.

gordonkoehn avatar May 10 '24 12:05 gordonkoehn

I still can't shake of a suspicion that your VSCode somehow picks up a wrong move-analyzer binary (though I am not sure how this could be possible). Let's try something else to see if this is what's happening.

  • build a new move-analyzer binary (I am assuming you have Rust toolchain installed):
cargo install --git https://github.com/MystenLabs/sui move-analyzer
  • In "Code->Settings->Settings" choose "Workspace", and then from drop-down menu choose "Extensions" and then "Move"
  • change value of Server:Path option from null (which is what it should be) to "~/.cargo/bin" (keep the double-quotes)
  • Restart VSCode

awelc avatar May 10 '24 20:05 awelc

YES!! Move v0.0.3 works for my hello world !

I followed your suggestions, but I assume you meant "~/.cargo/bin/move-analyzer," not just "~/.cargo/bin". Adding the latter led to Move failing upon VSCode restart.

First, thanks for debugging this with me.

What did I do wrong upon installation? Do you have a guess what happened?

gordonkoehn avatar May 11 '24 10:05 gordonkoehn

I followed your suggestions, but I assume you meant "~/.cargo/bin/move-analyzer," not just "~/.cargo/bin"

Yes, sorry for the imprecision

What did I do wrong upon installation? Do you have a guess what happened?

I honestly don't know. I plan to re-work the automated move-analyzer binary installation path in the extension soon, so hopefully next time you upgrade this is not going to be a problem.

This was a really weird one - I tried your own code with the same binary that is packaged with the v0.0.3 of the extension and I could not reproduce the problem. The only thing I was left thinking of was that somehow on your machine a different (earlier) version of move-analyzer was being picked up as I know the problem you reported but it was fixed before v0.0.2 and nothing I could see was indicating that it was re-introduced in v.0.0.3. An even more unlikely alternative was that indeed the analyzer bundled with v.0.0.3 did not work in your local setup. The last attempt to solve it was trying to address both these problems - provide an explicit custom path to the analyzer and have you work with the newest version.

In any case, my apologies for this - it's certainly not how we want developer experience to look like. Also, thank you for your patience! If you haven't lost it completely, I would ask you at some point to try a newer version (with a different move-analyzer installation path) to see if things work correctly.

awelc avatar May 11 '24 18:05 awelc

Thanks for enhancing the sui development experience! I am happy to support; just let me know when I shall test the new version on my system.

Thank you for the context of what might have happened. I appreciated it.

Until the next version, Thanks for investigating this with me! Feel free to close this issue/tag for later.

gordonkoehn avatar May 12 '24 14:05 gordonkoehn

@gordonkoehn , I realized that there might have been another problem and I was wondering if you'd be willing to give it a shot.

  • remove custom Server:Path from "Workspace" settings in "Code->Settings->Settings" (you can remove the whole line containing value for this option once the editor opens)
  • reinstall the newest version of the extension
  • restart VSCode

awelc avatar May 15 '24 01:05 awelc

Yes, this solves it as well!

What I did:

  • I removed the custom path and set it to "null", as it was before our edits.
  • Then, I updated the Move extension to the brand-new version, v1.0.2, and it worked.
  • The 'Hello World' error is gone.

I verified that downgrading to v0.0.3 still gives the error in my current setup.

Thank you for the seamless fix; I can't wait to build on Sui at the Consensus24 Hackathon with this setup.

Please close this issue at your discretion.

gordonkoehn avatar May 15 '24 09:05 gordonkoehn

v.1.0.2 of the extension finally solved the problem

awelc avatar May 15 '24 17:05 awelc