OCaml Platform lsp-server issue

Hello, I am completely new to OCaml, and trying to set up OCaml Platform for VSCode. However, I keep on getting the error:

Failed to start the language server. “ocaml-lsp-server” is not installed in the current sandbox.

even though it appears that it should be installed, based on the extension sidebar. I have attached a screenshot of this, which seems to show that default is the selected sandbox, and that ocaml-lsp-server isinstalled. Whenever I do OCaml: Restart Language Server, I keep on getting the error.

Any help would be greatly appreciated, thanks!

Have you tried restarting VSCode?

Yes I have, no luck unfortunately

What is the output of:

$ eval $(opam env)
$ opam switch
$ opam list

The output for opam switch is:

#  switch   compiler                                            description
   4.13.1   ocaml-base-compiler.4.13.1,ocaml-options-vanilla.1  ocaml-base-compiler = 4.13.1
   4.14     ocaml-base-compiler.4.14.2,ocaml-options-vanilla.1  ocaml-base-compiler = 4.14.2
→  default  ocaml-base-compiler.5.4.0,ocaml-options-vanilla.1   ocaml >= 4.05.0

and the output for opam list is

# Packages matching: installed
# Name                      # Installed # Synopsis
astring                     0.8.5       Alternative String module for OCaml
async                       v0.17.0     Monadic concurrency library
async_kernel                v0.17.0     Monadic concurrency library
async_log                   v0.17.0     Logging library built on top of Async_unix
async_rpc_kernel            v0.17.0     Platform-independent core of Async RPC library
async_unix                  v0.17.0     Monadic concurrency library
base                        v0.17.3     Full standard library replacement for OCaml
base-bigarray               base
base-bytes                  base        Bytes library distributed with the OCaml compiler
base-domains                base
base-effects                base
base-nnp                    base        Naked pointers prohibited in the OCaml heap
base-threads                base
base-unix                   base
base_bigstring              v0.17.0     String type based on [Bigarray], for use in I/O and C-bindings
base_quickcheck             v0.17.1     Randomized testing framework, designed for compatibility with Base
bin_prot                    v0.17.0-1   A binary protocol generator
camlp-streams               5.0.1       The Stream and Genlex libraries for use with Camlp4 and Camlp5
capitalization              v0.17.0     Defines case conventions and functions to rename identifiers according to them
chrome-trace                3.20.2      Chrome trace event generation library
cmdliner                    2.1.0       Declarative definition of command line interfaces for OCaml
core                        v0.17.1     Industrial strength alternative to OCaml's standard library
core_bench                  v0.17.0     Benchmarking library
core_extended               v0.17.0     Extra components that are not as closely vetted or as stable as Core
core_kernel                 v0.17.0     Industrial strength alternative to OCaml's standard library
core_unix                   v0.17.1     Unix-specific portions of Core
cppo                        1.8.0       Code preprocessor like cpp for OCaml
csexp                       1.5.2       Parsing and printing of S-expressions in Canonical form
cstruct                     6.2.0       Access C-like structures directly from OCaml
delimited_parsing           v0.17.0     Parsing of character (e.g., comma) separated and fixed-width values
dune                        3.20.2      Fast, portable, and opinionated build system
dune-build-info             3.20.2      Embed build information inside executable
dune-configurator           3.20.2      Helper library for gathering system configuration
dune-rpc                    3.20.2      Communicate with dune using rpc
dyn                         3.20.2      Dynamic type
either                      1.0.0       Compatibility Either module
expect_test_helpers_core    v0.17.0     Helpers for writing expectation tests
fiber                       3.7.0       Dune's monadic structured concurrency library
fieldslib                   v0.17.0     Syntax extension to define first class values representing record fields, to g
fix                         20250919    Algorithmic building blocks for memoization, recursion, and more
fmt                         0.11.0      OCaml Format pretty-printer combinators
fpath                       0.7.3       File system paths for OCaml
gel                         v0.17.0     A library to mark non-record fields global.
int_repr                    v0.17.0     Integers of various widths
jane-street-headers         v0.17.0     Jane Street C header files
jsonrpc                     1.25.0      Jsonrpc protocol implementation
jst-config                  v0.17.0     Compile-time configuration for Jane Street libraries
lambda-term                 3.3.2       Terminal manipulation library for OCaml
logs                        0.10.0      Logging infrastructure for OCaml
lsp                         1.25.0      LSP protocol implementation in OCaml
lwt                         5.9.2       Promises and event-driven I/O
lwt_react                   1.2.0       Helpers for using React with Lwt
menhir                      20250912    An LR(1) parser generator
menhirCST                   20250912    Runtime support library for unparsers generated by Menhir
menhirLib                   20250912    Runtime support library for parsers generated by Menhir
menhirSdk                   20250912    Compile-time library for auxiliary tools related to Menhir
merlin-lib                  5.6-504     Merlin's libraries
mew                         0.1.0       Modal editing witch
mew_vi                      0.5.0       Modal editing witch, VI interpreter
num                         1.6         The legacy Num library for arbitrary-precision integer and rational arithmetic
ocaml                       5.4.0       The OCaml compiler (virtual package)
ocaml-base-compiler         5.4.0       Official release of OCaml 5.4.0
ocaml-compiler              5.4.0       Official release of OCaml 5.4.0
ocaml-compiler-libs         v0.17.0     OCaml compiler libraries repackaged
ocaml-config                3           OCaml Switch Configuration
ocaml-index                 5.6-504     A tool that indexes value usages from cmt files
ocaml-lsp-server            1.25.0      pinned to version 1.25.0 at git+https://github.com/ocaml/ocaml-lsp.git
ocaml-options-vanilla       1           Ensure that OCaml is compiled with no special options enabled
ocaml-version               4.0.3       Manipulate, parse and generate OCaml compiler version strings
ocaml_intrinsics_kernel     v0.17.1     Intrinsics
ocamlbuild                  0.16.1      OCamlbuild is a build system with builtin rules to easily build most OCaml pro
ocamlc-loc                  3.20.2      Parse ocaml compiler output into structured form
ocamlfind                   1.9.8       A library manager for OCaml
ocamlformat                 0.28.1      Auto-formatter for OCaml code
ocamlformat-lib             0.28.1      OCaml Code Formatter
ocamlformat-rpc-lib         0.28.1      Auto-formatter for OCaml code (RPC mode)
ocp-indent                  1.9.0       A simple tool to indent OCaml programs
ocplib-endian               1.2         Optimised functions to read and write int16/32/64 from strings and bigarrays
ordering                    3.20.2      Element ordering
parsexp                     v0.17.0     S-expression parsing library
pp                          2.0.0       Pretty-printing library
ppx_assert                  v0.17.0     Assert-like extension nodes that raise useful errors on failure
ppx_base                    v0.17.0     Base set of ppx rewriters
ppx_bench                   v0.17.1     Syntax extension for writing in-line benchmarks in ocaml code
ppx_bin_prot                v0.17.1     Generation of bin_prot readers and writers from types
ppx_cold                    v0.17.0     Expands [@cold] into [@inline never][@specialise never][@local never]
ppx_compare                 v0.17.0     Generation of comparison functions from types
ppx_custom_printf           v0.17.0     Printf-style format-strings for user-defined string conversion
ppx_derivers                1.2.1       Shared [@@deriving] plugin registry
ppx_diff                    v0.17.1     A PPX rewriter that genreates the implementation of [Ldiffable.S].
ppx_disable_unused_warnings v0.17.0     Expands [@disable_unused_warnings] into [@warning "-20-26-32-33-34-35-36-37-38
ppx_enumerate               v0.17.0     Generate a list containing all values of a finite type
ppx_expect                  v0.17.3     Cram like framework for OCaml
ppx_fields_conv             v0.17.0     Generation of accessor and iteration functions for ocaml records
ppx_fixed_literal           v0.17.0     Simpler notation for fixed point literals
ppx_globalize               v0.17.2     A ppx rewriter that generates functions to copy local values to the global hea
ppx_hash                    v0.17.0     A ppx rewriter that generates hash functions from type expressions and definit
ppx_here                    v0.17.0     Expands [%here] into its location
ppx_ignore_instrumentation  v0.17.0     Ignore Jane Street specific instrumentation extensions
ppx_inline_test             v0.17.1     Syntax extension for writing in-line tests in ocaml code
ppx_jane                    v0.17.0     Standard Jane Street ppx rewriters
ppx_let                     v0.17.1     Monadic let-bindings
ppx_log                     v0.17.0     Ppx_sexp_message-like extension nodes for lazily rendering log messages
ppx_module_timer            v0.17.0     Ppx rewriter that records top-level module startup times
ppx_optcomp                 v0.17.1     Optional compilation for OCaml
ppx_optional                v0.17.0     Pattern matching on flat options
ppx_pipebang                v0.17.0     A ppx rewriter that inlines reverse application operators `|>` and `|!`
ppx_sexp_conv               v0.17.1     [@@deriving] plugin to generate S-expression conversion functions
ppx_sexp_message            v0.17.0     A ppx rewriter for easy construction of s-expressions
ppx_sexp_value              v0.17.0     A ppx rewriter that simplifies building s-expressions from ocaml values
ppx_stable                  v0.17.1     Stable types conversions generator
ppx_stable_witness          v0.17.0     Ppx extension for deriving a witness that a type is intended to be stable.  In
ppx_string                  v0.17.0     Ppx extension for string interpolation
ppx_string_conv             v0.17.0     Ppx extension for generating of_string & to_string
ppx_tydi                    v0.17.1     Let expressions, inferring pattern type from expression.
ppx_typerep_conv            v0.17.1     Generation of runtime types from type declarations
ppx_variants_conv           v0.17.1     Generation of accessor and iteration functions for ocaml variant types
ppx_yojson_conv_lib         v0.17.0     Runtime lib for ppx_yojson_conv
ppxlib                      0.37.0      Standard infrastructure for ppx rewriters
ppxlib_jane                 v0.17.4     Utilities for working with Jane Street AST constructs
protocol_version_header     v0.17.0     Protocol versioning
re                          1.14.0      RE is a regular expression library for OCaml
react                       1.2.2       Declarative events and signals for OCaml
record_builder              v0.17.0     A library which provides traversal of records with an applicative
result                      1.5         Compatibility Result module
sexp_pretty                 v0.17.0     S-expression pretty-printer
sexplib                     v0.17.0     Library for serializing OCaml values to and from S-expressions
sexplib0                    v0.17.0     Library containing the definition of S-expressions and some base converters
spawn                       v0.17.0     Spawning sub-processes
splittable_random           v0.17.0     PRNG that can be split into independent streams
stdio                       v0.17.0     Standard IO library for OCaml
stdlib-shims                0.3.0       Backport some of the new stdlib features to older compiler
stdune                      3.20.2      Dune's unstable standard library
textutils                   v0.17.0     Text output utilities
time_now                    v0.17.0     Reports the current time
timezone                    v0.17.0     Time-zone handling
topkg                       1.1.1       The transitory OCaml software packager
trie                        1.0.0       Strict impure trie tree
typerep                     v0.17.1     Typerep is a library for runtime types
uchar                       0.0.2       Compatibility library for OCaml's Uchar module
uopt                        v0.17.0     An [option]-like type that incurs no allocation, without requiring a reserved 
utop                        2.16.0      Universal toplevel for OCaml
uucp                        17.0.0      Unicode character properties for OCaml
uuseg                       17.0.0      Unicode text segmentation for OCaml
uutf                        1.0.4       Non-blocking streaming Unicode codec for OCaml
variantslib                 v0.17.0     Part of Jane Street's Core library
xdg                         3.20.2      XDG Base Directory Specification
yojson                      3.0.0       Yojson is an optimized parsing and printing library for the JSON format
zed                         3.2.3       Abstract engine for text edition in OCaml

Hmm, any reason why this package is pinned to GH? Wasn’t it installed with a command like opam install ocaml-lsp-server?

Mine shows:

ocaml-lsp-server        1.23.1       LSP Server for OCaml

in the acronym lsp, does the l stand for light or lite ?

Hello @julian and welcome here,

I have installed VSCode to try to reproduce your issue to help you:

1. I can reproduce your issue when VSCode is installed using Flatpak
2. Everything is working fine when I installed VSCode via package manager (or just downloading in my case .deb from VSCode webpage).

Can you confirm if you installed VSCode via Flatpak or similar to narrow possible reasons for your issue?

Thanks in advance!

Thanks everyone for the help, looks like I managed to figure out the issue.

Previously, I had a project open which was simply just a copy of the example in the guided tour in Real World OCaml. It seems like while having this project open, the OCaml Platform extension wasn’t working. However, when starting a new project with dune init proj, looks like it works.

Does anyone know why it wasn’t working before? I’m guessing there was something weird that I did in the previous project that threw off the extension. But this seems more like a bug in the extension than something specifically that I did?