Skip to content
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

Compilation error not shown in editor #4199

Open
mooreryan opened this issue Jan 25, 2025 · 3 comments
Open

Compilation error not shown in editor #4199

mooreryan opened this issue Jan 25, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@mooreryan
Copy link

I get a compilation error, which is expected due to a lack of type annotation on a function with an external JS implementation. However, nothing is shown in editor about the error (i.e., no problems/errors are displayed). Is this a bug in the LSP, or is it expected that the error not be shown?


Steps to reproduce:

  1. Start a new project, gleam new yo
  2. Add a yo_ffi.mjs file:
export function yo() {
  return "yo!";
}
  1. Add the yo.gleam file
import gleam/io

// No LSP error is shown for missing type annotation.
@external(javascript, "./yo_ffi.mjs", "yo")
fn yo() {
  "yo!"
}

pub fn main() {
  io.println(yo())
}
  1. Run with gleam run -- Ok!.
  2. Run with gleam run --target=javascript and get an error:
error: Missing type annotation
  ┌─ ./src/yo.gleam:4:1
  │
4 │ fn yo() {
  │ ^^^^^^^

A return annotation is missing from this function.

Functions with external implementations must have type annotations
so we can tell what type of values they accept and return.

However, no error is shown in the code editor.


Gleam version 1.7.0.
OS: Ubuntu 22.04.5 LTS.
VSCode:

Version: 1.96.4
Commit: cd4ee3b1c348a13bafd8f9ad8060705f6d4b9cba
Date: 2025-01-16T00:16:19.038Z
Electron: 32.2.6
ElectronBuildId: 10629634
Chromium: 128.0.6613.186
Node.js: 20.18.1
V8: 12.8.374.38-electron.0
OS: Linux x64 5.15.0-130-generic
@mooreryan mooreryan added the bug Something isn't working label Jan 25, 2025
@mooreryan
Copy link
Author

Huh, this is weird. I'm not sure how to reproduce this, but I was just playing around in the file adding code with errors below the rest of the stuff in the yo.gleam file, and for a second the missing annotation error appeared in the editor. However, when I built it again, then I restarted the Gleam server, it disappeared again. Not really sure what is going on with that.

@lpil
Copy link
Member

lpil commented Jan 25, 2025

Your language server could have been running in Erlang target mode, then there would be no error. Given you're running the CLI with the --target flag and you've not edited the gleam.toml in those steps it seems likely that's not what is set in gleam.toml.

@mooreryan
Copy link
Author

Yeah that was it. I think I must have had the target = "javascript" bit in there at some point, which led to the error actually being shown for a time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants