Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add in non-standard lsp request for resolving schemas on the client-side #395

Merged
merged 2 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
38 changes: 37 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -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<string, string, any, any> = new RequestType('vscode/content');
}

// eslint-disable-next-line @typescript-eslint/no-namespace
namespace DynamicCustomSchemaRequestRegistration {
// eslint-disable-next-line @typescript-eslint/ban-types
Expand Down Expand Up @@ -86,13 +106,29 @@ 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);
});
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;
Expand Down