Skip to content

Commit eb1cc74

Browse files
deankevorkianaminya
authored andcommitted
feat: added canAdapt & tests, exposed CommandExecutionAdapter
1 parent 672bd41 commit eb1cc74

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

lib/adapters/command-execution-adapter.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
import { ExecuteCommandParams } from "../languageclient";
1+
import { ExecuteCommandParams, ServerCapabilities } from "../languageclient";
22
import { LanguageClientConnection } from "../main";
33

44
export type CommandCustomCallbackFunction = (command: ExecuteCommandParams) => Promise<any | void>;
55

66
export default class CommandExecutionAdapter {
77
private static commandsCustomCallbacks: Map<string, CommandCustomCallbackFunction> = new Map<string, CommandCustomCallbackFunction>();
88

9+
public static canAdapt(serverCapabilities: ServerCapabilities): boolean {
10+
return serverCapabilities.executeCommandProvider != null;
11+
}
12+
913
public static registerCustomCallbackForCommand(command: string, callback: CommandCustomCallbackFunction): void {
1014
this.commandsCustomCallbacks.set(command, callback);
1115
}

lib/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Convert from './convert';
88
import { Logger, ConsoleLogger, FilteredLogger } from './logger';
99
import DownloadFile from './download-file';
1010
import LinterPushV2Adapter from './adapters/linter-push-v2-adapter';
11+
import CommandExecutionAdapter from './adapters/command-execution-adapter';
1112

1213
export * from './auto-languageclient';
1314
export {
@@ -18,4 +19,5 @@ export {
1819
FilteredLogger,
1920
DownloadFile,
2021
LinterPushV2Adapter,
22+
CommandExecutionAdapter
2123
};

test/adapters/command-execution-adapter.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ import { createSpyConnection } from '../helpers.js';
66
import { ExecuteCommandParams } from '../../lib/languageclient';
77

88
describe('CommandExecutionAdapter', () => {
9+
describe('canAdapt', () => {
10+
it('returns true if command execution is supported', () => {
11+
const result = CommandExecutionAdapter.canAdapt({
12+
executeCommandProvider: {commands: []},
13+
});
14+
expect(result).to.be.true;
15+
});
16+
17+
it('returns false it no formatting supported', () => {
18+
const result = CommandExecutionAdapter.canAdapt({});
19+
expect(result).to.be.false;
20+
});
21+
});
22+
923
describe('executeCommand', () => {
1024
it('invokes an executeCommand object from given inputs', async () => {
1125
const connection = createSpyConnection();

0 commit comments

Comments
 (0)