asciidoctor / asciidoctor-vscode

AsciiDoc support for Visual Studio Code using Asciidoctor
Other
341 stars 97 forks source link

Cant use asciidoctor in my own extension as soon as i active asciidoctor-vscode extension #881

Open flobilosaurus opened 6 months ago

flobilosaurus commented 6 months ago

Hello there, im the maintainer of a another extension based on asciidoc (https://github.com/flobilosaurus/vscode-asciidoc-slides).

As soon as i active this extension in my vscode, im unable to import asciidoctor in my extension code.

I just started a fresh extension from scratch and this does not work:

import * as vscode from 'vscode'
const asciidoctor = require('asciidoctor')()
export function activate(context: vscode.ExtensionContext) {

    console.log('Congratulations, your extension "helloworld-sample" is now active!');

    // The command has been defined in the package.json file
    // Now provide the implementation of the command with registerCommand
    // The commandId parameter must match the command field in package.json
    const disposable = vscode.commands.registerCommand('extension.helloWorld', () => {
        // The code you place here will be executed every time your command is executed

        // Display a message box to the user
        vscode.window.showInformationMessage(`Hello World!`);
    });
    context.subscriptions.push(disposable);
}

It works if your extension is uninstalled but i doesnt if its activated. The error message i get is the following:

2024-05-25 23:35:24.054 [error] TypeError: Opal.queue is not a function

I dont know much about Opal the following things seem to happen: Opal.queue seems to be undefined as soon as you extension is used. But this function seems to be required by asciidoctor.

Would be great if you could help me.

ggrossetie commented 6 months ago

Hey! You need to use version 5.1.0 of @asciidoctor/reveal.js which is transpiled using Opal 1.7.3 (compatible with Asciidoctor.js 3.x).

Please ask questions on https://chat.asciidoctor.org/

flobilosaurus commented 6 months ago

Hi @ggrossetie thanks for this quick reply. But i was not refering my current state of the repository of my extension. I created a fresh vscode extension from scratch:

npx --package yo --package generator-code -- yo code

And added asciidoctor:

yarn add asciidoctor

require asciidoctor in extension.ts like

import * as vscode from 'vscode'
const asciidoctor = require('asciidoctor')()
export function activate(context: vscode.ExtensionContext) {

    console.log('Congratulations, your extension "helloworld-sample" is now active!');

    // The command has been defined in the package.json file
    // Now provide the implementation of the command with registerCommand
    // The commandId parameter must match the command field in package.json
    const disposable = vscode.commands.registerCommand('extension.helloWorld', () => {
        // The code you place here will be executed every time your command is executed

        // Display a message box to the user
        vscode.window.showInformationMessage(`Hello World!`);
    });
    context.subscriptions.push(disposable);
}

and the "Hello World" example command will fail as soon as your extension is activated and it works if its not. I hope i could make thinks a little bit clearer here...

flobilosaurus commented 5 months ago

Hello @ggrossetie, please reopen this issue again and have a second look into it.

flobilosaurus commented 5 months ago

Hi @ggrossetie, did you have some time to look into this bug again?

ggrossetie commented 5 months ago

No but my guess is that the Asciidoctor VSCode is using @asciidoctor/core 2.2.7 and this new extension is using @asciidoctor/core 3.x.

Since Opal "mutates" the whole runtime you cannot have a library compiled with Opal version X and another one compiled with Opal version Y.

flobilosaurus commented 4 months ago

Hi, thanks @ggrossetie for the response. Would it be sufficient if you update asciidoctor/core to 3.x in this extension?

ggrossetie commented 4 months ago

The rule is that every extension that relies on Opal should use the exact same version. I guess it should work if we are both using the same version of Asciidoctor.js (and thus the same version of Opal).