Skip to content

Commit

Permalink
Fix expectations for suggested completions for import statements
Browse files Browse the repository at this point in the history
Adapt the expectations in automated tests, considering that some modules import the same module using different aliases.
The previous version was closer to behavior as observed with elm-format. However, looking closer at imports, the current version of elm-format seems to be not always compatible with Elm, sometimes breaking compiling code. For discussion of the issues around import statements, see:
avh4/elm-format#379 (comment)
avh4/elm-format#445
avh4/elm-format#577
  • Loading branch information
Viir committed Sep 13, 2021
1 parent 46ceb12 commit 114fcb6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
13 changes: 9 additions & 4 deletions implement/example-apps/elm-editor/src/LanguageService.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -164,6 +163,12 @@ provideCompletionItems request languageServiceState =
moduleNamesToNotSuggestForImport
)
)
|> List.sortBy
(.moduleDefinition
>> Elm.Syntax.Node.value
>> Elm.Syntax.Module.moduleName
>> String.join "."
)

importedModules =
implicitlyImportedModules ++ explicitlyImportedModules
Expand Down Expand Up @@ -295,7 +300,7 @@ provideCompletionItems request languageServiceState =
)
in
if List.head lineUntilPositionWords == Just "import" then
availableModulesNotImportedYet
modulesToSuggestForImport
|> List.map
(moduleCompletionItemFromModuleSyntax
{ importedModuleNameRestAfterPrefix = Nothing, importedName = Nothing }
Expand Down
44 changes: 42 additions & 2 deletions implement/example-apps/elm-editor/tests/LanguageServiceTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 114fcb6

Please sign in to comment.