From fda4be446ddef0de75b6629fc1075cafd2aa3046 Mon Sep 17 00:00:00 2001 From: Aurelien Saue Date: Tue, 18 Jul 2023 18:25:29 +0200 Subject: [PATCH 1/5] Display text of references --- ocaml-lsp-server/src/doc_to_md.ml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ocaml-lsp-server/src/doc_to_md.ml b/ocaml-lsp-server/src/doc_to_md.ml index a2a80a5d6..65d6101aa 100644 --- a/ocaml-lsp-server/src/doc_to_md.ml +++ b/ocaml-lsp-server/src/doc_to_md.ml @@ -61,9 +61,13 @@ let rec inline_element_to_inline let text = inline_element_list_to_inlines inlines in let meta = loc_to_meta location in style_inline ~meta style text - | { value = `Reference (_kind, _ref, _inlines); location = _location } -> + | { value = `Reference (kind, ref, inlines); location } -> (* TODO: add support for references *) - Inline.Break (Inline.Break.make `Hard, Meta.none) + let meta = loc_to_meta location in + begin match kind with + | `Simple -> Inline.Code_span (Inline.Code_span.of_string ref.value, meta) + | `With_text -> inline_element_list_to_inlines inlines + end | { value = `Link (link, inlines); location } -> let text = inline_element_list_to_inlines inlines in let ref = @@ -86,7 +90,7 @@ and inline_element_list_to_inlines inlines = let rec nestable_block_element_to_block (nestable : - Odoc_parser.Ast.nestable_block_element Odoc_parser.Loc.with_location) = + Odoc_parser.Ast.nestable_block_element Odoc_parser.Loc.with_location) = match nestable with | { value = `Paragraph text; location } -> let inline = inline_element_list_to_inlines text in From 1180a9da515ce99489ffcf168b4ba784eedc3b23 Mon Sep 17 00:00:00 2001 From: Aurelien Saue Date: Tue, 18 Jul 2023 18:36:28 +0200 Subject: [PATCH 2/5] update CHANGES.md --- CHANGES.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 5327552d9..c5a4cbd03 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,9 @@ +# Unreleased + +## Features + +- Display text of references in doc strings (#1166) + # 1.16.2 ## Fixes From c32a7d2a1644b54cec660662a2243d01ae0552c6 Mon Sep 17 00:00:00 2001 From: Aurelien Saue Date: Tue, 18 Jul 2023 18:39:27 +0200 Subject: [PATCH 3/5] Fix spacing --- ocaml-lsp-server/src/doc_to_md.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocaml-lsp-server/src/doc_to_md.ml b/ocaml-lsp-server/src/doc_to_md.ml index 65d6101aa..186841c3f 100644 --- a/ocaml-lsp-server/src/doc_to_md.ml +++ b/ocaml-lsp-server/src/doc_to_md.ml @@ -90,7 +90,7 @@ and inline_element_list_to_inlines inlines = let rec nestable_block_element_to_block (nestable : - Odoc_parser.Ast.nestable_block_element Odoc_parser.Loc.with_location) = + Odoc_parser.Ast.nestable_block_element Odoc_parser.Loc.with_location) = match nestable with | { value = `Paragraph text; location } -> let inline = inline_element_list_to_inlines text in From e2b86dd6d95e92e934aba4e665d65d7bf1d95354 Mon Sep 17 00:00:00 2001 From: Aurelien Saue Date: Tue, 18 Jul 2023 19:16:12 +0200 Subject: [PATCH 4/5] Add demo test --- .../test/e2e/__tests__/textDocument-signatureHelp.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ocaml-lsp-server/test/e2e/__tests__/textDocument-signatureHelp.ts b/ocaml-lsp-server/test/e2e/__tests__/textDocument-signatureHelp.ts index 80c598a69..97ffa66b5 100644 --- a/ocaml-lsp-server/test/e2e/__tests__/textDocument-signatureHelp.ts +++ b/ocaml-lsp-server/test/e2e/__tests__/textDocument-signatureHelp.ts @@ -254,6 +254,8 @@ describe_opt("textDocument/completion", () => { 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] @@ -358,6 +360,8 @@ describe_opt("textDocument/completion", () => { 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\` From a0ef15496241fd6285fa04ddfe171f60542f2e39 Mon Sep 17 00:00:00 2001 From: Aurelien Saue Date: Wed, 19 Jul 2023 17:28:59 +0200 Subject: [PATCH 5/5] formatting --- ocaml-lsp-server/src/doc_to_md.ml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ocaml-lsp-server/src/doc_to_md.ml b/ocaml-lsp-server/src/doc_to_md.ml index 186841c3f..1e2880105 100644 --- a/ocaml-lsp-server/src/doc_to_md.ml +++ b/ocaml-lsp-server/src/doc_to_md.ml @@ -61,13 +61,12 @@ let rec inline_element_to_inline let text = inline_element_list_to_inlines inlines in let meta = loc_to_meta location in style_inline ~meta style text - | { value = `Reference (kind, ref, inlines); location } -> + | { value = `Reference (kind, ref, inlines); location } -> ( (* TODO: add support for references *) let meta = loc_to_meta location in - begin match kind with - | `Simple -> Inline.Code_span (Inline.Code_span.of_string ref.value, meta) - | `With_text -> inline_element_list_to_inlines inlines - end + match kind with + | `Simple -> Inline.Code_span (Inline.Code_span.of_string ref.value, meta) + | `With_text -> inline_element_list_to_inlines inlines) | { value = `Link (link, inlines); location } -> let text = inline_element_list_to_inlines inlines in let ref =