Repository: elm-tooling/elm-language-server
Pull request #530 (2021-02-23 05:18:26)

Small improvements for exposing completions
Also add failing test for cons pattern. Should pass with https://github.com/elm-tooling/tree-sitter-elm/pull/84.


Patch:
diff --git a/src/providers/completionProvider.ts b/src/providers/completionProvider.ts
index 3ccdf1a..ff7debd 100644
--- a/src/providers/completionProvider.ts
+++ b/src/providers/completionProvider.ts
@@ -252,10 +252,20 @@ export class CompletionProvider {
       } else if (previousWord && previousWord === "module") {
         return undefined;
       } else if (
-        nodeAtPosition.parent?.type === "module_declaration" &&
-        nodeAtPosition.type === "exposing_list"
+        TreeUtils.findParentOfType("module_declaration", nodeAtPosition) &&
+        TreeUtils.findParentOfType("exposing_list", nodeAtPosition)
       ) {
-        return this.getSameFileTopLevelCompletions(tree, replaceRange, true);
+        const exposingList =
+          TreeUtils.findParentOfType(
+            "exposing_list",
+            nodeAtPosition,
+          )?.namedChildren.map((n) => n.text) ?? [];
+
+        return this.getSameFileTopLevelCompletions(
+          tree,
+          replaceRange,
+          true,
+        ).filter((completion) => !exposingList.includes(completion.label));
       } else if (
         nodeAtPosition.type === "exposing_list" &&
         nodeAtPosition.parent?.type === "import_clause" &&


Test patch:
diff --git a/test/completionProvider.test.ts b/test/completionProvider.test.ts
index 7a50696..79e9206 100644
--- a/test/completionProvider.test.ts
+++ b/test/completionProvider.test.ts
@@ -549,6 +549,48 @@ type alias TestType =
       ["testFunc", "Msg", "Msg(..)", "Msg1", "Msg2", "TestType"],
       "exactMatch",
     );
+
+    const source2 = `
+--@ Test.elm
+module Test exposing (t{-caret-})
+
+testFunc : String
+testFunc = 
+  ""
+
+type Msg = Msg1 | Msg2
+
+type alias TestType = 
+  { prop : String }
+`;
+
+    await testCompletions(
+      source2,
+      ["testFunc", "Msg", "Msg(..)", "Msg1", "Msg2", "TestType"],
+      "exactMatch",
+    );
+  });
+
+  it("Module exposing list should not have completions for already exposed", async () => {
+    const source = `
+--@ Test.elm
+module Test exposing (testFunc, Msg(..), {-caret-})
+
+testFunc : String
+testFunc = 
+  ""
+
+type Msg = Msg1 | Msg2
+
+type alias TestType = 
+  { prop : String }
+`;
+
+    await testCompletions(
+      source,
+      ["Msg", "Msg1", "Msg2", "TestType"],
+      "exactMatch",
+    );
   });
 
   it("Function name should have completions in annotation and declaration", async () => {
diff --git a/test/diagnosticTests/elmDiagnostics.test.ts b/test/diagnosticTests/elmDiagnostics.test.ts
index 6dc2660..fef0129 100644
--- a/test/diagnosticTests/elmDiagnostics.test.ts
+++ b/test/diagnosticTests/elmDiagnostics.test.ts
@@ -1406,4 +1406,24 @@ func result =
       true,
     );
   });
+
+  xtest("test missing case patterns should not have an error - multiple cons", async () => {
+    const source = `
+--@ Test.elm
+module Test exposing (..)
+
+func result =
+    case result of
+    --^
+        a :: b :: _ ->
+            ""
+          
+        a :: [] ->
+            ""
+
+        _ ->
+            ""
+  `;
+    await testTypeInference(basicsSources + source, [], true);
+  });
 });