Skip to content

Fix autocompletion in template expressions. #483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 9, 2022
Merged
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
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ clean:
test:
make -C analysis test

format:
make -C analysis format

checkformat:
make -C analysis checkformat

.DEFAULT_GOAL := build

.PHONY: build clean test
3 changes: 3 additions & 0 deletions analysis/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ clean:
make -C tests clean
make -C reanalyze clean

checkformat:
dune build @fmt

.DEFAULT_GOAL := build

.PHONY: build-analysis-binary build-reanalyze build-tests dce clean format test
12 changes: 11 additions & 1 deletion analysis/dune-project
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
(lang dune 2.0)

(name rescript-vscode)
(package
(name rescript-vscode)
(synopsis "ReScript vscode support")
(depends
(ocaml
(>= 4.10))
(ocamlformat
(= 0.22.4))
(reanalyze
(= 2.23.0))
dune))
2 changes: 1 addition & 1 deletion analysis/reanalyze/src/EmitJson.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let items = ref 0
let start () = Printf.printf "["
let finish ()= Printf.printf "\n]\n"
let finish () = Printf.printf "\n]\n"
let emitClose () = "\n}"

let emitItem ~ppf ~name ~kind ~file ~range ~message =
Expand Down
5 changes: 1 addition & 4 deletions analysis/reanalyze/src/Exception.ml
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,7 @@ let traverseAst () =
case.c_guard |> iterExprOpt self;
case.c_rhs |> iterExpr self)
in
let isRaise s =
s = "Pervasives.raise"
|| s = "Pervasives.raise_notrace"
in
let isRaise s = s = "Pervasives.raise" || s = "Pervasives.raise_notrace" in
let raiseArgs args =
match args with
| [(_, Some {Typedtree.exp_desc = Texp_construct ({txt}, _, _)})] ->
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions analysis/src/Cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ let main () =
Commands.codeAction ~path
~pos:(int_of_string line, int_of_string col)
~currentFile ~debug:false
| [_; "diagnosticSyntax"; path;] ->
Commands.diagnosticSyntax ~path
| [_; "diagnosticSyntax"; path] -> Commands.diagnosticSyntax ~path
| _ :: "reanalyze" :: _ ->
let len = Array.length Sys.argv in
for i = 1 to len - 2 do
Expand Down
3 changes: 1 addition & 2 deletions analysis/src/Commands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,7 @@ let format ~path =
else ""

let diagnosticSyntax ~path =
print_endline
(Diagnostics.document_syntax ~path |> Protocol.array)
print_endline (Diagnostics.document_syntax ~path |> Protocol.array)

let test ~path =
Uri.stripPath := true;
Expand Down
2 changes: 1 addition & 1 deletion analysis/src/Diagnostics.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ let document_syntax ~path =
Res_driver.parsingEngine.parseInterface ~forPrinter:false ~filename:path
in
get_diagnostics parseInterface.diagnostics
else []
else []
22 changes: 9 additions & 13 deletions analysis/src/Protocol.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@ type completionItem = {
documentation: markupContent option;
}

type location = {uri : string; range : range}
type documentSymbolItem = {name : string; kind : int; location : location}
type renameFile = {oldUri : string; newUri : string}
type textEdit = {range : range; newText : string}

type diagnostic = {
range : range;
message : string;
severity : int;
}
type location = {uri: string; range: range}
type documentSymbolItem = {name: string; kind: int; location: location}
type renameFile = {oldUri: string; newUri: string}
type textEdit = {range: range; newText: string}

type diagnostic = {range: range; message: string; severity: int}

type optionalVersionedTextDocumentIdentifier = {
version: int option;
Expand Down Expand Up @@ -134,11 +130,11 @@ let stringifyCodeAction ca =

(* https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#diagnostic *)
let stringifyDiagnostic d =
Printf.sprintf {|{
Printf.sprintf
{|{
"range": %s,
"message": "%s",
"severity": %d,
"source": "ReScript"
}|}
(stringifyRange d.range) (Json.escape d.message)
d.severity
(stringifyRange d.range) (Json.escape d.message) d.severity
14 changes: 14 additions & 0 deletions analysis/tests/src/Completion.res
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,17 @@ let _ = _ => {
// ^com
()
}

let red = "#ff0000"

let header1 = `
color: ${red}; `
// ^com

let header2 = `
color: ${red};
background-color: ${red}; `
// ^com

// let _ = `color: ${r
// ^com
76 changes: 68 additions & 8 deletions analysis/tests/src/expected/Completion.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -937,9 +937,9 @@ Completable: Cpath Value[ForAuto, a]

Complete src/Completion.res 234:34
posCursor:[234:34] posNoWhite:[234:33] Found expr:[234:18->234:36]
Pexp_apply ...__ghost__[0:-1->0:-1] (...[234:18->234:34], ...[234:34->234:36])
Pexp_apply ...__ghost__[0:-1->0:-1] (...[234:18->234:34], ...[234:34->234:35])
posCursor:[234:34] posNoWhite:[234:33] Found expr:[234:18->234:34]
Pexp_apply ...__ghost__[0:-1->0:-1] (...[234:18->234:32], ...[234:32->234:34])
Pexp_apply ...__ghost__[0:-1->0:-1] (...[234:18->234:30], ...[234:32->234:34])
posCursor:[234:34] posNoWhite:[234:33] Found expr:[234:32->234:34]
Pexp_ident na:[234:32->234:34]
Completable: Cpath Value[na]
Expand Down Expand Up @@ -1434,9 +1434,9 @@ Completable: Cpath Value[AndThatOther, T]

Complete src/Completion.res 378:24
posCursor:[378:24] posNoWhite:[378:23] Found expr:[378:12->378:26]
Pexp_apply ...__ghost__[0:-1->0:-1] (...[378:12->378:24], ...[378:24->378:26])
Pexp_apply ...__ghost__[0:-1->0:-1] (...[378:12->378:24], ...[378:24->378:25])
posCursor:[378:24] posNoWhite:[378:23] Found expr:[378:12->378:24]
Pexp_apply ...__ghost__[0:-1->0:-1] (...[378:12->378:16], ...[378:16->378:24])
Pexp_apply ...__ghost__[0:-1->0:-1] (...[378:12->378:14], ...[378:16->378:24])
posCursor:[378:24] posNoWhite:[378:23] Found expr:[378:16->378:24]
Pexp_ident ForAuto.:[378:16->378:24]
Completable: Cpath Value[ForAuto, ""]
Expand All @@ -1456,9 +1456,9 @@ Completable: Cpath Value[ForAuto, ""]

Complete src/Completion.res 381:38
posCursor:[381:38] posNoWhite:[381:37] Found expr:[381:12->381:41]
Pexp_apply ...__ghost__[0:-1->0:-1] (...[381:12->381:39], ...[381:39->381:41])
Pexp_apply ...__ghost__[0:-1->0:-1] (...[381:12->381:39], ...[381:39->381:40])
posCursor:[381:38] posNoWhite:[381:37] Found expr:[381:12->381:39]
Pexp_apply ...__ghost__[0:-1->0:-1] (...[381:12->381:19], ...[381:19->381:39])
Pexp_apply ...__ghost__[0:-1->0:-1] (...[381:12->381:17], ...[381:19->381:39])
posCursor:[381:38] posNoWhite:[381:37] Found expr:[381:19->381:39]
Pexp_send [381:38->381:38] e:[381:19->381:36]
Completable: Cpath Value[FAO, forAutoObject][""]
Expand All @@ -1478,9 +1478,9 @@ Completable: Cpath Value[FAO, forAutoObject][""]

Complete src/Completion.res 384:24
posCursor:[384:24] posNoWhite:[384:23] Found expr:[384:11->384:26]
Pexp_apply ...__ghost__[0:-1->0:-1] (...[384:11->384:24], ...[384:24->384:26])
Pexp_apply ...__ghost__[0:-1->0:-1] (...[384:11->384:24], ...[384:24->384:25])
posCursor:[384:24] posNoWhite:[384:23] Found expr:[384:11->384:24]
Pexp_apply ...__ghost__[0:-1->0:-1] (...[384:11->384:14], ...[384:14->384:24])
Pexp_apply ...__ghost__[0:-1->0:-1] (...[384:11->384:12], ...[384:14->384:24])
posCursor:[384:24] posNoWhite:[384:23] Found expr:[384:14->384:24]
Pexp_field [384:14->384:23] _:[384:24->384:24]
Completable: Cpath Value[funRecord].""
Expand Down Expand Up @@ -1518,3 +1518,63 @@ Completable: Cpath array->ma
"documentation": null
}]

Complete src/Completion.res 397:14
posCursor:[397:14] posNoWhite:[397:13] Found expr:[396:14->397:20]
Pexp_apply ...__ghost__[0:-1->0:-1] (...[396:14->397:16], ...[397:16->397:19])
posCursor:[397:14] posNoWhite:[397:13] Found expr:[396:14->397:16]
Pexp_apply ...__ghost__[0:-1->0:-1] (...[396:14->397:11], ...[397:13->397:16])
posCursor:[397:14] posNoWhite:[397:13] Found expr:[397:13->397:16]
Pexp_ident red:[397:13->397:16]
Completable: Cpath Value[red]
[{
"label": "red",
"kind": 12,
"tags": [],
"detail": "string",
"documentation": null
}]

Complete src/Completion.res 402:25
posCursor:[402:25] posNoWhite:[402:24] Found expr:[400:14->402:31]
Pexp_apply ...__ghost__[0:-1->0:-1] (...[400:14->402:27], ...[402:27->402:30])
posCursor:[402:25] posNoWhite:[402:24] Found expr:[400:14->402:27]
Pexp_apply ...__ghost__[0:-1->0:-1] (...[400:14->402:22], ...[402:24->402:27])
posCursor:[402:25] posNoWhite:[402:24] Found expr:[402:24->402:27]
Pexp_ident red:[402:24->402:27]
Completable: Cpath Value[red]
[{
"label": "red",
"kind": 12,
"tags": [],
"detail": "string",
"documentation": null
}]

Complete src/Completion.res 405:22
posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:11->408:0]
Pexp_apply ...__ghost__[0:-1->0:-1] (...[405:11->405:22], ...[408:0->408:0])
posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:11->405:22]
Pexp_apply ...__ghost__[0:-1->0:-1] (...[405:11->405:19], ...[405:21->405:22])
posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:21->405:22]
Pexp_ident r:[405:21->405:22]
Completable: Cpath Value[r]
[{
"label": "red",
"kind": 12,
"tags": [],
"detail": "string",
"documentation": null
}, {
"label": "retAA",
"kind": 12,
"tags": [],
"detail": "unit => aa",
"documentation": null
}, {
"label": "r",
"kind": 12,
"tags": [],
"detail": "rAlias",
"documentation": null
}]

2 changes: 1 addition & 1 deletion analysis/tests/src/expected/Dce.res.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
DCE src/Dce.res
issues:233
issues:235

1 change: 1 addition & 0 deletions analysis/vendor/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(dirs compiler-libs-406 ext res_outcome_printer json)
Loading