continuedev / continue

⏩ Continue is the leading open-source AI code assistant. You can connect any models and any context to build custom autocomplete and chat experiences inside VS Code and JetBrains
https://continue.dev/docs
Apache License 2.0
13.09k stars 888 forks source link

Support: Continue Diff causes Rust Anlayzer to crash #1409

Open chrisoutwright opened 1 month ago

chrisoutwright commented 1 month ago

Before submitting your bug report

Relevant environment info

- OS: Windows_NT x64 10.0.22631
- Continue: v0.8.38
- IDE: Version: 1.89.1 (user setup)

Commit: dc96b837cf6bb4af9cd736aa3af08cf8279f7685
Date: 2024-05-07T05:13:33.891Z
Electron: 28.2.8
ElectronBuildId: 27744544
Chromium: 120.0.6099.291
Node.js: 18.18.2
V8: 12.0.267.19-electron.0

- Rust Analyzer
INFO [6/2/2024, 7:12:05 PM]: c:\Users\chris\.vscode\extensions\rust-lang.rust-analyzer-0.3.1975-win32-x64\server\rust-analyzer.exe --version: 'rust-analyzer 0.3.1975-standalone (71a816a90 2024-05-26)

- LLM: Ollama self-hosted: codestral_22b-v0.1-q8_0

Description

When using the Continue extension in Visual Studio Code, attempting to open the Continue Diff feature causes the Rust Analyzer to crash. The crash occurs specifically when performing the following steps:

Highlight any code with Shift-Ctrl-L and choose the action /edit within the Continue panel. Wait for the Continue Diff to open. At this point, the Rust Analyzer panics and crashes with the following error message:

thread 'LspServer' panicked at crates\paths\src\lib.rs:200:9: assertion failed: path.is_absolute()

This issue results in the Rust Analyzer becoming unresponsive, and subsequent attempts to use its features fail. The error message indicates a problem with path handling in the Rust Analyze, but I am unsure how to cope with it, since I only encountered it with Continue Diff being openned, or LEFT openend when restarting!

To reproduce

1) Shift-Ctrl-L any code and choose action /edit within Continue panel for the relevant part 2) Wait till Continue Diff opens, Rust Analyzer will panic with

thread 'LspServer' panicked at crates\paths\src\lib.rs:200:9:
assertion failed: path.is_absolute()

Log output

thread 'LspServer' panicked at crates\paths\src\lib.rs:200:9:
assertion failed: path.is_absolute()
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\panicking.rs:645
   1: core::panicking::panic_fmt
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\core\src\panicking.rs:72
   2: core::panicking::panic
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\core\src\panicking.rs:145
   3: rust_analyzer::global_state::GlobalState::new
   4: rust_analyzer::main_loop::<impl rust_analyzer::global_state::GlobalState>::run
   5: rust_analyzer::main_loop::<impl rust_analyzer::global_state::GlobalState>::run
   6: rust_analyzer::main_loop::main_loop
   7: rust_analyzer::run_server
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread '<unnamed>' panicked at C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\lsp-server-0.7.6\src\stdio.rs:28:37:
receiver was dropped, failed to send a message: "SendError(..)"
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\panicking.rs:645
   1: core::panicking::panic_fmt
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\core\src\panicking.rs:72
   2: core::result::unwrap_failed
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\core\src\result.rs:1654
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread 'main' panicked at C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\jod-thread-0.1.2\src\lib.rs:33:22:
called `Result::unwrap()` on an `Err` value: Any { .. }
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\panicking.rs:645
   1: core::panicking::panic_fmt
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\core\src\panicking.rs:72
   2: core::result::unwrap_failed
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\core\src\result.rs:1654
   3: stdx::thread::JoinHandle<T>::join
   4: lsp_types::trace::_::<impl serde::de::Deserialize for lsp_types::trace::TraceValue>::deserialize
   5: lsp_types::trace::_::<impl serde::de::Deserialize for lsp_types::trace::TraceValue>::deserialize
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 6:39:28 PM] Client Rust Analyzer Language Server: connection to server is erroring. Shutting down server.
[Error - 6:39:28 PM] Request textDocument/semanticTokens/range failed.
  Message: write EPIPE
  Code: -32099 
[Error - 6:39:28 PM] Stopping server failed
  Message: Cannot call write after a stream was destroyed
  Code: -32099 
[Error - 6:39:28 PM] Stopping server failed
  Message: Cannot call write after a stream was destroyed
  Code: -32099
chrisoutwright commented 1 month ago

I tried:

"rust-analyzer.files.excludeDirs": [
  "C:\\Users\\chris\\.continue\\.diffs\\*",
  "C:\\Users\\chris\\.continue\\.diffs\\",
  "\\.continue\\.diffs\\",
  "/.continue/.diffs/"
]

Also I tried :

"files.watcherExclude": {
  "**/.continue/.diffs/**": true,
  "**/.continue/.diffs/*/**": true
}

but still happening. Settings wrong? What can I do next?

chrisoutwright commented 1 month ago

Seems to be an invalid path Continue is generating. In my example with Continue Diff: C:\Users\chris\.continue\.diffs\c:_b_Users_b_chris_b_rust_projects_b_cfg_parser_b_async_tutorials_b_ch05_b_framestack_tester_b_src_b_main.rs https://github.com/rust-lang/rust-analyzer/issues/17335#issuecomment-2144845280 Rust Analyzer Group took a look at it.

chrisoutwright commented 1 month ago

Why is the syntax for a temporary Continue Diff file containing the drive letter with colon in the middle of the path itself? .continue.diffs\c:_b_Users_b_chris_b_rust_projects_b_cfg_parser_b_async_tutorials_b_ch05_b_framestack_tester_b_src_b_main.rs

chrisoutwright commented 4 weeks ago

Maybe add an escaping for the drive letter?:

 private getNewFilepath(originalFilepath: string): string {
    if (vscode.env.remoteName) {
      // If we're in a remote, use the remote's temp directory
      // Doing this because there's no easy way to find the home directory,
      // and there aren't write permissions to the root directory
      // and writing these to local causes separate issues
      // because the vscode.diff command will always try to read from remote
      vscode.workspace.fs.createDirectory(uriFromFilePath(this.remoteTmpDir));
      return path.join(
        this.remoteTmpDir,
        this.escapeFilepath(originalFilepath),
      );
    }
    return path.join(DIFF_DIRECTORY, this.escapeFilepath(originalFilepath));
  }

Colon is not a thing to be used in a filepath except for the absolute with drive letter at the beginning.

chrisoutwright commented 3 weeks ago

can you include escaping the colon maybe?:

private escapeFilepath(filepath: string): string {
    return filepath.replace(/\//g, "_f_").replace(/\\/g, "_b_").replace(/:/g, "_c_");
}
mcthesw commented 5 days ago

Is there a solution to this problem yet?

chrisoutwright commented 4 days ago

I see no solution to this issue.

sestinj commented 4 days ago

@chrisoutwright your solution was correct and I apologize for not having seen it earlier. I've made the change here and it will be available for testing later today in pre-release (0.9.x)

I'll wait to close the issue until there's confirmation that this actually solves it.