Skip to content

Commit b2560d1

Browse files
authored
Merge pull request #395 from redhat-developer/content-request
Add in non-standard lsp request for resolving schemas on the client-side
2 parents 2278945 + e9bb0ef commit b2560d1

File tree

3 files changed

+57
-10
lines changed

3 files changed

+57
-10
lines changed

package-lock.json

Lines changed: 19 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@
186186
"vscode-test": "^1.4.0"
187187
},
188188
"dependencies": {
189+
"request-light": "^0.4.0",
189190
"vscode-languageclient": "5.2.1",
190191
"vscode-nls": "^3.2.1",
191192
"vscode-uri": "^2.0.3",

src/extension.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,17 @@
99
import * as path from 'path';
1010

1111
import { workspace, ExtensionContext, extensions } from 'vscode';
12-
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, NotificationType } from 'vscode-languageclient';
12+
import {
13+
LanguageClient,
14+
LanguageClientOptions,
15+
ServerOptions,
16+
TransportKind,
17+
NotificationType,
18+
RequestType,
19+
} from 'vscode-languageclient';
1320
import { CUSTOM_SCHEMA_REQUEST, CUSTOM_CONTENT_REQUEST, SchemaExtensionAPI } from './schema-extension-api';
1421
import { joinPath } from './paths';
22+
import { xhr, configure as configureHttpRequests, getErrorStatusDescription, XHRResponse } from 'request-light';
1523

1624
export interface ISchemaAssociations {
1725
[pattern: string]: string[];
@@ -30,6 +38,18 @@ namespace SchemaAssociationNotification {
3038
);
3139
}
3240

41+
// eslint-disable-next-line @typescript-eslint/no-namespace
42+
namespace VSCodeContentRequestRegistration {
43+
// eslint-disable-next-line @typescript-eslint/ban-types
44+
export const type: NotificationType<{}, {}> = new NotificationType('yaml/registerVSCodeContentRequest');
45+
}
46+
47+
// eslint-disable-next-line @typescript-eslint/no-namespace
48+
namespace VSCodeContentRequest {
49+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
50+
export const type: RequestType<string, string, any, any> = new RequestType('vscode/content');
51+
}
52+
3353
// eslint-disable-next-line @typescript-eslint/no-namespace
3454
namespace DynamicCustomSchemaRequestRegistration {
3555
// eslint-disable-next-line @typescript-eslint/ban-types
@@ -86,13 +106,29 @@ export function activate(context: ExtensionContext): SchemaExtensionAPI {
86106
});
87107
// Tell the server that the client is ready to provide custom schema content
88108
client.sendNotification(DynamicCustomSchemaRequestRegistration.type);
109+
// Tell the server that the client supports schema requests sent directly to it
110+
client.sendNotification(VSCodeContentRequestRegistration.type);
89111
// If the server asks for custom schema content, get it and send it back
90112
client.onRequest(CUSTOM_SCHEMA_REQUEST, (resource: string) => {
91113
return schemaExtensionAPI.requestCustomSchema(resource);
92114
});
93115
client.onRequest(CUSTOM_CONTENT_REQUEST, (uri: string) => {
94116
return schemaExtensionAPI.requestCustomSchemaContent(uri);
95117
});
118+
client.onRequest(VSCodeContentRequest.type, (uri: string) => {
119+
const httpSettings = workspace.getConfiguration('http');
120+
configureHttpRequests(httpSettings.http && httpSettings.http.proxy, httpSettings.http && httpSettings.http.proxyStrictSSL);
121+
122+
const headers = { 'Accept-Encoding': 'gzip, deflate' };
123+
return xhr({ url: uri, followRedirects: 5, headers }).then(
124+
(response) => {
125+
return response.responseText;
126+
},
127+
(error: XHRResponse) => {
128+
return Promise.reject(error.responseText || getErrorStatusDescription(error.status) || error.toString());
129+
}
130+
);
131+
});
96132
});
97133

98134
return schemaExtensionAPI;

0 commit comments

Comments
 (0)