nvarner / typst-lsp

[Deprecated] An early language server for Typst, plus a VS Code extension
MIT License
1.2k stars 77 forks source link

yaml: imported fields treated as type none #461

Open triodan opened 8 months ago

triodan commented 8 months ago

Issue

When a YAML file is imported and passed to a method, the receiving method treats the passed data as type none.

main.typ:

#let print_name(content) = [
  #for item in content [
    #item.name
  ]
]

#print_name(
  yaml("data.yaml")
)

data.yaml:

- name: Alice
- name: Bob

VSCode will report this error despite compilation preview being successful: image

triodan commented 8 months ago

I figured out that this is caused due to lack of null-checking for the passed-in variables. Adding checks like this in the function resolves the issue:

#if content != none {
 ...
}

However I think the current message is not intuitive, maybe it can be replaced with something like 'content' may be of type none?