diff --git a/implement/example-apps/elm-editor/src/LanguageService.elm b/implement/example-apps/elm-editor/src/LanguageService.elm index ef81ec2b..1b6bd7ec 100644 --- a/implement/example-apps/elm-editor/src/LanguageService.elm +++ b/implement/example-apps/elm-editor/src/LanguageService.elm @@ -147,10 +147,9 @@ provideCompletionItems request languageServiceState = ) moduleNamesToNotSuggestForImport = - fileOpenedInEditorModuleName - :: List.map .canonicalName explicitlyImportedModules + [ fileOpenedInEditorModuleName ] - availableModulesNotImportedYet = + modulesToSuggestForImport = languageServiceState.fileTreeParseCache |> FileTree.flatListOfBlobsFromFileTreeNode |> List.filterMap (Tuple.second >> .parsedFileLastSuccess >> Maybe.map .syntax) @@ -164,6 +163,12 @@ provideCompletionItems request languageServiceState = moduleNamesToNotSuggestForImport ) ) + |> List.sortBy + (.moduleDefinition + >> Elm.Syntax.Node.value + >> Elm.Syntax.Module.moduleName + >> String.join "." + ) importedModules = implicitlyImportedModules ++ explicitlyImportedModules @@ -295,7 +300,7 @@ provideCompletionItems request languageServiceState = ) in if List.head lineUntilPositionWords == Just "import" then - availableModulesNotImportedYet + modulesToSuggestForImport |> List.map (moduleCompletionItemFromModuleSyntax { importedModuleNameRestAfterPrefix = Nothing, importedName = Nothing } diff --git a/implement/example-apps/elm-editor/tests/LanguageServiceTests.elm b/implement/example-apps/elm-editor/tests/LanguageServiceTests.elm index 445ffc00..645518a1 100644 --- a/implement/example-apps/elm-editor/tests/LanguageServiceTests.elm +++ b/implement/example-apps/elm-editor/tests/LanguageServiceTests.elm @@ -230,7 +230,27 @@ from_beta_function : Int -> String otherFiles fileOpenedInEditor { textUntilPosition = "previousline\nimport " } - [ { label = "Epsilon" + [ { label = "Alpha" + , documentation = "Documentation comment on module Alpha" + , insertText = "Alpha" + , kind = FrontendWeb.MonacoEditor.ModuleCompletionItemKind + } + , { label = "Beta" + , documentation = "" + , insertText = "Beta" + , kind = FrontendWeb.MonacoEditor.ModuleCompletionItemKind + } + , { label = "Beta.Gamma" + , documentation = "" + , insertText = "Beta.Gamma" + , kind = FrontendWeb.MonacoEditor.ModuleCompletionItemKind + } + , { label = "Delta" + , documentation = "" + , insertText = "Delta" + , kind = FrontendWeb.MonacoEditor.ModuleCompletionItemKind + } + , { label = "Epsilon" , documentation = "" , insertText = "Epsilon" , kind = FrontendWeb.MonacoEditor.ModuleCompletionItemKind @@ -242,7 +262,27 @@ from_beta_function : Int -> String otherFiles fileOpenedInEditor { textUntilPosition = "previousline\nimport E" } - [ { label = "Epsilon" + [ { label = "Alpha" + , documentation = "Documentation comment on module Alpha" + , insertText = "Alpha" + , kind = FrontendWeb.MonacoEditor.ModuleCompletionItemKind + } + , { label = "Beta" + , documentation = "" + , insertText = "Beta" + , kind = FrontendWeb.MonacoEditor.ModuleCompletionItemKind + } + , { label = "Beta.Gamma" + , documentation = "" + , insertText = "Beta.Gamma" + , kind = FrontendWeb.MonacoEditor.ModuleCompletionItemKind + } + , { label = "Delta" + , documentation = "" + , insertText = "Delta" + , kind = FrontendWeb.MonacoEditor.ModuleCompletionItemKind + } + , { label = "Epsilon" , documentation = "" , insertText = "Epsilon" , kind = FrontendWeb.MonacoEditor.ModuleCompletionItemKind