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

bug(vfs): cairo-language-server unable to convert URI to filepath #112

Open
mkaput opened this issue Dec 18, 2024 · 2 comments
Open

bug(vfs): cairo-language-server unable to convert URI to filepath #112

mkaput opened this issue Dec 18, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@mkaput
Copy link
Member

mkaput commented Dec 18, 2024

@0xLucqs commented on 30.08.2023, 12:24:07:

Bug Report

Cairo version:

v2.2.0

Current behavior:

When trying to jump to the definition of a function or a trait defined with the #[generate_trait] macro the language server fails and outputs unable to convert URI to filepath: vfs://201/generate_trait.cairo

Expected behavior:

It shouldn't fail and jump to the definition.

Steps to reproduce:

Related code:

use bar::{A, DummyTrait};

fn main() {
    let a = A { b: 1 };
    a.dummy()
}
mod bar {
    #[derive(Drop)]
    struct A {
        b: u8
    }
    #[generate_trait]
    impl Dummy of DummyTrait {
        fn dummy(self: A) {}
    }
}

Now when trying to jump to the definition of a.dummy() or DummyTrait it fails

Other information:

Proposed solution

Drop the vfs:// scheme and write virtual files to a temporary directory just for presentation purposes instead. All of this should happen entirely within CairoLS without modifying Cairo compiler codebase.

@mkaput mkaput added the bug Something isn't working label Dec 18, 2024
@mkaput
Copy link
Member Author

mkaput commented Dec 18, 2024

@xJonathanLEI commented on 17.09.2023, 23:44:13:

(All code links in this comment were taken from commit starkware-libs/cairo@2fbb7b1)

Note that this issue only happens on non-VS-Code editors (e.g. Helix) but not VS Code. I originally thought that this is a universal problem, and thus submitted helix-editor/helix#6000 to Helix to ignore vfs URLs altogether. However, @LucasLvy reminded me that it works in VS Code so I took a look and it does indeed work. Good news right? Not really...

Upon further debugging, it turns out that the Cairo LSP defines a custom method vfs_provide:

https://github.com/starkware-libs/cairo/blob/2fbb7b142c96d9007886ddacc0a10889c951cd2a/crates/cairo-lang-language-server/src/lib.rs#L89-L91

How the heck does VS Code know about this method then?? Well, in the extension:

https://github.com/starkware-libs/cairo/blob/2fbb7b142c96d9007886ddacc0a10889c951cd2a/vscode-cairo/src/extension.ts#L357-L363

So... basically the Cairo LSP is proprietary... Any other editors that expect a compliant LSP wouldn't work 100% with the Cairo LSP.

IMO, the ideal way to handle ephemeral files is to simply use a directory like target to actually generate the file and serve the actual path (instead of vfs) to clients.

@mkaput
Copy link
Member Author

mkaput commented Dec 18, 2024

@mkaput commented on 2.08.2024, 15:45:40:

Writing down my proposed solution to this:

Instead of employing a custom vfs/provide method, CairoLS should lazily emit virtual files as temporary files in /tmp (follow platform conventions). These files should only be written whenever an URL for them is being generated. Implementor should pay great attention that unused files are deleted by OS (for example on system shutdown).

@github-project-automation github-project-automation bot moved this to Triage in CairoLS Dec 18, 2024
@mkaput mkaput moved this from Triage to Backlog in CairoLS Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

1 participant