From 9aa9e5b9e19cfbc0dabd0aa5f2d29352a6c6ba95 Mon Sep 17 00:00:00 2001 From: Josh Pinkney Date: Thu, 19 Nov 2020 22:16:30 -0500 Subject: [PATCH 1/2] Add in non-standard lsp request for resolving schemas on the client-side Signed-off-by: Josh Pinkney --- package-lock.json | 28 +++++++++++++++++++--------- package.json | 1 + src/extension.ts | 38 +++++++++++++++++++++++++++++++++++++- 3 files changed, 57 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9e2c7ac9..4905de0e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1590,13 +1590,13 @@ "dev": true }, "request-light": { - "version": "0.2.5", - "resolved": "https://registry.npmjs.org/request-light/-/request-light-0.2.5.tgz", - "integrity": "sha512-eBEh+GzJAftUnex6tcL6eV2JCifY0+sZMIUpUPOVXbs2nV5hla4ZMmO3icYKGuGVuQ2zHE9evh4OrRcH4iyYYw==", + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/request-light/-/request-light-0.4.0.tgz", + "integrity": "sha512-fimzjIVw506FBZLspTAXHdpvgvQebyjpNyLRd0e6drPPRq7gcrROeGWRyF81wLqFg5ijPgnOQbmfck5wdTqpSA==", "requires": { "http-proxy-agent": "^2.1.0", - "https-proxy-agent": "^2.2.3", - "vscode-nls": "^4.1.1" + "https-proxy-agent": "^2.2.4", + "vscode-nls": "^4.1.2" }, "dependencies": { "vscode-nls": { @@ -2130,15 +2130,15 @@ "dev": true }, "yaml-language-server": { - "version": "0.12.1-5c483ee.0", - "resolved": "https://registry.npmjs.org/yaml-language-server/-/yaml-language-server-0.12.1-5c483ee.0.tgz", - "integrity": "sha512-aaHxnrU+RDZBtvMk8vCeBoHZTCBqV/mKTEKP7U1qgR1GYOF3Y4ofC8DsRGnIuW6Rwyqymyscrsvj1tf8zmEr3Q==", + "version": "0.13.1-33b090a.0", + "resolved": "https://registry.npmjs.org/yaml-language-server/-/yaml-language-server-0.13.1-33b090a.0.tgz", + "integrity": "sha512-4hNSDsdt9BVAM+tHshBaikVXnN4ZR8zaNcNpmYpAYkZ1MdAz6w4zPZUCVCkfmQ5tUKvIgiXtDkITShOJ32lqhw==", "requires": { "js-yaml": "^3.13.1", "jsonc-parser": "^2.2.1", "prettier": "2.0.5", "request-light": "^0.2.4", - "vscode-json-languageservice": "^3.6.0", + "vscode-json-languageservice": "^3.10.0", "vscode-languageserver": "^5.2.1", "vscode-languageserver-types": "^3.15.1", "vscode-nls": "^4.1.2", @@ -2146,6 +2146,16 @@ "yaml-language-server-parser": "^0.1.2-eb3160b.0" }, "dependencies": { + "request-light": { + "version": "0.2.5", + "resolved": "https://registry.npmjs.org/request-light/-/request-light-0.2.5.tgz", + "integrity": "sha512-eBEh+GzJAftUnex6tcL6eV2JCifY0+sZMIUpUPOVXbs2nV5hla4ZMmO3icYKGuGVuQ2zHE9evh4OrRcH4iyYYw==", + "requires": { + "http-proxy-agent": "^2.1.0", + "https-proxy-agent": "^2.2.3", + "vscode-nls": "^4.1.1" + } + }, "vscode-nls": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/vscode-nls/-/vscode-nls-4.1.2.tgz", diff --git a/package.json b/package.json index ab3a746f..c20ce430 100755 --- a/package.json +++ b/package.json @@ -186,6 +186,7 @@ "vscode-test": "^1.4.0" }, "dependencies": { + "request-light": "^0.4.0", "vscode-languageclient": "5.2.1", "vscode-nls": "^3.2.1", "vscode-uri": "^2.0.3", diff --git a/src/extension.ts b/src/extension.ts index 9693051a..22d60cc1 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -9,9 +9,17 @@ import * as path from 'path'; import { workspace, ExtensionContext, extensions } from 'vscode'; -import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, NotificationType } from 'vscode-languageclient'; +import { + LanguageClient, + LanguageClientOptions, + ServerOptions, + TransportKind, + NotificationType, + RequestType, +} from 'vscode-languageclient'; import { CUSTOM_SCHEMA_REQUEST, CUSTOM_CONTENT_REQUEST, SchemaExtensionAPI } from './schema-extension-api'; import { joinPath } from './paths'; +import { xhr, configure as configureHttpRequests, getErrorStatusDescription, XHRResponse } from 'request-light'; export interface ISchemaAssociations { [pattern: string]: string[]; @@ -30,6 +38,18 @@ namespace SchemaAssociationNotification { ); } +// eslint-disable-next-line @typescript-eslint/no-namespace +namespace ContentRequestRegistration { + // eslint-disable-next-line @typescript-eslint/ban-types + export const type: NotificationType<{}, {}> = new NotificationType('yaml/registerContentRequest'); +} + +// eslint-disable-next-line @typescript-eslint/no-namespace +namespace VSCodeContentRequest { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + export const type: RequestType = new RequestType('vscode/content'); +} + // eslint-disable-next-line @typescript-eslint/no-namespace namespace DynamicCustomSchemaRequestRegistration { // eslint-disable-next-line @typescript-eslint/ban-types @@ -86,6 +106,8 @@ export function activate(context: ExtensionContext): SchemaExtensionAPI { }); // Tell the server that the client is ready to provide custom schema content client.sendNotification(DynamicCustomSchemaRequestRegistration.type); + // Tell the server that the client supports schema requests sent directly to it + client.sendNotification(ContentRequestRegistration.type); // If the server asks for custom schema content, get it and send it back client.onRequest(CUSTOM_SCHEMA_REQUEST, (resource: string) => { return schemaExtensionAPI.requestCustomSchema(resource); @@ -93,6 +115,20 @@ export function activate(context: ExtensionContext): SchemaExtensionAPI { client.onRequest(CUSTOM_CONTENT_REQUEST, (uri: string) => { return schemaExtensionAPI.requestCustomSchemaContent(uri); }); + client.onRequest(VSCodeContentRequest.type, (uri: string) => { + const httpSettings = workspace.getConfiguration('http'); + configureHttpRequests(httpSettings.http && httpSettings.http.proxy, httpSettings.http && httpSettings.http.proxyStrictSSL); + + const headers = { 'Accept-Encoding': 'gzip, deflate' }; + return xhr({ url: uri, followRedirects: 5, headers }).then( + (response) => { + return response.responseText; + }, + (error: XHRResponse) => { + return Promise.reject(error.responseText || getErrorStatusDescription(error.status) || error.toString()); + } + ); + }); }); return schemaExtensionAPI; From e9bb0ef2f1ee45780bac73b52a753300095601d0 Mon Sep 17 00:00:00 2001 From: Josh Pinkney Date: Thu, 26 Nov 2020 07:59:35 -0500 Subject: [PATCH 2/2] Update the name of the content request notification to be: yaml/registerVSCodeContentRequest Signed-off-by: Josh Pinkney --- src/extension.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 22d60cc1..a7a449fd 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -39,9 +39,9 @@ namespace SchemaAssociationNotification { } // eslint-disable-next-line @typescript-eslint/no-namespace -namespace ContentRequestRegistration { +namespace VSCodeContentRequestRegistration { // eslint-disable-next-line @typescript-eslint/ban-types - export const type: NotificationType<{}, {}> = new NotificationType('yaml/registerContentRequest'); + export const type: NotificationType<{}, {}> = new NotificationType('yaml/registerVSCodeContentRequest'); } // eslint-disable-next-line @typescript-eslint/no-namespace @@ -107,7 +107,7 @@ export function activate(context: ExtensionContext): SchemaExtensionAPI { // Tell the server that the client is ready to provide custom schema content client.sendNotification(DynamicCustomSchemaRequestRegistration.type); // Tell the server that the client supports schema requests sent directly to it - client.sendNotification(ContentRequestRegistration.type); + client.sendNotification(VSCodeContentRequestRegistration.type); // If the server asks for custom schema content, get it and send it back client.onRequest(CUSTOM_SCHEMA_REQUEST, (resource: string) => { return schemaExtensionAPI.requestCustomSchema(resource);