rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
13.8k stars 1.53k forks source link

The vscode plugin keeps crashing #16799

Open lvzhenbo opened 3 months ago

lvzhenbo commented 3 months ago

rust-analyzer version: 0.3.1868-standalone (037924c4d 2024-03-03)

rustc version: 1.76.0 (07dca489a 2024-02-04)

relevant settings: I don't know what can be provided

repository link (if public, optional): Not yet. I am currently learning how to use tauri 2.0. Perhaps I can create a tauri 2.0 project and give it a try

code snippet to reproduce:

// add your code here
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn greet(name: &str) -> String {
    format!("Hello, {}! You've been greeted from Rust!", name)
}

#[tauri::command]
async fn read_file(path: std::path::PathBuf) -> Result<Vec<u8>, String> {
    match std::fs::read(path) {
        Ok(data) => Ok(data),
        Err(err) => Err(format!("Failed to read file: {}", err)),
    }
}

#[tauri::command]
async fn write_file(path: std::path::PathBuf, data: Vec<u8>) -> Result<(), String> {
    match std::fs::write(path, data) {
        Ok(_) => Ok(()),
        Err(err) => Err(format!("Failed to write file: {}", err)),
    }
}

fn main() {
    tauri::Builder::default()
        .plugin(tauri_plugin_fs::init())
        .plugin(tauri_plugin_shell::init())
        .invoke_handler(tauri::generate_handler![greet, read_file, write_file])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

log

INFO [2024/3/10 15:17:17]: PersistentState: { serverVersion: '0.3.1868' }
INFO [2024/3/10 15:17:17]: Extension version: 0.3.1868
INFO [2024/3/10 15:17:17]: Using configuration {
  cargoRunner: null,
  runnables: {
    extraEnv: null,
    problemMatcher: [ '$rustc' ],
    command: null,
    extraArgs: []
  },
  statusBar: { clickAction: 'openLogs' },
  server: { path: null, extraEnv: null },
  trace: { server: 'off', extension: false },
  debug: {
    engine: 'auto',
    sourceFileMap: {
      '/rustc/<id>': '${env:USERPROFILE}/.rustup/toolchains/<toolchain-id>/lib/rustlib/src/rust'
    },
    openDebugPane: false,
    engineSettings: {}
  },
  restartServerOnConfigChange: false,
  typing: {
    continueCommentsOnNewline: true,
    autoClosingAngleBrackets: { enable: false }
  },
  diagnostics: {
    previewRustcOutput: false,
    useRustcErrorCode: false,
    disabled: [],
    enable: true,
    experimental: { enable: false },
    remapPrefix: {},
    warningsAsHint: [],
    warningsAsInfo: []
  },
  discoverProjectRunner: null,
  showUnlinkedFileNotification: true,
  showRequestFailedErrorNotification: true,
  showDependenciesExplorer: true,
  assist: { emitMustUse: false, expressionFillDefault: 'todo' },
  cachePriming: { enable: true, numThreads: 0 },
  cargo: {
    autoreload: true,
    buildScripts: {
      enable: true,
      invocationLocation: 'workspace',
      invocationStrategy: 'per_workspace',
      overrideCommand: null,
      rebuildOnSave: true,
      useRustcWrapper: true
    },
    cfgs: {},
    extraArgs: [],
    extraEnv: {},
    features: [],
    noDefaultFeatures: false,
    sysroot: 'discover',
    sysrootQueryMetadata: false,
    sysrootSrc: null,
    target: null,
    targetDir: null,
    unsetTest: [ 'core' ]
  },
  checkOnSave: true,
  check: {
    allTargets: true,
    command: 'check',
    extraArgs: [],
    extraEnv: {},
    features: null,
    ignore: [],
    invocationLocation: 'workspace',
    invocationStrategy: 'per_workspace',
    noDefaultFeatures: null,
    overrideCommand: null,
    targets: null,
    workspace: true
  },
  completion: {
    autoimport: { enable: true },
    autoself: { enable: true },
    callable: { snippets: 'fill_arguments' },
    fullFunctionSignatures: { enable: false },
    limit: null,
    postfix: { enable: true },
    privateEditable: { enable: false },
    snippets: {
      custom: {
        'Arc::new': {
          postfix: 'arc',
          body: 'Arc::new(${receiver})',
          requires: 'std::sync::Arc',
          description: 'Put the expression into an `Arc`',
          scope: 'expr'
        },
        'Rc::new': {
          postfix: 'rc',
          body: 'Rc::new(${receiver})',
          requires: 'std::rc::Rc',
          description: 'Put the expression into an `Rc`',
          scope: 'expr'
        },
        'Box::pin': {
          postfix: 'pinbox',
          body: 'Box::pin(${receiver})',
          requires: 'std::boxed::Box',
          description: 'Put the expression into a pinned `Box`',
          scope: 'expr'
        },
        Ok: {
          postfix: 'ok',
          body: 'Ok(${receiver})',
          description: 'Wrap the expression in a `Result::Ok`',
          scope: 'expr'
        },
        Err: {
          postfix: 'err',
          body: 'Err(${receiver})',
          description: 'Wrap the expression in a `Result::Err`',
          scope: 'expr'
        },
        Some: {
          postfix: 'some',
          body: 'Some(${receiver})',
          description: 'Wrap the expression in an `Option::Some`',
          scope: 'expr'
        }
      }
    },
    termSearch: { enable: false }
  },
  files: { excludeDirs: [], watcher: 'client' },
  highlightRelated: {
    breakPoints: { enable: true },
    closureCaptures: { enable: true },
    exitPoints: { enable: true },
    references: { enable: true },
    yieldPoints: { enable: true }
  },
  hover: {
    actions: {
      debug: { enable: true },
      enable: true,
      gotoTypeDef: { enable: true },
      implementations: { enable: true },
      references: { enable: false },
      run: { enable: true }
    },
    documentation: { enable: true, keywords: { enable: true } },
    links: { enable: true },
    memoryLayout: {
      alignment: 'hexadecimal',
      enable: true,
      niches: false,
      offset: 'hexadecimal',
      size: 'both'
    }
  },
  imports: {
    granularity: { enforce: false, group: 'crate' },
    group: { enable: true },
    merge: { glob: true },
    preferNoStd: false,
    preferPrelude: false,
    prefix: 'plain'
  },
  inlayHints: {
    bindingModeHints: { enable: false },
    chainingHints: { enable: true },
    closingBraceHints: { enable: true, minLines: 25 },
    closureCaptureHints: { enable: false },
    closureReturnTypeHints: { enable: 'never' },
    closureStyle: 'impl_fn',
    discriminantHints: { enable: 'never' },
    expressionAdjustmentHints: { enable: 'never', hideOutsideUnsafe: false, mode: 'prefix' },
    implicitDrops: { enable: false },
    lifetimeElisionHints: { enable: 'never', useParameterNames: false },
    maxLength: 25,
    parameterHints: { enable: true },
    rangeExclusiveHints: { enable: false },
    reborrowHints: { enable: 'never' },
    renderColons: true,
    typeHints: {
      enable: true,
      hideClosureInitialization: false,
      hideNamedConstructor: false
    }
  },
  interpret: { tests: false },
  joinLines: {
    joinAssignments: true,
    joinElseIf: true,
    removeTrailingComma: true,
    unwrapTrivialBlock: true
  },
  lens: {
    debug: { enable: true },
    enable: true,
    forceCustomCommands: true,
    implementations: { enable: true },
    location: 'above_name',
    references: {
      adt: { enable: false },
      enumVariant: { enable: false },
      method: { enable: false },
      trait: { enable: false }
    },
    run: { enable: true }
  },
  linkedProjects: [],
  lru: { capacity: null, query: { capacities: {} } },
  notifications: { cargoTomlNotFound: true, unindexedProject: false },
  numThreads: null,
  procMacro: {
    attributes: { enable: true },
    enable: true,
    ignored: {},
    server: null
  },
  references: { excludeImports: false, excludeTests: false },
  rustc: { source: null },
  rustfmt: {
    extraArgs: [],
    overrideCommand: null,
    rangeFormatting: { enable: false }
  },
  semanticHighlighting: {
    doc: { comment: { inject: { enable: true } } },
    nonStandardTokens: true,
    operator: { enable: true, specialization: { enable: false } },
    punctuation: {
      enable: false,
      separate: { macro: { bang: false } },
      specialization: { enable: false }
    },
    strings: { enable: true }
  },
  signatureInfo: { detail: 'full', documentation: { enable: true } },
  workspace: {
    symbol: { search: { kind: 'only_types', limit: 128, scope: 'workspace' } }
  }
}
INFO [2024/3/10 15:17:17]: Starting language client
INFO [2024/3/10 15:17:18]: Using server binary at c:\Users\29422\.vscode\extensions\rust-lang.rust-analyzer-0.3.1868-win32-x64\server\rust-analyzer.exe
INFO [2024/3/10 15:17:18]: c:\Users\29422\.vscode\extensions\rust-lang.rust-analyzer-0.3.1868-win32-x64\server\rust-analyzer.exe --version: {
  status: 0,
  signal: null,
  output: [
    null,
    'rust-analyzer 0.3.1868-standalone (037924c4d 2024-03-03)\n',
    ''
  ],
  pid: 11904,
  stdout: 'rust-analyzer 0.3.1868-standalone (037924c4d 2024-03-03)\n',
  stderr: ''
}
INFO [2024/3/10 15:21:07]: Disposing language client
INFO [2024/3/10 15:21:07]: Starting language client
INFO [2024/3/10 15:21:07]: Using server binary at c:\Users\29422\.vscode\extensions\rust-lang.rust-analyzer-0.3.1868-win32-x64\server\rust-analyzer.exe
INFO [2024/3/10 15:21:07]: c:\Users\29422\.vscode\extensions\rust-lang.rust-analyzer-0.3.1868-win32-x64\server\rust-analyzer.exe --version: {
  status: 0,
  signal: null,
  output: [
    null,
    'rust-analyzer 0.3.1868-standalone (037924c4d 2024-03-03)\n',
    ''
  ],
  pid: 2700,
  stdout: 'rust-analyzer 0.3.1868-standalone (037924c4d 2024-03-03)\n',
  stderr: ''
}
thread 'Worker' has overflowed its stack
[Error - 15:18:48] Client Rust Analyzer Language Server: connection to server is erroring. Shutting down server.
[Error - 15:18:48] Request textDocument/inlayHint failed.
  Message: write EPIPE
  Code: -32099 
[Error - 15:18:48] Connection to server got closed. Server will not be restarted.
[Error - 15:18:48] Stopping server failed
  Message: Cannot call write after a stream was destroyed
  Code: -32099 
[Error - 15:18:48] Stopping server failed
  Message: Cannot call write after a stream was destroyed
  Code: -32099 

thread 'Worker' has overflowed its stack
[Info  - 15:23:14] Connection to server got closed. Server will restart.
true

thread 'Worker' has overflowed its stack
Error: Os { code: 232, kind: BrokenPipe, message: "管道正在被关闭。" }
[Info  - 15:24:21] Connection to server got closed. Server will restart.
true

thread 'Worker' has overflowed its stack
[Info  - 15:31:48] Connection to server got closed. Server will restart.
true
FlooferLand commented 3 months ago

Experiencing this crash as well constantly, it results in errors still showing up even after they're resolved, makes everything out of date in general.

@lvzhenbo I would recommend editing the post so the log is contained in a collapsed section since it was painful to scroll all the way down.

  <details>
    <summary>Click to reveal</summary>

    ### Log
Put the log here!
```

<details>
  <summary>Click to reveal</summary>

  ### Log

Put the log here!


</details>
IchbinLuka commented 3 months ago

Having the same problem. In my case the plugin freezes the whole system for a few seconds before crashing. Looking at the system logs it seems like this is due to an Out of memory error. Maybe there is some kind of memory leak?

Out of memory: Killed process 5591 (rust-analyzer) total-vm:40205328kB, anon-rss:29264800kB, file-rss:384kB, shmem-rss:0kB, UID:1000 pgtables:60508kB oom_score_adj:0

My OS is Ubuntu 22.04.4

IchbinLuka commented 3 months ago

So this may be related to #16934

FlooferLand commented 3 months ago

Maybe there is some kind of memory leak?

Not in my case at least. I have 32 GBs of RAM and I haven't noticed it crawl up at all.