diff --git a/Makefile b/Makefile index 4c49d9de4..8afdbd1b7 100644 --- a/Makefile +++ b/Makefile @@ -70,7 +70,7 @@ 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) && yarn fmt + cd $(TEST_E2E_DIR) .PHONY: watch watch: ## Watch for the filesystem and rebuild on every change @@ -97,7 +97,7 @@ nix-tests: nix-fmt: $(MAKE) yarn-install dune build @fmt --auto-promote - cd $(TEST_E2E_DIR) && yarn fmt + cd $(TEST_E2E_DIR) .PHONY: coverage-deps coverage-deps: diff --git a/ocaml-lsp-server/test/e2e/__tests__/ocamllsp-hoverExtended.ts b/ocaml-lsp-server/test/e2e/__tests__/ocamllsp-hoverExtended.ts index 2a4c1afa3..912654ca5 100644 --- a/ocaml-lsp-server/test/e2e/__tests__/ocamllsp-hoverExtended.ts +++ b/ocaml-lsp-server/test/e2e/__tests__/ocamllsp-hoverExtended.ts @@ -27,13 +27,24 @@ describe("ocamllsp/hoverExtended", () => { verbosity: 0, }); - expect(result).toMatchObject({ - contents: { kind: "plaintext", value: "int" }, - range: { - end: { character: 5, line: 0 }, - start: { character: 4, line: 0 }, - }, - }); + expect(result).toMatchInlineSnapshot(` +Object { + "contents": Object { + "kind": "plaintext", + "value": "int", + }, + "range": Object { + "end": Object { + "character": 5, + "line": 0, + }, + "start": Object { + "character": 4, + "line": 0, + }, + }, +} +`); }); it("returns type inferred under cursor (markdown formatting)", async () => { @@ -63,13 +74,26 @@ describe("ocamllsp/hoverExtended", () => { verbosity: 0, }); - expect(result).toMatchObject({ - contents: { kind: "markdown", value: "```ocaml\nint\n```" }, - range: { - end: { character: 5, line: 0 }, - start: { character: 4, line: 0 }, - }, - }); + expect(result).toMatchInlineSnapshot(` +Object { + "contents": Object { + "kind": "markdown", + "value": "\`\`\`ocaml +int +\`\`\`", + }, + "range": Object { + "end": Object { + "character": 5, + "line": 0, + }, + "start": Object { + "character": 4, + "line": 0, + }, + }, +} +`); }); it("returns type inferred under cursor with documentation", async () => { @@ -104,18 +128,28 @@ describe("ocamllsp/hoverExtended", () => { verbosity: 0, }); - expect(result).toMatchObject({ - contents: { - kind: "markdown", - value: outdent` - \`\`\`ocaml - 'a -> 'a - \`\`\` - --- - This function has a nice documentation - `, - }, - }); + expect(result).toMatchInlineSnapshot(` +Object { + "contents": Object { + "kind": "markdown", + "value": "\`\`\`ocaml +'a -> 'a +\`\`\` +--- +This function has a nice documentation", + }, + "range": Object { + "end": Object { + "character": 11, + "line": 3, + }, + "start": Object { + "character": 9, + "line": 3, + }, + }, +} +`); }); it("returns type inferred under cursor with documentation with tags (markdown formatting)", async () => { @@ -170,48 +204,58 @@ describe("ocamllsp/hoverExtended", () => { verbosity: 0, }); - expect(result).toMatchObject({ - contents: { - kind: "markdown", - value: outdent` - \`\`\`ocaml - int -> int -> int - \`\`\` - --- - This function has a nice documentation. + expect(result).toMatchInlineSnapshot(` +Object { + "contents": Object { + "kind": "markdown", + "value": "\`\`\`ocaml +int -> int -> int +\`\`\` +--- +This function has a nice documentation. - It performs division of two integer numbers. +It performs division of two integer numbers. - ***@param*** \`x\` - dividend +***@param*** \`x\` +dividend - ***@param*** divisor +***@param*** divisor - ***@return*** - *quotient*, i.e. result of division +***@return*** +*quotient*, i.e. result of division - ***@raise*** \`Division_by_zero\` - raised when divided by zero +***@raise*** \`Division_by_zero\` +raised when divided by zero - ***@see*** [link](https://en.wikipedia.org/wiki/Arithmetic#Division_\\(%C3%B7,_or_/\\)) - article +***@see*** [link](https://en.wikipedia.org/wiki/Arithmetic#Division_\\\\(%C3%B7,_or_/\\\\)) +article - ***@see*** \`arithmetic.ml\` - for more context +***@see*** \`arithmetic.ml\` +for more context - ***@since*** \`4.0.0\` +***@since*** \`4.0.0\` - ***@before*** \`4.4.0\` +***@before*** \`4.4.0\` - ***@deprecated*** - use \`(/)\` +***@deprecated*** +use \`(/)\` - ***@version*** \`1.0.0\` +***@version*** \`1.0.0\` - ***@author*** John Doe - `, - }, - }); +***@author*** John Doe", + }, + "range": Object { + "end": Object { + "character": 11, + "line": 23, + }, + "start": Object { + "character": 8, + "line": 23, + }, + }, +} +`); }); it("returns good type when cursor is between values", async () => { @@ -246,16 +290,26 @@ describe("ocamllsp/hoverExtended", () => { verbosity: 0, }); - expect(result).toMatchObject({ - contents: { - kind: "markdown", - value: "```ocaml\nint\n```", - }, - range: { - start: { character: 12, line: 3 }, - end: { character: 13, line: 3 }, - }, - }); + expect(result).toMatchInlineSnapshot(` +Object { + "contents": Object { + "kind": "markdown", + "value": "\`\`\`ocaml +int +\`\`\`", + }, + "range": Object { + "end": Object { + "character": 13, + "line": 3, + }, + "start": Object { + "character": 12, + "line": 3, + }, + }, +} +`); }); it("regression test for #343", async () => { diff --git a/ocaml-lsp-server/test/e2e/__tests__/textDocument-codeLens.test.ts b/ocaml-lsp-server/test/e2e/__tests__/textDocument-codeLens.test.ts index 76abcabb6..d3ea891c9 100644 --- a/ocaml-lsp-server/test/e2e/__tests__/textDocument-codeLens.test.ts +++ b/ocaml-lsp-server/test/e2e/__tests__/textDocument-codeLens.test.ts @@ -51,28 +51,57 @@ describe("textDocument/references", () => { let result = await query(); - expect(result).toMatchObject([ - { - command: { command: "", title: "int -> int -> int" }, - range: { - end: { character: 19, line: 4 }, - start: { character: 2, line: 4 }, - }, + expect(result).toMatchInlineSnapshot(` +Array [ + Object { + "command": Object { + "command": "", + "title": "int -> int -> int", + }, + "range": Object { + "end": Object { + "character": 19, + "line": 4, }, - { - command: { command: "", title: "string" }, - range: { - end: { character: 20, line: 1 }, - start: { character: 0, line: 1 }, - }, + "start": Object { + "character": 2, + "line": 4, }, - { - command: { command: "", title: "int" }, - range: { - end: { character: 12, line: 0 }, - start: { character: 0, line: 0 }, - }, + }, + }, + Object { + "command": Object { + "command": "", + "title": "string", + }, + "range": Object { + "end": Object { + "character": 20, + "line": 1, + }, + "start": Object { + "character": 0, + "line": 1, + }, + }, + }, + Object { + "command": Object { + "command": "", + "title": "int", + }, + "range": Object { + "end": Object { + "character": 12, + "line": 0, + }, + "start": Object { + "character": 0, + "line": 0, }, - ]); + }, + }, +] +`); }); }); diff --git a/ocaml-lsp-server/test/e2e/__tests__/textDocument-declaration.test.ts b/ocaml-lsp-server/test/e2e/__tests__/textDocument-declaration.test.ts index 2d22883c2..60299f419 100644 --- a/ocaml-lsp-server/test/e2e/__tests__/textDocument-declaration.test.ts +++ b/ocaml-lsp-server/test/e2e/__tests__/textDocument-declaration.test.ts @@ -67,10 +67,18 @@ describe("textDocument/declaration", () => { ); expect(result.length).toBe(1); - expect(result[0].range).toMatchObject({ - end: { character: 0, line: 0 }, - start: { character: 0, line: 0 }, - }); + expect(result[0].range).toMatchInlineSnapshot(` +Object { + "end": Object { + "character": 0, + "line": 0, + }, + "start": Object { + "character": 0, + "line": 0, + }, +} +`); expect(result[0].uri).toEqualUri(testUri(createPathForFile("lib.mli"))); }); }); diff --git a/ocaml-lsp-server/test/e2e/__tests__/textDocument-documentHighlight.test.ts b/ocaml-lsp-server/test/e2e/__tests__/textDocument-documentHighlight.test.ts index 09ebc3433..16fca85f1 100644 --- a/ocaml-lsp-server/test/e2e/__tests__/textDocument-documentHighlight.test.ts +++ b/ocaml-lsp-server/test/e2e/__tests__/textDocument-documentHighlight.test.ts @@ -44,46 +44,48 @@ describe("textDocument/references", () => { let result = await query(Types.Position.create(0, 4)); - expect(result).toMatchObject([ - { - range: { - end: { - character: 7, - line: 0, - }, - start: { - character: 4, - line: 0, - }, - }, - kind: 1, + expect(result).toMatchInlineSnapshot(` +Array [ + Object { + "kind": 1, + "range": Object { + "end": Object { + "character": 7, + "line": 0, }, - { - range: { - end: { - character: 13, - line: 1, - }, - start: { - character: 10, - line: 1, - }, - }, - kind: 1, + "start": Object { + "character": 4, + "line": 0, }, - { - range: { - end: { - character: 20, - line: 2, - }, - start: { - character: 17, - line: 2, - }, - }, - kind: 1, + }, + }, + Object { + "kind": 1, + "range": Object { + "end": Object { + "character": 13, + "line": 1, + }, + "start": Object { + "character": 10, + "line": 1, + }, + }, + }, + Object { + "kind": 1, + "range": Object { + "end": Object { + "character": 20, + "line": 2, + }, + "start": Object { + "character": 17, + "line": 2, }, - ]); + }, + }, +] +`); }); }); diff --git a/ocaml-lsp-server/test/e2e/__tests__/textDocument-formatting.test.ts b/ocaml-lsp-server/test/e2e/__tests__/textDocument-formatting.test.ts index bfa4da0de..dca1566ac 100644 --- a/ocaml-lsp-server/test/e2e/__tests__/textDocument-formatting.test.ts +++ b/ocaml-lsp-server/test/e2e/__tests__/textDocument-formatting.test.ts @@ -83,15 +83,24 @@ maybeDescribe("textDocument/formatting", () => { ); let result = await query(languageServer, name); - expect(result).toMatchObject([ - { - range: { - start: { character: 0, line: 2 }, - end: { character: 0, line: 3 }, - }, - newText: " | 0, n\n", - }, - ]); + expect(result).toMatchInlineSnapshot(` +Array [ + Object { + "newText": " | 0, n +", + "range": Object { + "end": Object { + "character": 0, + "line": 3, + }, + "start": Object { + "character": 0, + "line": 2, + }, + }, + }, +] +`); }); it("leaves unchanged files alone", async () => { @@ -127,15 +136,24 @@ maybeDescribe("textDocument/formatting", () => { let result = await query(languageServer, name); - expect(result).toMatchObject([ - { - range: { - start: { character: 0, line: 0 }, - end: { character: 0, line: 1 }, - }, - newText: "module Test : sig\n", - }, - ]); + expect(result).toMatchInlineSnapshot(` +Array [ + Object { + "newText": "module Test : sig +", + "range": Object { + "end": Object { + "character": 0, + "line": 1, + }, + "start": Object { + "character": 0, + "line": 0, + }, + }, + }, +] +`); }); it("does not format ignored files", async () => { diff --git a/ocaml-lsp-server/test/e2e/__tests__/textDocument-hover.test.ts b/ocaml-lsp-server/test/e2e/__tests__/textDocument-hover.test.ts index 39810c0bc..0c6148440 100644 --- a/ocaml-lsp-server/test/e2e/__tests__/textDocument-hover.test.ts +++ b/ocaml-lsp-server/test/e2e/__tests__/textDocument-hover.test.ts @@ -26,13 +26,24 @@ describe("textDocument/hover", () => { position: Types.Position.create(0, 4), }); - expect(result).toMatchObject({ - contents: { kind: "plaintext", value: "int" }, - range: { - end: { character: 5, line: 0 }, - start: { character: 4, line: 0 }, - }, - }); + expect(result).toMatchInlineSnapshot(` +Object { + "contents": Object { + "kind": "plaintext", + "value": "int", + }, + "range": Object { + "end": Object { + "character": 5, + "line": 0, + }, + "start": Object { + "character": 4, + "line": 0, + }, + }, +} +`); }); it("returns type inferred under cursor (markdown formatting)", async () => { @@ -61,13 +72,26 @@ describe("textDocument/hover", () => { position: Types.Position.create(0, 4), }); - expect(result).toMatchObject({ - contents: { kind: "markdown", value: "```ocaml\nint\n```" }, - range: { - end: { character: 5, line: 0 }, - start: { character: 4, line: 0 }, - }, - }); + expect(result).toMatchInlineSnapshot(` +Object { + "contents": Object { + "kind": "markdown", + "value": "\`\`\`ocaml +int +\`\`\`", + }, + "range": Object { + "end": Object { + "character": 5, + "line": 0, + }, + "start": Object { + "character": 4, + "line": 0, + }, + }, +} +`); }); // checks for regression https://github.com/ocaml/merlin/issues/1540 @@ -102,18 +126,28 @@ describe("textDocument/hover", () => { position: Types.Position.create(1, 4), }); - expect(result).toMatchObject({ - contents: { - kind: "markdown", - value: outdent` - \`\`\`ocaml - 'a -> 'a - \`\`\` - --- - This function has a nice documentation - `, - }, - }); + expect(result).toMatchInlineSnapshot(` +Object { + "contents": Object { + "kind": "markdown", + "value": "\`\`\`ocaml +'a -> 'a +\`\`\` +--- +This function has a nice documentation", + }, + "range": Object { + "end": Object { + "character": 6, + "line": 1, + }, + "start": Object { + "character": 4, + "line": 1, + }, + }, +} +`); }); it("returns type inferred under cursor with documentation", async () => { @@ -147,18 +181,28 @@ describe("textDocument/hover", () => { position: Types.Position.create(3, 9), }); - expect(result).toMatchObject({ - contents: { - kind: "markdown", - value: outdent` - \`\`\`ocaml - 'a -> 'a - \`\`\` - --- - This function has a nice documentation - `, - }, - }); + expect(result).toMatchInlineSnapshot(` +Object { + "contents": Object { + "kind": "markdown", + "value": "\`\`\`ocaml +'a -> 'a +\`\`\` +--- +This function has a nice documentation", + }, + "range": Object { + "end": Object { + "character": 11, + "line": 3, + }, + "start": Object { + "character": 9, + "line": 3, + }, + }, +} +`); }); it("returns type inferred under cursor with documentation with tags (markdown formatting)", async () => { @@ -212,48 +256,58 @@ describe("textDocument/hover", () => { position: Types.Position.create(23, 9), }); - expect(result).toMatchObject({ - contents: { - kind: "markdown", - value: outdent` - \`\`\`ocaml - int -> int -> int - \`\`\` - --- - This function has a nice documentation. + expect(result).toMatchInlineSnapshot(` +Object { + "contents": Object { + "kind": "markdown", + "value": "\`\`\`ocaml +int -> int -> int +\`\`\` +--- +This function has a nice documentation. - It performs division of two integer numbers. +It performs division of two integer numbers. - ***@param*** \`x\` - dividend +***@param*** \`x\` +dividend - ***@param*** divisor +***@param*** divisor - ***@return*** - *quotient*, i.e. result of division +***@return*** +*quotient*, i.e. result of division - ***@raise*** \`Division_by_zero\` - raised when divided by zero +***@raise*** \`Division_by_zero\` +raised when divided by zero - ***@see*** [link](https://en.wikipedia.org/wiki/Arithmetic#Division_\\(%C3%B7,_or_/\\)) - article +***@see*** [link](https://en.wikipedia.org/wiki/Arithmetic#Division_\\\\(%C3%B7,_or_/\\\\)) +article - ***@see*** \`arithmetic.ml\` - for more context +***@see*** \`arithmetic.ml\` +for more context - ***@since*** \`4.0.0\` +***@since*** \`4.0.0\` - ***@before*** \`4.4.0\` +***@before*** \`4.4.0\` - ***@deprecated*** - use \`(/)\` +***@deprecated*** +use \`(/)\` - ***@version*** \`1.0.0\` +***@version*** \`1.0.0\` - ***@author*** John Doe - `, - }, - }); +***@author*** John Doe", + }, + "range": Object { + "end": Object { + "character": 11, + "line": 23, + }, + "start": Object { + "character": 8, + "line": 23, + }, + }, +} +`); }); it("returns good type when cursor is between values", async () => { @@ -287,16 +341,26 @@ describe("textDocument/hover", () => { position: Types.Position.create(3, 13), }); - expect(result).toMatchObject({ - contents: { - kind: "markdown", - value: "```ocaml\nint\n```", - }, - range: { - start: { character: 12, line: 3 }, - end: { character: 13, line: 3 }, - }, - }); + expect(result).toMatchInlineSnapshot(` +Object { + "contents": Object { + "kind": "markdown", + "value": "\`\`\`ocaml +int +\`\`\`", + }, + "range": Object { + "end": Object { + "character": 13, + "line": 3, + }, + "start": Object { + "character": 12, + "line": 3, + }, + }, +} +`); }); it("regression test for #343", async () => { @@ -330,25 +394,25 @@ describe("textDocument/hover", () => { }); expect(hover1).toMatchInlineSnapshot(` - Object { - "contents": Object { - "kind": "markdown", - "value": "\`\`\`ocaml - type s = t - \`\`\`", - }, - "range": Object { - "end": Object { - "character": 14, - "line": 1, - }, - "start": Object { - "character": 0, - "line": 1, - }, - }, - } - `); +Object { + "contents": Object { + "kind": "markdown", + "value": "\`\`\`ocaml +type s = t +\`\`\`", + }, + "range": Object { + "end": Object { + "character": 14, + "line": 1, + }, + "start": Object { + "character": 0, + "line": 1, + }, + }, +} +`); let hover2 = await languageServer.sendRequest("textDocument/hover", { textDocument: Types.TextDocumentIdentifier.create("file:///test.ml"), @@ -356,25 +420,25 @@ describe("textDocument/hover", () => { }); expect(hover2).toMatchInlineSnapshot(` - Object { - "contents": Object { - "kind": "markdown", - "value": "\`\`\`ocaml - type 'a fib = ('a -> unit) -> unit - \`\`\`", - }, - "range": Object { - "end": Object { - "character": 34, - "line": 2, - }, - "start": Object { - "character": 0, - "line": 2, - }, - }, - } - `); +Object { + "contents": Object { + "kind": "markdown", + "value": "\`\`\`ocaml +type 'a fib = ('a -> unit) -> unit +\`\`\`", + }, + "range": Object { + "end": Object { + "character": 34, + "line": 2, + }, + "start": Object { + "character": 0, + "line": 2, + }, + }, +} +`); }); it("regression test for #403", async () => { @@ -398,23 +462,23 @@ let x : foo = 1 }); expect(result).toMatchInlineSnapshot(` - Object { - "contents": Object { - "kind": "plaintext", - "value": "foo", - }, - "range": Object { - "end": Object { - "character": 5, - "line": 2, - }, - "start": Object { - "character": 4, - "line": 2, - }, - }, - } - `); +Object { + "contents": Object { + "kind": "plaintext", + "value": "foo", + }, + "range": Object { + "end": Object { + "character": 5, + "line": 2, + }, + "start": Object { + "character": 4, + "line": 2, + }, + }, +} +`); }); it("FIXME: reproduce [#344](https://github.com/ocaml/ocaml-lsp/issues/344)", async () => { @@ -474,25 +538,25 @@ let x : foo = 1 }); expect(hoverOverK).toMatchInlineSnapshot(` - Object { - "contents": Object { - "kind": "markdown", - "value": "\`\`\`ocaml - unit - \`\`\`", - }, - "range": Object { - "end": Object { - "character": 5, - "line": 24, - }, - "start": Object { - "character": 4, - "line": 24, - }, - }, - } - `); +Object { + "contents": Object { + "kind": "markdown", + "value": "\`\`\`ocaml +unit +\`\`\`", + }, + "range": Object { + "end": Object { + "character": 5, + "line": 24, + }, + "start": Object { + "character": 4, + "line": 24, + }, + }, +} +`); // we trigger the bug let autocompleteForListm = await languageServer.sendRequest( @@ -513,24 +577,24 @@ let x : foo = 1 // now the same hover as before comes with unrelated documentation expect(buggedHoverOverK).toMatchInlineSnapshot(` - Object { - "contents": Object { - "kind": "markdown", - "value": "\`\`\`ocaml - unit - \`\`\`", - }, - "range": Object { - "end": Object { - "character": 5, - "line": 24, - }, - "start": Object { - "character": 4, - "line": 24, - }, - }, - } - `); +Object { + "contents": Object { + "kind": "markdown", + "value": "\`\`\`ocaml +unit +\`\`\`", + }, + "range": Object { + "end": Object { + "character": 5, + "line": 24, + }, + "start": Object { + "character": 4, + "line": 24, + }, + }, +} +`); }); }); diff --git a/ocaml-lsp-server/test/e2e/__tests__/textDocument-references.test.ts b/ocaml-lsp-server/test/e2e/__tests__/textDocument-references.test.ts index 804452965..3386cecde 100644 --- a/ocaml-lsp-server/test/e2e/__tests__/textDocument-references.test.ts +++ b/ocaml-lsp-server/test/e2e/__tests__/textDocument-references.test.ts @@ -45,46 +45,48 @@ describe("textDocument/references", () => { let result = await query(Types.Position.create(0, 4)); - expect(result).toMatchObject([ - { - range: { - end: { - character: 7, - line: 0, - }, - start: { - character: 4, - line: 0, - }, - }, - uri: "file:///test.ml", + expect(result).toMatchInlineSnapshot(` +Array [ + Object { + "range": Object { + "end": Object { + "character": 7, + "line": 0, }, - { - range: { - end: { - character: 13, - line: 1, - }, - start: { - character: 10, - line: 1, - }, - }, - uri: "file:///test.ml", + "start": Object { + "character": 4, + "line": 0, }, - { - range: { - end: { - character: 20, - line: 2, - }, - start: { - character: 17, - line: 2, - }, - }, - uri: "file:///test.ml", + }, + "uri": "file:///test.ml", + }, + Object { + "range": Object { + "end": Object { + "character": 13, + "line": 1, + }, + "start": Object { + "character": 10, + "line": 1, + }, + }, + "uri": "file:///test.ml", + }, + Object { + "range": Object { + "end": Object { + "character": 20, + "line": 2, + }, + "start": Object { + "character": 17, + "line": 2, }, - ]); + }, + "uri": "file:///test.ml", + }, +] +`); }); }); diff --git a/ocaml-lsp-server/test/e2e/__tests__/textDocument-rename.test.ts b/ocaml-lsp-server/test/e2e/__tests__/textDocument-rename.test.ts index 91dbaee58..87dd2ba49 100644 --- a/ocaml-lsp-server/test/e2e/__tests__/textDocument-rename.test.ts +++ b/ocaml-lsp-server/test/e2e/__tests__/textDocument-rename.test.ts @@ -74,10 +74,18 @@ describe("textDocument/rename", () => { `); let result = await query_prepare(Types.Position.create(0, 4)); - expect(result).toMatchObject({ - start: { line: 0, character: 4 }, - end: { line: 0, character: 7 }, - }); + expect(result).toMatchInlineSnapshot(` +Object { + "end": Object { + "character": 7, + "line": 0, + }, + "start": Object { + "character": 4, + "line": 0, + }, +} +`); }); it("rename value in a file without documentChanges capability", async () => { @@ -95,38 +103,40 @@ describe("textDocument/rename", () => { let result = await query(Types.Position.create(0, 4)); - expect(result).toMatchObject({ - changes: { - "file:///test.ml": [ - { - range: { - start: { - line: 0, - character: 4, - }, - end: { - line: 0, - character: 7, - }, - }, - newText: "new_num", + expect(result).toMatchInlineSnapshot(` +Object { + "changes": Object { + "file:///test.ml": Array [ + Object { + "newText": "new_num", + "range": Object { + "end": Object { + "character": 7, + "line": 0, }, - { - range: { - start: { - line: 1, - character: 10, - }, - end: { - line: 1, - character: 13, - }, - }, - newText: "new_num", + "start": Object { + "character": 4, + "line": 0, }, - ], + }, }, - }); + Object { + "newText": "new_num", + "range": Object { + "end": Object { + "character": 13, + "line": 1, + }, + "start": Object { + "character": 10, + "line": 1, + }, + }, + }, + ], + }, +} +`); }); it("rename value in a file with documentChanges capability", async () => { @@ -144,44 +154,46 @@ describe("textDocument/rename", () => { let result = await query(Types.Position.create(0, 4)); - expect(result).toMatchObject({ - documentChanges: [ - { - textDocument: { - version: 0, - uri: "file:///test.ml", + expect(result).toMatchInlineSnapshot(` +Object { + "documentChanges": Array [ + Object { + "edits": Array [ + Object { + "newText": "new_num", + "range": Object { + "end": Object { + "character": 7, + "line": 0, + }, + "start": Object { + "character": 4, + "line": 0, + }, }, - edits: [ - { - range: { - start: { - line: 0, - character: 4, - }, - end: { - line: 0, - character: 7, - }, - }, - newText: "new_num", + }, + Object { + "newText": "new_num", + "range": Object { + "end": Object { + "character": 13, + "line": 1, }, - { - range: { - start: { - line: 1, - character: 10, - }, - end: { - line: 1, - character: 13, - }, - }, - newText: "new_num", + "start": Object { + "character": 10, + "line": 1, }, - ], + }, }, ], - }); + "textDocument": Object { + "uri": "file:///test.ml", + "version": 0, + }, + }, + ], +} +`); }); it("rename a var used as a named argument", async () => { diff --git a/ocaml-lsp-server/test/e2e/__tests__/textDocument-selectionRange.test.ts b/ocaml-lsp-server/test/e2e/__tests__/textDocument-selectionRange.test.ts index 5839d5b0a..0f5457822 100644 --- a/ocaml-lsp-server/test/e2e/__tests__/textDocument-selectionRange.test.ts +++ b/ocaml-lsp-server/test/e2e/__tests__/textDocument-selectionRange.test.ts @@ -47,19 +47,141 @@ describe("textDocument/selectionRange", () => { `); let result = await selectionRange([Types.Position.create(1, 17)]); - expect(result).toMatchObject([ - { - range: { - start: { - line: 1, - character: 15, + expect(result).toMatchInlineSnapshot(` +Array [ + Object { + "parent": Object { + "parent": Object { + "parent": Object { + "parent": Object { + "parent": Object { + "parent": Object { + "parent": Object { + "parent": Object { + "parent": Object { + "parent": Object { + "range": Object { + "end": Object { + "character": 17, + "line": 3, + }, + "start": Object { + "character": 0, + "line": 0, + }, + }, + }, + "range": Object { + "end": Object { + "character": 17, + "line": 3, + }, + "start": Object { + "character": 0, + "line": 0, + }, + }, + }, + "range": Object { + "end": Object { + "character": 17, + "line": 3, + }, + "start": Object { + "character": 0, + "line": 0, + }, + }, + }, + "range": Object { + "end": Object { + "character": 17, + "line": 3, + }, + "start": Object { + "character": 8, + "line": 0, + }, + }, + }, + "range": Object { + "end": Object { + "character": 17, + "line": 3, + }, + "start": Object { + "character": 8, + "line": 0, + }, + }, + }, + "range": Object { + "end": Object { + "character": 17, + "line": 3, + }, + "start": Object { + "character": 10, + "line": 0, + }, + }, + }, + "range": Object { + "end": Object { + "character": 17, + "line": 3, + }, + "start": Object { + "character": 10, + "line": 0, + }, + }, }, - end: { - line: 1, - character: 18, + "range": Object { + "end": Object { + "character": 17, + "line": 3, + }, + "start": Object { + "character": 2, + "line": 1, + }, }, }, + "range": Object { + "end": Object { + "character": 22, + "line": 1, + }, + "start": Object { + "character": 2, + "line": 1, + }, + }, + }, + "range": Object { + "end": Object { + "character": 22, + "line": 1, + }, + "start": Object { + "character": 15, + "line": 1, + }, + }, + }, + "range": Object { + "end": Object { + "character": 18, + "line": 1, + }, + "start": Object { + "character": 15, + "line": 1, }, - ]); + }, + }, +] +`); }); }); diff --git a/ocaml-lsp-server/test/e2e/__tests__/textDocument-signatureHelp.ts b/ocaml-lsp-server/test/e2e/__tests__/textDocument-signatureHelp.ts index c0f59e5ce..b96776d56 100644 --- a/ocaml-lsp-server/test/e2e/__tests__/textDocument-signatureHelp.ts +++ b/ocaml-lsp-server/test/e2e/__tests__/textDocument-signatureHelp.ts @@ -65,23 +65,31 @@ describe_opt("textDocument/completion", () => { `); let items = await querySignatureHelp(Types.Position.create(2, 11)); - expect(items).toMatchObject({ - signatures: [ - { - label: "map : f:('a -> 'b) -> 'a list -> 'b list", - parameters: [ - { - label: [6, 18], - }, - { - label: [22, 29], - }, + expect(items).toMatchInlineSnapshot(` +Object { + "activeParameter": 1, + "activeSignature": 0, + "signatures": Array [ + Object { + "label": "map : f:('a -> 'b) -> 'a list -> 'b list", + "parameters": Array [ + Object { + "label": Array [ + 6, + 18, + ], + }, + Object { + "label": Array [ + 22, + 29, ], }, ], - activeSignature: 0, - activeParameter: 1, - }); + }, + ], +} +`); }); it("can provide signature help for an operator", async () => { @@ -92,23 +100,31 @@ describe_opt("textDocument/completion", () => { `); let items = await querySignatureHelp(Types.Position.create(2, 13)); - expect(items).toMatchObject({ - signatures: [ - { - label: "(+) : int -> int -> int", - parameters: [ - { - label: [6, 9], - }, - { - label: [13, 16], - }, + expect(items).toMatchInlineSnapshot(` +Object { + "activeParameter": 1, + "activeSignature": 0, + "signatures": Array [ + Object { + "label": "(+) : int -> int -> int", + "parameters": Array [ + Object { + "label": Array [ + 6, + 9, + ], + }, + Object { + "label": Array [ + 13, + 16, ], }, ], - activeSignature: 0, - activeParameter: 1, - }); + }, + ], +} +`); }); it("can provide signature help for an anonymous function", async () => { @@ -117,20 +133,25 @@ describe_opt("textDocument/completion", () => { `); let items = await querySignatureHelp(Types.Position.create(0, 26)); - expect(items).toMatchObject({ - signatures: [ - { - label: "_ : int -> int", - parameters: [ - { - label: [4, 7], - }, + expect(items).toMatchInlineSnapshot(` +Object { + "activeParameter": 0, + "activeSignature": 0, + "signatures": Array [ + Object { + "label": "_ : int -> int", + "parameters": Array [ + Object { + "label": Array [ + 4, + 7, ], }, ], - activeSignature: 0, - activeParameter: 0, - }); + }, + ], +} +`); }); it("can make the non-labelled parameter active", async () => { @@ -141,23 +162,31 @@ describe_opt("textDocument/completion", () => { `); let items = await querySignatureHelp(Types.Position.create(2, 14)); - expect(items).toMatchObject({ - signatures: [ - { - label: "map : f:('a -> 'b) -> 'a list -> 'b list", - parameters: [ - { - label: [6, 18], - }, - { - label: [22, 29], - }, + expect(items).toMatchInlineSnapshot(` +Object { + "activeParameter": 1, + "activeSignature": 0, + "signatures": Array [ + Object { + "label": "map : f:('a -> 'b) -> 'a list -> 'b list", + "parameters": Array [ + Object { + "label": Array [ + 6, + 18, + ], + }, + Object { + "label": Array [ + 22, + 29, ], }, ], - activeSignature: 0, - activeParameter: 1, - }); + }, + ], +} +`); }); it("can make the labelled parameter active", async () => { @@ -168,23 +197,31 @@ describe_opt("textDocument/completion", () => { `); let items = await querySignatureHelp(Types.Position.create(2, 22)); - expect(items).toMatchObject({ - signatures: [ - { - label: "map : f:(int -> int) -> int list -> int list", - parameters: [ - { - label: [6, 20], - }, - { - label: [24, 32], - }, + expect(items).toMatchInlineSnapshot(` +Object { + "activeParameter": 0, + "activeSignature": 0, + "signatures": Array [ + Object { + "label": "map : f:(int -> int) -> int list -> int list", + "parameters": Array [ + Object { + "label": Array [ + 6, + 20, + ], + }, + Object { + "label": Array [ + 24, + 32, ], }, ], - activeSignature: 0, - activeParameter: 0, - }); + }, + ], +} +`); }); it("can make a labelled parameter active by prefix", async () => { @@ -195,23 +232,31 @@ describe_opt("textDocument/completion", () => { `); let items = await querySignatureHelp(Types.Position.create(2, 15)); - expect(items).toMatchObject({ - signatures: [ - { - label: "mem : 'a -> set:'a list -> bool", - parameters: [ - { - label: [6, 8], - }, - { - label: [12, 23], - }, + expect(items).toMatchInlineSnapshot(` +Object { + "activeParameter": 1, + "activeSignature": 0, + "signatures": Array [ + Object { + "label": "mem : 'a -> set:'a list -> bool", + "parameters": Array [ + Object { + "label": Array [ + 6, + 8, + ], + }, + Object { + "label": Array [ + 12, + 23, ], }, ], - activeSignature: 0, - activeParameter: 1, - }); + }, + ], +} +`); }); it("can make an optional parameter active by prefix", async () => { @@ -222,23 +267,31 @@ describe_opt("textDocument/completion", () => { `); let items = await querySignatureHelp(Types.Position.create(2, 18)); - expect(items).toMatchObject({ - signatures: [ - { - label: "create : ?random:bool -> int -> ('a, 'b) Hashtbl.t", - parameters: [ - { - label: [9, 21], - }, - { - label: [25, 28], - }, + expect(items).toMatchInlineSnapshot(` +Object { + "activeParameter": 0, + "activeSignature": 0, + "signatures": Array [ + Object { + "label": "create : ?random:bool -> int -> ('a, 'b) Hashtbl.t", + "parameters": Array [ + Object { + "label": Array [ + 9, + 21, + ], + }, + Object { + "label": Array [ + 25, + 28, ], }, ], - activeSignature: 0, - activeParameter: 0, - }); + }, + ], +} +`); }); it("can return documentation for the function being applied", async () => { @@ -247,32 +300,32 @@ describe_opt("textDocument/completion", () => { (** This is an example of a docstring that demonstrates various ocamldoc syntax features. {3 Sections and Labels} - + We can create sections using {3 Section title} and labels using {3:label_name Section title with label} - + {3 Links and Cross-references} - + External links: {{:https://ocaml.org/} OCaml's official website} - + Cross-references: {!List.length} {{!List.length} Replacement text} - + {3 Inline Formatting} - + {b Bold}, {i Italic}, {e Emphasize}, {^ Superscript}, {_ Subscript}, and [inline code] - + {3 Text Alignment} - + {C Centered text} {L Left-aligned text} {R Right-aligned text} - + {3 Lists} - + {ol {- Ordered list item 1} {- Ordered list item 2} } - + {ul {- Unordered list item 1} {- Unordered list item 2} @@ -282,7 +335,7 @@ describe_opt("textDocument/completion", () => { - Unordered list item 2 {3 Code Blocks} - + {[ let square x = x * x let result = square 3 @@ -292,18 +345,18 @@ describe_opt("textDocument/completion", () => { def f(): return 0 ]} - + {3 Verbatim} - + {v This text will be displayed verbatim. No formatting will be applied. v} - + {3 Module List} - + {!modules: Array List String} - + @param x dividend @param divisor @@ -328,119 +381,126 @@ describe_opt("textDocument/completion", () => { ); let items = await querySignatureHelp(Types.Position.create(80, 13)); - expect(items).toMatchObject({ - activeSignature: 0, - activeParameter: 0, - signatures: [ - { - label: "div : int -> int -> int", - parameters: [ - { - label: [6, 9], - }, - { - label: [13, 16], - }, + expect(items).toMatchInlineSnapshot(` +Object { + "activeParameter": 0, + "activeSignature": 0, + "signatures": Array [ + Object { + "documentation": Object { + "kind": "markdown", + "value": "This is an example of a docstring that demonstrates various ocamldoc syntax features. + +#### Sections and Labels + +We can create sections using + +#### Section title + +and labels using + +#### Section title with label + +#### Links and Cross-references + +External links: [OCaml's official website](https://ocaml.org/) + +Cross-references: \`List.length\` Replacement text + +#### Inline Formatting + +**Bold**, *Italic*, *Emphasize*, ^{Superscript}, \\\\_{Subscript}, and \`inline code\` + +#### Text Alignment + +Centered text + +Left-aligned text + +Right-aligned text + +#### Lists + +1. Ordered list item 1 +2. Ordered list item 2 + +- Unordered list item 1 +- Unordered list item 2 + +- Unordered list item 1 +- Unordered list item 2 + +#### Code Blocks + +\`\`\`ocaml +let square x = x * x +let result = square 3 +\`\`\` + +\`\`\`python +def f(): + return 0 +\`\`\` + +#### Verbatim + +\`\`\`verb + This text will be displayed verbatim. + No formatting will be applied. +\`\`\` + +#### Module List + +* Array +* List +* String + +***@param*** \`x\` +dividend + +***@param*** divisor + +***@return*** +*quotient*, i.e. result of division + +***@raise*** \`Division_by_zero\` +raised when divided by zero + +***@see*** [link](https://en.wikipedia.org/wiki/Arithmetic#Division_\\\\(%C3%B7,_or_/\\\\)) +article + +***@see*** \`arithmetic.ml\` +for more context + +***@since*** \`4.0.0\` + +***@before*** \`4.4.0\` + +***@deprecated*** +use \`(/)\` + +***@version*** \`1.0.0\` + +***@author*** John Doe", + }, + "label": "div : int -> int -> int", + "parameters": Array [ + Object { + "label": Array [ + 6, + 9, + ], + }, + Object { + "label": Array [ + 13, + 16, ], - documentation: { - kind: "markdown", - value: outdent`This is an example of a docstring that demonstrates various ocamldoc syntax features. - - #### Sections and Labels - - We can create sections using - - #### Section title - - and labels using - - #### Section title with label - - #### Links and Cross-references - - External links: [OCaml's official website](https://ocaml.org/) - - Cross-references: \`List.length\` Replacement text - - #### Inline Formatting - - **Bold**, *Italic*, *Emphasize*, ^{Superscript}, \\_{Subscript}, and \`inline code\` - - #### Text Alignment - - Centered text - - Left-aligned text - - Right-aligned text - - #### Lists - - 1. Ordered list item 1 - 2. Ordered list item 2 - - - Unordered list item 1 - - Unordered list item 2 - - - Unordered list item 1 - - Unordered list item 2 - - #### Code Blocks - - \`\`\`ocaml - let square x = x * x - let result = square 3 - \`\`\` - - \`\`\`python - def f(): - return 0 - \`\`\` - - #### Verbatim - - \`\`\`verb - This text will be displayed verbatim. - No formatting will be applied. - \`\`\` - - #### Module List - - * Array - * List - * String - - ***@param*** \`x\` - dividend - - ***@param*** divisor - - ***@return*** - *quotient*, i.e. result of division - - ***@raise*** \`Division_by_zero\` - raised when divided by zero - - ***@see*** [link](https://en.wikipedia.org/wiki/Arithmetic#Division_\\(%C3%B7,_or_/\\)) - article - - ***@see*** \`arithmetic.ml\` - for more context - - ***@since*** \`4.0.0\` - - ***@before*** \`4.4.0\` - - ***@deprecated*** - use \`(/)\` - - ***@version*** \`1.0.0\` - - ***@author*** John Doe - `, - }, }, ], - }); + }, + ], +} +`); }); }); diff --git a/ocaml-lsp-server/test/e2e/__tests__/textDocument-typeDefinition.test.ts b/ocaml-lsp-server/test/e2e/__tests__/textDocument-typeDefinition.test.ts index 8ba405960..43f4746b3 100644 --- a/ocaml-lsp-server/test/e2e/__tests__/textDocument-typeDefinition.test.ts +++ b/ocaml-lsp-server/test/e2e/__tests__/textDocument-typeDefinition.test.ts @@ -59,10 +59,18 @@ describe("textDocument/definition", () => { let result = await queryDefinition(Types.Position.create(3, 4)); expect(result.length).toBe(1); - expect(result[0].range).toMatchObject({ - end: { character: 0, line: 1 }, - start: { character: 0, line: 1 }, - }); + expect(result[0].range).toMatchInlineSnapshot(` +Object { + "end": Object { + "character": 0, + "line": 1, + }, + "start": Object { + "character": 0, + "line": 1, + }, +} +`); expect(result[0].uri).toEqualUri(testUri("file.ml")); }); @@ -78,10 +86,18 @@ describe("textDocument/definition", () => { let result = await queryDefinition(Types.Position.create(4, 4)); expect(result.length).toBe(1); - expect(result[0].range).toMatchObject({ - end: { character: 0, line: 1 }, - start: { character: 0, line: 1 }, - }); + expect(result[0].range).toMatchInlineSnapshot(` +Object { + "end": Object { + "character": 0, + "line": 1, + }, + "start": Object { + "character": 0, + "line": 1, + }, +} +`); expect(result[0].uri).toEqualUri(testUri("file.ml")); }); @@ -96,10 +112,18 @@ describe("textDocument/definition", () => { let result = await queryDefinition(Types.Position.create(3, 4)); expect(result.length).toBe(1); - expect(result[0].range).toMatchObject({ - end: { character: 0, line: 1 }, - start: { character: 0, line: 1 }, - }); + expect(result[0].range).toMatchInlineSnapshot(` +Object { + "end": Object { + "character": 0, + "line": 1, + }, + "start": Object { + "character": 0, + "line": 1, + }, +} +`); expect(result[0].uri).toEqualUri(testUri("file.ml")); }); }); diff --git a/ocaml-lsp-server/test/e2e/package.json b/ocaml-lsp-server/test/e2e/package.json index 2f9a908cf..878c1c8cd 100644 --- a/ocaml-lsp-server/test/e2e/package.json +++ b/ocaml-lsp-server/test/e2e/package.json @@ -2,8 +2,6 @@ "name": "ocaml-lsp", "private": true, "scripts": { - "fmt-check": "prettier --check .", - "fmt": "prettier --write .", "test": "jest", "promote": "jest --updateSnapshot" }, @@ -15,7 +13,6 @@ "@types/jest": "28.1.3", "@types/node": "^20.14.2", "jest": "28.1.1", - "prettier": "3.3.2", "ts-jest": "28.0.5", "typescript": "5.4.5", "vscode-jsonrpc": "8.0.1", diff --git a/ocaml-lsp-server/test/e2e/yarn.lock b/ocaml-lsp-server/test/e2e/yarn.lock index ee3c18986..073d49476 100644 --- a/ocaml-lsp-server/test/e2e/yarn.lock +++ b/ocaml-lsp-server/test/e2e/yarn.lock @@ -1832,11 +1832,6 @@ pkg-dir@^4.2.0: dependencies: find-up "^4.0.0" -prettier@3.3.2: - version "3.3.2" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.3.2.tgz#03ff86dc7c835f2d2559ee76876a3914cec4a90a" - integrity sha512-rAVeHYMcv8ATV5d508CFdn+8/pHPpXeIid1DdrPwXnaAdH7cqjVbpJaT5eq4yRAFU/lsbwYwSF/n5iNrdJHPQA== - pretty-format@^28.0.0, pretty-format@^28.1.3: version "28.1.3" resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-28.1.3.tgz#c9fba8cedf99ce50963a11b27d982a9ae90970d5"