Skip to content

Commit

Permalink
Merge pull request #660 from elm-tooling/respect-module-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
razzeee committed Nov 18, 2021
2 parents a318913 + 4308ee6 commit 898ea62
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/util/refactorEditUtils.ts
Expand Up @@ -200,6 +200,7 @@ export class RefactorEditUtils {
): TextEdit | undefined {
const lastImportNode =
TreeUtils.getLastImportNode(tree) ??
TreeUtils.getModuleNameCommentNode(tree) ??
TreeUtils.getModuleNameNode(tree)?.parent;

return TextEdit.insert(
Expand Down
8 changes: 8 additions & 0 deletions src/util/treeUtils.ts
Expand Up @@ -35,6 +35,14 @@ export class TreeUtils {
return moduleDeclaration?.childForFieldName("name") ?? undefined;
}

public static getModuleNameCommentNode(tree: Tree): SyntaxNode | undefined {
const moduleDeclaration: SyntaxNode | undefined =
this.findModuleDeclaration(tree);
return moduleDeclaration?.nextNamedSibling?.type === "block_comment"
? moduleDeclaration.nextNamedSibling
: undefined;
}

public static getModuleExposingListNodes(tree: Tree): SyntaxNode[] {
const moduleNode = TreeUtils.findModuleDeclaration(tree);

Expand Down
71 changes: 66 additions & 5 deletions test/completionProvider.test.ts
Expand Up @@ -47,9 +47,8 @@ describe("CompletionProvider", () => {
await treeParser.init();
const completionProvider = new MockCompletionProvider();

const { newSources, position, fileWithCaret } = getCaretPositionFromSource(
source,
);
const { newSources, position, fileWithCaret } =
getCaretPositionFromSource(source);

if (!position) {
throw new Error("Getting position failed");
Expand Down Expand Up @@ -1147,7 +1146,6 @@ test = Module.{-caret-}
const source = `
--@ Module.elm
module Module exposing (..)
testFunc = ""
type Msg = Msg1 | Msg2
Expand All @@ -1156,7 +1154,6 @@ type alias Model = { field : String }
--@ Test.elm
module Test exposing (..)
test = div [] [ Module.{-caret-} ]
`;

Expand Down Expand Up @@ -1204,6 +1201,70 @@ test = div [] [ Module.{-caret-} ]
);
});

it("Non imported qualified modules should have value completions with auto imports after module docs", async () => {
const source = `
--@ Module.elm
module Module exposing (..)
testFunc = ""
type Msg = Msg1 | Msg2
type alias Model = { field : String }
--@ Test.elm
module Test exposing (..)
{-| Test
-}
{-| test
-}
test = div [] [ Module.{-caret-} ]
`;

await testCompletions(
source,
[
{
label: "testFunc",
detail: "Auto import module 'Module'",
additionalTextEdits: [
TextEdit.insert(Position.create(3, 0), "import Module\n"),
],
},
{
label: "Msg",
detail: "Auto import module 'Module'",
additionalTextEdits: [
TextEdit.insert(Position.create(3, 0), "import Module\n"),
],
},
{
label: "Msg1",
detail: "Auto import module 'Module'",
additionalTextEdits: [
TextEdit.insert(Position.create(3, 0), "import Module\n"),
],
},
{
label: "Msg2",
detail: "Auto import module 'Module'",
additionalTextEdits: [
TextEdit.insert(Position.create(3, 0), "import Module\n"),
],
},
{
label: "Model",
detail: "Auto import module 'Module'",
additionalTextEdits: [
TextEdit.insert(Position.create(3, 0), "import Module\n"),
],
},
],
"exactMatch",
"triggeredByDot",
);
});

// Ref: https://github.com/elm-tooling/elm-language-server/issues/288
it("Record completions should not interfere with Module completions", async () => {
const source = `
Expand Down

0 comments on commit 898ea62

Please sign in to comment.