volar-service-json 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/out/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import type { Service } from '@volar/language-service';
2
+ import * as json from 'vscode-json-languageservice';
3
+ declare const _default: (settings?: json.LanguageSettings) => Service;
4
+ export default _default;
package/out/index.js ADDED
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const json = __importStar(require("vscode-json-languageservice"));
27
+ exports.default = (settings) => (context) => {
28
+ // https://github.com/microsoft/vscode/blob/09850876e652688fb142e2e19fd00fd38c0bc4ba/extensions/json-language-features/server/src/jsonServer.ts#L150
29
+ const triggerCharacters = ['"', ':'];
30
+ if (!context) {
31
+ return { triggerCharacters };
32
+ }
33
+ const jsonDocuments = new WeakMap();
34
+ const jsonLs = json.getLanguageService({ schemaRequestService: context.env.schemaRequestService });
35
+ if (settings) {
36
+ jsonLs.configure(settings);
37
+ }
38
+ return {
39
+ triggerCharacters,
40
+ async resolveRuleContext(context) {
41
+ await worker(context.document, async (jsonDocument) => {
42
+ context.json = {
43
+ document: jsonDocument,
44
+ languageService: jsonLs,
45
+ };
46
+ });
47
+ return context;
48
+ },
49
+ provideCompletionItems(document, position) {
50
+ return worker(document, async (jsonDocument) => {
51
+ return await jsonLs.doComplete(document, position, jsonDocument);
52
+ });
53
+ },
54
+ resolveCompletionItem(item) {
55
+ return jsonLs.doResolve(item);
56
+ },
57
+ provideDefinition(document, position) {
58
+ return worker(document, async (jsonDocument) => {
59
+ return await jsonLs.findDefinition(document, position, jsonDocument);
60
+ });
61
+ },
62
+ provideDiagnostics(document) {
63
+ return worker(document, async (jsonDocument) => {
64
+ const documentLanguageSettings = undefined; // await getSettings(); // TODO
65
+ return await jsonLs.doValidation(document, jsonDocument, documentLanguageSettings, undefined);
66
+ });
67
+ },
68
+ provideHover(document, position) {
69
+ return worker(document, async (jsonDocument) => {
70
+ return await jsonLs.doHover(document, position, jsonDocument);
71
+ });
72
+ },
73
+ provideDocumentLinks(document) {
74
+ return worker(document, async (jsonDocument) => {
75
+ return await jsonLs.findLinks(document, jsonDocument);
76
+ });
77
+ },
78
+ provideDocumentSymbols(document) {
79
+ return worker(document, async (jsonDocument) => {
80
+ return await jsonLs.findDocumentSymbols2(document, jsonDocument);
81
+ });
82
+ },
83
+ provideDocumentColors(document) {
84
+ return worker(document, async (jsonDocument) => {
85
+ return await jsonLs.findDocumentColors(document, jsonDocument);
86
+ });
87
+ },
88
+ provideColorPresentations(document, color, range) {
89
+ return worker(document, async (jsonDocument) => {
90
+ return await jsonLs.getColorPresentations(document, jsonDocument, color, range);
91
+ });
92
+ },
93
+ provideFoldingRanges(document) {
94
+ return worker(document, async () => {
95
+ return await jsonLs.getFoldingRanges(document);
96
+ });
97
+ },
98
+ provideSelectionRanges(document, positions) {
99
+ return worker(document, async (jsonDocument) => {
100
+ return await jsonLs.getSelectionRanges(document, positions, jsonDocument);
101
+ });
102
+ },
103
+ provideDocumentFormattingEdits(document, range, options) {
104
+ return worker(document, async () => {
105
+ const options_2 = await context.env.getConfiguration?.('json.format');
106
+ if (!(options_2?.enable ?? true)) {
107
+ return;
108
+ }
109
+ return jsonLs.format(document, range, {
110
+ ...options_2,
111
+ ...options,
112
+ });
113
+ });
114
+ },
115
+ };
116
+ function worker(document, callback) {
117
+ const jsonDocument = getJsonDocument(document);
118
+ if (!jsonDocument)
119
+ return;
120
+ return callback(jsonDocument);
121
+ }
122
+ function getJsonDocument(textDocument) {
123
+ if (textDocument.languageId !== 'json' && textDocument.languageId !== 'jsonc')
124
+ return;
125
+ const cache = jsonDocuments.get(textDocument);
126
+ if (cache) {
127
+ const [cacheVersion, cacheDoc] = cache;
128
+ if (cacheVersion === textDocument.version) {
129
+ return cacheDoc;
130
+ }
131
+ }
132
+ const doc = jsonLs.parseJSONDocument(textDocument);
133
+ jsonDocuments.set(textDocument, [textDocument.version, doc]);
134
+ return doc;
135
+ }
136
+ };
137
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "volar-service-json",
3
+ "version": "0.0.0",
4
+ "main": "out/index.js",
5
+ "license": "MIT",
6
+ "files": [
7
+ "rules.d.ts",
8
+ "out/**/*.js",
9
+ "out/**/*.d.ts"
10
+ ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/volarjs/services.git",
14
+ "directory": "packages/json"
15
+ },
16
+ "dependencies": {
17
+ "vscode-json-languageservice": "^5.2.0",
18
+ "vscode-languageserver-protocol": "^3.17.3",
19
+ "vscode-languageserver-textdocument": "^1.0.8"
20
+ },
21
+ "peerDependencies": {
22
+ "@volar/language-service": "*"
23
+ },
24
+ "peerDependenciesMeta": {
25
+ "@volar/language-service": {
26
+ "optional": true
27
+ }
28
+ },
29
+ "gitHead": "1011561ac4bbf79c53c3b80c27692569bf861519"
30
+ }
package/rules.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import * as json from 'vscode-json-languageservice';
2
+
3
+ declare module '@volar/language-service' {
4
+ interface RuleContext {
5
+ json?: {
6
+ document: json.JSONDocument;
7
+ languageService: json.LanguageService;
8
+ }
9
+ }
10
+ }