erlang-language-platform icon indicating copy to clipboard operation
erlang-language-platform copied to clipboard

Keep popping up fail notification

Open shionryuu opened this issue 1 year ago • 6 comments

Describe the bug

erlang-language-platform keep popping up fail notification

[Error - 4:59:24 PM] Request textDocument/semanticTokens/range failed.
  Message: internal error
  Code: -32603 
Panic context:
> 
request: textDocument/inlayHint InlayHintParams {
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
    text_document: TextDocumentIdentifier {
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/path/to/erlang/module.erl",
            query: None,
            fragment: None,
        },
    },
    range: Range {
        start: Position {
            line: 0,
            character: 0,
        },
        end: Position {
            line: 76,
            character: 30,
        },
    },
}

thread '<unnamed>' panicked at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/salsa-0.17.0-pre.2/src/runtime.rs:306:18:
called `Option::unwrap()` on a `None` value
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 4:59:24 PM] Request textDocument/inlayHint failed.
  Message: internal error
  Code: -32603 
Panic context:
> 
request: textDocument/semanticTokens/range SemanticTokensRangeParams {
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
    partial_result_params: PartialResultParams {
        partial_result_token: None,
    },
    text_document: TextDocumentIdentifier {
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/path/to/erlang/module.erl",
            query: None,
            fragment: None,
        },
    },
    range: Range {
        start: Position {
            line: 0,
            character: 0,
        },
        end: Position {
            line: 46,
            character: 63,
        },
    },
}

thread '<unnamed>' panicked at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/salsa-0.17.0-pre.2/src/runtime.rs:306:18:
called `Option::unwrap()` on a `None` value
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 4:59:24 PM] Request textDocument/semanticTokens/range failed.
  Message: internal error
  Code: -32603 

Panic context:
> 
request: textDocument/hover HoverParams {
    text_document_position_params: TextDocumentPositionParams {
        text_document: TextDocumentIdentifier {
            uri: Url {
                scheme: "file",
                cannot_be_a_base: false,
                username: "",
                password: None,
                host: None,
                port: None,
                path: "/home/ryuu/Workspace/erlang/vtnemo/src/node/game.erl",
                query: None,
                fragment: None,
            },
        },
        position: Position {
            line: 68,
            character: 8,
        },
    },
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
}

thread '<unnamed>' panicked at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/salsa-0.17.0-pre.2/src/runtime.rs:306:18:
called `Option::unwrap()` on a `None` value
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 5:03:51 PM] Request textDocument/hover failed.
  Message: internal error
  Code: -32603 

To Reproduce**

open project and browse codes

Expected behavior

work normally

Actual behavior

keep popping up fail notification

Context

  • ELP Version (output of elp version): elp 1.1.0+build-2024-05-17
  • Editor used: VSCode

shionryuu avatar May 18 '24 09:05 shionryuu

Hi @shionryuu and thanks for reporting! Do you have a project/code snippet you could share to help us troubleshooting the issue?

robertoaloi avatar May 20 '24 09:05 robertoaloi

Also, this seems to be triggered in Salsa itself, in the report_unexpected_cycle function:

let start_index = query_stack
                .iter()
                .rposition(|active_query| active_query.database_key_index == database_key_index)
                .unwrap();

robertoaloi avatar May 20 '24 09:05 robertoaloi

@shionryuu We'd need a few more info to be able to investigate this. The error suggests some case where a cycle in the code is not handled correctly (e.g. header including itself, behaviours requiring each other, etc).

Maybe you could check the code for a similar pattern and provide a simplified version that triggers this behaviours?

Additionally, you can go visit the ELP settings (e.g. in VS Code) and change "ELP: Log" from error to debug. That should give us more info.

FYI @alanz @michalmuskala

robertoaloi avatar May 20 '24 10:05 robertoaloi

Two headers of my project include each other, notifaction disapper if I fix the code.

The following codes will trigger fail notifaction:

$ cat include/common.hrl
-ifndef(__COMMON_H__).
-define(__COMMON_H__, 0).

-include("log.hrl").

-endif.
$ cat include/log.hrl
-ifndef(__LOG_H__).
-define(__LOG_H__, 0).

-include("common.hrl").

-endif.

shionryuu avatar May 20 '24 15:05 shionryuu

We do not currently process macro conditionals (-ifndef). So ELP will currently always include both, which will give a loop.

alanz avatar May 20 '24 16:05 alanz

We do have some protections against cyclic dependencies, but perhaps there are some places where this isn't fully correctly handled:

https://github.com/WhatsApp/erlang-language-platform/blob/4e174709871850e24f661ec817d69e36f2ea64fa/crates/hir/src/def_map.rs#L317-L354

michalmuskala avatar May 22 '24 10:05 michalmuskala