From 8807ffa7280a5a653068919c35d73abe2e397e17 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Tue, 31 Jan 2023 18:30:35 +0100 Subject: [PATCH 1/5] add failing test --- analysis/tests/src/CompletionJsx.res | 2 + .../tests/src/expected/CompletionJsx.res.txt | 220 ++++++++++-------- 2 files changed, 123 insertions(+), 99 deletions(-) diff --git a/analysis/tests/src/CompletionJsx.res b/analysis/tests/src/CompletionJsx.res index df43305ae..38014c8ed 100644 --- a/analysis/tests/src/CompletionJsx.res +++ b/analysis/tests/src/CompletionJsx.res @@ -28,6 +28,8 @@ module SomeComponent = { // ^com // {someArr->a} // ^com + // } } diff --git a/analysis/tests/src/expected/CompletionJsx.res.txt b/analysis/tests/src/expected/CompletionJsx.res.txt index 9bd380aab..9893ba6d6 100644 --- a/analysis/tests/src/expected/CompletionJsx.res.txt +++ b/analysis/tests/src/expected/CompletionJsx.res.txt @@ -16,12 +16,12 @@ Completable: Cpath Value[someString]->st }] Complete src/CompletionJsx.res 13:21 -posCursor:[13:21] posNoWhite:[13:20] Found expr:[8:13->31:3] -posCursor:[13:21] posNoWhite:[13:20] Found expr:[9:4->30:10] -posCursor:[13:21] posNoWhite:[13:20] Found expr:[10:4->30:10] -posCursor:[13:21] posNoWhite:[13:20] Found expr:[11:4->30:10] -posCursor:[13:21] posNoWhite:[13:20] Found expr:[12:4->30:10] -posCursor:[13:21] posNoWhite:[13:20] Found expr:[13:7->30:10] +posCursor:[13:21] posNoWhite:[13:20] Found expr:[8:13->33:3] +posCursor:[13:21] posNoWhite:[13:20] Found expr:[9:4->32:10] +posCursor:[13:21] posNoWhite:[13:20] Found expr:[10:4->32:10] +posCursor:[13:21] posNoWhite:[13:20] Found expr:[11:4->32:10] +posCursor:[13:21] posNoWhite:[13:20] Found expr:[12:4->32:10] +posCursor:[13:21] posNoWhite:[13:20] Found expr:[13:7->32:10] posCursor:[13:21] posNoWhite:[13:20] Found expr:[13:7->13:21] Completable: Cpath Value[someString]->st <> [{ @@ -47,22 +47,22 @@ Completable: Cpath Value[someString]->st <> }] Complete src/CompletionJsx.res 18:24 -posCursor:[18:24] posNoWhite:[18:23] Found expr:[8:13->31:3] -posCursor:[18:24] posNoWhite:[18:23] Found expr:[9:4->30:10] -posCursor:[18:24] posNoWhite:[18:23] Found expr:[10:4->30:10] -posCursor:[18:24] posNoWhite:[18:23] Found expr:[11:4->30:10] -posCursor:[18:24] posNoWhite:[18:23] Found expr:[12:4->30:10] -posCursor:[18:24] posNoWhite:[18:23] Found expr:[15:5->30:10] +posCursor:[18:24] posNoWhite:[18:23] Found expr:[8:13->33:3] +posCursor:[18:24] posNoWhite:[18:23] Found expr:[9:4->32:10] +posCursor:[18:24] posNoWhite:[18:23] Found expr:[10:4->32:10] +posCursor:[18:24] posNoWhite:[18:23] Found expr:[11:4->32:10] +posCursor:[18:24] posNoWhite:[18:23] Found expr:[12:4->32:10] +posCursor:[18:24] posNoWhite:[18:23] Found expr:[15:5->32:10] JSX 15:8] > _children:15:8 -posCursor:[18:24] posNoWhite:[18:23] Found expr:[15:8->30:4] -Pexp_construct :::[16:7->30:4] [16:7->30:4] -posCursor:[18:24] posNoWhite:[18:23] Found expr:[16:7->30:4] -posCursor:[18:24] posNoWhite:[18:23] Found expr:[17:7->30:4] -Pexp_construct :::[17:7->30:4] [17:7->30:4] -posCursor:[18:24] posNoWhite:[18:23] Found expr:[17:7->30:4] -posCursor:[18:24] posNoWhite:[18:23] Found expr:[18:10->30:4] -Pexp_construct :::[18:10->30:4] [18:10->30:4] -posCursor:[18:24] posNoWhite:[18:23] Found expr:[18:10->30:4] +posCursor:[18:24] posNoWhite:[18:23] Found expr:[15:8->32:4] +Pexp_construct :::[16:7->32:4] [16:7->32:4] +posCursor:[18:24] posNoWhite:[18:23] Found expr:[16:7->32:4] +posCursor:[18:24] posNoWhite:[18:23] Found expr:[17:7->32:4] +Pexp_construct :::[17:7->32:4] [17:7->32:4] +posCursor:[18:24] posNoWhite:[18:23] Found expr:[17:7->32:4] +posCursor:[18:24] posNoWhite:[18:23] Found expr:[18:10->32:4] +Pexp_construct :::[18:10->32:4] [18:10->32:4] +posCursor:[18:24] posNoWhite:[18:23] Found expr:[18:10->32:4] posCursor:[18:24] posNoWhite:[18:23] Found expr:[18:10->18:24] Completable: Cpath Value[someString]->st <> [{ @@ -88,22 +88,22 @@ Completable: Cpath Value[someString]->st <> }] Complete src/CompletionJsx.res 20:27 -posCursor:[20:27] posNoWhite:[20:26] Found expr:[8:13->31:3] -posCursor:[20:27] posNoWhite:[20:26] Found expr:[9:4->30:10] -posCursor:[20:27] posNoWhite:[20:26] Found expr:[10:4->30:10] -posCursor:[20:27] posNoWhite:[20:26] Found expr:[11:4->30:10] -posCursor:[20:27] posNoWhite:[20:26] Found expr:[12:4->30:10] -posCursor:[20:27] posNoWhite:[20:26] Found expr:[15:5->30:10] +posCursor:[20:27] posNoWhite:[20:26] Found expr:[8:13->33:3] +posCursor:[20:27] posNoWhite:[20:26] Found expr:[9:4->32:10] +posCursor:[20:27] posNoWhite:[20:26] Found expr:[10:4->32:10] +posCursor:[20:27] posNoWhite:[20:26] Found expr:[11:4->32:10] +posCursor:[20:27] posNoWhite:[20:26] Found expr:[12:4->32:10] +posCursor:[20:27] posNoWhite:[20:26] Found expr:[15:5->32:10] JSX 15:8] > _children:15:8 -posCursor:[20:27] posNoWhite:[20:26] Found expr:[15:8->30:4] -Pexp_construct :::[16:7->30:4] [16:7->30:4] -posCursor:[20:27] posNoWhite:[20:26] Found expr:[16:7->30:4] -posCursor:[20:27] posNoWhite:[20:26] Found expr:[17:7->30:4] -Pexp_construct :::[17:7->30:4] [17:7->30:4] -posCursor:[20:27] posNoWhite:[20:26] Found expr:[17:7->30:4] -posCursor:[20:27] posNoWhite:[20:26] Found expr:[20:10->30:4] -Pexp_construct :::[20:10->30:4] [20:10->30:4] -posCursor:[20:27] posNoWhite:[20:26] Found expr:[20:10->30:4] +posCursor:[20:27] posNoWhite:[20:26] Found expr:[15:8->32:4] +Pexp_construct :::[16:7->32:4] [16:7->32:4] +posCursor:[20:27] posNoWhite:[20:26] Found expr:[16:7->32:4] +posCursor:[20:27] posNoWhite:[20:26] Found expr:[17:7->32:4] +Pexp_construct :::[17:7->32:4] [17:7->32:4] +posCursor:[20:27] posNoWhite:[20:26] Found expr:[17:7->32:4] +posCursor:[20:27] posNoWhite:[20:26] Found expr:[20:10->32:4] +Pexp_construct :::[20:10->32:4] [20:10->32:4] +posCursor:[20:27] posNoWhite:[20:26] Found expr:[20:10->32:4] posCursor:[20:27] posNoWhite:[20:26] Found expr:[20:10->20:27] Completable: Cpath string->st <> [{ @@ -129,22 +129,22 @@ Completable: Cpath string->st <> }] Complete src/CompletionJsx.res 22:44 -posCursor:[22:44] posNoWhite:[22:43] Found expr:[8:13->31:3] -posCursor:[22:44] posNoWhite:[22:43] Found expr:[9:4->30:10] -posCursor:[22:44] posNoWhite:[22:43] Found expr:[10:4->30:10] -posCursor:[22:44] posNoWhite:[22:43] Found expr:[11:4->30:10] -posCursor:[22:44] posNoWhite:[22:43] Found expr:[12:4->30:10] -posCursor:[22:44] posNoWhite:[22:43] Found expr:[15:5->30:10] +posCursor:[22:44] posNoWhite:[22:43] Found expr:[8:13->33:3] +posCursor:[22:44] posNoWhite:[22:43] Found expr:[9:4->32:10] +posCursor:[22:44] posNoWhite:[22:43] Found expr:[10:4->32:10] +posCursor:[22:44] posNoWhite:[22:43] Found expr:[11:4->32:10] +posCursor:[22:44] posNoWhite:[22:43] Found expr:[12:4->32:10] +posCursor:[22:44] posNoWhite:[22:43] Found expr:[15:5->32:10] JSX 15:8] > _children:15:8 -posCursor:[22:44] posNoWhite:[22:43] Found expr:[15:8->30:4] -Pexp_construct :::[16:7->30:4] [16:7->30:4] -posCursor:[22:44] posNoWhite:[22:43] Found expr:[16:7->30:4] -posCursor:[22:44] posNoWhite:[22:43] Found expr:[17:7->30:4] -Pexp_construct :::[17:7->30:4] [17:7->30:4] -posCursor:[22:44] posNoWhite:[22:43] Found expr:[17:7->30:4] -posCursor:[22:44] posNoWhite:[22:43] Found expr:[22:10->30:4] -Pexp_construct :::[22:10->30:4] [22:10->30:4] -posCursor:[22:44] posNoWhite:[22:43] Found expr:[22:10->30:4] +posCursor:[22:44] posNoWhite:[22:43] Found expr:[15:8->32:4] +Pexp_construct :::[16:7->32:4] [16:7->32:4] +posCursor:[22:44] posNoWhite:[22:43] Found expr:[16:7->32:4] +posCursor:[22:44] posNoWhite:[22:43] Found expr:[17:7->32:4] +Pexp_construct :::[17:7->32:4] [17:7->32:4] +posCursor:[22:44] posNoWhite:[22:43] Found expr:[17:7->32:4] +posCursor:[22:44] posNoWhite:[22:43] Found expr:[22:10->32:4] +Pexp_construct :::[22:10->32:4] [22:10->32:4] +posCursor:[22:44] posNoWhite:[22:43] Found expr:[22:10->32:4] posCursor:[22:44] posNoWhite:[22:43] Found expr:[22:10->22:44] Completable: Cpath Value[Js, String2, trim](Nolabel)->st <> [{ @@ -170,22 +170,22 @@ Completable: Cpath Value[Js, String2, trim](Nolabel)->st <> }] Complete src/CompletionJsx.res 24:19 -posCursor:[24:19] posNoWhite:[24:18] Found expr:[8:13->31:3] -posCursor:[24:19] posNoWhite:[24:18] Found expr:[9:4->30:10] -posCursor:[24:19] posNoWhite:[24:18] Found expr:[10:4->30:10] -posCursor:[24:19] posNoWhite:[24:18] Found expr:[11:4->30:10] -posCursor:[24:19] posNoWhite:[24:18] Found expr:[12:4->30:10] -posCursor:[24:19] posNoWhite:[24:18] Found expr:[15:5->30:10] +posCursor:[24:19] posNoWhite:[24:18] Found expr:[8:13->33:3] +posCursor:[24:19] posNoWhite:[24:18] Found expr:[9:4->32:10] +posCursor:[24:19] posNoWhite:[24:18] Found expr:[10:4->32:10] +posCursor:[24:19] posNoWhite:[24:18] Found expr:[11:4->32:10] +posCursor:[24:19] posNoWhite:[24:18] Found expr:[12:4->32:10] +posCursor:[24:19] posNoWhite:[24:18] Found expr:[15:5->32:10] JSX 15:8] > _children:15:8 -posCursor:[24:19] posNoWhite:[24:18] Found expr:[15:8->30:4] -Pexp_construct :::[16:7->30:4] [16:7->30:4] -posCursor:[24:19] posNoWhite:[24:18] Found expr:[16:7->30:4] -posCursor:[24:19] posNoWhite:[24:18] Found expr:[17:7->30:4] -Pexp_construct :::[17:7->30:4] [17:7->30:4] -posCursor:[24:19] posNoWhite:[24:18] Found expr:[17:7->30:4] -posCursor:[24:19] posNoWhite:[24:18] Found expr:[24:10->30:4] -Pexp_construct :::[24:10->30:4] [24:10->30:4] -posCursor:[24:19] posNoWhite:[24:18] Found expr:[24:10->30:4] +posCursor:[24:19] posNoWhite:[24:18] Found expr:[15:8->32:4] +Pexp_construct :::[16:7->32:4] [16:7->32:4] +posCursor:[24:19] posNoWhite:[24:18] Found expr:[16:7->32:4] +posCursor:[24:19] posNoWhite:[24:18] Found expr:[17:7->32:4] +Pexp_construct :::[17:7->32:4] [17:7->32:4] +posCursor:[24:19] posNoWhite:[24:18] Found expr:[17:7->32:4] +posCursor:[24:19] posNoWhite:[24:18] Found expr:[24:10->32:4] +Pexp_construct :::[24:10->32:4] [24:10->32:4] +posCursor:[24:19] posNoWhite:[24:18] Found expr:[24:10->32:4] posCursor:[24:19] posNoWhite:[24:18] Found expr:[24:10->0:-1] Completable: Cpath Value[someInt]-> <> [{ @@ -247,22 +247,22 @@ Completable: Cpath Value[someInt]-> <> }] Complete src/CompletionJsx.res 26:14 -posCursor:[26:14] posNoWhite:[26:13] Found expr:[8:13->31:3] -posCursor:[26:14] posNoWhite:[26:13] Found expr:[9:4->30:10] -posCursor:[26:14] posNoWhite:[26:13] Found expr:[10:4->30:10] -posCursor:[26:14] posNoWhite:[26:13] Found expr:[11:4->30:10] -posCursor:[26:14] posNoWhite:[26:13] Found expr:[12:4->30:10] -posCursor:[26:14] posNoWhite:[26:13] Found expr:[15:5->30:10] +posCursor:[26:14] posNoWhite:[26:13] Found expr:[8:13->33:3] +posCursor:[26:14] posNoWhite:[26:13] Found expr:[9:4->32:10] +posCursor:[26:14] posNoWhite:[26:13] Found expr:[10:4->32:10] +posCursor:[26:14] posNoWhite:[26:13] Found expr:[11:4->32:10] +posCursor:[26:14] posNoWhite:[26:13] Found expr:[12:4->32:10] +posCursor:[26:14] posNoWhite:[26:13] Found expr:[15:5->32:10] JSX 15:8] > _children:15:8 -posCursor:[26:14] posNoWhite:[26:13] Found expr:[15:8->30:4] -Pexp_construct :::[16:7->30:4] [16:7->30:4] -posCursor:[26:14] posNoWhite:[26:13] Found expr:[16:7->30:4] -posCursor:[26:14] posNoWhite:[26:13] Found expr:[17:7->30:4] -Pexp_construct :::[17:7->30:4] [17:7->30:4] -posCursor:[26:14] posNoWhite:[26:13] Found expr:[17:7->30:4] -posCursor:[26:14] posNoWhite:[26:13] Found expr:[26:10->30:4] -Pexp_construct :::[26:10->30:4] [26:10->30:4] -posCursor:[26:14] posNoWhite:[26:13] Found expr:[26:10->30:4] +posCursor:[26:14] posNoWhite:[26:13] Found expr:[15:8->32:4] +Pexp_construct :::[16:7->32:4] [16:7->32:4] +posCursor:[26:14] posNoWhite:[26:13] Found expr:[16:7->32:4] +posCursor:[26:14] posNoWhite:[26:13] Found expr:[17:7->32:4] +Pexp_construct :::[17:7->32:4] [17:7->32:4] +posCursor:[26:14] posNoWhite:[26:13] Found expr:[17:7->32:4] +posCursor:[26:14] posNoWhite:[26:13] Found expr:[26:10->32:4] +Pexp_construct :::[26:10->32:4] [26:10->32:4] +posCursor:[26:14] posNoWhite:[26:13] Found expr:[26:10->32:4] posCursor:[26:14] posNoWhite:[26:13] Found expr:[26:10->0:-1] Completable: Cpath int-> <> [{ @@ -324,22 +324,22 @@ Completable: Cpath int-> <> }] Complete src/CompletionJsx.res 28:20 -posCursor:[28:20] posNoWhite:[28:19] Found expr:[8:13->31:3] -posCursor:[28:20] posNoWhite:[28:19] Found expr:[9:4->30:10] -posCursor:[28:20] posNoWhite:[28:19] Found expr:[10:4->30:10] -posCursor:[28:20] posNoWhite:[28:19] Found expr:[11:4->30:10] -posCursor:[28:20] posNoWhite:[28:19] Found expr:[12:4->30:10] -posCursor:[28:20] posNoWhite:[28:19] Found expr:[15:5->30:10] +posCursor:[28:20] posNoWhite:[28:19] Found expr:[8:13->33:3] +posCursor:[28:20] posNoWhite:[28:19] Found expr:[9:4->32:10] +posCursor:[28:20] posNoWhite:[28:19] Found expr:[10:4->32:10] +posCursor:[28:20] posNoWhite:[28:19] Found expr:[11:4->32:10] +posCursor:[28:20] posNoWhite:[28:19] Found expr:[12:4->32:10] +posCursor:[28:20] posNoWhite:[28:19] Found expr:[15:5->32:10] JSX 15:8] > _children:15:8 -posCursor:[28:20] posNoWhite:[28:19] Found expr:[15:8->30:4] -Pexp_construct :::[16:7->30:4] [16:7->30:4] -posCursor:[28:20] posNoWhite:[28:19] Found expr:[16:7->30:4] -posCursor:[28:20] posNoWhite:[28:19] Found expr:[17:7->30:4] -Pexp_construct :::[17:7->30:4] [17:7->30:4] -posCursor:[28:20] posNoWhite:[28:19] Found expr:[17:7->30:4] -posCursor:[28:20] posNoWhite:[28:19] Found expr:[28:10->30:4] -Pexp_construct :::[28:10->30:4] [28:10->30:4] -posCursor:[28:20] posNoWhite:[28:19] Found expr:[28:10->30:4] +posCursor:[28:20] posNoWhite:[28:19] Found expr:[15:8->32:4] +Pexp_construct :::[16:7->32:4] [16:7->32:4] +posCursor:[28:20] posNoWhite:[28:19] Found expr:[16:7->32:4] +posCursor:[28:20] posNoWhite:[28:19] Found expr:[17:7->32:4] +Pexp_construct :::[17:7->32:4] [17:7->32:4] +posCursor:[28:20] posNoWhite:[28:19] Found expr:[17:7->32:4] +posCursor:[28:20] posNoWhite:[28:19] Found expr:[28:10->32:4] +Pexp_construct :::[28:10->32:4] [28:10->32:4] +posCursor:[28:20] posNoWhite:[28:19] Found expr:[28:10->32:4] posCursor:[28:20] posNoWhite:[28:19] Found expr:[28:10->28:20] Completable: Cpath Value[someArr]->a <> [{ @@ -358,9 +358,31 @@ Completable: Cpath Value[someArr]->a <> "documentation": {"kind": "markdown", "value": "Deprecated: `append` is not type-safe. Use `concat` instead.\n\n"} }] -Complete src/CompletionJsx.res 43:23 -posCursor:[43:23] posNoWhite:[43:22] Found expr:[43:4->43:23] -JSX 43:21] n[43:22->43:23]=...[43:22->43:23]> _children:None +Complete src/CompletionJsx.res 30:11 +posCursor:[30:11] posNoWhite:[30:10] Found expr:[8:13->33:3] +posCursor:[30:11] posNoWhite:[30:10] Found expr:[9:4->32:10] +posCursor:[30:11] posNoWhite:[30:10] Found expr:[10:4->32:10] +posCursor:[30:11] posNoWhite:[30:10] Found expr:[11:4->32:10] +posCursor:[30:11] posNoWhite:[30:10] Found expr:[12:4->32:10] +posCursor:[30:11] posNoWhite:[30:10] Found expr:[15:5->32:10] +JSX 15:8] > _children:15:8 +posCursor:[30:11] posNoWhite:[30:10] Found expr:[15:8->32:4] +Pexp_construct :::[16:7->32:4] [16:7->32:4] +posCursor:[30:11] posNoWhite:[30:10] Found expr:[16:7->32:4] +posCursor:[30:11] posNoWhite:[30:10] Found expr:[17:7->32:4] +Pexp_construct :::[17:7->32:4] [17:7->32:4] +posCursor:[30:11] posNoWhite:[30:10] Found expr:[17:7->32:4] +posCursor:[30:11] posNoWhite:[30:10] Found expr:[30:10->32:4] +Pexp_construct :::[30:10->32:4] [30:10->32:4] +posCursor:[30:11] posNoWhite:[30:10] Found expr:[30:10->32:4] +posCursor:[30:11] posNoWhite:[30:10] Found expr:[30:10->30:11] +JSX 30:11] > _children:None +Completable: Cpath Module[d] +[] + +Complete src/CompletionJsx.res 45:23 +posCursor:[45:23] posNoWhite:[45:22] Found expr:[45:4->45:23] +JSX 45:21] n[45:22->45:23]=...[45:22->45:23]> _children:None Completable: Cjsx([CompWithoutJsxPpx], n, [n]) [{ "label": "name", From 4cb204ad22e143b8fee670cb9b815623101569af Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Tue, 31 Jan 2023 20:13:45 +0100 Subject: [PATCH 2/5] completion for lowercase JSX as HTML elements --- analysis/src/CompletionBackEnd.ml | 23 +- analysis/src/CompletionFrontEnd.ml | 6 +- analysis/src/CompletionJsx.ml | 200 ++++++++++++++++++ analysis/src/SharedTypes.ml | 12 +- analysis/tests/src/CompletionJsx.res | 4 +- .../tests/src/expected/CompletionJsx.res.txt | 55 +++-- 6 files changed, 275 insertions(+), 25 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 6cf90cde5..d9f9c04fa 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -211,7 +211,7 @@ let getEnvWithOpens ~scope ~(env : QueryEnv.t) ~package | None -> None | Some env -> ResolvePath.resolvePath ~env ~package ~path)) -let detail name (kind : Completion.kind) = +let kindToDetail name (kind : Completion.kind) = match kind with | Type {decl} -> decl |> Shared.declToString name | Value typ -> typ |> Shared.typeToString @@ -568,11 +568,17 @@ let completionToItem insertText; insertTextFormat; filterText; + detail; } = let item = mkItem ~name ~kind:(Completion.kindToInt kind) - ~deprecated ~detail:(detail name kind) ~docstring + ~deprecated + ~detail: + (match detail with + | None -> kindToDetail name kind + | Some detail -> detail) + ~docstring in if !Cfg.supportsSnippets then {item with sortText; insertText; insertTextFormat; filterText} @@ -1526,3 +1532,16 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover | _ -> [c]) | _ -> [c]) |> List.flatten + | ChtmlElement {prefix} -> + CompletionJsx.htmlElements + |> List.filter_map (fun (elementName, description, deprecated) -> + if Utils.startsWith elementName prefix then + let name = "<" ^ elementName ^ ">" in + Some + (Completion.create name ~kind:(Label name) ~detail:description ~env + ~docstring:[description] ~insertText:elementName + ?deprecated: + (match deprecated with + | true -> Some "true" + | false -> None)) + else None) diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index c917fa91c..e8a66ea0f 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -735,7 +735,11 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = in if jsxCompletable <> None then setResultOpt jsxCompletable else if compName.loc |> Loc.hasPos ~pos:posBeforeCursor then - setResult (Cpath (CPId (compNamePath, Module))) + setResult + (match compNamePath with + | [prefix] when Char.lowercase_ascii prefix.[0] = prefix.[0] -> + ChtmlElement {prefix} + | _ -> Cpath (CPId (compNamePath, Module))) | Pexp_apply ( {pexp_desc = Pexp_ident {txt = Lident "|."}}, [ diff --git a/analysis/src/CompletionJsx.ml b/analysis/src/CompletionJsx.ml index d9cfe4557..2be4a4d1a 100644 --- a/analysis/src/CompletionJsx.ml +++ b/analysis/src/CompletionJsx.ml @@ -487,6 +487,206 @@ let domLabels = ("suppressContentEditableWarning", bool); ] +let htmlElements = + [ + ("a", "Defines a hyperlink.", false); + ("abbr", "Defines an abbreviated form of a longer word or phrase.", false); + ("acronym", "Defines an acronym. Use instead.", true); + ("address", "Specifies the author's contact information.", false); + ( "applet", + "Embeds a Java applet (mini Java applications) on the page. Use \ + instead.", + true ); + ("area", "Defines a specific area within an image map.", false); + ("article", "Defines an article.", false); + ("aside", "Defines some content loosely related to the page content.", false); + ("audio", "Embeds a sound, or an audio stream in an HTML document.", false); + ("b", "Displays text in a bold style.", false); + ("base", "Defines the base URL for all relative URLs in a document.", false); + ("basefont", "Specifies the base font for a page. Use CSS instead.", true); + ( "bdi", + "Represents text that is isolated from its surrounding for the purposes \ + of bidirectional text formatting.", + false ); + ("bdo", "Overrides the current text direction.", false); + ("big", "Displays text in a large size. Use CSS instead.", true); + ( "blockquote", + "Represents a section that is quoted from another source.", + false ); + ("body", "Defines the document's body.", false); + ("br", "Produces a single line break.", false); + ("button", "Creates a clickable button.", false); + ( "canvas", + "Defines a region in the document, which can be used to draw graphics on \ + the fly via scripting (usually JavaScript).", + false ); + ("caption", "Defines the caption or title of the table.", false); + ("center", "Align contents in the center. Use CSS instead.", true); + ("cite", "Indicates a citation or reference to another source.", false); + ("code", "Specifies text as computer code.", false); + ( "col", + "Defines attribute values for one or more columns in a table.", + false ); + ("colgroup", "Specifies attributes for multiple columns in a table.", false); + ( "data", + "Links a piece of content with a machine-readable translation.", + false ); + ( "datalist", + "Represents a set of pre-defined options for an element.", + false ); + ( "dd", + "Specifies a description, or value for the term (
) in a description \ + list (
).", + false ); + ("del", "Represents text that has been deleted from the document.", false); + ( "details", + "Represents a widget from which the user can obtain additional \ + information or controls on-demand.", + false ); + ("dfn", "Specifies a definition.", false); + ("dialog", "Defines a dialog box or subwindow.", false); + ("dir", "Defines a directory list. Use
    instead.", true); + ("div", "Specifies a division or a section in a document.", false); + ("dl", "Defines a description list.", false); + ("dt", "Defines a term (an item) in a description list.", false); + ("em", "Defines emphasized text.", false); + ( "embed", + "Embeds external application, typically multimedia content like audio or \ + video into an HTML document.", + false ); + ("fieldset", "Specifies a set of related form fields.", false); + ("figcaption", "Defines a caption or legend for a figure.", false); + ("figure", "Represents a figure illustrated as part of the document.", false); + ("font", "Defines font, color, and size for text. Use CSS instead.", true); + ("footer", "Represents the footer of a document or a section.", false); + ("form", "Defines an HTML form for user input.", false); + ("frame", "Defines a single frame within a frameset.", true); + ("frameset", "Defines a collection of frames or other frameset.", true); + ( "head", + "Defines the head portion of the document that contains information \ + about the document such as title.", + false ); + ("header", "Represents the header of a document or a section.", false); + ("hgroup", "Defines a group of headings.", false); + ("h1", "to
    \tDefines HTML headings.", false); + ("hr", "Produce a horizontal line.", false); + ("html", "Defines the root of an HTML document.", false); + ("i", "Displays text in an italic style.", false); + ("iframe", "Displays a URL in an inline frame.", false); + ("img", "Represents an image.", false); + ("input", "Defines an input control.", false); + ( "ins", + "Defines a block of text that has been inserted into a document.", + false ); + ("kbd", "Specifies text as keyboard input.", false); + ( "keygen", + "Represents a control for generating a public-private key pair.", + false ); + ("label", "Defines a label for an control.", false); + ("legend", "Defines a caption for a
    element.", false); + ("li", "Defines a list item.", false); + ( "link", + "Defines the relationship between the current document and an external \ + resource.", + false ); + ("main", "Represents the main or dominant content of the document.", false); + ("map", "Defines a client-side image-map.", false); + ("mark", "Represents text highlighted for reference purposes.", false); + ("menu", "Represents a list of commands.", false); + ( "menuitem", + "Defines a list (or menuitem) of commands that a user can perform.", + false ); + ("meta", "Provides structured metadata about the document content.", false); + ("meter", "Represents a scalar measurement within a known range.", false); + ("nav", "Defines a section of navigation links.", false); + ( "noframes", + "Defines an alternate content that displays in browsers that do not \ + support frames.", + true ); + ( "noscript", + "Defines alternative content to display when the browser doesn't support \ + scripting.", + false ); + ("object", "Defines an embedded object.", false); + ("ol", "Defines an ordered list.", false); + ( "optgroup", + "Defines a group of related options in a selection list.", + false ); + ("option", "Defines an option in a selection list.", false); + ("output", "Represents the result of a calculation.", false); + ("p", "Defines a paragraph.", false); + ("param", "Defines a parameter for an object or applet element.", false); + ("picture", "Defines a container for multiple image sources.", false); + ("pre", "Defines a block of preformatted text.", false); + ("progress", "Represents the completion progress of a task.", false); + ("q", "Defines a short inline quotation.", false); + ( "rp", + "Provides fall-back parenthesis for browsers that that don't support \ + ruby annotations.", + false ); + ( "rt", + "Defines the pronunciation of character presented in a ruby annotations.", + false ); + ("ruby", "Represents a ruby annotation.", false); + ( "s", + "Represents contents that are no longer accurate or no longer relevant.", + false ); + ("samp", "Specifies text as sample output from a computer program.", false); + ( "script", + "Places script in the document for client-side processing.", + false ); + ( "section", + "Defines a section of a document, such as header, footer etc.", + false ); + ("select", "Defines a selection list within a form.", false); + ("small", "Displays text in a smaller size.", false); + ( "source", + "Defines alternative media resources for the media elements like