gleam-lang / gleam

⭐️ A friendly language for building type-safe, scalable systems!
https://gleam.run
Apache License 2.0
17.26k stars 715 forks source link

Unable to give completions to LSP for dot completions #3036

Closed u9g closed 4 months ago

u9g commented 4 months ago

The following code can't be completed using ctrl+space because it fails to parse.

import ct/reflection
import ct/item

pub fn get_item_from_give_code(give_code: String) -> item.Item {
  reflection.
}

You will not know about it though, as compilation silently fails, however when I remove the silent failing, we get the following error:

Panic: C:\Users\---\Documents\code\4-20-24\gleam\compiler-core\src\build\package_compiler.rs:123
    called `Result::unwrap()` on an `Err` value: Parse { path: "c:\\Users\\Jason\\Documents\\code\\4-20-24\\examplemod\\src\\ct\\act.gleam", src: "import ct/reflection\r\nimport ct/item\r\n\r\npub fn get_item_from_give_code(give_code: String) -> item.Item {\r\n  reflection.\r\n  todo\r\n}\r\n", error: ParseError { error: UnexpectedToken { expected: ["A positive integer or a field name."], hint: None }, location: SrcSpan { start: 123, end: 128 } } }

This is a big problem because if we always need completely valid code to offer completions, we can never offer dot completions.

I'm not sure what the next steps are here but I am open to ideas. Maybe something like adding a placeholder for XX.\n to the parser that will allow us to finish parsing the line so that we can still get diagnostics?

u9g commented 4 months ago

Another thing to consider is that the user has no idea there is a parse error if we silently dispose of parse errors.

lpil commented 4 months ago

Hello! This is not implemented yet.