Skip to content

No code completion #6065

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

Closed
funnym0nk3y opened this issue Sep 23, 2020 · 8 comments
Closed

No code completion #6065

funnym0nk3y opened this issue Sep 23, 2020 · 8 comments

Comments

@funnym0nk3y
Copy link

Hey,

after a few recommendations I started, or better, tried to start using rust-analyzer. Unfortunately in my projects and files (mainly rustlings) I don't get completion of functions and implementations. I already tried reinstalling rust via rustup, but the issue persists.
Would be nice, if I could get some help with figuring this out and diagnosing what's wrong.

funnym0nk3y

@lnicola
Copy link
Member

lnicola commented Sep 23, 2020

Which editor and extension are you using? And does it also happen on a project created with cargo new?

@funnym0nk3y
Copy link
Author

I'm sorry, totally forgot to mention, that I'm using vscode with the rust-analyzer extension on Win10.

This issue still persists with projects created via cargo new.

@lnicola
Copy link
Member

lnicola commented Sep 23, 2020

There should be a couple of output channels related to Rust Analyzer in the Output pane. What do they say? (Please use a <details> tag if it's a lot of text).

Do you also have the Rust extension installed?

@funnym0nk3y
Copy link
Author

funnym0nk3y commented Sep 23, 2020

This is the output of the Rust Analyzer Client Output:

INFO [23.9.2020, 15:26:41]: Extension version: 0.2.320
INFO [23.9.2020, 15:26:41]: Using configuration {
  lruCapacity: null,
  files: { watcher: 'client', exclude: [] },
  notifications: { cargoTomlNotFound: true },
  cargo: {
    autoreload: true,
    noDefaultFeatures: false,
    allFeatures: true,
    features: [],
    loadOutDirsFromCheck: false,
    target: null
  },
  rustfmt: { extraArgs: [], overrideCommand: null },
  checkOnSave: {
    enable: true,
    extraArgs: [],
    command: 'check',
    overrideCommand: null,
    allTargets: true,
    noDefaultFeatures: null,
    allFeatures: null,
    features: null,
    target: null
  },
  cargoRunner: null,
  runnableEnv: null,
  inlayHints: {
    enable: true,
    typeHints: true,
    chainingHints: true,
    parameterHints: true,
    maxLength: 20
  },
  completion: {
    addCallParenthesis: true,
    addCallArgumentSnippets: true,
    postfix: { enable: true }
  },
  callInfo: { full: true },
  updates: { channel: 'stable', askBeforeDownload: true },
  serverPath: null,
  trace: { server: 'off', extension: false },
  procMacro: { enable: false },
  debug: {
    engine: 'auto',
    sourceFileMap: {
      '/rustc/<id>': '${env:USERPROFILE}/.rustup/toolchains/<toolchain-id>/lib/rustlib/src/rust'
    },
    openDebugPane: false,
    engineSettings: {}
  },
  lens: { enable: true, run: true, debug: true, implementations: true },
  hoverActions: {
    enable: true,
    implementations: true,
    run: true,
    debug: true,
    gotoTypeDef: true
  },
  linkedProjects: null,
  withSysroot: true,
  diagnostics: {
    enable: true,
    enableExperimental: true,
    disabled: [],
    warningsAsInfo: [],
    warningsAsHint: []
  },
  assist: { importMergeBehaviour: 'full' }
}
INFO [23.9.2020, 15:26:41]: PersistentState: {
  lastCheck: undefined,
  releaseId: undefined,
  serverVersion: '0.2.313'
}
INFO [23.9.2020, 15:26:49]: Using server binary at c:\Users\funnym0nk3y\AppData\Roaming\Code\User\globalStorage\matklad.rust-analyzer\rust-analyzer-windows.exe
WARN [23.9.2020, 15:27:04]: LSP request timed out {
  method: 'rust-analyzer/inlayHints',
  param: {
    textDocument: {
      uri: 'file:///c%3A/Users/funnm0nk3y/Software/Rust/rustlings/rustlings/exercises/error_handling/errors1.rs'
    }
  },
  error: [ResponseError: canceled by client
  	at handleResponse (c:\Users\funnym0nk3y\.vscode\extensions\matklad.rust-analyzer-0.2.320\out\src\main.js:3779:48)
  	at processMessageQueue (c:\Users\funnym0nk3y\.vscode\extensions\matklad.rust-analyzer-0.2.320\out\src\main.js:3594:17)
  	at Immediate.<anonymous> (c:\Users\funnym0nk3y\.vscode\extensions\matklad.rust-analyzer-0.2.320\out\src\main.js:3578:13)
  	at processImmediate (internal/timers.js:439:21)] {
    code: -32800,
    data: undefined
  }
}

From the language server trace there is no output. I have the RLS extension installed, but globally deactivated.

@lnicola
Copy link
Member

lnicola commented Sep 23, 2020

I don't see anything unusual there with the exception of the "LSP request timed out" error.

@Veetaha
Copy link
Contributor

Veetaha commented Sep 24, 2020

I recommend you to add this to your settings (settings.json) to get more verbose client logs:

{
    "rust-analyzer.trace.extension": true
}

I see the extension is working for you, but there might just be some problem with the particular project.
As I see the rust file for which inlay-hints request failed resides in some non-standard location:

file:///c%3A/Users/funnm0nk3y/Software/Rust/rustlings/rustlings/exercises/error_handling/errors1.rs

By default rust-analyzer expects a layout of a cargo project:

- Cargo.toml
- src
    - main.rs / lib.rs

Could you try to run cargo new, paste the code from errors1.rs file into the lib.rs (or main.rs file, just be sure to have a main() {} function there). It's important to open the exact same folder that contains Cargo.toml and src in vscode.

Anyway, the most helpful input would be a repo with the reproduction of the problem

@funnym0nk3y
Copy link
Author

Okay, thanks for your help! The issue was, that rust-analyzer expects a particular folder structure. Following @Veetaha instructions and creating and opening the folder containing Cargo.toml and src solves that issue.

I think this is very inconvenient as there is help from rust-analyzer in just that standard case and not in cases like rustlings, etc. Will there be, let me call it out of tree, completion in the future?

@lnicola
Copy link
Member

lnicola commented Sep 26, 2020

a particular folder structure

The one used by cargo, specifically. That's why I asked if new projects work.

I think this is very inconvenient as there is help from rust-analyzer in just that standard case and not in cases like rustlings, etc. Will there be, let me call it out of tree, completion in the future?

Maybe, but I feel that rustlings should consider using a more standard structure instead. To paraphrase Tolstoy, all projects with a standard organization are alike, every non-standard one is non-standard in its own way. See LukeMathWalker/build-your-own-jira-with-rust#33 for a similar issue that was impossible to work around in RA, but was fixable in that project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants