in packages/azure-openapi-validator/autorest/src/jsonrpc/plugin-host.ts [38:93]
public async Run(): Promise<void> {
// connection setup
const channel = createMessageConnection(process.stdin, process.stdout, {
error(message) {
console.error("error: ", message)
},
info(message) {
console.error("info: ", message)
},
log(message) {
console.error("log: ", message)
},
warn(message) {
console.error("warn: ", message)
},
})
channel.onRequest(IAutoRestPluginTarget_Types.GetPluginNames, async () => Object.keys(this.plugins))
channel.onRequest(IAutoRestPluginTarget_Types.Process, async (pluginName: string, sessionId: string) => {
try {
const handler = this.plugins[pluginName]
if (!handler) {
throw new Error(`Plugin host could not find requested plugin '${pluginName}'.`)
}
await handler({
async ReadFile(filename: string): Promise<string> {
return await channel.sendRequest(IAutoRestPluginInitiator_Types.ReadFile, sessionId, filename)
},
async GetValue(key: string): Promise<any> {
return await channel.sendRequest(IAutoRestPluginInitiator_Types.GetValue, sessionId, key)
},
async ListInputs(): Promise<string[]> {
return await channel.sendRequest(IAutoRestPluginInitiator_Types.ListInputs, sessionId)
},
WriteFile(filename: string, content: string, sourceMap?: Mapping[] | RawSourceMap): void {
channel.sendNotification(IAutoRestPluginInitiator_Types.WriteFile, sessionId, filename, content, sourceMap)
},
Message(message: Message): void {
channel.sendNotification(IAutoRestPluginInitiator_Types.Message, sessionId, message)
},
})
return true
} catch (e) {
channel.sendNotification(IAutoRestPluginInitiator_Types.Message, sessionId, {
Channel: "fatal" as any,
Text: "" + e,
Details: e,
} as Message)
return false
}
})
// activate
channel.listen()
}