gyscos / cursive

A Text User Interface library for the Rust programming language
MIT License
4.26k stars 243 forks source link

[BUG] The recent "Move examples to the repo root" commit broke rust-analyzer for the examples #783

Closed matta closed 2 months ago

matta commented 4 months ago

TLDR

Reverting the recent a9c0e46e97fa4342e017a481f9e5b7a2f9d490d0 commit fixes the issue. It appears that LSP functions when the "examples" directory is in the root of a crate, but not the root directory of a workspace.

Describe the bug

When I load any of cursive's examples/*.rs files in an editor, rust-analyzer is broken. It appears to not function, as if it were not source code.

This is true for VSCode, nvim, and helix. Seems to be a behavior of rust-analyzer itself and not the editor.

To Reproduce

Edit any of examples/*.rs files and try to do something like "Go to definition" of a Cursive API. It doesn't work.

Make an obvious typo edit in the file. No error is shown.

Expected behavior

Code navigation features, such as "Go to definition" function. This is a great way to explore a new package, so it would be nice if this worked.

Environment

Debian Linux in a recent git clone of https://github.com/gyscos/cursive

Additional context

Explicitly editing files with names examples/cursive/examples/*.rs does not work, so that doesn't appear to be an available workaround.

correabuscar commented 4 months ago

see what else that commit broke also: https://ci.appveyor.com/project/gyscos/cursive/builds/49884693/job/p3kn5kftd8rgveq3

it's kinda odd since it works locally, and the symlink is there examples -> ../examples/

All the `rust-analyzer` errors I see locally: ```rust Diagnostic { code: RustcHardError("E0599"), message: "no method `or_insert` on type `Entry<'_, (String, TypeId), Box, Global>`", range: FileRange { file_id: FileId(1515), range: 2643..2652 }, severity: Error, unused: false, experimental: true, fixes: None, main_node: None } ``` ```rust Diagnostic { code: RustcHardError("E0599"), message: "no method `load_theme_file` on type `CursiveRunnable`", range: FileRange { file_id: FileId(24), range: 173..188 }, severity: Error, unused: false, experimental: true, fixes: None, main_node: None } Diagnostic { code: RustcHardError("E0599"), message: "no method `load_toml` on type `CursiveRunnable`", range: FileRange { file_id: FileId(24), range: 308..317 }, severity: Error, unused: false, experimental: true, fixes: None, main_node: None } ``` ```rust Diagnostic { code: RustcHardError("E0599"), message: "no method `insert` on type `&mut HashMap<(i16, i16), i16, RandomState>`", range: FileRange { file_id: FileId(1410), range: 5909..5915 }, severity: Error, unused: false, experimental: true, fixes: None, main_node: None } Diagnostic { code: RustcHardError("E0599"), message: "no method `get` on type `RefMut<'_, HashMap<(i16, i16), i16, RandomState>>`", range: FileRange { file_id: FileId(1410), range: 6305..6308 }, severity: Error, unused: false, experimental: true, fixes: None, main_node: None } ```
gyscos commented 4 months ago

Eh~~ I could very well revert that commit, since it didn't work as intended anyway.

correabuscar commented 4 months ago

this is fixed: https://github.com/gyscos/cursive/commit/3d7d6b725e4107d355f0c7dd4c6dc82dd7d01cba

matta commented 4 months ago

Another way to put the examples in the root and still use a workspace is to give each example a working Cargo.toml. I saw this done in the velo repo, and verified that rust-analyzer works fine.

For example: https://github.com/linebender/vello/tree/9a98543c03c954732ac1dc202dd1181fbd515e36/examples/simple

gyscos commented 2 months ago

Should be fixed now, feel free to re-open if you think you're still having this issue.