I am developing an Ocaml project using WSL and VSCode with the Ocaml Platform extension running ocaml-lsp-server. My project builds and runs correctly, but in VSCode there are a bunch of red squiggly lines with the error "unbound module" for tons of modules including Core, Cmdliner, etc.

I have seen many posts on various forums about this problem and none of the fixes suggested have seemed to work for me. I think there may be a problem specific to using WSL, but I'm not sure.
In the .vscode folder for VSCode, there is a settings.json file where you can specify the ocaml sandbox. I have updated this file to the following:
{
"ocaml.sandbox": {
"kind": "custom",
"template": "**wsl** opam exec --switch=4.12.0 --set-switch -- $prog $args"
}
}
The default is simply
opam exec --switch=4.12.0 --set-switch -- $prog $args
but I added "wsl" in front to make VSCode enter a wsl shell first to run opam. Otherwise, I get the error "opam is not recognized as an internal or external command" since I believe it is trying to run opam on my regular Windows machine, and it is not installed there (it is only installed on WSL). Using this edit, my ocaml-lsp-server is running and it seems to be partially working (the extension is annotating types, etc...) but it is still not recognizing a bunch of modules, even though everything is building properly.
My guess is that ocamllsp is not recognizing the dune file properly. Here are its contents, which I believe should be including the modules that ocamllsp is not recognizing:
(library
(name compiler)
(libraries core cmdliner yojson)
(inline_tests)
(preprocess
(pps ppx_jane ppx_expect)))
; makes subdirs not be their own module/library
(include_subdirs unqualified)
Here is the output of opam list:
# Packages matching: installed
# Name # Installed # Synopsis
astring 0.8.5 Alternative String module for OCaml
base v0.14.3 Full standard library replacement for OCaml
base-bigarray base
base-bytes base Bytes library distributed with the OCaml compiler
base-threads base
base-unix base
base_bigstring v0.14.0 String type based on [Bigarray], for use in I/O and C-bindings
base_quickcheck v0.14.1 Randomized testing framework, designed for compatibility with Base
bin_prot v0.14.1 A binary protocol generator
camlp-streams 5.0.1 The Stream and Genlex libraries for use with Camlp4 and Camlp5
cmdliner 1.2.0 Declarative definition of command line interfaces for OCaml
core v0.14.1 Industrial strength alternative to OCaml's standard library
core_kernel v0.14.2 Industrial strength alternative to OCaml's standard library
cppo 1.6.9 Code preprocessor like cpp for OCaml
csexp 1.5.2 Parsing and printing of S-expressions in Canonical form
dot-merlin-reader 4.5 Reads config files for merlin
dune 3.13.0 Fast, portable, and opinionated build system
dune-build-info 3.13.0 Embed build information inside executable
dune-configurator 3.13.0 Helper library for gathering system configuration
either 1.0.0 Compatibility Either module
fieldslib v0.14.0 Syntax extension to define first class values representing record fiel
fix 20230505 Algorithmic building blocks for memoization, recursion, and more
fpath 0.7.3 File system paths for OCaml
jane-street-headers v0.14.0 Jane Street C header files
jst-config v0.14.1 Compile-time configuration for Jane Street libraries
lambda-term 3.3.2 Terminal manipulation library for OCaml
logs 0.7.0 Logging infrastructure for OCaml
lwt 5.7.0 Promises and event-driven I/O
lwt_react 1.2.0 Helpers for using React with Lwt
menhir 20231231 An LR(1) parser generator
menhirCST 20231231 Runtime support library for parsers generated by Menhir
menhirLib 20231231 Runtime support library for parsers generated by Menhir
menhirSdk 20231231 Compile-time library for auxiliary tools related to Menhir
merlin 4.7-412 Editor helper, provides completion, typing and source browsing in Vim
mew 0.1.0 Modal editing witch
mew_vi 0.5.0 Modal editing witch, VI interpreter
num 1.5 The legacy Num library for arbitrary-precision integer and rational ar
ocaml 4.12.0 The OCaml compiler (virtual package)
ocaml-base-compiler 4.12.0 Official release 4.12.0
ocaml-compiler-libs v0.12.4 OCaml compiler libraries repackaged
ocaml-config 2 OCaml Switch Configuration
ocaml-lsp-server 1.9.0 pinned to version 1.9.0
ocaml-options-vanilla 1 Ensure that OCaml is compiled with no special options enabled
ocaml-version 3.6.4 Manipulate, parse and generate OCaml compiler version strings
ocamlbuild 0.14.3 OCamlbuild is a build system with builtin rules to easily build most O
ocamlfind 1.9.6 A library manager for OCaml
ocamlformat 0.26.1 Auto-formatter for OCaml code
ocamlformat-lib 0.26.1 OCaml Code Formatter
ocamlformat-rpc-lib 0.19.0 Auto-formatter for OCaml code (RPC mode)
ocp-indent 1.8.1 A simple tool to indent OCaml programs
ocplib-endian 1.2 Optimised functions to read and write int16/32/64 from strings and big
octavius 1.2.2 Ocamldoc comment syntax parser
parsexp v0.14.2 S-expression parsing library
pp 1.2.0 Pretty-printing library
ppx_assert v0.14.0 Assert-like extension nodes that raise useful errors on failure
ppx_base v0.14.0 Base set of ppx rewriters
ppx_bench v0.14.1 Syntax extension for writing in-line benchmarks in ocaml code
ppx_bin_prot v0.14.0 Generation of bin_prot readers and writers from types
ppx_cold v0.14.0 Expands [@cold] into [@inline never][@specialise never][@local never]
ppx_compare v0.14.0 Generation of comparison functions from types
ppx_custom_printf v0.14.1 Printf-style format-strings for user-defined string conversion
ppx_derivers 1.2.1 Shared [@@deriving] plugin registry
ppx_enumerate v0.14.0 Generate a list containing all values of a finite type
ppx_expect v0.14.2 Cram like framework for OCaml
ppx_fields_conv v0.14.2 Generation of accessor and iteration functions for ocaml records
ppx_fixed_literal v0.14.0 Simpler notation for fixed point literals
ppx_hash v0.14.0 A ppx rewriter that generates hash functions from type expressions and
ppx_here v0.14.0 Expands [%here] into its location
ppx_inline_test v0.14.1 Syntax extension for writing in-line tests in ocaml code
ppx_jane v0.14.0 Standard Jane Street ppx rewriters
ppx_js_style v0.14.1 Code style checker for Jane Street Packages
ppx_let v0.14.0 Monadic let-bindings
ppx_module_timer v0.14.0 Ppx rewriter that records top-level module startup times
ppx_optcomp v0.14.3 Optional compilation for OCaml
ppx_optional v0.14.0 Pattern matching on flat options
ppx_pipebang v0.14.0 A ppx rewriter that inlines reverse application operators `|>` and `|!
ppx_sexp_conv v0.14.3 [@@deriving] plugin to generate S-expression conversion functions
ppx_sexp_message v0.14.1 A ppx rewriter for easy construction of s-expressions
ppx_sexp_value v0.14.0 A ppx rewriter that simplifies building s-expressions from ocaml value
ppx_stable v0.14.1 Stable types conversions generator
ppx_string v0.14.1 Ppx extension for string interpolation
ppx_typerep_conv v0.14.2 Generation of runtime types from type declarations
ppx_variants_conv v0.14.2 Generation of accessor and iteration functions for ocaml variant types
ppx_yojson_conv_lib v0.15.0 Runtime lib for ppx_yojson_conv
ppxlib 0.25.1 Standard library for ppx rewriters
re 1.11.0 RE is a regular expression library for OCaml
react 1.2.2 Declarative events and signals for OCaml
result 1.5 Compatibility Result module
seq base Compatibility package for OCaml's standard iterator type starting from
sexplib v0.14.0 Library for serializing OCaml values to and from S-expressions
sexplib0 v0.14.0 Library containing the definition of S-expressions and some base conve
spawn v0.15.1 Spawning sub-processes
splittable_random v0.14.0 PRNG that can be split into independent streams
stdio v0.14.0 Standard IO library for OCaml
stdlib-shims 0.3.0 Backport some of the new stdlib features to older compiler
time_now v0.14.0 Reports the current time
timezone v0.14.0 Time-zone handling
topkg 1.0.7 The transitory OCaml software packager
trie 1.0.0 Strict impure trie tree
typerep v0.14.0 Typerep is a library for runtime types
uchar 0.0.2 Compatibility library for OCaml's Uchar module
utop 2.13.1 Universal toplevel for OCaml
uucp 15.0.0 Unicode character properties for OCaml
uuseg 15.0.0 Unicode text segmentation for OCaml
uutf 1.0.3 Non-blocking streaming Unicode codec for OCaml
variantslib v0.14.0 Part of Jane Street's Core library
xdg 3.13.0 XDG Base Directory Specification
yojson 2.1.2 Yojson is an optimized parsing and printing library for the JSON forma
zed 3.2.3 Abstract engine for text edition in OCaml