jsonLanguageService.js 5.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  6. if (k2 === undefined) k2 = k;
  7. Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  8. }) : (function(o, m, k, k2) {
  9. if (k2 === undefined) k2 = k;
  10. o[k2] = m[k];
  11. }));
  12. var __exportStar = (this && this.__exportStar) || function(m, exports) {
  13. for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
  14. };
  15. (function (factory) {
  16. if (typeof module === "object" && typeof module.exports === "object") {
  17. var v = factory(require, exports);
  18. if (v !== undefined) module.exports = v;
  19. }
  20. else if (typeof define === "function" && define.amd) {
  21. define(["require", "exports", "./services/jsonCompletion", "./services/jsonHover", "./services/jsonValidation", "./services/jsonDocumentSymbols", "./parser/jsonParser", "./services/configuration", "./services/jsonSchemaService", "./services/jsonFolding", "./services/jsonSelectionRanges", "jsonc-parser", "./jsonLanguageTypes", "./services/jsonLinks", "./jsonLanguageTypes"], factory);
  22. }
  23. })(function (require, exports) {
  24. "use strict";
  25. Object.defineProperty(exports, "__esModule", { value: true });
  26. exports.getLanguageService = void 0;
  27. var jsonCompletion_1 = require("./services/jsonCompletion");
  28. var jsonHover_1 = require("./services/jsonHover");
  29. var jsonValidation_1 = require("./services/jsonValidation");
  30. var jsonDocumentSymbols_1 = require("./services/jsonDocumentSymbols");
  31. var jsonParser_1 = require("./parser/jsonParser");
  32. var configuration_1 = require("./services/configuration");
  33. var jsonSchemaService_1 = require("./services/jsonSchemaService");
  34. var jsonFolding_1 = require("./services/jsonFolding");
  35. var jsonSelectionRanges_1 = require("./services/jsonSelectionRanges");
  36. var jsonc_parser_1 = require("jsonc-parser");
  37. var jsonLanguageTypes_1 = require("./jsonLanguageTypes");
  38. var jsonLinks_1 = require("./services/jsonLinks");
  39. __exportStar(require("./jsonLanguageTypes"), exports);
  40. function getLanguageService(params) {
  41. var promise = params.promiseConstructor || Promise;
  42. var jsonSchemaService = new jsonSchemaService_1.JSONSchemaService(params.schemaRequestService, params.workspaceContext, promise);
  43. jsonSchemaService.setSchemaContributions(configuration_1.schemaContributions);
  44. var jsonCompletion = new jsonCompletion_1.JSONCompletion(jsonSchemaService, params.contributions, promise, params.clientCapabilities);
  45. var jsonHover = new jsonHover_1.JSONHover(jsonSchemaService, params.contributions, promise);
  46. var jsonDocumentSymbols = new jsonDocumentSymbols_1.JSONDocumentSymbols(jsonSchemaService);
  47. var jsonValidation = new jsonValidation_1.JSONValidation(jsonSchemaService, promise);
  48. return {
  49. configure: function (settings) {
  50. jsonSchemaService.clearExternalSchemas();
  51. if (settings.schemas) {
  52. settings.schemas.forEach(function (settings) {
  53. jsonSchemaService.registerExternalSchema(settings.uri, settings.fileMatch, settings.schema);
  54. });
  55. }
  56. jsonValidation.configure(settings);
  57. },
  58. resetSchema: function (uri) { return jsonSchemaService.onResourceChange(uri); },
  59. doValidation: jsonValidation.doValidation.bind(jsonValidation),
  60. parseJSONDocument: function (document) { return jsonParser_1.parse(document, { collectComments: true }); },
  61. newJSONDocument: function (root, diagnostics) { return jsonParser_1.newJSONDocument(root, diagnostics); },
  62. getMatchingSchemas: jsonSchemaService.getMatchingSchemas.bind(jsonSchemaService),
  63. doResolve: jsonCompletion.doResolve.bind(jsonCompletion),
  64. doComplete: jsonCompletion.doComplete.bind(jsonCompletion),
  65. findDocumentSymbols: jsonDocumentSymbols.findDocumentSymbols.bind(jsonDocumentSymbols),
  66. findDocumentSymbols2: jsonDocumentSymbols.findDocumentSymbols2.bind(jsonDocumentSymbols),
  67. findDocumentColors: jsonDocumentSymbols.findDocumentColors.bind(jsonDocumentSymbols),
  68. getColorPresentations: jsonDocumentSymbols.getColorPresentations.bind(jsonDocumentSymbols),
  69. doHover: jsonHover.doHover.bind(jsonHover),
  70. getFoldingRanges: jsonFolding_1.getFoldingRanges,
  71. getSelectionRanges: jsonSelectionRanges_1.getSelectionRanges,
  72. findDefinition: function () { return Promise.resolve([]); },
  73. findLinks: jsonLinks_1.findLinks,
  74. format: function (d, r, o) {
  75. var range = undefined;
  76. if (r) {
  77. var offset = d.offsetAt(r.start);
  78. var length = d.offsetAt(r.end) - offset;
  79. range = { offset: offset, length: length };
  80. }
  81. var options = { tabSize: o ? o.tabSize : 4, insertSpaces: (o === null || o === void 0 ? void 0 : o.insertSpaces) === true, insertFinalNewline: (o === null || o === void 0 ? void 0 : o.insertFinalNewline) === true, eol: '\n' };
  82. return jsonc_parser_1.format(d.getText(), range, options).map(function (e) {
  83. return jsonLanguageTypes_1.TextEdit.replace(jsonLanguageTypes_1.Range.create(d.positionAt(e.offset), d.positionAt(e.offset + e.length)), e.content);
  84. });
  85. }
  86. };
  87. }
  88. exports.getLanguageService = getLanguageService;
  89. });