Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"request": "launch",
"runtimeArgs": [
"--test",
"./lib/umd/test/**/*.test.js"
"./lib/esm/test/**/*.test.js"
],
"cwd": "${workspaceRoot}",
"sourceMaps": true,
"outFiles": [ "${workspaceRoot}/lib/umd/**/*.js" ],
"outFiles": [ "${workspaceRoot}/lib/esm/**/*.js" ],
"preLaunchTask": "npm: watch"
},
{
Expand Down
38 changes: 19 additions & 19 deletions build/bundle-schemas.cjs → build/bundle-schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

const fs = require('fs').promises;
const Bundler = require("@hyperjump/json-schema-bundle");
import { writeFile } from 'node:fs/promises';
import Bundler from '@hyperjump/json-schema-bundle';

(async function () {
bundle(`https://json-schema.org/draft/2019-09/schema`, 'draft-2019-09', 'https://json-schema.org/draft/2019-09');
bundle(`https://json-schema.org/draft/2020-12/schema`, 'draft-2020-12', 'https://json-schema.org/draft/2020-12');
bundle('https://json-schema.org/draft/2019-09/schema', 'draft-2019-09', 'https://json-schema.org/draft/2019-09');
bundle('https://json-schema.org/draft/2020-12/schema', 'draft-2020-12', 'https://json-schema.org/draft/2020-12');
}());

async function bundle(uri, filename, derivedURL) {
const metaSchema = await Bundler.get(uri);
let bundle = await Bundler.bundle(metaSchema);
bundle = JSON.parse(JSON.stringify(bundle, null, 2).replace(/"undefined": ""/g, '"$dynamicAnchor": "meta"'));
fs.writeFile(`./${filename}.json`, JSON.stringify(bundle, null, 2), 'utf8');
await writeFile(`./${filename}.json`, JSON.stringify(bundle, null, 2), 'utf8');
bundle = flattenDraftMetaSchema(bundle);
const jsified = getCopyright(derivedURL) + 'export default ' + printObject(bundle);
fs.writeFile(`./${filename}-flat.json`, JSON.stringify(bundle, null, 2), 'utf8');
fs.writeFile(`./src/services/schemas/${filename}-flat.ts`, jsified, 'utf8');
await writeFile(`./${filename}-flat.json`, JSON.stringify(bundle, null, 2), 'utf8');
await writeFile(`./src/services/schemas/${filename}-flat.ts`, jsified, 'utf8');
}
function getCopyright(derivedURL) {
return [
Expand Down Expand Up @@ -55,7 +55,7 @@ function indent(level) {
function printObject(obj, indentLevel = 0) {
const result = [];
if (Array.isArray(obj)) {
result.push(`[`);
result.push('[');
for (const item of obj) {
if (typeof item === 'object' && item !== null) {
result.push(`${indent(indentLevel + 1)}${printObject(item, indentLevel + 1)},`);
Expand All @@ -67,11 +67,11 @@ function printObject(obj, indentLevel = 0) {
return result.join('\n');
}
if (obj === null) {
result.push(`null`);
result.push('null');
return result.join('\n');
}

result.push(`{`);
result.push('{');
for (const [key, value] of Object.entries(obj)) {
if (typeof value === 'object' && value !== null) {
result.push(`${indent(indentLevel + 1)}${printKey(key)}: ${printObject(value, indentLevel + 1)},`);
Expand Down Expand Up @@ -106,9 +106,9 @@ function replaceDynamicRefs(node, anchorName = DEFAULT_ANCHOR) {
visit(node, (n, k) => {
const v = n[k];
if (k === '$dynamicRef' && v === '#' + anchorName) {
n['$ref'] = '#';
delete n['$dynamicRef'];
};
n.$ref = '#';
delete n.$dynamicRef;
}
});
}

Expand All @@ -117,9 +117,9 @@ function replaceRecursiveRefs(node, anchorName = DEFAULT_ANCHOR) {
visit(node, (n, k) => {
const v = n[k];
if (k === '$recursiveRef') {
n['$ref'] = v;
delete n['$recursiveRef'];
};
n.$ref = v;
delete n.$recursiveRef;
}
});
}

Expand All @@ -130,7 +130,7 @@ function replaceOldRefs(node, anchorName = DEFAULT_ANCHOR) {
if (k === '$ref' && typeof v === 'string' && v.startsWith(anchorName + '/')) {
const segments = v.split('#');
if (segments.length === 2) {
n['$ref'] = `#${segments[1]}`;
n.$ref = `#${segments[1]}`;
}
}
});
Expand All @@ -149,7 +149,7 @@ function stripDynamicAnchors(node) {
function collectVocabularies(schema) {
const vocabularies = [];
const defs = schema.$defs || {};
for (const [key, value] of Object.entries(defs)) {
for (const [, value] of Object.entries(defs)) {
if (value && typeof value === 'object' && !Array.isArray(value) && value.$id && value.$dynamicAnchor === DEFAULT_ANCHOR && value.properties) {
vocabularies.push(value);
}
Expand Down Expand Up @@ -251,4 +251,4 @@ function flattenDraftMetaSchema(original) {
}

return schema;
}
}
15 changes: 9 additions & 6 deletions build/remove-sourcemap-refs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,33 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

const fs = require('fs');
const path = require('path');
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

function deleteRefs(dir) {
const files = fs.readdirSync(dir);
for (let file of files) {
for (const file of files) {
const filePath = path.join(dir, file);
const stat = fs.statSync(filePath);
if (stat.isDirectory()) {
deleteRefs(filePath);
} else if (path.extname(file) === '.js') {
const content = fs.readFileSync(filePath, 'utf8');
const newContent = content.replace(/\/\/\# sourceMappingURL=[^]+.js.map/, '')
const newContent = content.replace(/\/\/\# sourceMappingURL=[^]+.js.map/, '');
if (content.length !== newContent.length) {
console.log('remove sourceMappingURL in ' + filePath);
fs.writeFileSync(filePath, newContent);
}
} else if (path.extname(file) === '.map') {
fs.unlinkSync(filePath)
fs.unlinkSync(filePath);
console.log('remove ' + filePath);
}
}
}

let location = path.join(__dirname, '..', 'lib');
const location = path.join(__dirname, '..', 'lib');
console.log('process ' + location);
deleteRefs(location);
4 changes: 2 additions & 2 deletions package-lock.json

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

21 changes: 13 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{
"name": "vscode-json-languageservice",
"version": "5.7.2",
"version": "6.0.0-next.1",
"description": "Language service for JSON",
"main": "./lib/umd/jsonLanguageService.js",
"typings": "./lib/umd/jsonLanguageService",
"module": "./lib/esm/jsonLanguageService.js",
"type": "module",
"types": "./lib/esm/jsonLanguageService.d.ts",
"exports": {
".": {
"types": "./lib/esm/jsonLanguageService.d.ts",
"import": "./lib/esm/jsonLanguageService.js"
}
},
"author": "Microsoft Corporation",
"repository": {
"type": "git",
Expand All @@ -31,18 +36,18 @@
"@vscode/l10n": "^0.0.18"
},
"scripts": {
"prepack": "npm run clean && npm run compile-esm && npm run test && npm run remove-sourcemap-refs",
"prepack": "npm run clean && npm run compile && npm run test && npm run remove-sourcemap-refs",
"compile": "tsc -p ./src",
"compile-esm": "tsc -p ./src/tsconfig.esm.json",
"clean": "rimraf lib",
"bundle-schemas": "node ./build/bundle-schemas.js",
"remove-sourcemap-refs": "node ./build/remove-sourcemap-refs.js",
"watch": "tsc -w -p ./src",
"pretest": "npm run compile",
"test": "node --test ./lib/umd/test/**/*.test.js",
"test": "node --test ./lib/esm/test/**/*.test.js",
"posttest": "npm run lint",
"coverage": "npx nyc -r lcov npm run test",
"lint": "eslint src/**/*.ts",
"install-types-next": "npm install vscode-languageserver-types@next -f -S && npm install vscode-languageserver-textdocument@next -f -S",
"sample": "npm run compile && node ./lib/umd/example/sample.js"
"sample": "npm run compile && node ./lib/esm/example/sample.js"
}
}
2 changes: 1 addition & 1 deletion src/example/sample.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


import { getLanguageService, TextDocument } from '../jsonLanguageService';
import { getLanguageService, TextDocument } from '../jsonLanguageService.js';

async function main() {
const jsonContentUri = 'foo://server/example.data.json';
Expand Down
2 changes: 1 addition & 1 deletion src/jsonContributions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { MarkedString, CompletionItem } from './jsonLanguageService';
import { MarkedString, CompletionItem } from './jsonLanguageService.js';

export interface JSONWorkerContribution {
getInfoContribution(uri: string, location: JSONPath): PromiseLike<MarkedString[]>;
Expand Down
28 changes: 14 additions & 14 deletions src/jsonLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { JSONCompletion } from './services/jsonCompletion';
import { JSONHover } from './services/jsonHover';
import { JSONValidation } from './services/jsonValidation';
import { JSONCompletion } from './services/jsonCompletion.js';
import { JSONHover } from './services/jsonHover.js';
import { JSONValidation } from './services/jsonValidation.js';

import { JSONDocumentSymbols } from './services/jsonDocumentSymbols';
import { parse as parseJSON, newJSONDocument } from './parser/jsonParser';
import { schemaContributions } from './services/configuration';
import { JSONSchemaService } from './services/jsonSchemaService';
import { getFoldingRanges } from './services/jsonFolding';
import { getSelectionRanges } from './services/jsonSelectionRanges';
import { sort } from './utils/sort';
import { format } from './utils/format';
import { JSONDocumentSymbols } from './services/jsonDocumentSymbols.js';
import { parse as parseJSON, newJSONDocument } from './parser/jsonParser.js';
import { schemaContributions } from './services/configuration.js';
import { JSONSchemaService } from './services/jsonSchemaService.js';
import { getFoldingRanges } from './services/jsonFolding.js';
import { getSelectionRanges } from './services/jsonSelectionRanges.js';
import { sort } from './utils/sort.js';
import { format } from './utils/format.js';

import {
ASTNode,
Expand All @@ -24,15 +24,15 @@ import {
TextDocument,
Position, CompletionItem, CompletionList, Hover, Range, SymbolInformation, Diagnostic,
TextEdit, FormattingOptions, DocumentSymbol, DefinitionLink, MatchingSchema, JSONLanguageStatus, SortOptions
} from './jsonLanguageTypes';
import { findLinks } from './services/jsonLinks';
} from './jsonLanguageTypes.js';
import { findLinks } from './services/jsonLinks.js';
import { DocumentLink } from 'vscode-languageserver-types';

export type JSONDocument = {
root: ASTNode | undefined;
getNodeFromOffset(offset: number, includeRightBound?: boolean): ASTNode | undefined;
};
export * from './jsonLanguageTypes';
export * from './jsonLanguageTypes.js';

export interface LanguageService {
configure(settings: LanguageSettings): void;
Expand Down
4 changes: 2 additions & 2 deletions src/jsonLanguageTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { JSONWorkerContribution, JSONPath, Segment, CompletionsCollector } from './jsonContributions';
import { JSONSchema } from './jsonSchema';
import { JSONWorkerContribution, JSONPath, Segment, CompletionsCollector } from './jsonContributions.js';
import { JSONSchema } from './jsonSchema.js';
import {
Range, Position, DocumentUri, MarkupContent, MarkupKind,
Color, ColorInformation, ColorPresentation,
Expand Down
8 changes: 4 additions & 4 deletions src/parser/jsonParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
*--------------------------------------------------------------------------------------------*/

import * as Json from 'jsonc-parser';
import { JSONSchema, JSONSchemaRef } from '../jsonSchema';
import { isNumber, equals, isBoolean, isString, isDefined, isObject } from '../utils/objects';
import { extendedRegExp, stringLength } from '../utils/strings';
import { TextDocument, ASTNode, ObjectASTNode, ArrayASTNode, BooleanASTNode, NumberASTNode, StringASTNode, NullASTNode, PropertyASTNode, JSONPath, ErrorCode, Diagnostic, DiagnosticSeverity, Range, SchemaDraft } from '../jsonLanguageTypes';
import { JSONSchema, JSONSchemaRef } from '../jsonSchema.js';
import { isNumber, equals, isBoolean, isString, isDefined, isObject } from '../utils/objects.js';
import { extendedRegExp, stringLength } from '../utils/strings.js';
import { TextDocument, ASTNode, ObjectASTNode, ArrayASTNode, BooleanASTNode, NumberASTNode, StringASTNode, NullASTNode, PropertyASTNode, JSONPath, ErrorCode, Diagnostic, DiagnosticSeverity, Range, SchemaDraft } from '../jsonLanguageTypes.js';
import { URI } from 'vscode-uri';

import * as l10n from '@vscode/l10n';
Expand Down
6 changes: 3 additions & 3 deletions src/services/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { ISchemaContributions } from './jsonSchemaService';
import draft201909Flat from './schemas/draft-2019-09-flat';
import draft202012Flat from './schemas/draft-2020-12-flat';
import { ISchemaContributions } from './jsonSchemaService.js';
import draft201909Flat from './schemas/draft-2019-09-flat.js';
import draft202012Flat from './schemas/draft-2020-12-flat.js';

import * as l10n from '@vscode/l10n';

Expand Down
16 changes: 8 additions & 8 deletions src/services/jsonCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as Parser from '../parser/jsonParser';
import * as Parser from '../parser/jsonParser.js';
import * as Json from 'jsonc-parser';
import * as SchemaService from './jsonSchemaService';
import { JSONSchema, JSONSchemaRef } from '../jsonSchema';
import { JSONWorkerContribution, CompletionsCollector, JSONCompletionItem } from '../jsonContributions';
import { stringifyObject } from '../utils/json';
import { endsWith, extendedRegExp } from '../utils/strings';
import { isDefined } from '../utils/objects';
import * as SchemaService from './jsonSchemaService.js';
import { JSONSchema, JSONSchemaRef } from '../jsonSchema.js';
import { JSONWorkerContribution, CompletionsCollector, JSONCompletionItem } from '../jsonContributions.js';
import { stringifyObject } from '../utils/json.js';
import { endsWith, extendedRegExp } from '../utils/strings.js';
import { isDefined } from '../utils/objects.js';
import {
PromiseConstructor,
ASTNode, ObjectASTNode, ArrayASTNode, PropertyASTNode, ClientCapabilities,
TextDocument,
CompletionItem, CompletionItemKind, CompletionList, Position, Range, TextEdit, InsertTextFormat, MarkupContent, MarkupKind
} from '../jsonLanguageTypes';
} from '../jsonLanguageTypes.js';

import * as l10n from '@vscode/l10n';

Expand Down
10 changes: 5 additions & 5 deletions src/services/jsonDocumentSymbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as Parser from '../parser/jsonParser';
import * as Strings from '../utils/strings';
import { colorFromHex } from '../utils/colors';
import * as Parser from '../parser/jsonParser.js';
import * as Strings from '../utils/strings.js';
import { colorFromHex } from '../utils/colors.js';
import * as l10n from '@vscode/l10n';

import {
TextDocument, ColorInformation, ColorPresentation, Color, ASTNode, PropertyASTNode, DocumentSymbolsContext, Range, TextEdit,
SymbolInformation, SymbolKind, DocumentSymbol, Location
} from "../jsonLanguageTypes";
} from "../jsonLanguageTypes.js";

import { IJSONSchemaService } from "./jsonSchemaService";
import { IJSONSchemaService } from "./jsonSchemaService.js";

export class JSONDocumentSymbols {

Expand Down
2 changes: 1 addition & 1 deletion src/services/jsonFolding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { createScanner, SyntaxKind, ScanError } from 'jsonc-parser';
import { TextDocument, FoldingRangeKind, FoldingRange, FoldingRangesContext, Position } from '../jsonLanguageTypes';
import { TextDocument, FoldingRangeKind, FoldingRange, FoldingRangesContext, Position } from '../jsonLanguageTypes.js';

export function getFoldingRanges(document: TextDocument, context?: FoldingRangesContext): FoldingRange[] {
const ranges: FoldingRange[] = [];
Expand Down
8 changes: 4 additions & 4 deletions src/services/jsonHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as Parser from '../parser/jsonParser';
import * as SchemaService from './jsonSchemaService';
import { JSONWorkerContribution } from '../jsonContributions';
import { TextDocument, PromiseConstructor, Position, Range, Hover, MarkedString } from '../jsonLanguageTypes';
import * as Parser from '../parser/jsonParser.js';
import * as SchemaService from './jsonSchemaService.js';
import { JSONWorkerContribution } from '../jsonContributions.js';
import { TextDocument, PromiseConstructor, Position, Range, Hover, MarkedString } from '../jsonLanguageTypes.js';

export class JSONHover {

Expand Down
Loading