tact-lang / tact-vscode

Tact VS Code plugin
Apache License 2.0
14 stars 7 forks source link

Got error when I applied the formatting #3

Closed howardpen9 closed 1 year ago

howardpen9 commented 1 year ago
image image

I installed the vsix file successfully

logvik commented 1 year ago

Hi, thank you for this report. Can you share here some code snippet that I can use for the testing this issue?

defi-pickle commented 1 year ago

yeah i've got the same problem. When selecting the default formater it gives error code:

Request textDocument/formatting failed.
  Message: Unhandled method textDocument/formatting
  Code: -32601 

reproduction sample:

  import "@stdlib/deploy";

  message Add {
    amount: Int as uint32;
  }

  contract SampleTactContract with Deployable {

    owner: Address;
    counter: Int as uint32;

    init(owner: Address) {
        self.owner = owner;
        self.counter = 0;
    }

    fun add(v: Int) {

        // Check sender
        let ctx: Context = context();
        require(ctx.sender == self.owner, "Invalid sender");

        // Update counter
        self.counter = (self.counter + v);
    }

    receive(msg: Add) {
        self.add(msg.amount);
    }

    receive("increment") {
        self.add(1);
    }

    get fun counter(): Int {
        return self.counter;
    }
  }
defi-pickle commented 1 year ago

Issue is non existent on version 0.2.5

defi-pickle commented 1 year ago

Hey, i've narrow it down to documentFormattingProvider. I've removed it as a temp workaround here: https://github.com/tact-lang/tact-vscode/pull/4 There is probably something wrong with this bit:

    context.subscriptions.push(
        languages.registerDocumentFormattingEditProvider('tact', {
            provideDocumentFormattingEdits(document: TextDocument, options: FormattingOptions, token: CancellationToken): ProviderResult<TextEdit[]> {
                return Promise.resolve(formatDocument(document, context));
            },
    }));

Something is not right with formatDocument. I will try to fix that later but this might be enough to get you started.

logvik commented 1 year ago

Fixed on v.1.0.1