Lsp-mode: Rust Analyzer doesn't autocomplete

Created on 25 Dec 2019  路  37Comments  路  Source: emacs-lsp/lsp-mode

Describe the bug
LSP using Rust-Analyzer doesn't autocomplete code.

To Reproduce

  • Install rust-analyzer, use the latest lsp-mode.el
  • Reproduce the following issue - Spacemacs #9023

Expected behavior
I would expect LSP to autocomplete the function len() for the arr variable.

Which Language Server did you use
Rust-Analyzer

OS
Manjaro Linux x86_64 - 4.19.91-1-MANJARO

rust rust-analyzer bug

All 37 comments

Completion doesn't currently work in macros in rust-analyzer. This is much more complicated than you might be expecting: the syntax inside a macro can mean basically anything. Try writing arr. outside of the println.

Closing based on the @flodiebold comment. Please reopen if you disagree.

image

Just tried but seems like it doesn't work.

I do get completion candidates outside of macros, but I don't get len.

@brotzeit Which do you get?

ra

It turns out this 'simple' example is even more complicated: https://github.com/rust-analyzer/rust-analyzer/issues/2670

As long as there are some completions as in @brotzeit 's picture, lsp-mode is clearly working though.

Weird that it doesn't even show only options that start with 'l'.
I think I will just go back to RLS as of now unless you need me to help you debug this issue (in case it'll appear in any other situations)

Weird that it doesn't even show only options that start with 'l'.

I think this is an option I have turned on. If there are candidates with the starting letter they are at the top, if they contain the letter they are below and if the letter isn't contained in any candidate company displays all possible candidates even if they don't match.

Weird that it doesn't even show only options that start with 'l'.

I think this is an option I have turned on. If there are candidates with the starting letter they are at the top, if they contain the letter they are below and if the letter isn't contained in any candidate company displays all possible candidates even if they don't match.

This is company-lsp bug it does not filter candidates client side after initial retrieval.

Oh, ok =)

It seems that company-lsp isn't supported anymore? There are several PR's without any answer.
Is it about time to fork it? Every time I'm trying to use rust-analyzer I basically cannot because of broken company integration.

Can you try with company-capf instead? Setting lsp-prefer-capf to t and restart lsp-mode

For anyone else coming across this issue using doom-emacs
(setq lsp-rust-server 'rust-analyzer)
is no longer used.
It has been replaced by(setq rustic-lsp-server 'rust-analyzer)
due to https://github.com/hlissner/doom-emacs/commit/cd3103b

Can you try with company-capf instead? Setting lsp-prefer-capf to t and restart lsp-mode

It works better with method/function completion by still the same for regular variables and module names. As far as I remember capf was the reason of performance issues, for example when editing comments. I remember removing it myself from the list of backends and then I think lsp-mode started doing it for me by default.

Anyways my main complaint it that completion suggestions either completely missing, or given in random order which makes them basically unusable. rls works perfectly fine on the same codebase. Also it seems that rust_analyzer is slower and uses more memory.

I still don't understand whether it's my local problem or rust_analyzer is generally unusable in Emacs.

As far as I remember capf was the reason of performance issues, for example when editing comments. I remember removing it myself from the list of backends and then I think lsp-mode started doing it for me by default.

We fixed that and now we are trying it to polish it and make it the default company-backend for lsp-mode.

by still the same for regular variables and module names.

Can you open an issue for the cases that dont work?

For anyone else coming across this issue
(setq lsp-rust-server 'rust-analyzer)
is no longer used.
It has been replaced by (setq rustic-lsp-server 'rust-analyzer)
due to hlissner/doom-emacs@cd3103b

@Dummyc0m that's not quite correct. rustic-lsp-server is supposed to also work with eglot. lsp-rust-server is still relevant if you don't use rustic.

I still don't understand whether it's my local problem or rust_analyzer is generally unusable in Emacs.

@TatriX I think this is not related to emacs. @flodiebold right ?

rust-analyzer is perfectly usable in Emacs, I use it every day (with company). It should also be faster than RLS for large projects, though not always for completion (but completion will almost always be much more complete than RLS).

rust-analyzer is perfectly usable in Emacs

Does completion work for you? I haven't put all the cases I found in the already closed issue, but even with (setq lsp-prefer-capf t) here's how local modules completion look like:
2020-02-24-131826_941x407_scrot
Module on the screenshot has several pub modules, it doesn't have any structs defined.

Module completion including built-in names is a bug that has been recently fixed. The modules you're expecting are in the list, though, right?

Yep, they are. I'll get the latest version and try again. Thanks.

Hi @flodiebold , I just come to the emacs world for a few days. I still cannot get any completion list on spacemacs... Can you share ur setting regarding the autocompletion?
When I tap Tab, it did not show anything and pop out no completion list...
Thanks!

@w93163red first make sure that everything is working as expected by doing M-x lsp-describe-session. Then, to force completion popup you may try M-x company-complete.

@w93163red first make sure that everything is working as expected by doing M-x lsp-describe-session. Then, to force completion popup you may try M-x company-complete.

@yyoncho Thanks for the reply!
image

This is what I got from lsp-describe-session.
When I tried M-x company-complete, it shows no completion found.

This sounds like a separate issue. Can you check if company-complete actually performs the call to the server(set lsp-print-io to t and then lsp-workspace-show-log)? Also, can you make sure the project root contains the cargo file?

@yyoncho
The project root contains cargo.toml.
I did not see any log related to company-complete

[Trace - 02:53:31 AM] Sending request 'textDocument/codeAction - (121)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "range": {
    "start": {
      "line": 62,
      "character": 0
    },
    "end": {
      "line": 62,
      "character": 0
    }
  },
  "context": {
    "diagnostics": [],
    "only": null
  }
}


[Trace - 02:53:31 AM] Received response 'textDocument/codeAction - (121)' in 10ms.
Result: []


[Trace - 02:53:32 AM] Sending request 'textDocument/codeAction - (122)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "range": {
    "start": {
      "line": 63,
      "character": 0
    },
    "end": {
      "line": 63,
      "character": 0
    }
  },
  "context": {
    "diagnostics": [],
    "only": null
  }
}


[Trace - 02:53:32 AM] Received response 'textDocument/codeAction - (122)' in 10ms.
Result: []


[Trace - 02:53:32 AM] Sending request 'textDocument/codeAction - (123)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "range": {
    "start": {
      "line": 63,
      "character": 8
    },
    "end": {
      "line": 63,
      "character": 8
    }
  },
  "context": {
    "diagnostics": [],
    "only": null
  }
}


[Trace - 02:53:32 AM] Sending notification 'textDocument/didChange'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs",
    "version": 40
  },
  "contentChanges": [
    {
      "text": "// enums3.rs\n// Address all the TODOs to make the tests pass!\n\nenum Message {\n    ChangeColor(i32, i32, i32),\n    Echo(String),\n    Move { x: i32, y: i32 },\n    Quit,\n}\n\nstruct Point {\n    x: i32,\n    y: i32,\n}\n\nstruct State {\n    color: (i32, i32, i32),\n    position: Point,\n    quit: bool,\n}\n\nimpl State {\n    fn change_color(&mut self, color: (i32, i32, i32)) {\n        self.color = color;\n    }\n\n    fn quit(&mut self) {\n        self.quit = true;\n    }\n\n    fn echo(&self, s: String) {\n        println!(\"{}\", s);\n    }\n\n    fn move_position(&mut self, p: Point) {\n        self.position = p;\n    }\n\n    fn process(&mut self, message: Message) {\n        match message {\n            Message::ChangeColor(a, b, c) => self.color = self.change_color((a, b, c)),\n            Message::Move { x, y } => self.position = self.move_position(Point { x, y }),\n            Message::Quit => self.quit(),\n            _ => (),\n        }\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    #[test]\n    fn test_match_message_call() {\n        let mut state = State {\n            quit: false,\n            position: Point { x: 0, y: 0 },\n            color: (0, 0, 0),\n        };\n\n        state.process(Message::Echo(String::from(\"hello world\")));\n        state.process(Message::Move { x: 10, y: 15 });\n        state.process(Message::Quit);\n        \n        assert_eq!(state.color, (255, 0, 255));\n        assert_eq!(state.position.x, 10);\n        assert_eq!(state.position.y, 15);\n        assert_eq!(state.quit, true);\n    }\n}\n"
    }
  ]
}


[Trace - 02:53:32 AM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs",
  "diagnostics": []
}


[Trace - 02:53:32 AM] Received response 'textDocument/codeAction - (123)' in 13ms.
Result: []


[Trace - 02:53:32 AM] Sending request 'textDocument/codeAction - (124)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "range": {
    "start": {
      "line": 63,
      "character": 8
    },
    "end": {
      "line": 63,
      "character": 8
    }
  },
  "context": {
    "diagnostics": [],
    "only": null
  }
}


[Trace - 02:53:32 AM] Received response 'textDocument/codeAction - (124)' in 8ms.
Result: []


[Trace - 02:53:33 AM] Sending request 'textDocument/onTypeFormatting - (125)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "options": {
    "tabSize": 4,
    "insertSpaces": true
  },
  "ch": ".",
  "position": {
    "line": 63,
    "character": 14
  }
}


[Trace - 02:53:33 AM] Sending notification 'textDocument/didChange'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs",
    "version": 46
  },
  "contentChanges": [
    {
      "text": "// enums3.rs\n// Address all the TODOs to make the tests pass!\n\nenum Message {\n    ChangeColor(i32, i32, i32),\n    Echo(String),\n    Move { x: i32, y: i32 },\n    Quit,\n}\n\nstruct Point {\n    x: i32,\n    y: i32,\n}\n\nstruct State {\n    color: (i32, i32, i32),\n    position: Point,\n    quit: bool,\n}\n\nimpl State {\n    fn change_color(&mut self, color: (i32, i32, i32)) {\n        self.color = color;\n    }\n\n    fn quit(&mut self) {\n        self.quit = true;\n    }\n\n    fn echo(&self, s: String) {\n        println!(\"{}\", s);\n    }\n\n    fn move_position(&mut self, p: Point) {\n        self.position = p;\n    }\n\n    fn process(&mut self, message: Message) {\n        match message {\n            Message::ChangeColor(a, b, c) => self.color = self.change_color((a, b, c)),\n            Message::Move { x, y } => self.position = self.move_position(Point { x, y }),\n            Message::Quit => self.quit(),\n            _ => (),\n        }\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    #[test]\n    fn test_match_message_call() {\n        let mut state = State {\n            quit: false,\n            position: Point { x: 0, y: 0 },\n            color: (0, 0, 0),\n        };\n\n        state.process(Message::Echo(String::from(\"hello world\")));\n        state.process(Message::Move { x: 10, y: 15 });\n        state.process(Message::Quit);\n        state.\n        assert_eq!(state.color, (255, 0, 255));\n        assert_eq!(state.position.x, 10);\n        assert_eq!(state.position.y, 15);\n        assert_eq!(state.quit, true);\n    }\n}\n"
    }
  ]
}


[Trace - 02:53:33 AM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs",
  "diagnostics": [
    {
      "source": "rust-analyzer",
      "severity": 1,
      "range": {
        "start": {
          "line": 64,
          "character": 17
        },
        "end": {
          "line": 64,
          "character": 17
        }
      },
      "message": "Syntax Error: expected SEMI"
    }
  ]
}


[Trace - 02:53:33 AM] Received response 'textDocument/onTypeFormatting - (125)' in 14ms.
Result: null


[Trace - 02:53:34 AM] Sending request 'textDocument/completion - (126)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "position": {
    "line": 63,
    "character": 17
  },
  "context": {
    "triggerKind": 1
  }
}


[Trace - 02:53:34 AM] Sending notification 'textDocument/didChange'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs",
    "version": 49
  },
  "contentChanges": [
    {
      "text": "// enums3.rs\n// Address all the TODOs to make the tests pass!\n\nenum Message {\n    ChangeColor(i32, i32, i32),\n    Echo(String),\n    Move { x: i32, y: i32 },\n    Quit,\n}\n\nstruct Point {\n    x: i32,\n    y: i32,\n}\n\nstruct State {\n    color: (i32, i32, i32),\n    position: Point,\n    quit: bool,\n}\n\nimpl State {\n    fn change_color(&mut self, color: (i32, i32, i32)) {\n        self.color = color;\n    }\n\n    fn quit(&mut self) {\n        self.quit = true;\n    }\n\n    fn echo(&self, s: String) {\n        println!(\"{}\", s);\n    }\n\n    fn move_position(&mut self, p: Point) {\n        self.position = p;\n    }\n\n    fn process(&mut self, message: Message) {\n        match message {\n            Message::ChangeColor(a, b, c) => self.color = self.change_color((a, b, c)),\n            Message::Move { x, y } => self.position = self.move_position(Point { x, y }),\n            Message::Quit => self.quit(),\n            _ => (),\n        }\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    #[test]\n    fn test_match_message_call() {\n        let mut state = State {\n            quit: false,\n            position: Point { x: 0, y: 0 },\n            color: (0, 0, 0),\n        };\n\n        state.process(Message::Echo(String::from(\"hello world\")));\n        state.process(Message::Move { x: 10, y: 15 });\n        state.process(Message::Quit);\n        state.pro\n        assert_eq!(state.color, (255, 0, 255));\n        assert_eq!(state.position.x, 10);\n        assert_eq!(state.position.y, 15);\n        assert_eq!(state.quit, true);\n    }\n}\n"
    }
  ]
}


[Trace - 02:53:34 AM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs",
  "diagnostics": [
    {
      "source": "rust-analyzer",
      "severity": 1,
      "range": {
        "start": {
          "line": 63,
          "character": 17
        },
        "end": {
          "line": 63,
          "character": 17
        }
      },
      "message": "Syntax Error: expected SEMI"
    }
  ]
}


[Trace - 02:53:34 AM] Received response 'textDocument/completion - (126)' in 5ms.
Result: []


[Trace - 02:53:34 AM] Sending request 'textDocument/codeAction - (127)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "range": {
    "start": {
      "line": 63,
      "character": 17
    },
    "end": {
      "line": 63,
      "character": 17
    }
  },
  "context": {
    "diagnostics": [
      {
        "source": "rust-analyzer",
        "severity": 1,
        "range": {
          "start": {
            "line": 63,
            "character": 17
          },
          "end": {
            "line": 63,
            "character": 17
          }
        },
        "message": "Syntax Error: expected SEMI"
      }
    ],
    "only": null
  }
}


[Trace - 02:53:34 AM] Sending request 'textDocument/hover - (128)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "position": {
    "line": 63,
    "character": 17
  }
}


[Trace - 02:53:34 AM] Received response 'textDocument/codeAction - (127)' in 12ms.
Result: []


[Trace - 02:53:34 AM] Received response 'textDocument/hover - (128)' in 11ms.
Result: null


[Trace - 02:53:34 AM] Sending request 'textDocument/completion - (129)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "position": {
    "line": 63,
    "character": 17
  },
  "context": {
    "triggerKind": 1
  }
}


[Trace - 02:53:34 AM] Received response 'textDocument/completion - (129)' in 0ms.
Result: []


[Trace - 02:53:34 AM] Sending request 'textDocument/hover - (130)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "position": {
    "line": 63,
    "character": 17
  }
}


[Trace - 02:53:34 AM] Received response 'textDocument/hover - (130)' in 11ms.
Result: null


[Trace - 02:53:35 AM] Sending request 'textDocument/completion - (131)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "position": {
    "line": 63,
    "character": 21
  },
  "context": {
    "triggerKind": 1
  }
}


[Trace - 02:53:35 AM] Sending notification 'textDocument/didChange'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs",
    "version": 53
  },
  "contentChanges": [
    {
      "text": "// enums3.rs\n// Address all the TODOs to make the tests pass!\n\nenum Message {\n    ChangeColor(i32, i32, i32),\n    Echo(String),\n    Move { x: i32, y: i32 },\n    Quit,\n}\n\nstruct Point {\n    x: i32,\n    y: i32,\n}\n\nstruct State {\n    color: (i32, i32, i32),\n    position: Point,\n    quit: bool,\n}\n\nimpl State {\n    fn change_color(&mut self, color: (i32, i32, i32)) {\n        self.color = color;\n    }\n\n    fn quit(&mut self) {\n        self.quit = true;\n    }\n\n    fn echo(&self, s: String) {\n        println!(\"{}\", s);\n    }\n\n    fn move_position(&mut self, p: Point) {\n        self.position = p;\n    }\n\n    fn process(&mut self, message: Message) {\n        match message {\n            Message::ChangeColor(a, b, c) => self.color = self.change_color((a, b, c)),\n            Message::Move { x, y } => self.position = self.move_position(Point { x, y }),\n            Message::Quit => self.quit(),\n            _ => (),\n        }\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    #[test]\n    fn test_match_message_call() {\n        let mut state = State {\n            quit: false,\n            position: Point { x: 0, y: 0 },\n            color: (0, 0, 0),\n        };\n\n        state.process(Message::Echo(String::from(\"hello world\")));\n        state.process(Message::Move { x: 10, y: 15 });\n        state.process(Message::Quit);\n        state.process\n        assert_eq!(state.color, (255, 0, 255));\n        assert_eq!(state.position.x, 10);\n        assert_eq!(state.position.y, 15);\n        assert_eq!(state.quit, true);\n    }\n}\n"
    }
  ]
}


[Trace - 02:53:35 AM] Sending request 'textDocument/codeAction - (132)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "range": {
    "start": {
      "line": 63,
      "character": 21
    },
    "end": {
      "line": 63,
      "character": 21
    }
  },
  "context": {
    "diagnostics": [
      {
        "source": "rust-analyzer",
        "severity": 1,
        "range": {
          "start": {
            "line": 63,
            "character": 17
          },
          "end": {
            "line": 63,
            "character": 17
          }
        },
        "message": "Syntax Error: expected SEMI"
      }
    ],
    "only": null
  }
}


[Trace - 02:53:35 AM] Sending request 'textDocument/hover - (133)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "position": {
    "line": 63,
    "character": 21
  }
}


[Trace - 02:53:35 AM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs",
  "diagnostics": [
    {
      "source": "rust-analyzer",
      "severity": 1,
      "range": {
        "start": {
          "line": 63,
          "character": 21
        },
        "end": {
          "line": 63,
          "character": 21
        }
      },
      "message": "Syntax Error: expected SEMI"
    }
  ]
}


[Trace - 02:53:35 AM] Received response 'textDocument/completion - (131)' in 11ms.
Result: []


[Trace - 02:53:35 AM] Received response 'textDocument/codeAction - (132)' in 5ms.
Result: []


[Trace - 02:53:35 AM] Received response 'textDocument/hover - (133)' in 4ms.
Result: null


[Trace - 02:53:35 AM] Sending request 'textDocument/codeAction - (134)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "range": {
    "start": {
      "line": 63,
      "character": 21
    },
    "end": {
      "line": 63,
      "character": 21
    }
  },
  "context": {
    "diagnostics": [
      {
        "source": "rust-analyzer",
        "severity": 1,
        "range": {
          "start": {
            "line": 63,
            "character": 21
          },
          "end": {
            "line": 63,
            "character": 21
          }
        },
        "message": "Syntax Error: expected SEMI"
      }
    ],
    "only": null
  }
}


[Trace - 02:53:35 AM] Received response 'textDocument/codeAction - (134)' in 10ms.
Result: []


[Trace - 02:53:35 AM] Sending request 'textDocument/codeAction - (135)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "range": {
    "start": {
      "line": 63,
      "character": 22
    },
    "end": {
      "line": 63,
      "character": 22
    }
  },
  "context": {
    "diagnostics": [
      {
        "source": "rust-analyzer",
        "severity": 1,
        "range": {
          "start": {
            "line": 63,
            "character": 21
          },
          "end": {
            "line": 63,
            "character": 21
          }
        },
        "message": "Syntax Error: expected SEMI"
      }
    ],
    "only": null
  }
}


[Trace - 02:53:35 AM] Sending notification 'textDocument/didChange'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs",
    "version": 57
  },
  "contentChanges": [
    {
      "text": "// enums3.rs\n// Address all the TODOs to make the tests pass!\n\nenum Message {\n    ChangeColor(i32, i32, i32),\n    Echo(String),\n    Move { x: i32, y: i32 },\n    Quit,\n}\n\nstruct Point {\n    x: i32,\n    y: i32,\n}\n\nstruct State {\n    color: (i32, i32, i32),\n    position: Point,\n    quit: bool,\n}\n\nimpl State {\n    fn change_color(&mut self, color: (i32, i32, i32)) {\n        self.color = color;\n    }\n\n    fn quit(&mut self) {\n        self.quit = true;\n    }\n\n    fn echo(&self, s: String) {\n        println!(\"{}\", s);\n    }\n\n    fn move_position(&mut self, p: Point) {\n        self.position = p;\n    }\n\n    fn process(&mut self, message: Message) {\n        match message {\n            Message::ChangeColor(a, b, c) => self.color = self.change_color((a, b, c)),\n            Message::Move { x, y } => self.position = self.move_position(Point { x, y }),\n            Message::Quit => self.quit(),\n            _ => (),\n        }\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    #[test]\n    fn test_match_message_call() {\n        let mut state = State {\n            quit: false,\n            position: Point { x: 0, y: 0 },\n            color: (0, 0, 0),\n        };\n\n        state.process(Message::Echo(String::from(\"hello world\")));\n        state.process(Message::Move { x: 10, y: 15 });\n        state.process(Message::Quit);\n        state.process()\n        assert_eq!(state.color, (255, 0, 255));\n        assert_eq!(state.position.x, 10);\n        assert_eq!(state.position.y, 15);\n        assert_eq!(state.quit, true);\n    }\n}\n"
    }
  ]
}


[Trace - 02:53:35 AM] Sending request 'textDocument/hover - (136)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "position": {
    "line": 63,
    "character": 22
  }
}


[Trace - 02:53:35 AM] Sending request 'textDocument/signatureHelp - (137)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "position": {
    "line": 63,
    "character": 22
  }
}


[Trace - 02:53:35 AM] Sending request 'textDocument/documentHighlight - (138)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "position": {
    "line": 63,
    "character": 22
  }
}


[Trace - 02:53:35 AM] Sending notification '$/cancelRequest'.
Params: {
  "id": 137
}


[Trace - 02:53:35 AM] Sending request 'textDocument/signatureHelp - (139)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "position": {
    "line": 63,
    "character": 22
  }
}


[Trace - 02:53:35 AM] Sending notification '$/cancelRequest'.
Params: {
  "id": 138
}


[Trace - 02:53:35 AM] Sending request 'textDocument/documentHighlight - (140)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "position": {
    "line": 63,
    "character": 22
  }
}


[Trace - 02:53:35 AM] Sending notification '$/cancelRequest'.
Params: {
  "id": 139
}


[Trace - 02:53:35 AM] Sending request 'textDocument/signatureHelp - (141)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "position": {
    "line": 63,
    "character": 22
  }
}


[Trace - 02:53:35 AM] Sending notification '$/cancelRequest'.
Params: {
  "id": 140
}


[Trace - 02:53:35 AM] Sending request 'textDocument/documentHighlight - (142)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "position": {
    "line": 63,
    "character": 22
  }
}


[Trace - 02:53:35 AM] Sending notification '$/cancelRequest'.
Params: {
  "id": 141
}


[Trace - 02:53:35 AM] Sending request 'textDocument/signatureHelp - (143)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "position": {
    "line": 63,
    "character": 22
  }
}


[Trace - 02:53:35 AM] Sending notification '$/cancelRequest'.
Params: {
  "id": 142
}


[Trace - 02:53:35 AM] Sending request 'textDocument/documentHighlight - (144)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "position": {
    "line": 63,
    "character": 22
  }
}


[Trace - 02:53:35 AM] Sending notification '$/cancelRequest'.
Params: {
  "id": 143
}


[Trace - 02:53:35 AM] Sending request 'textDocument/signatureHelp - (145)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "position": {
    "line": 63,
    "character": 22
  }
}


[Trace - 02:53:35 AM] Sending notification '$/cancelRequest'.
Params: {
  "id": 144
}


[Trace - 02:53:35 AM] Sending request 'textDocument/documentHighlight - (146)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "position": {
    "line": 63,
    "character": 22
  }
}


[Trace - 02:53:35 AM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs",
  "diagnostics": [
    {
      "source": "rust-analyzer",
      "severity": 1,
      "range": {
        "start": {
          "line": 63,
          "character": 23
        },
        "end": {
          "line": 63,
          "character": 23
        }
      },
      "message": "Syntax Error: expected SEMI"
    }
  ]
}


[Trace - 02:53:35 AM] Received response 'textDocument/codeAction - (135)' in 46ms.
Result: []


[Trace - 02:53:35 AM] Received response 'textDocument/hover - (136)' in 44ms.
Result: null


[Trace - 02:53:35 AM] Received response 'nil - (137)' in 0ms.
Result: null


[Trace - 02:53:35 AM] Received response 'nil - (138)' in 0ms.
Result: null


[Trace - 02:53:35 AM] Received response 'nil - (139)' in 0ms.
Result: null


[Trace - 02:53:35 AM] Received response 'nil - (140)' in 0ms.
Result: null


[Trace - 02:53:35 AM] Received response 'nil - (141)' in 0ms.
Result: null


[Trace - 02:53:35 AM] Received response 'nil - (142)' in 0ms.
Result: null


[Trace - 02:53:35 AM] Received response 'nil - (143)' in 0ms.
Result: null


[Trace - 02:53:35 AM] Received response 'nil - (144)' in 0ms.
Result: null


[Trace - 02:53:35 AM] Received response 'textDocument/signatureHelp - (145)' in 29ms.
Result: null


[Trace - 02:53:35 AM] Sending notification '$/cancelRequest'.
Params: {
  "id": 145
}


[Trace - 02:53:35 AM] Received response 'textDocument/documentHighlight - (146)' in 28ms.
Result: null


[Trace - 02:53:35 AM] Sending request 'textDocument/codeAction - (147)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "range": {
    "start": {
      "line": 63,
      "character": 22
    },
    "end": {
      "line": 63,
      "character": 22
    }
  },
  "context": {
    "diagnostics": [
      {
        "source": "rust-analyzer",
        "severity": 1,
        "range": {
          "start": {
            "line": 63,
            "character": 23
          },
          "end": {
            "line": 63,
            "character": 23
          }
        },
        "message": "Syntax Error: expected SEMI"
      }
    ],
    "only": null
  }
}


[Trace - 02:53:35 AM] Received response 'textDocument/codeAction - (147)' in 8ms.
Result: []


[Trace - 02:53:36 AM] Sending request 'textDocument/codeAction - (148)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "range": {
    "start": {
      "line": 63,
      "character": 24
    },
    "end": {
      "line": 63,
      "character": 24
    }
  },
  "context": {
    "diagnostics": [
      {
        "source": "rust-analyzer",
        "severity": 1,
        "range": {
          "start": {
            "line": 63,
            "character": 23
          },
          "end": {
            "line": 63,
            "character": 23
          }
        },
        "message": "Syntax Error: expected SEMI"
      }
    ],
    "only": null
  }
}


[Trace - 02:53:36 AM] Sending notification 'textDocument/didChange'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs",
    "version": 60
  },
  "contentChanges": [
    {
      "text": "// enums3.rs\n// Address all the TODOs to make the tests pass!\n\nenum Message {\n    ChangeColor(i32, i32, i32),\n    Echo(String),\n    Move { x: i32, y: i32 },\n    Quit,\n}\n\nstruct Point {\n    x: i32,\n    y: i32,\n}\n\nstruct State {\n    color: (i32, i32, i32),\n    position: Point,\n    quit: bool,\n}\n\nimpl State {\n    fn change_color(&mut self, color: (i32, i32, i32)) {\n        self.color = color;\n    }\n\n    fn quit(&mut self) {\n        self.quit = true;\n    }\n\n    fn echo(&self, s: String) {\n        println!(\"{}\", s);\n    }\n\n    fn move_position(&mut self, p: Point) {\n        self.position = p;\n    }\n\n    fn process(&mut self, message: Message) {\n        match message {\n            Message::ChangeColor(a, b, c) => self.color = self.change_color((a, b, c)),\n            Message::Move { x, y } => self.position = self.move_position(Point { x, y }),\n            Message::Quit => self.quit(),\n            _ => (),\n        }\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    #[test]\n    fn test_match_message_call() {\n        let mut state = State {\n            quit: false,\n            position: Point { x: 0, y: 0 },\n            color: (0, 0, 0),\n        };\n\n        state.process(Message::Echo(String::from(\"hello world\")));\n        state.process(Message::Move { x: 10, y: 15 });\n        state.process(Message::Quit);\n        state.process();\n        assert_eq!(state.color, (255, 0, 255));\n        assert_eq!(state.position.x, 10);\n        assert_eq!(state.position.y, 15);\n        assert_eq!(state.quit, true);\n    }\n}\n"
    }
  ]
}


[Trace - 02:53:36 AM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs",
  "diagnostics": []
}


[Trace - 02:53:36 AM] Received response 'textDocument/codeAction - (148)' in 18ms.
Result: []


[Trace - 02:53:36 AM] Sending request 'textDocument/codeAction - (149)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "range": {
    "start": {
      "line": 63,
      "character": 24
    },
    "end": {
      "line": 63,
      "character": 24
    }
  },
  "context": {
    "diagnostics": [],
    "only": null
  }
}


[Trace - 02:53:36 AM] Received response 'textDocument/codeAction - (149)' in 11ms.
Result: []


[Trace - 02:53:36 AM] Sending request 'textDocument/codeAction - (150)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "range": {
    "start": {
      "line": 63,
      "character": 23
    },
    "end": {
      "line": 63,
      "character": 23
    }
  },
  "context": {
    "diagnostics": [],
    "only": null
  }
}


[Trace - 02:53:36 AM] Sending request 'textDocument/hover - (151)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "position": {
    "line": 63,
    "character": 23
  }
}


[Trace - 02:53:36 AM] Sending request 'textDocument/documentHighlight - (152)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/lingxiangwang/code/learning/rustlings/exercises/enums/enums3.rs"
  },
  "position": {
    "line": 63,
    "character": 23
  }
}


[Trace - 02:53:36 AM] Received response 'textDocument/codeAction - (150)' in 24ms.
Result: []


[Trace - 02:53:36 AM] Received response 'textDocument/hover - (151)' in 23ms.
Result: null


[Trace - 02:53:36 AM] Received response 'textDocument/documentHighlight - (152)' in 22ms.
Result: null

@w93163red why did you strip the log? In the first version there were compilation errors - can you try fixing them before trying to complete? Also, can you provide this project?

@w93163red why did you strip the log? In the first version there were compilation errors - can you try fixing them before trying to complete? Also, can you provide this project?

@yyoncho
Since it was too long... when I did not finish the full statement, it will pop out the error. That is the cause of compilation error
The project is rustlings.
https://github.com/rust-lang/rustlings
If I switch to rls, rls can provide the auto-completion.

I wouldn't expect rust-analyzer to work in the rustlings exercises. They're not a part of the normal Cargo project, rather the actual cargo project contains special code to compile them, and RA cannot know about that.

At this point, I don't think there is anything to address in this issue after @kiennq rewrite of company-capf integration. Please reopen if you disagree(or file another issue).

@yyoncho I'm facing the same problem as @w93163red. I'm trying Rustlings repo and I had to switch back to RLS for the time being. Could rust-analyzer consider a feature request for enabling support for standalone *.rs files? For example, assuming a basic Cargo.toml file with no dependencies. This could be enabled only with an option for example.

@deavid I guess it will but the feature request should go in rust analyzer repo(we are only a client).

@yyoncho Which release contains the fix? I try 20200409.1449, but still have this problem.

@yyoncho Which release contains the fix? I try 20200409.1449, but still have this problem.

Which problem do you have now?

image

It seems company can't filter candicates?
After setq lsp-prefer-capf t, everything works as expected.
image

Out of curiosity, I want to know why we need to prefer capf?

@jiacai2050 It's because company-lsp seems not to be maintained anymore, and we now prefer new capf as backend. You can remove company-lsp and it should automatically using capf.
@yyoncho

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cprussin picture cprussin  路  3Comments

michaelpj picture michaelpj  路  4Comments

raxod502 picture raxod502  路  4Comments

kmdouglass picture kmdouglass  路  3Comments

dchneric picture dchneric  路  3Comments