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

Keep popping up fail notification #27

Open
shionryuu opened this issue May 18, 2024 · 6 comments
Open

Keep popping up fail notification #27

shionryuu opened this issue May 18, 2024 · 6 comments
Labels
bug Something isn't working prio-mid

Comments

@shionryuu
Copy link

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 shionryuu added the bug Something isn't working label May 18, 2024
@robertoaloi
Copy link
Contributor

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

@robertoaloi
Copy link
Contributor

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
Copy link
Contributor

@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

@shionryuu
Copy link
Author

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.

@alanz
Copy link
Member

alanz commented May 20, 2024

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

@michalmuskala
Copy link
Member

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

pub(crate) fn def_map_query(db: &dyn DefDatabase, file_id: FileId) -> Arc<DefMap> {
let local = db.local_def_map(file_id);
let form_list = db.file_form_list(file_id);
let mut remote = Self::default();
form_list
.includes()
.filter_map(|(idx, _)| db.resolve_include(InFile::new(file_id, idx)))
// guard against naive cycles of headers including themselves
.filter(|&included_file_id| included_file_id != file_id)
.map(|included_file_id| (included_file_id, db.def_map(included_file_id)))
.for_each(|(file_id, def_map)| {
remote.included.insert(file_id);
remote.merge(&def_map)
});
// Small optimisation for a case where we have no headers or headers don't contain defintitions
// we're inrested in - should be hit frequently in headers themselves
if remote.is_empty() {
local
} else {
remote.merge(&local);
remote.fixup_exports();
remote.fixup_deprecated();
Arc::new(remote)
}
}
// This handles the case of headers accidentally forming other cycles.
// Return just the local def map in such cases, not resolving nested includes at all
pub(crate) fn recover_cycle(
db: &dyn DefDatabase,
_cycle: &[String],
file_id: &FileId,
) -> Arc<DefMap> {
db.local_def_map(*file_id)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working prio-mid
Projects
None yet
Development

No branches or pull requests

4 participants