-
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: Update the client/server api (#2859)
- Loading branch information
Showing
29 changed files
with
571 additions
and
412 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ codeblock | |
codicon | ||
codicons | ||
colorscheme | ||
comms | ||
cosmiconfig | ||
darkblue | ||
dcopy | ||
|
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
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,11 @@ | ||
import type { ConfigurationTarget } from './apiModels.js'; | ||
import type { OrPromise } from './types.js'; | ||
|
||
export interface CommandsToClient { | ||
addWordsToVSCodeSettingsFromServer: (words: string[], documentUri: string, target: ConfigurationTarget) => void; | ||
addWordsToDictionaryFileFromServer: (words: string[], documentUri: string, dict: { uri: string; name: string }) => void; | ||
addWordsToConfigFileFromServer: (words: string[], documentUri: string, config: { uri: string; name: string }) => void; | ||
} | ||
export type ClientSideCommandHandlerApi = { | ||
[command in keyof CommandsToClient as `cSpell.${command}`]: (...params: Parameters<CommandsToClient[command]>) => OrPromise<void>; | ||
}; |
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,111 @@ | ||
import type { | ||
ApiPrefix, | ||
ApplyNotificationAPI, | ||
ApplyRequestAPI, | ||
ClientAPIDef, | ||
ClientSideMethods, | ||
Logger, | ||
MessageConnection, | ||
RpcAPI, | ||
ServerAPIDef, | ||
ServerSideMethods, | ||
} from 'json-rpc-api'; | ||
import { createClientApi, createServerApi } from 'json-rpc-api'; | ||
|
||
import type { | ||
GetConfigurationForDocumentRequest, | ||
GetConfigurationForDocumentResult, | ||
IsSpellCheckEnabledResult, | ||
OnSpellCheckDocumentStep, | ||
SpellingSuggestionsResult, | ||
SplitTextIntoWordsResult, | ||
TextDocumentInfo, | ||
WorkspaceConfigForDocumentRequest, | ||
WorkspaceConfigForDocumentResponse, | ||
} from './apiModels.js'; | ||
|
||
export type { Logger, MessageConnection } from 'json-rpc-api'; | ||
|
||
/** Requests that can be made to the server */ | ||
export interface ServerRequestsAPI { | ||
getConfigurationForDocument(req: GetConfigurationForDocumentRequest): GetConfigurationForDocumentResult; | ||
isSpellCheckEnabled(req: TextDocumentInfo): IsSpellCheckEnabledResult; | ||
splitTextIntoWords(req: string): SplitTextIntoWordsResult; | ||
spellingSuggestions(req: TextDocumentInfo): SpellingSuggestionsResult; | ||
} | ||
|
||
/** Notifications that can be sent to the server */ | ||
export interface ServerNotificationsAPI { | ||
notifyConfigChange: () => void; | ||
registerConfigurationFile: (path: string) => void; | ||
} | ||
|
||
/** | ||
* Requests that can be made from the server to the client(vscode extension) | ||
* Note: RPC requests to the client/extension is rare. | ||
*/ | ||
export interface ClientRequestsAPI { | ||
// addWordsToVSCodeSettingsFromServer: (words: string[], documentUri: string, target: ConfigurationTarget) => void; | ||
// addWordsToDictionaryFileFromServer: (words: string[], documentUri: string, dict: { uri: string; name: string }) => void; | ||
// addWordsToConfigFileFromServer: (words: string[], documentUri: string, config: { uri: string; name: string }) => void; | ||
onWorkspaceConfigForDocumentRequest: (req: WorkspaceConfigForDocumentRequest) => WorkspaceConfigForDocumentResponse; | ||
} | ||
|
||
/** Notifications from the server to the client(vscode extension) */ | ||
export interface ClientNotificationsAPI { | ||
onSpellCheckDocument(step: OnSpellCheckDocumentStep): void; | ||
} | ||
|
||
export interface SpellCheckerServerAPI extends RpcAPI { | ||
serverRequests: ApplyRequestAPI<ServerRequestsAPI>; | ||
serverNotifications: ApplyNotificationAPI<ServerNotificationsAPI>; | ||
clientRequests: ApplyRequestAPI<ClientRequestsAPI>; | ||
clientNotifications: ApplyNotificationAPI<ClientNotificationsAPI>; | ||
} | ||
|
||
/** | ||
* Used on the server side to communicate with the client(extension). | ||
*/ | ||
export interface ServerSideApi extends ServerSideMethods<SpellCheckerServerAPI> {} | ||
/** | ||
* Used in the client(extension) to communicate with the server. | ||
*/ | ||
export interface ClientSideApi extends ClientSideMethods<SpellCheckerServerAPI> {} | ||
|
||
export type ServerSideApiDef = ServerAPIDef<SpellCheckerServerAPI>; | ||
export type ClientSideApiDef = ClientAPIDef<SpellCheckerServerAPI>; | ||
|
||
export interface ServerSideHandlers { | ||
serverRequests: DefineHandlers<ServerSideApiDef['serverRequests']>; | ||
serverNotifications: DefineHandlers<ServerSideApiDef['serverNotifications']>; | ||
} | ||
|
||
// todo: make '' when all old apis are removed. | ||
const pfx = '_'; | ||
|
||
const apiPrefix: ApiPrefix = { | ||
serverNotifications: pfx, | ||
serverRequests: pfx, | ||
clientNotifications: pfx, | ||
clientRequests: pfx, | ||
}; | ||
|
||
export function createServerSideApi( | ||
connection: MessageConnection, | ||
api: ServerAPIDef<SpellCheckerServerAPI>, | ||
logger: Logger | undefined, | ||
): ServerSideApi { | ||
return createServerApi(connection, api, logger, apiPrefix); | ||
} | ||
|
||
export function createClientSideApi( | ||
connection: MessageConnection, | ||
api: ClientAPIDef<SpellCheckerServerAPI>, | ||
logger: Logger | undefined, | ||
): ClientSideApi { | ||
return createClientApi(connection, api, logger, apiPrefix); | ||
} | ||
|
||
type DefineHandlers<T> = { | ||
[P in keyof T]: Exclude<T[P], boolean>; | ||
}; |
Oops, something went wrong.