Skip to content

Commit dd1cb30

Browse files
committed
add empty string case
1 parent 4d2b45b commit dd1cb30

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

analysis/src/CompletionBackEndRevamped.ml

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ let findRecordField ~env ~package ~fieldName typ =
1919
fields |> List.find_opt (fun (field : field) -> field.fname.txt = fieldName)
2020

2121
let completeEmptyPattern ~env ~package typ =
22-
prerr_endline (Shared.typeToString typ);
2322
match TypeUtils.extractType ~env ~package typ with
2423
| None -> []
2524
| Some (completionType, typeArgContext) -> (
@@ -42,6 +41,11 @@ let completeEmptyPattern ~env ~package typ =
4241
Completion.create ?typeArgContext "false" ~includesSnippets:true
4342
~insertText:"false" ~sortText:"A" ~kind:(Value typ) ~env;
4443
]
44+
| Tstring _ ->
45+
[
46+
Completion.create ?typeArgContext "\"\"" ~includesSnippets:true
47+
~insertText:"\"$0\"" ~sortText:"A" ~kind:(Value typ) ~env;
48+
]
4549
| _ -> [])
4650

4751
let processCompletable ~debug ~full ~scope ~env ~pos

tests/analysis_new_tests/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
These tests test the analysis functionality for the editor tooling.
44

5+
## TLDR; Contributing
6+
7+
To make a new completion feature easy to review, follow these steps:
8+
9+
1. Add a new (or extend an existing) test file in `test_files` with a non-working test. Make sure you use good, clear naming. Commit the (non functional) test snapshot
10+
2. Implement your changes
11+
3. Update snapshots to show things now work. Ensure no other test results have changed unexpectedly
12+
4. PR!
13+
514
## Test Structure
615

716
Test files are located in the `test_files` directory and follow a specific format:

tests/analysis_new_tests/tests/test_files/SwitchCaseCompletions.res

+7
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@ let x = switch true {
1717
|
1818
// ^com
1919
}
20+
21+
// == TEST: Empty case, string
22+
let str = "hello"
23+
let x = switch str {
24+
|
25+
// ^com
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Found Completable: Cpattern
2+
3+
1 + // Empty case, string
4+
2 + let str = "hello"
5+
3 + let x = switch str {
6+
---
7+
4 + |
8+
5 + // ^com
9+
6 + }
10+
11+
[{
12+
"label": "\"\"",
13+
"kind": 12,
14+
"tags": [],
15+
"detail": "string",
16+
"documentation": null,
17+
"sortText": "A",
18+
"insertText": "\"$0\"",
19+
"insertTextFormat": 2
20+
}]
21+

0 commit comments

Comments
 (0)