Skip to content

Commit

Permalink
Prevent user from unexposing the last function
Browse files Browse the repository at this point in the history
This might lead to problems or unexpected things from the users POV, but I think it's better then breaking the syntax or battling elm-format @jmbockhorst
  • Loading branch information
razzeee committed Mar 30, 2020
1 parent d2a5890 commit b12d157
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 1 addition & 4 deletions src/providers/handlers/exposeUnexposeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import { ExposeUnexposeParams } from "../../protocol";
import { RefactorEditUtils } from "../../util/refactorEditUtils";

export class ExposeUnexposeHandler {
constructor(
private connection: IConnection,
private elmWorkspaces: ElmWorkspace[],
) {
constructor(private connection: IConnection, elmWorkspaces: ElmWorkspace[]) {
this.connection.onRequest(
ExposeRequest,
new ElmWorkspaceMatcher(elmWorkspaces, (params: ExposeUnexposeParams) =>
Expand Down
8 changes: 7 additions & 1 deletion src/util/refactorEditUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ export class RefactorEditUtils {
valueName: string,
): TextEdit | undefined {
const exposedNodes = TreeUtils.getModuleExposingListNodes(tree);
return this.removeValueFromExposingList(exposedNodes, valueName);

if (exposedNodes.length <= 1) {
// We can't remove the last exposed one and removing the whole module annotation would just lead to elm-format readding it
return undefined;
} else {
return this.removeValueFromExposingList(exposedNodes, valueName);
}
}

public static exposeValueInModule(
Expand Down

0 comments on commit b12d157

Please sign in to comment.