Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ jobs:
node-version: lts/*

- name: Install npm packages
run: yarn --frozen-lockfile
working-directory: ocaml-lsp-server/test/e2e
run: yarn install --frozen-lockfile

- name: Set-up OCaml
uses: ocaml/setup-ocaml@v3
Expand Down Expand Up @@ -93,6 +92,10 @@ jobs:
git config --global user.name github-actions[bot]
git config --global user.email github-actions[bot]@users.noreply.github.com

# Remove this pin once a compatible version of Merlin has been released
- name: Pin dev Merlin
run: opam --cli=2.1 pin --with-version=5.6-504 https://github.com/voodoos/merlin.git#main

- name: Install dependencies
run: |
opam install . --deps-only
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
_opam/
_build/
_opam/
.idea/
.log/
.vscode/
node_modules/
tmp/
.DS_Store
.merlin
Expand Down
21 changes: 21 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# 1.25.0

## Features

- Make `code-lens` for nested let bindings configurable (#1567)
- Add support for `.mlx` files, including formatting via `ocamlformat-mlx` and most OCaml LSP features (diagnostics, code actions, hover, etc.) (#1528)
- Add `typeExpression` custom request (#1576)
- Add `locate` custom request (#1576)
- Add `phrase` custom request (#1576)

## Fixes

- Improve precision of collected metrics timestamps. (#1565)
- Fallback on `.merlin` configuration if no `dune-project` file is found and if
`dot-merlin-reader` is installed. (#1563, fixes #1522)

- Fix hover on method calls not showing the type. (#1553, fixes #1552)
- Fix error on opening `.mll` files (#1557)
- Ensure compatibility with both yojson 2.0 and 3.0. (#1534)

# 1.21.0

## Features
Expand Down Expand Up @@ -42,6 +62,7 @@
[`ocamllsp/typeSearch`](/ocaml-lsp-server/docs/ocamllsp/typeSearch-spec.md) request (#1369)

- Make MerlinJump code action configurable (#1376)
- Add support for OCaml 5.3 (#1386)

- Add custom [`ocamllsp/jump`](/ocaml-lsp-server/docs/ocamllsp/merlinJump-spec.md) request (#1374)

Expand Down
11 changes: 3 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ TEST_E2E_DIR = ocaml-lsp-server/test/e2e

.PHONY: yarn-install
yarn-install:
cd $(TEST_E2E_DIR) && yarn --frozen-lockfile
yarn install --frozen-lockfile

-include Makefile.dev

Expand Down Expand Up @@ -39,7 +39,6 @@ lock: ## Generate the lock files
bench: ##
dune exec ocaml-lsp-server/bench/ocaml_lsp_bench.exe --profile bench


.PHONY: test-ocaml
test-ocaml: ## Run the unit tests
dune build @lsp/test/runtest @lsp-fiber/runtest @jsonrpc-fiber/runtest @ocaml-lsp-server/runtest
Expand Down Expand Up @@ -70,7 +69,6 @@ clean: ## Clean build artifacts and other generated files
.PHONY: fmt
fmt: ## Format the codebase with ocamlformat
dune build @fmt --auto-promote
cd $(TEST_E2E_DIR)

.PHONY: watch
watch: ## Watch for the filesystem and rebuild on every change
Expand All @@ -89,15 +87,12 @@ release: ## Release on Opam
dune-release opam submit

.PHONY: nix-tests
nix-tests:
(cd $(TEST_E2E_DIR) && yarn --frozen-lockfile)
nix-tests: yarn-install
make test

.PHONY: nix-fmt
nix-fmt:
$(MAKE) yarn-install
nix-fmt: yarn-install
dune build @fmt --auto-promote
cd $(TEST_E2E_DIR)

.PHONY: coverage-deps
coverage-deps:
Expand Down
33 changes: 27 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,33 @@ To add the language server to an esy project, run in terminal:
$ esy add @opam/ocaml-lsp-server
```

#### Dune

If you are using [Dune for package
management](https://dune.readthedocs.io/en/stable/explanation/package-management.html)
on the [latest nightly build](https://preview.dune.build/) or version 3.21 or
later, you can install `ocamllsp` locally within the current project by
running:
```sh
$ dune tools install ocamllsp
```

This will compile `ocamllsp` with the same OCaml compiler as the project itself -
a requirement for `ocamllsp` to be able to analyze the code in the project.

To make sure your editor sees the correct instance of `ocamllsp` for the
project, run `eval $(dune tools env)` from your shell before launching your
editor from the same shell. This can be automated by adding `eval $(dune tools
env)` to a `.envrc` file in the project's root directory and using
[direnv](https://direnv.net). Editors that aren't launched from the terminal
require plugin support to locate the appropriate `ocamllsp` executable
installed by Dune. For VSCode use the [OCaml
Platform](https://marketplace.visualstudio.com/items?itemName=ocamllabs.ocaml-platform)
plugin, and for Emacs use the
[ocaml-eglot](https://github.com/tarides/ocaml-eglot) package and follow
[these](https://github.com/tarides/ocaml-eglot?tab=readme-ov-file#usage-with-dune-pkg)
instructions.

### Installing from sources

This project uses submodules to handle dependencies. This is done so that users
Expand Down Expand Up @@ -415,9 +442,3 @@ date. Also, both servers seem deprecated.
use merlin which means that it supports fewer versions of OCaml and offers less
"smart" functionality - especially in the face of sources that do not yet
compile.

- [ocaml-language-server](https://github.com/ocaml-lsp/ocaml-language-server)
This project is extremely similar in the functionality it provides because it
also reuses merlin on the backend. The essential difference is that this
project is written in typescript, while our server is in OCaml. We feel that
it's best to use OCaml to maximize the contributor pool.
23 changes: 23 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "node_modules/@biomejs/biome/configuration_schema.json",
"formatter": {
"enabled": true,
"ignore": ["lsp/bin/metamodel/metaModel.json", "package.json"],
"useEditorconfig": true
},
"linter": {
"enabled": true,
"ignore": ["ocaml-lsp-server/test/e2e/**"],
"rules": {
"recommended": true
}
},
"organizeImports": {
"enabled": true
},
"vcs": {
"clientKind": "git",
"enabled": true,
"useIgnoreFile": true
}
}
7 changes: 4 additions & 3 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ possible and does not make any assumptions about IO.
(synopsis "LSP Server for OCaml")
(description "An LSP server for OCaml.")
(depends
(yojson (< 3.0.0))
yojson
(base (>= v0.16.0))
(lsp (= :version))
(jsonrpc (= :version))
Expand All @@ -63,7 +63,7 @@ possible and does not make any assumptions about IO.
spawn
astring
camlp-streams
(ppx_expect (and (>= v0.15.0) (< 0.17.0) :with-test))
(ppx_expect (and (>= v0.17.0) :with-test))
(ocamlformat (and :with-test (= 0.27.0)))
(ocamlc-loc (>= 3.7.0))
(pp (>= 1.1.2))
Expand All @@ -75,8 +75,9 @@ possible and does not make any assumptions about IO.

(package
(name jsonrpc)
(synopsis "Jsonrpc protocol implemenation")
(synopsis "Jsonrpc protocol implementation")
(description "See https://www.jsonrpc.org/specification")
(depends
(yojson (>= 2.0))
(ocaml (>= 4.08))
(odoc :with-doc)))
6 changes: 3 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
outputs = { self, flake-utils, nixpkgs, ... }@inputs:
let
package = "ocaml-lsp-server";
ocamlformat = pkgs: pkgs.ocamlformat_0_26_2;
ocamlformat = pkgs: pkgs.ocamlformat_0_27_0;
basePackage = {
duneVersion = "3";
version = "n/a";
Expand All @@ -31,7 +31,7 @@
fixPreBuild = o: {
propagatedBuildInputs = o.propagatedBuildInputs ++ [ oself.pp ];
preBuild = ''
rm -r vendor/csexp vendor/pp
rm -rf vendor/csexp vendor/pp
'';
};
in {
Expand All @@ -48,7 +48,7 @@
});
};
ocamlVersionOverlay =
(ocaml: self: super: { ocamlPackages = ocaml super.ocaml-ng; });
(ocaml: self: super: { ocamlPackages = super.ocaml-ng.${ocaml}; });
makeLocalPackages = pkgs:
let buildDunePackage = pkgs.ocamlPackages.buildDunePackage;
in rec {
Expand Down
3 changes: 2 additions & 1 deletion jsonrpc.opam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "Jsonrpc protocol implemenation"
synopsis: "Jsonrpc protocol implementation"
description: "See https://www.jsonrpc.org/specification"
maintainer: ["Rudi Grinberg <me@rgrinberg.com>"]
authors: [
Expand All @@ -20,6 +20,7 @@ homepage: "https://github.com/ocaml/ocaml-lsp"
bug-reports: "https://github.com/ocaml/ocaml-lsp/issues"
depends: [
"dune" {>= "3.0"}
"yojson" {>= "2.0"}
"ocaml" {>= "4.08"}
"odoc" {with-doc}
]
Expand Down
1 change: 1 addition & 0 deletions jsonrpc/src/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(library
(public_name jsonrpc)
(libraries yojson)
(instrumentation
(backend bisect_ppx)))
13 changes: 1 addition & 12 deletions jsonrpc/src/import.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,7 @@ module Option = struct
end

module Json = struct
type t =
[ `Assoc of (string * t) list
| `Bool of bool
| `Float of float
| `Int of int
| `Intlit of string
| `List of t list
| `Null
| `String of string
| `Tuple of t list
| `Variant of string * t option
]
type t = Yojson.Safe.t

exception Of_json of (string * t)

Expand Down
13 changes: 1 addition & 12 deletions jsonrpc/src/jsonrpc.mli
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
(** Jsonrpc implementation *)

module Json : sig
type t =
[ `Assoc of (string * t) list
| `Bool of bool
| `Float of float
| `Int of int
| `Intlit of string
| `List of t list
| `Null
| `String of string
| `Tuple of t list
| `Variant of string * t option
]
type t = Yojson.Safe.t

(** Raised when conversions from json fail *)
exception Of_json of (string * t)
Expand Down
6 changes: 3 additions & 3 deletions lsp-fiber/src/import.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ module Json = struct
| `Bool f -> Bool f
| `Assoc o -> Record (List.map o ~f:(fun (k, v) -> k, to_dyn v))
| `List l -> List (List.map l ~f:to_dyn)
| `Tuple args -> Tuple (List.map args ~f:to_dyn)
| `Null -> Dyn.Variant ("Null", [])
| `Variant (name, Some arg) -> Variant (name, [ to_dyn arg ])
| `Variant (name, None) -> Variant (name, [])
| `Intlit s -> String s
| _ -> Dyn.Variant ("Unsupported", [])
(* This last case is unused with Yojson >= 3 *)
[@@warning "-11"]
;;
end

Expand Down
16 changes: 10 additions & 6 deletions lsp/bin/cinaps.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let preprocess_metamodel =
method! or_ path (types : Metamodel.type_ list) =
match
List.filter_map types ~f:(function
| Literal (Record []) -> None
| Metamodel.Literal (Record []) -> None
| _ as t -> Some (self#type_ path t))
with
| [] -> assert false
Expand All @@ -17,10 +17,13 @@ let preprocess_metamodel =
| Top (Alias s) when s.name = "TextDocumentContentChangeEvent" ->
let t =
let union_fields l1 l2 ~f =
let of_map =
String.Map.of_list_map_exn ~f:(fun (x : Metamodel.property) -> x.name, x)
let of_map xs =
List.map xs ~f:(fun (x : Metamodel.property) -> x.name, x)
|> String.Map.of_list
in
String.Map.merge (of_map l1) (of_map l2) ~f |> String.Map.values
String.Map.merge (of_map l1) (of_map l2) ~f
|> String.Map.bindings
|> List.map ~f:snd
in
union_fields f1 f2 ~f:(fun k t1 t2 ->
if k = "text"
Expand Down Expand Up @@ -81,8 +84,9 @@ let expand_superclasses db (m : Metamodel.t) =
let structures =
let uniquify_fields fields =
List.fold_left fields ~init:String.Map.empty ~f:(fun acc (f : Metamodel.property) ->
String.Map.set acc f.name f)
|> String.Map.values
String.Map.add acc ~key:f.name ~data:f)
|> String.Map.bindings
|> List.map ~f:snd
in
let rec fields_of_type (t : Metamodel.type_) =
match t with
Expand Down
4 changes: 2 additions & 2 deletions lsp/bin/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(test
(name test_metamodel)
(modules test_metamodel)
(libraries stdune yojson lsp_gen)
(libraries yojson lsp_gen)
(deps metamodel/metaModel.json)
(action
(run ./test_metamodel.exe %{deps})))
Expand All @@ -13,4 +13,4 @@
(instrumentation
(backend bisect_ppx))
(modules :standard \ test_metamodel)
(libraries stdune dyn pp yojson))
(libraries dyn pp yojson))
Loading
Loading