jaredly / jaredly/reason-language-server

`bs.unwrap`, `bs.string`, `bs.int` and `bs.as` cause warning 101 in interface files.

Open
#378 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
OCaml
Stars
649
Forks
85
PR merge metrics
No merged PRs in 30d

Description

According to https://bucklescript.github.io/docs/en/intro-to-external, we should add `[@bs.blabla]` in interface files but doing so with `bs.unwrap`, `bs.string`, `bs.int` or `bs.as` cause a warning 101 to be displayed in VSCode by RLS but it compiles without problem.
I tested it with RLS V1.7.4 and BS 5.2.1, 6.2.1, 7.0.1 and 7.0.2-dev.1 .
I made a demo repo here:
https://github.com/tsnobip/unwrap_warning_demo

In `node_modules/.lsp/debug.log` we can indeed find these warnings:
```
Read message
{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///Users/paul/code/unwrap_warning/src/Demo.rei","languageId":"reason","version":1,"text":"type foo;\n/**\n * this binding works as expected\n */ [@bs.val] external foo: foo = \"foo\";\n\n/**\n * this binding shows a warning at `bs.unwrap`\n * Warning 101: Unused BuckleScript attribute: bs.unwrap\n */\n[@bs.val]\nexternal bar: ([@bs.unwrap] [ | `Int(int) | `Str(string)]) => foo = \"bar\";\n\n/**\n * this binding shows a warning at the polymorphic variant\n * Warning 103: BuckleScript FFI warning: Here a OCaml polymorphic variant type\n * passed into JS, probably you forgot annotations like `[@bs.int]` or `[@bs.string]`\n */\n// [@bs.val]\n// external baz: [ | `Int(int) | `Str(string)] => foo = \"baz\";\n\n/**\n * this binding shows a warning at `bs.string`\n * Warning 101: Unused BuckleScript attribute: bs.unwrap\n * and another one at `bs.as\n * Warning 101: Unused BuckleScript attribute: bs.unwrap\n * Removing `bs.as` raises the following error:\n * The implementation src/Demo.re\n does not match the interface src/demo-Unwrapwarning.cmi:\n Values do not match:\n [@bs...] external barString: [ `Bar | `Foo ] => foo = \"bar\"\n is not included in\n [@bs...] external barString: [ `Bar | `Foo ] => foo = \"bar\"\n File \"src/Demo.re\", line 10, characters 0-91:\n Actual declaration\n */\n[@bs.val]\nexternal barString: ([@bs.string] [ | `Foo | [@bs.as \"baz\"] `Bar]) => foo = \"bar\";\n\n/**\n * this binding shows a warning at the polymorphic variant\n * Warning 103: BuckleScript FFI warning: Here a OCaml polymorphic variant type\n * passed into JS, probably you forgot annotations like `[@bs.int]` or `[@bs.string]`\n * Uncommenting this binding would raise an error:\n * Some fatal warnings were triggered (1 occurrences)\n */\n// [@bs.val]\n// external bazString: [ | `Foo | [@bs.as \"baz\"] `Bar] => foo = \"baz\";\n\n/**\n * this binding shows a warning at `bs.int`\n * Warning 101: Unused BuckleScript attribute: bs.unwrap\n * and another one at `bs.as\n * Warning 101: Unused BuckleScript attribute: bs.unwrap\n */\n[@bs.val]\nexternal barInt: ([@bs.int] [ | `Foo | [@bs.as 10] `Bar]) => foo = \"bar\";\n\n/**\n * this binding shows a warning at the polymorphic variant\n * Warning 103: BuckleScript FFI warning: Here a OCaml polymorphic variant type\n * passed into JS, probably you forgot annotations like `[@bs.int]` or `[@bs.string]`\n * Uncommenting this binding would raise an error:\n * Some fatal warnings were triggered (1 occurrences)\n */\n// [@bs.val]\n// external bazInt: [ | `Foo | [@bs.as 10] `Bar] => foo = \"baz\";\n"}}}
```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the demo repository and reproduce the warnings in the Reason interface example, then inspect node_modules/.lsp/debug.log and the referenced src/Demo.re declarations. Done means the bs.unwrap, bs.string, bs.int, and bs.as annotations no longer produce the reported warning 101 messages while the interface still matches its implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
ocaml
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.