rune-rs / rune

An embeddable dynamic programming language for Rust.
https://rune-rs.github.io
Apache License 2.0
1.7k stars 85 forks source link

Can't get custom language server support to work #724

Closed VorpalBlade closed 2 months ago

VorpalBlade commented 2 months ago

I cannot get the custom language server support to work with the VSCode plugin (for the latest release of rune, I haven't tried the git version).

INFO [06/07/2024, 15:31:39]: Cargo: cargo 1.79.0 (ffa9cf99a 2024-06-03)
INFO [06/07/2024, 15:31:39]: /home/arvid/src/paketkoll
INFO [06/07/2024, 15:31:47]: No executable
ERROR [06/07/2024, 15:31:47]: Error: Rune Language Server is not available.
    at t.Ctx.bootstrap (/home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.0/dist/extension.js:1:40672)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at t.Ctx.setupClient (/home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.0/dist/extension.js:1:40027)
    at t.Ctx.activate (/home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.0/dist/extension.js:1:39840)
    at /home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.0/dist/extension.js:1:39450
    at h (/opt/visual-studio-code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:153:200468)

The binary does exist and I can successfully use it to generate documentation with the doc sub command using cargo run --bin konfigkoll_rune -- doc --output doc/api. According to --help it has a languageserver sub-command too.

INFO [06/07/2024, 15:34:25]: Using server binary at /home/arvid/src/paketkoll/target/debug/konfigkoll_rune
ERROR [06/07/2024, 15:34:25]: r [Error]: Pending response rejected since connection got disposed
    at Object.dispose (/home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.0/dist/extension.js:1:75665)
    at Object.dispose (/home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.0/dist/extension.js:1:127336)
    at b.handleConnectionClosed (/home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.0/dist/extension.js:1:127614)
    at b.handleConnectionClosed (/home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.0/dist/extension.js:1:282933)
    at /home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.0/dist/extension.js:1:127424
    at n.invoke (/home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.0/dist/extension.js:1:77374)
    at o.fire (/home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.0/dist/extension.js:1:78139)
    at Z (/home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.0/dist/extension.js:1:64021)
    at n.invoke (/home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.0/dist/extension.js:1:77374)
    at o.fire (/home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.0/dist/extension.js:1:78139)
    at g.fireClose (/home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.0/dist/extension.js:1:85951)
    at Socket.<anonymous> (/home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.0/dist/extension.js:1:87507)
    at Socket.emit (node:events:526:35)
    at Pipe.<anonymous> (node:net:337:12) {
  code: -32097,
  data: undefined
}

After this point I cannot reload the Rune extension any more and have to restart vscode to get it back up and running.

Versions:

VorpalBlade commented 2 months ago

I have pushed the feature branch with this in (if you need to test) to https://github.com/VorpalBlade/paketkoll/tree/feature/konfigkoll

Please be advised that this is a work in progress and I'm a heavy user of history rewriting and force pushing in my feature branches.

udoprog commented 2 months ago

Thanks for the report!

For what it's worth, once you change the visual studio code configuration, you should just be able to click to restart the rune extension.

What seems to have happened here is that the format of the package identifier has changed since that feature of the extension was written, the relevant line we are looking for now looks like this:

{
  "reason": "compiler-artifact",
  "package_id": "path+file:///home/udoprog/repo/paketkoll/crates/konfigkoll_rune#0.1.0",
  "manifest_path": "/home/udoprog/repo/paketkoll/crates/konfigkoll_rune/Cargo.toml",
  "target": {
    "kind": [
      "bin"
    ],
    "crate_types": [
      "bin"
    ],
    "name": "konfigkoll_rune",
    "src_path": "/home/udoprog/repo/paketkoll/crates/konfigkoll_rune/src/main.rs",
    "edition": "2021",
    "doc": true,
    "doctest": false,
    "test": true
  },
  "profile": {
    "opt_level": "0",
    "debuginfo": 2,
    "debug_assertions": true,
    "overflow_checks": true,
    "test": false
  },
  "features": [],
  "filenames": [
    "/home/udoprog/repo/paketkoll/target/debug/konfigkoll_rune"
  ],
  "executable": "/home/udoprog/repo/paketkoll/target/debug/konfigkoll_rune",
  "fresh": true
}

The code to decode it looks like this:

out.on('line', (data) => {
    log.debug(data);

    let output = JSON.parse(data) as ReasonOutput;

    if (output.reason === "compiler-artifact") {
        let artifact = output as CompilerArtifact;
        this.statusBar.text = `rune: cargo (${artifact.target.name})`;

        let [id, ...rest] = artifact.package_id.split(" ");

        if (id === name && artifact.target.kind.includes("bin")) {
            executable = artifact.executable;
        }
    }
});
VorpalBlade commented 2 months ago

What seems to have happened here is that the format of the package identifier has changed since that feature of the extension was written, the relevant line we are looking for now looks like this:

I hope it can be fixed, I have no experience in js/ts, so I have no idea how to apply what you just wrote.

Also, the second error where I provided a fixed path would not be solved by this I assume?

udoprog commented 2 months ago

Please update the extension to 0.13.1 (once it's available) and try again.

VorpalBlade commented 2 months ago
INFO [07/07/2024, 00:21:11]: Using configuration {
  updates: { channel: 'nightly', checkInterval: 7200, askBeforeDownload: true },
  typing: { continueCommentsOnNewline: true },
  server: {
    cargoPackage: '',
    path: '/home/arvid/src/paketkoll/target/debug/konfigkoll_rune',
    extraEnv: null
  },
  trace: { extension: false }
}
INFO [07/07/2024, 00:21:17]: Using server binary at /home/arvid/src/paketkoll/target/debug/konfigkoll_rune
ERROR [07/07/2024, 00:21:17]: r [Error]: Pending response rejected since connection got disposed
    at Object.dispose (/home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.1/dist/extension.js:1:75641)
    at Object.dispose (/home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.1/dist/extension.js:1:127312)
    at b.handleConnectionClosed (/home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.1/dist/extension.js:1:127590)
    at b.handleConnectionClosed (/home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.1/dist/extension.js:1:282909)
    at /home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.1/dist/extension.js:1:127400
    at n.invoke (/home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.1/dist/extension.js:1:77350)
    at o.fire (/home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.1/dist/extension.js:1:78115)
    at Z (/home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.1/dist/extension.js:1:63997)
    at n.invoke (/home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.1/dist/extension.js:1:77350)
    at o.fire (/home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.1/dist/extension.js:1:78115)
    at v.fireClose (/home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.1/dist/extension.js:1:89452)
    at Socket.<anonymous> (/home/arvid/.vscode/extensions/udoprog.rune-vscode-0.13.1/dist/extension.js:1:90182)
    at Socket.emit (node:events:514:28)
    at Pipe.<anonymous> (node:net:337:12) {
  code: -32097,
  data: undefined
}

But this works:

INFO [07/07/2024, 00:22:58]: Cargo: cargo 1.79.0 (ffa9cf99a 2024-06-03)
INFO [07/07/2024, 00:22:58]: /home/arvid/src/paketkoll
INFO [07/07/2024, 00:22:59]: Executable: /home/arvid/src/paketkoll/target/debug/konfigkoll_rune
INFO [07/07/2024, 00:22:59]: Using server binary at /home/arvid/src/paketkoll/target/debug/konfigkoll_rune
INFO [07/07/2024, 00:23:00]: Using configuration {
  updates: { channel: 'nightly', checkInterval: 7200, askBeforeDownload: true },
  typing: { continueCommentsOnNewline: true },
  server: { cargoPackage: 'konfigkoll_rune', path: '', extraEnv: null },
  trace: { extension: false }
}

To me those look like the same path, just resolved in two different ways. I'm quite baffled.

udoprog commented 2 months ago

Ah!

So I believe when specifying a custom binary it actually expects the language server to be called in a different way which is the "old" instantiation. We still publish and use them, for example here. The entry point for them would look slightly different.

I'd want to deprecate this behavior at some point, but since I don't want to break existing extensions I at least want to make sure there's a smooth path to upgrade.

VorpalBlade commented 2 months ago

I'd want to deprecate this behavior at some point, but since I don't want to break existing extensions I at least want to make sure there's a smooth path to upgrade.

If you mean to deprecate being able to use a non-cargo target that would be unfortunate. I would expect most development of projects in rune are not happening while also developing the associated rust code.

In other words: I don't expect my users to have to clone the rust repo to use the LSP, they should be able to point at a binary in /usr/bin installed with their package manager. (I would prefer if that could be the same binary as my main program, but that is currently not practical, and is anyway a separate feature request I do plan to file later).