Skip to content

Commit c0fd17f

Browse files
authored
Update analysis metadata and Markdown navigation links (#9031)
* Update analysis metadata and Markdown navigation links Why: Extract the editor-facing analysis changes from the LSP branch without depending on the new server. Identify syntax diagnostics consistently and remove the VSCode-specific navigation command. Representation modified (code action document version): Before (text): "version": null After (text): "version": 0 Diagnostic modified (syntax diagnostic source): Before (text): No source field After (text): "source": "ReScript" Format modified (definition links in Markdown): Before (text): command:rescript-vscode.go_to_location?... After (text): file:///workspace/Test.res#L5,8 Review: Does version zero represent every open document? No. This extraction preserves the LSP branch's fixed version zero. Clients may reject edits when their document version has advanced. Add serialization and URI regression tests and refresh only snapshots affected by the diagnostic source and one-based navigation fragments. Signed-off-by: Pedro Castro <aspeddro@gmail.com> * remove test Signed-off-by: Pedro Castro <aspeddro@gmail.com> * remove deadcode Signed-off-by: Pedro Castro <aspeddro@gmail.com> --------- Signed-off-by: Pedro Castro <aspeddro@gmail.com>
1 parent 533bff8 commit c0fd17f

15 files changed

Lines changed: 52 additions & 83 deletions

‎analysis/src/code_actions.ml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
let make ~title ~kind ~uri ~new_text ~range =
44
let text_document =
5-
Lsp.Types.OptionalVersionedTextDocumentIdentifier.create
5+
Lsp.Types.OptionalVersionedTextDocumentIdentifier.create ~version:0
66
~uri:(Uri.from_string uri) ()
77
in
88
let edit =

‎analysis/src/diagnostics.ml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ let document_syntax ~source ~kind_file =
1616
~end_:
1717
(Lsp.Types.Position.create ~line:(endline - 1) ~character:endcol)
1818
in
19-
Lsp.Types.Diagnostic.create ~range
19+
Lsp.Types.Diagnostic.create ~range ~source:"ReScript"
2020
~message:(`String (Res_diagnostics.explain diagnostic))
2121
~severity:Lsp.Types.DiagnosticSeverity.Error ())
2222
in

‎analysis/src/markdown.ml‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@ let divider = "\n---\n"
44

55
type link = {start_pos: Lsp.Types.Position.t; file: string; label: string}
66

7-
let link_to_command_args link =
8-
Printf.sprintf "[\"%s\",%i,%i]" link.file link.start_pos.line
9-
link.start_pos.character
10-
117
let make_goto_command link =
12-
Printf.sprintf "[%s](command:rescript-vscode.go_to_location?%s)" link.label
13-
(Uri.encode_uri_component (link_to_command_args link))
8+
Printf.sprintf "[%s](%s#L%d,%d)" link.label link.file (link.start_pos.line + 1)
9+
(link.start_pos.character + 1)
1410

1511
let go_to_definition_text ~env ~pos =
1612
let start_line, start_col = Pos.of_lexing pos in

‎analysis/src/uri.ml‎

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,3 @@ let to_top_level_loc (uri : Lsp.Uri.t) =
2424
let to_string t =
2525
if !strip_path then Filename.basename (Lsp.Uri.to_path t)
2626
else Lsp.Uri.to_string t
27-
28-
(* Light weight, hopefully-enough-for-the-purpose fn to encode URI components.
29-
Built to handle the reserved characters listed in
30-
https://en.wikipedia.org/wiki/Percent-encoding. Note that this function is not
31-
general purpose, rather it's currently only for URL encoding the argument list
32-
passed to command links in markdown. *)
33-
let encode_uri_component text =
34-
let ln = String.length text in
35-
let buf = Buffer.create ln in
36-
let rec loop i =
37-
if i < ln then (
38-
(match text.[i] with
39-
| '"' -> Buffer.add_string buf "%22"
40-
| '\'' -> Buffer.add_string buf "%22"
41-
| ':' -> Buffer.add_string buf "%3A"
42-
| ';' -> Buffer.add_string buf "%3B"
43-
| '/' -> Buffer.add_string buf "%2F"
44-
| '\\' -> Buffer.add_string buf "%5C"
45-
| ',' -> Buffer.add_string buf "%2C"
46-
| '&' -> Buffer.add_string buf "%26"
47-
| '[' -> Buffer.add_string buf "%5B"
48-
| ']' -> Buffer.add_string buf "%5D"
49-
| '#' -> Buffer.add_string buf "%23"
50-
| '$' -> Buffer.add_string buf "%24"
51-
| '+' -> Buffer.add_string buf "%2B"
52-
| '=' -> Buffer.add_string buf "%3D"
53-
| '?' -> Buffer.add_string buf "%3F"
54-
| '@' -> Buffer.add_string buf "%40"
55-
| '%' -> Buffer.add_string buf "%25"
56-
| c -> Buffer.add_char buf c);
57-
loop (i + 1))
58-
in
59-
loop 0;
60-
Buffer.contents buf
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- Label syntax diagnostics with `ReScript` as their source.
2+
- Use file URI links with one-based line and column fragments in analysis Markdown
3+
instead of the VSCode-specific navigation command.
4+
- Include document version `0` in analysis-generated code action edits.

‎tests/analysis_tests/tests/not_compiled/expected/Diagnostics.res.txt‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,26 @@
55
"end": { "character": 6, "line": 2 },
66
"start": { "character": 4, "line": 2 }
77
},
8-
"severity": 1
8+
"severity": 1,
9+
"source": "ReScript"
910
},
1011
{
1112
"message": "This let-binding misses an expression",
1213
"range": {
1314
"end": { "character": 11, "line": 1 },
1415
"start": { "character": 9, "line": 1 }
1516
},
16-
"severity": 1
17+
"severity": 1,
18+
"source": "ReScript"
1719
},
1820
{
1921
"message": "I was expecting a name for this let-binding. Example: `let message = \"hello\"`",
2022
"range": {
2123
"end": { "character": 5, "line": 0 },
2224
"start": { "character": 4, "line": 0 }
2325
},
24-
"severity": 1
26+
"severity": 1,
27+
"source": "ReScript"
2528
}
2629
]
2730

‎tests/analysis_tests/tests/src/expected/Completion.res.txt‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎tests/analysis_tests/tests/src/expected/Fragment.res.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ Hover src/Fragment.res 6:19
22
{
33
"contents": {
44
"kind": "markdown",
5-
"value": "```rescript\nReact.component<SectionHeader.props<React.element>>\n```\n\n---\n\n```\n \n```\n```rescript\ntype React.component<'props> = Jsx.component<'props>\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22React.res%22%2C13%2C0%5D)\n\n\n---\n\n```\n \n```\n```rescript\ntype SectionHeader.props<'children> = {children: 'children}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Fragment.res%22%2C1%2C2%5D)\n\n\n---\n\n```\n \n```\n```rescript\ntype React.element = Jsx.element\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22React.res%22%2C0%2C0%5D)\n"
5+
"value": "```rescript\nReact.component<SectionHeader.props<React.element>>\n```\n\n---\n\n```\n \n```\n```rescript\ntype React.component<'props> = Jsx.component<'props>\n```\nGo to: [Type definition](React.res#L14,1)\n\n\n---\n\n```\n \n```\n```rescript\ntype SectionHeader.props<'children> = {children: 'children}\n```\nGo to: [Type definition](Fragment.res#L2,3)\n\n\n---\n\n```\n \n```\n```rescript\ntype React.element = Jsx.element\n```\nGo to: [Type definition](React.res#L1,1)\n"
66
}
77
}
88

99
Hover src/Fragment.res 9:56
1010
{
1111
"contents": {
1212
"kind": "markdown",
13-
"value": "```rescript\nReact.component<React.fragmentProps>\n```\n\n---\n\n```\n \n```\n```rescript\ntype React.component<'props> = Jsx.component<'props>\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22React.res%22%2C13%2C0%5D)\n\n\n---\n\n```\n \n```\n```rescript\ntype React.fragmentProps = {children?: element}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22React.res%22%2C42%2C0%5D)\n"
13+
"value": "```rescript\nReact.component<React.fragmentProps>\n```\n\n---\n\n```\n \n```\n```rescript\ntype React.component<'props> = Jsx.component<'props>\n```\nGo to: [Type definition](React.res#L14,1)\n\n\n---\n\n```\n \n```\n```rescript\ntype React.fragmentProps = {children?: element}\n```\nGo to: [Type definition](React.res#L43,1)\n"
1414
}
1515
}
1616

‎tests/analysis_tests/tests/src/expected/Hover.res.txt‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,15 @@ Hover src/Hover.res 116:16
126126
{
127127
"contents": {
128128
"kind": "markdown",
129-
"value": "```rescript\nAA.cond<([< #str(string)] as 'a)> => AA.cond<'a>\n```\n\n---\n\n```\n \n```\n```rescript\ntype AA.cond<'a> = 'a\n constraint 'a = [< #str(string)]\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C110%2C2%5D)\n"
129+
"value": "```rescript\nAA.cond<([< #str(string)] as 'a)> => AA.cond<'a>\n```\n\n---\n\n```\n \n```\n```rescript\ntype AA.cond<'a> = 'a\n constraint 'a = [< #str(string)]\n```\nGo to: [Type definition](Hover.res#L111,3)\n"
130130
}
131131
}
132132

133133
Hover src/Hover.res 119:25
134134
{
135135
"contents": {
136136
"kind": "markdown",
137-
"value": "```rescript\nAA.cond<([< #str(string)] as 'a)> => AA.cond<'a>\n```\n\n---\n\n```\n \n```\n```rescript\ntype AA.cond<'a> = 'a\n constraint 'a = [< #str(string)]\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C110%2C2%5D)\n"
137+
"value": "```rescript\nAA.cond<([< #str(string)] as 'a)> => AA.cond<'a>\n```\n\n---\n\n```\n \n```\n```rescript\ntype AA.cond<'a> = 'a\n constraint 'a = [< #str(string)]\n```\nGo to: [Type definition](Hover.res#L111,3)\n"
138138
}
139139
}
140140

@@ -203,15 +203,15 @@ Hover src/Hover.res 165:23
203203
{
204204
"contents": {
205205
"kind": "markdown",
206-
"value": "```rescript\nfoo<bar>\n```\n\n---\n\n```\n \n```\n```rescript\ntype foo<'a> = {content: 'a, zzz: string}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C161%2C2%5D)\n\n\n---\n\n```\n \n```\n```rescript\ntype bar = {age: int}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C162%2C2%5D)\n"
206+
"value": "```rescript\nfoo<bar>\n```\n\n---\n\n```\n \n```\n```rescript\ntype foo<'a> = {content: 'a, zzz: string}\n```\nGo to: [Type definition](Hover.res#L162,3)\n\n\n---\n\n```\n \n```\n```rescript\ntype bar = {age: int}\n```\nGo to: [Type definition](Hover.res#L163,3)\n"
207207
}
208208
}
209209

210210
Hover src/Hover.res 167:22
211211
{
212212
"contents": {
213213
"kind": "markdown",
214-
"value": "```rescript\nfoobar\n```\n\n---\n\n```\n \n```\n```rescript\ntype foobar = foo<bar>\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C163%2C2%5D)\n"
214+
"value": "```rescript\nfoobar\n```\n\n---\n\n```\n \n```\n```rescript\ntype foobar = foo<bar>\n```\nGo to: [Type definition](Hover.res#L164,3)\n"
215215
}
216216
}
217217

@@ -387,15 +387,15 @@ Hover src/Hover.res 197:4
387387
{
388388
"contents": {
389389
"kind": "markdown",
390-
"value": "```rescript\nCompV4.props<int, string> => React.element\n```\n\n---\n\n```\n \n```\n```rescript\ntype CompV4.props<'n, 's> = {n?: 'n, s: 's}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C190%2C2%5D)\n\n\n---\n\n```\n \n```\n```rescript\ntype React.element = Jsx.element\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22React.res%22%2C0%2C0%5D)\n"
390+
"value": "```rescript\nCompV4.props<int, string> => React.element\n```\n\n---\n\n```\n \n```\n```rescript\ntype CompV4.props<'n, 's> = {n?: 'n, s: 's}\n```\nGo to: [Type definition](Hover.res#L191,3)\n\n\n---\n\n```\n \n```\n```rescript\ntype React.element = Jsx.element\n```\nGo to: [Type definition](React.res#L1,1)\n"
391391
}
392392
}
393393

394394
Hover src/Hover.res 202:16
395395
{
396396
"contents": {
397397
"kind": "markdown",
398-
"value": "```rescript\nuseR\n```\n\n---\n\n```\n \n```\n```rescript\ntype useR = {x: int, y: list<option<r<float>>>}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C200%2C0%5D)\n\n\n---\n\n```\n \n```\n```rescript\ntype r<'a> = {i: 'a, f: float}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C101%2C0%5D)\n"
398+
"value": "```rescript\nuseR\n```\n\n---\n\n```\n \n```\n```rescript\ntype useR = {x: int, y: list<option<r<float>>>}\n```\nGo to: [Type definition](Hover.res#L201,1)\n\n\n---\n\n```\n \n```\n```rescript\ntype r<'a> = {i: 'a, f: float}\n```\nGo to: [Type definition](Hover.res#L102,1)\n"
399399
}
400400
}
401401

@@ -413,7 +413,7 @@ Resolved opens 1 Stdlib
413413
{
414414
"contents": {
415415
"kind": "markdown",
416-
"value": "```rescript\nuseR\n```\n\n---\n\n```\n \n```\n```rescript\ntype useR = {x: int, y: list<option<r<float>>>}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C200%2C0%5D)\n\n\n---\n\n```\n \n```\n```rescript\ntype r<'a> = {i: 'a, f: float}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C101%2C0%5D)\n"
416+
"value": "```rescript\nuseR\n```\n\n---\n\n```\n \n```\n```rescript\ntype useR = {x: int, y: list<option<r<float>>>}\n```\nGo to: [Type definition](Hover.res#L201,1)\n\n\n---\n\n```\n \n```\n```rescript\ntype r<'a> = {i: 'a, f: float}\n```\nGo to: [Type definition](Hover.res#L102,1)\n"
417417
}
418418
}
419419

@@ -470,31 +470,31 @@ Hover src/Hover.res 253:20
470470
{
471471
"contents": {
472472
"kind": "markdown",
473-
"value": "```rescript\nvariant\nCoolVariant\n```\n---\n Cool variant! \n\n---\n\n```\n \n```\n```rescript\ntype variant = CoolVariant | OtherCoolVariant\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C251%2C0%5D)\n"
473+
"value": "```rescript\nvariant\nCoolVariant\n```\n---\n Cool variant! \n\n---\n\n```\n \n```\n```rescript\ntype variant = CoolVariant | OtherCoolVariant\n```\nGo to: [Type definition](Hover.res#L252,1)\n"
474474
}
475475
}
476476

477477
Hover src/Hover.res 258:22
478478
{
479479
"contents": {
480480
"kind": "markdown",
481-
"value": "```rescript\npayloadVariants\nInlineRecord({field1: int, field2: bool})\n```\n\n---\n\n```\n \n```\n```rescript\ntype payloadVariants =\n | InlineRecord({field1: int, field2: bool})\n | Args(int, bool)\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C256%2C0%5D)\n"
481+
"value": "```rescript\npayloadVariants\nInlineRecord({field1: int, field2: bool})\n```\n\n---\n\n```\n \n```\n```rescript\ntype payloadVariants =\n | InlineRecord({field1: int, field2: bool})\n | Args(int, bool)\n```\nGo to: [Type definition](Hover.res#L257,1)\n"
482482
}
483483
}
484484

485485
Hover src/Hover.res 261:23
486486
{
487487
"contents": {
488488
"kind": "markdown",
489-
"value": "```rescript\npayloadVariants\nArgs(int, bool)\n```\n\n---\n\n```\n \n```\n```rescript\ntype payloadVariants =\n | InlineRecord({field1: int, field2: bool})\n | Args(int, bool)\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C256%2C0%5D)\n"
489+
"value": "```rescript\npayloadVariants\nArgs(int, bool)\n```\n\n---\n\n```\n \n```\n```rescript\ntype payloadVariants =\n | InlineRecord({field1: int, field2: bool})\n | Args(int, bool)\n```\nGo to: [Type definition](Hover.res#L257,1)\n"
490490
}
491491
}
492492

493493
Hover src/Hover.res 268:42
494494
{
495495
"contents": {
496496
"kind": "markdown",
497-
"value": "```rescript\nRecursiveVariants.t\nAction1(int)\n```\n\n---\n\n```\n \n```\n```rescript\ntype RecursiveVariants.t =\n | Action1(int)\n | Action2(float)\n | Batch(array<t>)\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C265%2C2%5D)\n"
497+
"value": "```rescript\nRecursiveVariants.t\nAction1(int)\n```\n\n---\n\n```\n \n```\n```rescript\ntype RecursiveVariants.t =\n | Action1(int)\n | Action2(float)\n | Batch(array<t>)\n```\nGo to: [Type definition](Hover.res#L266,3)\n"
498498
}
499499
}
500500

@@ -540,7 +540,7 @@ Hover src/Hover.res 281:6
540540
{
541541
"contents": {
542542
"kind": "markdown",
543-
"value": "```rescript\ntype aliased = variant\n```\n\n---\n\n```\n \n```\n```rescript\ntype variant = CoolVariant | OtherCoolVariant\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C251%2C0%5D)\n"
543+
"value": "```rescript\ntype aliased = variant\n```\n\n---\n\n```\n \n```\n```rescript\ntype variant = CoolVariant | OtherCoolVariant\n```\nGo to: [Type definition](Hover.res#L252,1)\n"
544544
}
545545
}
546546

‎tests/analysis_tests/tests/src/expected/Jsx2.res.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,15 +396,15 @@ Hover src/Jsx2.res 162:12
396396
{
397397
"contents": {
398398
"kind": "markdown",
399-
"value": "```rescript\nComp.props<int>\n```\n\n---\n\n```\n \n```\n```rescript\ntype Comp.props<'age> = {age: 'age}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Jsx2.res%22%2C157%2C2%5D)\n"
399+
"value": "```rescript\nComp.props<int>\n```\n\n---\n\n```\n \n```\n```rescript\ntype Comp.props<'age> = {age: 'age}\n```\nGo to: [Type definition](Jsx2.res#L158,3)\n"
400400
}
401401
}
402402

403403
Hover src/Jsx2.res 167:16
404404
{
405405
"contents": {
406406
"kind": "markdown",
407-
"value": "```rescript\nComp.props<int>\n```\n\n---\n\n```\n \n```\n```rescript\ntype Comp.props<'age> = {age: 'age}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Jsx2.res%22%2C157%2C2%5D)\n"
407+
"value": "```rescript\nComp.props<int>\n```\n\n---\n\n```\n \n```\n```rescript\ntype Comp.props<'age> = {age: 'age}\n```\nGo to: [Type definition](Jsx2.res#L158,3)\n"
408408
}
409409
}
410410

0 commit comments

Comments
 (0)