@aws/language-server-runtimes
Advanced tools
Comparing version 0.2.24 to 0.2.25
{ | ||
"name": "@aws/language-server-runtimes", | ||
"version": "0.2.24", | ||
"version": "0.2.25", | ||
"description": "Runtimes to host Language Servers for AWS", | ||
@@ -37,3 +37,3 @@ "files": [ | ||
"@aws/language-server-runtimes-types": "^0.0.7", | ||
"jose": "^5.9.3", | ||
"jose": "^5.9.6", | ||
"rxjs": "^7.8.1", | ||
@@ -40,0 +40,0 @@ "vscode-languageserver": "^9.0.1", |
@@ -70,2 +70,10 @@ import { _EM } from 'vscode-jsonrpc'; | ||
clientDataFolder?: string; | ||
/** | ||
* The client signals AWS capabilities it supports. | ||
*/ | ||
awsClientCapabilities?: { | ||
window?: { | ||
notifications?: boolean; | ||
}; | ||
}; | ||
} | ||
@@ -72,0 +80,0 @@ /** |
import { MessageType, ProtocolNotificationType } from './lsp'; | ||
export interface EventIdentifier { | ||
readonly id: string; | ||
} | ||
export interface FollowupIdentifier { | ||
readonly source: EventIdentifier; | ||
} | ||
export interface NotificationContent { | ||
@@ -29,4 +35,3 @@ readonly text: string; | ||
} | ||
export interface NotificationParams { | ||
readonly id?: string; | ||
export interface NotificationParams extends Partial<EventIdentifier> { | ||
readonly type: MessageType; | ||
@@ -36,5 +41,4 @@ readonly content: NotificationContent; | ||
} | ||
export interface NotificationFollowupParams { | ||
readonly id: string; | ||
readonly actions: FollowupNotificationActionType[]; | ||
export interface NotificationFollowupParams extends FollowupIdentifier { | ||
readonly action: FollowupNotificationActionType; | ||
} | ||
@@ -49,4 +53,7 @@ /** | ||
* sends to the server to provide asynchronous customer followup to notification shown. | ||
* This method is optional per notification, as not all notifications require followup. | ||
* This method is expected to be used only for notification that require followup. | ||
* | ||
* Client is responsible for passing `id` of source notification that triggered the followup notification | ||
* in the parameters. | ||
*/ | ||
export declare const notificationFollowupRequestType: ProtocolNotificationType<NotificationFollowupParams, void>; |
@@ -22,5 +22,8 @@ "use strict"; | ||
* sends to the server to provide asynchronous customer followup to notification shown. | ||
* This method is optional per notification, as not all notifications require followup. | ||
* This method is expected to be used only for notification that require followup. | ||
* | ||
* Client is responsible for passing `id` of source notification that triggered the followup notification | ||
* in the parameters. | ||
*/ | ||
exports.notificationFollowupRequestType = new lsp_1.ProtocolNotificationType('aws/window/notificationFollowup'); | ||
//# sourceMappingURL=notification.js.map |
@@ -228,3 +228,3 @@ # Language Server Runtimes | ||
The notification feature can be used to send custom customer-facing notifications to clients. Notifications can contain actions, like show URL, but also followup actions, like request customer acknowledgement. When customer reacts to followup actions, asynchronous notification can be sent from client to server to notify server about this. | ||
The notification feature can be used to send custom customer-facing notifications to clients. Notifications can contain actions, like show URL, but also followup actions, like request customer acknowledgement. When customer reacts to followup actions, asynchronous notification is expected to be sent from client to server to notify server about this. | ||
@@ -231,0 +231,0 @@ Notifications should be used in rare / exceptional cases that require customer attention (like some change happened or action recommended), but are not blocking the main flow. Clients can decide to throttle notifications, if too many are sent. |
@@ -11,2 +11,3 @@ import { CancellationToken, DidChangeConfigurationParams, ExecuteCommandParams, GetConfigurationFromServerParams, InitializedParams, InitializeError, InitializeParams, InitializeResult, ResponseError } from '../../../protocol'; | ||
constructor(lspConnection: Connection, name: string, version?: string | undefined); | ||
get clientSupportsShowNotification(): boolean; | ||
initialize: (params: InitializeParams, token: CancellationToken) => Promise<InitializeResult | ResponseError<InitializeError>>; | ||
@@ -13,0 +14,0 @@ executeCommand: (params: ExecuteCommandParams, token: CancellationToken) => Promise<any | undefined | null>; |
@@ -23,2 +23,13 @@ "use strict"; | ||
this.clientInitializeParams = params; | ||
let responsesList = yield Promise.all(this.servers.map(s => s.initialize(params, token))); | ||
responsesList = responsesList.filter(r => r != undefined); | ||
const responseError = responsesList.find(el => el instanceof protocol_1.ResponseError); | ||
if (responseError) { | ||
return responseError; | ||
} | ||
const dupServerNames = (0, util_1.findDuplicates)(responsesList.map(r => { var _a; return (_a = r.serverInfo) === null || _a === void 0 ? void 0 : _a.name; })); | ||
if (dupServerNames) { | ||
return new protocol_1.ResponseError(protocol_1.ErrorCodes.InternalError, `Duplicate servers defined: ${dupServerNames.join(', ')}`); | ||
} | ||
const resultList = responsesList; | ||
const defaultResponse = { | ||
@@ -36,8 +47,2 @@ serverInfo: { | ||
}; | ||
let responsesList = yield Promise.all(this.servers.map(s => s.initialize(params, token))); | ||
responsesList = responsesList.filter(r => r != undefined); | ||
if (responsesList.some(el => el instanceof protocol_1.ResponseError)) { | ||
return responsesList.find(el => el instanceof protocol_1.ResponseError); | ||
} | ||
const resultList = responsesList; | ||
resultList.unshift(defaultResponse); | ||
@@ -86,4 +91,8 @@ return resultList.reduceRight((acc, curr) => { | ||
} | ||
get clientSupportsShowNotification() { | ||
var _a, _b, _c, _d, _e; | ||
return ((_e = (_d = (_c = (_b = (_a = this.clientInitializeParams) === null || _a === void 0 ? void 0 : _a.initializationOptions) === null || _b === void 0 ? void 0 : _b.aws.awsClientCapabilities) === null || _c === void 0 ? void 0 : _c.window) === null || _d === void 0 ? void 0 : _d.notifications) !== null && _e !== void 0 ? _e : false); | ||
} | ||
} | ||
exports.LspRouter = LspRouter; | ||
//# sourceMappingURL=lspRouter.js.map |
@@ -48,2 +48,18 @@ "use strict"; | ||
}); | ||
it('should set clientSupportsShowNotification from InitializeParam', () => { | ||
assert_1.default.equal(lspRouter.clientSupportsShowNotification, false); | ||
const initParam = { | ||
initializationOptions: { | ||
aws: { | ||
awsClientCapabilities: { | ||
window: { | ||
notifications: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
initializeHandler(initParam, {}); | ||
assert_1.default.equal(lspRouter.clientSupportsShowNotification, true); | ||
}); | ||
it('should return the default response when no handlers are registered', () => __awaiter(void 0, void 0, void 0, function* () { | ||
@@ -85,2 +101,5 @@ const result = yield initializeHandler({}, {}); | ||
return { | ||
serverInfo: { | ||
name: 'Q Inline Completion Server', | ||
}, | ||
capabilities: { | ||
@@ -170,2 +189,17 @@ completionProvider: { resolveProvider: true }, | ||
})); | ||
it('should return error if duplicate server names set', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const handlers = [ | ||
() => ({ serverInfo: { name: 'A' } }), | ||
() => ({ serverInfo: { name: 'B' } }), | ||
() => ({ serverInfo: { name: 'A' } }), | ||
() => ({ serverInfo: { name: 'B' } }), | ||
() => ({ serverInfo: { name: 'C' } }), | ||
]; | ||
handlers.forEach(h => { | ||
lspRouter.servers.push(newServer({ initializeHandler: h })); | ||
}); | ||
const result = yield initializeHandler({}, {}); | ||
(0, assert_1.default)(result instanceof protocol_1.ResponseError); | ||
assert_1.default.equal(result.message, 'Duplicate servers defined: A, B'); | ||
})); | ||
}); | ||
@@ -172,0 +206,0 @@ describe('executeCommand', () => { |
@@ -5,1 +5,2 @@ export declare function asPromise<T>(value: Promise<T>): Promise<T>; | ||
export declare function mergeObjects(obj1: any, obj2: any): any; | ||
export declare function findDuplicates<T>(array: T[]): T[] | undefined; |
@@ -5,2 +5,3 @@ "use strict"; | ||
exports.mergeObjects = mergeObjects; | ||
exports.findDuplicates = findDuplicates; | ||
function func(value) { | ||
@@ -53,2 +54,15 @@ return typeof value === 'function'; | ||
} | ||
function findDuplicates(array) { | ||
const seen = new Set(); | ||
const dups = array | ||
.filter(a => a !== undefined) | ||
.filter(function (a) { | ||
if (seen.has(a)) { | ||
return true; | ||
} | ||
seen.add(a); | ||
return false; | ||
}); | ||
return dups.length > 0 ? dups : undefined; | ||
} | ||
//# sourceMappingURL=util.js.map |
@@ -174,3 +174,6 @@ "use strict"; | ||
const notification = { | ||
showNotification: params => lspConnection.sendNotification(protocol_1.showNotificationRequestType.method, params), | ||
showNotification: params => { | ||
var _a; | ||
return (_a = lspRouter.clientSupportsShowNotification) !== null && _a !== void 0 ? _a : lspConnection.sendNotification(protocol_1.showNotificationRequestType.method, params); | ||
}, | ||
onNotificationFollowup: handler => lspConnection.onNotification(protocol_1.notificationFollowupRequestType.method, handler), | ||
@@ -177,0 +180,0 @@ }; |
@@ -73,3 +73,6 @@ "use strict"; | ||
const notification = { | ||
showNotification: params => lspConnection.sendNotification(protocol_1.showNotificationRequestType.method, params), | ||
showNotification: params => { | ||
var _a; | ||
return (_a = lspRouter.clientSupportsShowNotification) !== null && _a !== void 0 ? _a : lspConnection.sendNotification(protocol_1.showNotificationRequestType.method, params); | ||
}, | ||
onNotificationFollowup: handler => lspConnection.onNotification(protocol_1.notificationFollowupRequestType.method, handler), | ||
@@ -76,0 +79,0 @@ }; |
@@ -6,2 +6,13 @@ import { CompletionItem, CompletionList, CompletionParams, ConfigurationOptions, DidChangeConfigurationParams, DidChangeTextDocumentParams, DidChangeWorkspaceFoldersParams, DidCloseTextDocumentParams, DidOpenTextDocumentParams, DocumentFormattingParams, ExecuteCommandParams, GetConfigurationFromServerParams, Hover, HoverParams, InitializeError, InitializeParams, InitializedParams, InlineCompletionItem, InlineCompletionItemWithReferences, InlineCompletionList, InlineCompletionListWithReferences, InlineCompletionParams, LogInlineCompletionSessionResultsParams, NotificationHandler, ProgressToken, ProgressType, PublishDiagnosticsParams, ChatOptions, RequestHandler, ServerCapabilities, TextEdit, SemanticTokensParams, SemanticTokens, SignatureHelp, SignatureHelpParams, ShowMessageParams, ShowMessageRequestParams, MessageActionItem, ShowDocumentParams, ShowDocumentResult, LSPAny, ApplyWorkspaceEditParams, ApplyWorkspaceEditResult } from '../protocol'; | ||
export type PartialInitializeResult<T = any> = { | ||
/** | ||
* Information about the server respresented by @type {Server}. | ||
* serverInfo is used to differentiate servers internally in the system and is not exposed to the client. | ||
*/ | ||
serverInfo?: { | ||
/** | ||
* The name is expect to be unique per server. It also has to be persistent/durable | ||
* across sessions and versions of application. | ||
*/ | ||
name: string; | ||
}; | ||
capabilities: PartialServerCapabilities<T>; | ||
@@ -8,0 +19,0 @@ awsServerCapabilities?: { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
335292
3855
Updatedjose@^5.9.6