Skip to content

Commit

Permalink
[json] update service (fixes #58956)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeschli committed Sep 20, 2018
1 parent 5037516 commit 1b38a64
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 51 deletions.
2 changes: 1 addition & 1 deletion extensions/json-language-features/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dependencies": {
"jsonc-parser": "^2.0.2",
"request-light": "^0.2.4",
"vscode-json-languageservice": "^3.1.7",
"vscode-json-languageservice": "^3.2.0-next.2",
"vscode-languageserver": "^5.1.0",
"vscode-nls": "^4.0.0",
"vscode-uri": "^1.0.6"
Expand Down
103 changes: 56 additions & 47 deletions extensions/json-language-features/server/src/jsonServerMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,55 @@ process.on('uncaughtException', (e: any) => {
console.log = connection.console.log.bind(connection.console);
console.error = connection.console.error.bind(connection.console);

const workspaceContext = {
resolveRelativePath: (relativePath: string, resource: string) => {
return URL.resolve(resource, relativePath);
}
};

const schemaRequestService = (uri: string): Thenable<string> => {
if (startsWith(uri, 'file://')) {
const fsPath = URI.parse(uri).fsPath;
return new Promise<string>((c, e) => {
fs.readFile(fsPath, 'UTF-8', (err, result) => {
err ? e('') : c(result.toString());
});
});
} else if (startsWith(uri, 'vscode://')) {
return connection.sendRequest(VSCodeContentRequest.type, uri).then(responseText => {
return responseText;
}, error => {
return Promise.reject(error.message);
});
}
if (uri.indexOf('//schema.management.azure.com/') !== -1) {
/* __GDPR__
"json.schema" : {
"schemaURL" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
connection.telemetry.logEvent({
key: 'json.schema',
value: {
schemaURL: uri
}
});
}
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());
});
};

// create the JSON language service
let languageService = getLanguageService({
schemaRequestService,
workspaceContext,
contributions: [],
});

// Create a simple text document manager. The text document manager
// supports full document sync only
const documents: TextDocuments = new TextDocuments();
Expand All @@ -65,6 +114,13 @@ let hierarchicalDocumentSymbolSupport = false;
// in the passed params the rootPath of the workspace plus the client capabilities.
connection.onInitialize((params: InitializeParams): InitializeResult => {

languageService = getLanguageService({
schemaRequestService,
workspaceContext,
contributions: [],
clientCapabilities: params.capabilities
});

function getClientCapability<T>(name: string, def: T) {
const keys = name.split('.');
let c: any = params.capabilities;
Expand Down Expand Up @@ -95,54 +151,7 @@ connection.onInitialize((params: InitializeParams): InitializeResult => {
return { capabilities };
});

const workspaceContext = {
resolveRelativePath: (relativePath: string, resource: string) => {
return URL.resolve(resource, relativePath);
}
};

const schemaRequestService = (uri: string): Thenable<string> => {
if (startsWith(uri, 'file://')) {
const fsPath = URI.parse(uri).fsPath;
return new Promise<string>((c, e) => {
fs.readFile(fsPath, 'UTF-8', (err, result) => {
err ? e('') : c(result.toString());
});
});
} else if (startsWith(uri, 'vscode://')) {
return connection.sendRequest(VSCodeContentRequest.type, uri).then(responseText => {
return responseText;
}, error => {
return Promise.reject(error.message);
});
}
if (uri.indexOf('//schema.management.azure.com/') !== -1) {
/* __GDPR__
"json.schema" : {
"schemaURL" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
connection.telemetry.logEvent({
key: 'json.schema',
value: {
schemaURL: uri
}
});
}
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());
});
};

// create the JSON language service
const languageService = getLanguageService({
schemaRequestService,
workspaceContext,
contributions: []
});

// The settings interface describes the server relevant settings part
interface Settings {
Expand Down
6 changes: 3 additions & 3 deletions extensions/json-language-features/server/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ request-light@^0.2.4:
https-proxy-agent "^2.2.1"
vscode-nls "^4.0.0"

vscode-json-languageservice@^3.1.7:
version "3.1.7"
resolved "https://registry.yarnpkg.com/vscode-json-languageservice/-/vscode-json-languageservice-3.1.7.tgz#ace6ef40c340262b2a6fcd7f72be99c99751010c"
vscode-json-languageservice@^3.2.0-next.2:
version "3.2.0-next.2"
resolved "https://registry.yarnpkg.com/vscode-json-languageservice/-/vscode-json-languageservice-3.2.0-next.2.tgz#4f70bc960855f3055af093b59859a4de4672381a"
dependencies:
jsonc-parser "^2.0.2"
vscode-languageserver-types "^3.13.0"
Expand Down

0 comments on commit 1b38a64

Please sign in to comment.