-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b0737b
commit bfb2071
Showing
16 changed files
with
259 additions
and
70 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
File renamed without changes.
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,26 @@ | ||
import Commands from "."; | ||
import Logger from "../logger"; | ||
import { LanguageClient } from "vscode-languageclient/node"; | ||
import ServerCommands from "../serverCommands/server-commands"; | ||
|
||
interface Context { | ||
client: LanguageClient; | ||
} | ||
|
||
const reindexProject: Commands.T<Context> = { | ||
id: "lexical.server.reindexProject", | ||
createHandler: ({ client }) => { | ||
function handle() { | ||
if (!client.isRunning()) { | ||
Logger.error("Client is not running, cannot send command to server."); | ||
return; | ||
} | ||
|
||
ServerCommands.reindex(client); | ||
} | ||
|
||
return handle; | ||
}, | ||
}; | ||
|
||
export default reindexProject; |
4 changes: 2 additions & 2 deletions
4
src/commands/restart-server.ts → src/clientCommands/restart-server.ts
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,17 @@ | ||
import { | ||
ExecuteCommandRequest, | ||
LanguageClient, | ||
} from "vscode-languageclient/node"; | ||
|
||
const REINDEX_COMMAND_NAME = "Reindex"; | ||
|
||
namespace ServerCommands { | ||
export async function reindex(client: LanguageClient): Promise<void> { | ||
await client.sendRequest(ExecuteCommandRequest.type, { | ||
command: REINDEX_COMMAND_NAME, | ||
arguments: [], | ||
}); | ||
} | ||
} | ||
|
||
export default ServerCommands; |
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,29 @@ | ||
import { describe, expect, test } from "@jest/globals"; | ||
import reindexProject from "../../clientCommands/reindex-project"; | ||
import { mockResolvedValue } from "../utils/strict-mocks"; | ||
import ServerCommands from "../../serverCommands/server-commands"; | ||
import clientStub from "../fixtures/client-stub"; | ||
|
||
describe("reindexProject", () => { | ||
test("should call the 'Reindex' server command", () => { | ||
const handler = reindexProject.createHandler({ | ||
client: clientStub({ isRunning: true }), | ||
}); | ||
mockResolvedValue(ServerCommands, "reindex"); | ||
|
||
handler(); | ||
|
||
expect(ServerCommands.reindex).toHaveBeenCalled(); | ||
}); | ||
|
||
test("given client is not running, it should do nothing", () => { | ||
const handler = reindexProject.createHandler({ | ||
client: clientStub({ isRunning: false }), | ||
}); | ||
mockResolvedValue(ServerCommands, "reindex"); | ||
|
||
handler(); | ||
|
||
expect(ServerCommands.reindex).not.toHaveBeenCalled(); | ||
}); | ||
}); |
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,25 @@ | ||
import { jest } from "@jest/globals"; | ||
import { LanguageClient } from "vscode-languageclient/node"; | ||
|
||
interface Opts { | ||
sendRequest?: jest.Mock; | ||
isRunning?: boolean; | ||
restart?: jest.Mock; | ||
start?: jest.Mock; | ||
} | ||
|
||
export default function clientStub({ | ||
sendRequest = jest.fn(), | ||
isRunning = true, | ||
restart = jest.fn(), | ||
start = jest.fn(), | ||
}: Opts): LanguageClient { | ||
return { | ||
isRunning() { | ||
return isRunning; | ||
}, | ||
sendRequest, | ||
start, | ||
restart, | ||
} as unknown as LanguageClient; | ||
} |
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,18 @@ | ||
import { describe, expect, jest, test } from "@jest/globals"; | ||
import { ExecuteCommandRequest } from "vscode-languageclient/node"; | ||
import ServerCommands from "../../serverCommands/server-commands"; | ||
import clientStub from "../fixtures/client-stub"; | ||
|
||
describe("reindex", () => { | ||
test("it should send a request to the server with the 'Reindex' command", () => { | ||
const sendRequest = jest.fn(); | ||
const client = clientStub({ sendRequest }); | ||
|
||
ServerCommands.reindex(client); | ||
|
||
expect(sendRequest).toHaveBeenCalledWith(ExecuteCommandRequest.type, { | ||
command: "Reindex", | ||
arguments: [], | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.