This repository has been archived by the owner on Dec 25, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setting to prevent unused import removal
Using feature added to the language server in v0.7.0 Resolves #273
- Loading branch information
Showing
6 changed files
with
144 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
(global as any).nova = Object.assign(nova, { | ||
commands: { | ||
invoke: jest.fn(), | ||
}, | ||
config: { | ||
onDidChange: jest.fn(), | ||
["get"]: jest.fn(), | ||
}, | ||
workspace: { | ||
config: { onDidChange: jest.fn(), ["get"]: jest.fn() }, | ||
}, | ||
}); | ||
|
||
describe("skipDestructiveOrganizeImports", () => { | ||
beforeEach(() => { | ||
(nova.workspace.config.get as jest.Mock).mockReset(); | ||
(nova.config.get as jest.Mock).mockReset(); | ||
}); | ||
|
||
const { | ||
skipDestructiveOrganizeImports, | ||
} = require("./skipDestructiveOrganizeImports"); | ||
|
||
describe("reloads extension when it changes", () => { | ||
it("globally and for the workspace", () => { | ||
expect(nova.config.onDidChange).toBeCalledTimes(1); | ||
expect(nova.config.onDidChange).toBeCalledWith( | ||
"apexskier.typescript.config.skipDestructiveOrganizeImports", | ||
expect.any(Function) | ||
); | ||
expect(nova.workspace.config.onDidChange).toBeCalledTimes(1); | ||
expect(nova.workspace.config.onDidChange).toBeCalledWith( | ||
"apexskier.typescript.config.skipDestructiveOrganizeImports", | ||
expect.any(Function) | ||
); | ||
// same function | ||
const onWorkspaceChange = (nova.workspace.config.onDidChange as jest.Mock) | ||
.mock.calls[0][1]; | ||
const onGlobalChange = (nova.config.onDidChange as jest.Mock).mock | ||
.calls[0][1]; | ||
expect(onWorkspaceChange).toBe(onGlobalChange); | ||
}); | ||
|
||
it("by calling the reload command", () => { | ||
const reload = (nova.config.onDidChange as jest.Mock).mock.calls[0][1]; | ||
reload(); | ||
expect(nova.commands.invoke).toBeCalledTimes(1); | ||
expect(nova.commands.invoke).toBeCalledWith( | ||
"apexskier.typescript.reload" | ||
); | ||
}); | ||
}); | ||
|
||
describe("is true by default", () => { | ||
expect(skipDestructiveOrganizeImports()).toBe(true); | ||
}); | ||
|
||
describe("can be disabled globally", () => { | ||
(nova.workspace.config.get as jest.Mock).mockReturnValueOnce(null); | ||
(nova.config.get as jest.Mock).mockReturnValueOnce(false); | ||
expect(skipDestructiveOrganizeImports()).toBe(false); | ||
}); | ||
|
||
describe("can be enabled globally", () => { | ||
(nova.workspace.config.get as jest.Mock).mockReturnValueOnce(null); | ||
(nova.config.get as jest.Mock).mockReturnValueOnce(true); | ||
expect(skipDestructiveOrganizeImports()).toBe(true); | ||
}); | ||
|
||
describe("can be disabled in the workspace", () => { | ||
(nova.workspace.config.get as jest.Mock).mockReturnValueOnce("False"); | ||
(nova.config.get as jest.Mock).mockReturnValueOnce(true); | ||
expect(skipDestructiveOrganizeImports()).toBe(false); | ||
}); | ||
|
||
describe("can be enabled in the workspace", () => { | ||
(nova.workspace.config.get as jest.Mock).mockReturnValueOnce("True"); | ||
(nova.config.get as jest.Mock).mockReturnValueOnce(false); | ||
expect(skipDestructiveOrganizeImports()).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
function reload() { | ||
nova.commands.invoke("apexskier.typescript.reload"); | ||
} | ||
nova.config.onDidChange( | ||
"apexskier.typescript.config.skipDestructiveOrganizeImports", | ||
reload | ||
); | ||
nova.workspace.config.onDidChange( | ||
"apexskier.typescript.config.skipDestructiveOrganizeImports", | ||
reload | ||
); | ||
|
||
function getWorkspaceSetting(): boolean | null { | ||
const str = nova.workspace.config.get( | ||
"apexskier.typescript.config.skipDestructiveOrganizeImports", | ||
"string" | ||
); | ||
switch (str) { | ||
case "False": | ||
return false; | ||
case "True": | ||
return true; | ||
default: | ||
return null; | ||
} | ||
} | ||
|
||
export function skipDestructiveOrganizeImports(): boolean { | ||
return ( | ||
getWorkspaceSetting() ?? | ||
nova.config.get( | ||
"apexskier.typescript.config.skipDestructiveOrganizeImports", | ||
"boolean" | ||
) ?? | ||
true | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters