vscode-json-languageservice
Advanced tools
Comparing version 5.2.0 to 5.3.0
@@ -0,1 +1,6 @@ | ||
5.3.0 / 2023-02-15 | ||
================ | ||
* new API `LanguageService.sort` for sorting all properties in a JSON document | ||
* new API `SortOptions` | ||
5.2.0 / 2023-02-02 | ||
@@ -2,0 +7,0 @@ ================ |
@@ -1,2 +0,2 @@ | ||
import { Thenable, ASTNode, Color, ColorInformation, ColorPresentation, LanguageServiceParams, LanguageSettings, DocumentLanguageSettings, FoldingRange, JSONSchema, SelectionRange, FoldingRangesContext, DocumentSymbolsContext, ColorInformationContext as DocumentColorsContext, TextDocument, Position, CompletionItem, CompletionList, Hover, Range, SymbolInformation, Diagnostic, TextEdit, FormattingOptions, DocumentSymbol, DefinitionLink, MatchingSchema, JSONLanguageStatus } from './jsonLanguageTypes'; | ||
import { Thenable, ASTNode, Color, ColorInformation, ColorPresentation, LanguageServiceParams, LanguageSettings, DocumentLanguageSettings, FoldingRange, JSONSchema, SelectionRange, FoldingRangesContext, DocumentSymbolsContext, ColorInformationContext as DocumentColorsContext, TextDocument, Position, CompletionItem, CompletionList, Hover, Range, SymbolInformation, Diagnostic, TextEdit, FormattingOptions, DocumentSymbol, DefinitionLink, MatchingSchema, JSONLanguageStatus, SortOptions } from './jsonLanguageTypes'; | ||
import { DocumentLink } from 'vscode-languageserver-types'; | ||
@@ -23,3 +23,2 @@ export type JSONDocument = { | ||
doHover(document: TextDocument, position: Position, doc: JSONDocument): Thenable<Hover | null>; | ||
format(document: TextDocument, range: Range, options: FormattingOptions): TextEdit[]; | ||
getFoldingRanges(document: TextDocument, context?: FoldingRangesContext): FoldingRange[]; | ||
@@ -29,3 +28,5 @@ getSelectionRanges(document: TextDocument, positions: Position[], doc: JSONDocument): SelectionRange[]; | ||
findLinks(document: TextDocument, doc: JSONDocument): Thenable<DocumentLink[]>; | ||
format(document: TextDocument, range: Range, options: FormattingOptions): TextEdit[]; | ||
sort(document: TextDocument, options: SortOptions): TextEdit[]; | ||
} | ||
export declare function getLanguageService(params: LanguageServiceParams): LanguageService; |
@@ -14,4 +14,4 @@ /*--------------------------------------------------------------------------------------------- | ||
import { getSelectionRanges } from './services/jsonSelectionRanges'; | ||
import { format as formatJSON } from 'jsonc-parser'; | ||
import { Range, TextEdit } from './jsonLanguageTypes'; | ||
import { sort } from './utils/sort'; | ||
import { format } from './utils/format'; | ||
import { findLinks } from './services/jsonLinks'; | ||
@@ -50,15 +50,5 @@ export * from './jsonLanguageTypes'; | ||
findLinks, | ||
format: (d, r, o) => { | ||
let range = undefined; | ||
if (r) { | ||
const offset = d.offsetAt(r.start); | ||
const length = d.offsetAt(r.end) - offset; | ||
range = { offset, length }; | ||
} | ||
const options = { tabSize: o ? o.tabSize : 4, insertSpaces: o?.insertSpaces === true, insertFinalNewline: o?.insertFinalNewline === true, eol: '\n', keepLines: o?.keepLines === true }; | ||
return formatJSON(d.getText(), range, options).map(e => { | ||
return TextEdit.replace(Range.create(d.positionAt(e.offset), d.positionAt(e.offset + e.length)), e.content); | ||
}); | ||
} | ||
format: (document, range, options) => format(document, options, range), | ||
sort: (document, options) => sort(document, options) | ||
}; | ||
} |
import { JSONWorkerContribution, JSONPath, Segment, CompletionsCollector } from './jsonContributions'; | ||
import { JSONSchema } from './jsonSchema'; | ||
import { Range, Position, DocumentUri, MarkupContent, MarkupKind, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, SelectionRange, Diagnostic, DiagnosticSeverity, CompletionItem, CompletionItemKind, CompletionList, CompletionItemTag, InsertTextFormat, SymbolInformation, SymbolKind, DocumentSymbol, Location, Hover, MarkedString, FormattingOptions as LSPFormattingOptions, DefinitionLink, CodeActionContext, Command, CodeAction, DocumentHighlight, DocumentLink, WorkspaceEdit, TextEdit, CodeActionKind, TextDocumentEdit, VersionedTextDocumentIdentifier, DocumentHighlightKind } from 'vscode-languageserver-types'; | ||
import { TextDocument } from 'vscode-languageserver-textdocument'; | ||
export { TextDocument, Range, Position, DocumentUri, MarkupContent, MarkupKind, JSONSchema, JSONWorkerContribution, JSONPath, Segment, CompletionsCollector, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, SelectionRange, Diagnostic, DiagnosticSeverity, CompletionItem, CompletionItemKind, CompletionList, CompletionItemTag, InsertTextFormat, DefinitionLink, SymbolInformation, SymbolKind, DocumentSymbol, Location, Hover, MarkedString, CodeActionContext, Command, CodeAction, DocumentHighlight, DocumentLink, WorkspaceEdit, TextEdit, CodeActionKind, TextDocumentEdit, VersionedTextDocumentIdentifier, DocumentHighlightKind }; | ||
import { TextDocument, TextDocumentContentChangeEvent } from 'vscode-languageserver-textdocument'; | ||
export { TextDocument, TextDocumentContentChangeEvent, Range, Position, DocumentUri, MarkupContent, MarkupKind, JSONSchema, JSONWorkerContribution, JSONPath, Segment, CompletionsCollector, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, SelectionRange, Diagnostic, DiagnosticSeverity, CompletionItem, CompletionItemKind, CompletionList, CompletionItemTag, InsertTextFormat, DefinitionLink, SymbolInformation, SymbolKind, DocumentSymbol, Location, Hover, MarkedString, CodeActionContext, Command, CodeAction, DocumentHighlight, DocumentLink, WorkspaceEdit, TextEdit, CodeActionKind, TextDocumentEdit, VersionedTextDocumentIdentifier, DocumentHighlightKind }; | ||
/** | ||
@@ -298,1 +298,4 @@ * Error codes used by diagnostics | ||
} | ||
export interface SortOptions extends LSPFormattingOptions { | ||
insertFinalNewline?: boolean; | ||
} |
@@ -690,3 +690,3 @@ /*--------------------------------------------------------------------------------------------- | ||
getInsertTextForValue(value, separatorAfter) { | ||
var text = JSON.stringify(value, null, '\t'); | ||
const text = JSON.stringify(value, null, '\t'); | ||
if (text === '{}') { | ||
@@ -809,3 +809,3 @@ return '{$1}' + separatorAfter; | ||
if (nValueProposals === 0) { | ||
var type = Array.isArray(propertySchema.type) ? propertySchema.type[0] : propertySchema.type; | ||
let type = Array.isArray(propertySchema.type) ? propertySchema.type[0] : propertySchema.type; | ||
if (!type) { | ||
@@ -850,4 +850,4 @@ if (propertySchema.properties) { | ||
getCurrentWord(document, offset) { | ||
var i = offset - 1; | ||
var text = document.getText(); | ||
let i = offset - 1; | ||
const text = document.getText(); | ||
while (i >= 0 && ' \t\n\r\v":{[,]}'.indexOf(text.charAt(i)) === -1) { | ||
@@ -854,0 +854,0 @@ i--; |
@@ -8,2 +8,3 @@ /*--------------------------------------------------------------------------------------------- | ||
import { colorFromHex } from '../utils/colors'; | ||
import * as l10n from '@vscode/l10n'; | ||
import { Range, TextEdit, SymbolKind, Location } from "../jsonLanguageTypes"; | ||
@@ -30,3 +31,3 @@ export class JSONDocumentSymbols { | ||
const location = Location.create(document.uri, getRange(document, item)); | ||
result.push({ name: Parser.getNodeValue(property.valueNode), kind: SymbolKind.Function, location: location }); | ||
result.push({ name: getName(property.valueNode), kind: SymbolKind.Function, location: location }); | ||
limit--; | ||
@@ -105,3 +106,3 @@ if (limit <= 0) { | ||
const selectionRange = getRange(document, property.keyNode); | ||
result.push({ name: Parser.getNodeValue(property.valueNode), kind: SymbolKind.Function, range, selectionRange }); | ||
result.push({ name: getName(property.valueNode), kind: SymbolKind.Function, range, selectionRange }); | ||
limit--; | ||
@@ -271,1 +272,4 @@ if (limit <= 0) { | ||
} | ||
function getName(node) { | ||
return Parser.getNodeValue(node) || l10n.t('<empty>'); | ||
} |
@@ -31,3 +31,3 @@ /*--------------------------------------------------------------------------------------------- | ||
const hoverRange = Range.create(document.positionAt(hoverRangeNode.offset), document.positionAt(hoverRangeNode.offset + hoverRangeNode.length)); | ||
var createHover = (contents) => { | ||
const createHover = (contents) => { | ||
const result = { | ||
@@ -34,0 +34,0 @@ contents: contents, |
@@ -21,3 +21,3 @@ /*--------------------------------------------------------------------------------------------- | ||
} | ||
var i, key; | ||
let i, key; | ||
if (Array.isArray(one)) { | ||
@@ -34,3 +34,3 @@ if (one.length !== other.length) { | ||
else { | ||
var oneKeys = []; | ||
const oneKeys = []; | ||
for (key in one) { | ||
@@ -40,3 +40,3 @@ oneKeys.push(key); | ||
oneKeys.sort(); | ||
var otherKeys = []; | ||
const otherKeys = []; | ||
for (key in other) { | ||
@@ -43,0 +43,0 @@ otherKeys.push(key); |
@@ -35,3 +35,3 @@ /*--------------------------------------------------------------------------------------------- | ||
export function repeat(value, count) { | ||
var s = ''; | ||
let s = ''; | ||
while (count > 0) { | ||
@@ -38,0 +38,0 @@ if ((count & 1) === 1) { |
@@ -1,2 +0,2 @@ | ||
import { Thenable, ASTNode, Color, ColorInformation, ColorPresentation, LanguageServiceParams, LanguageSettings, DocumentLanguageSettings, FoldingRange, JSONSchema, SelectionRange, FoldingRangesContext, DocumentSymbolsContext, ColorInformationContext as DocumentColorsContext, TextDocument, Position, CompletionItem, CompletionList, Hover, Range, SymbolInformation, Diagnostic, TextEdit, FormattingOptions, DocumentSymbol, DefinitionLink, MatchingSchema, JSONLanguageStatus } from './jsonLanguageTypes'; | ||
import { Thenable, ASTNode, Color, ColorInformation, ColorPresentation, LanguageServiceParams, LanguageSettings, DocumentLanguageSettings, FoldingRange, JSONSchema, SelectionRange, FoldingRangesContext, DocumentSymbolsContext, ColorInformationContext as DocumentColorsContext, TextDocument, Position, CompletionItem, CompletionList, Hover, Range, SymbolInformation, Diagnostic, TextEdit, FormattingOptions, DocumentSymbol, DefinitionLink, MatchingSchema, JSONLanguageStatus, SortOptions } from './jsonLanguageTypes'; | ||
import { DocumentLink } from 'vscode-languageserver-types'; | ||
@@ -23,3 +23,2 @@ export type JSONDocument = { | ||
doHover(document: TextDocument, position: Position, doc: JSONDocument): Thenable<Hover | null>; | ||
format(document: TextDocument, range: Range, options: FormattingOptions): TextEdit[]; | ||
getFoldingRanges(document: TextDocument, context?: FoldingRangesContext): FoldingRange[]; | ||
@@ -29,3 +28,5 @@ getSelectionRanges(document: TextDocument, positions: Position[], doc: JSONDocument): SelectionRange[]; | ||
findLinks(document: TextDocument, doc: JSONDocument): Thenable<DocumentLink[]>; | ||
format(document: TextDocument, range: Range, options: FormattingOptions): TextEdit[]; | ||
sort(document: TextDocument, options: SortOptions): TextEdit[]; | ||
} | ||
export declare function getLanguageService(params: LanguageServiceParams): LanguageService; |
@@ -25,3 +25,3 @@ /*--------------------------------------------------------------------------------------------- | ||
else if (typeof define === "function" && define.amd) { | ||
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); | ||
define(["require", "exports", "./services/jsonCompletion", "./services/jsonHover", "./services/jsonValidation", "./services/jsonDocumentSymbols", "./parser/jsonParser", "./services/configuration", "./services/jsonSchemaService", "./services/jsonFolding", "./services/jsonSelectionRanges", "./utils/sort", "./utils/format", "./services/jsonLinks", "./jsonLanguageTypes"], factory); | ||
} | ||
@@ -41,4 +41,4 @@ })(function (require, exports) { | ||
const jsonSelectionRanges_1 = require("./services/jsonSelectionRanges"); | ||
const jsonc_parser_1 = require("jsonc-parser"); | ||
const jsonLanguageTypes_1 = require("./jsonLanguageTypes"); | ||
const sort_1 = require("./utils/sort"); | ||
const format_1 = require("./utils/format"); | ||
const jsonLinks_1 = require("./services/jsonLinks"); | ||
@@ -77,14 +77,4 @@ __exportStar(require("./jsonLanguageTypes"), exports); | ||
findLinks: jsonLinks_1.findLinks, | ||
format: (d, r, o) => { | ||
let range = undefined; | ||
if (r) { | ||
const offset = d.offsetAt(r.start); | ||
const length = d.offsetAt(r.end) - offset; | ||
range = { offset, length }; | ||
} | ||
const options = { tabSize: o ? o.tabSize : 4, insertSpaces: o?.insertSpaces === true, insertFinalNewline: o?.insertFinalNewline === true, eol: '\n', keepLines: o?.keepLines === true }; | ||
return (0, jsonc_parser_1.format)(d.getText(), range, options).map(e => { | ||
return jsonLanguageTypes_1.TextEdit.replace(jsonLanguageTypes_1.Range.create(d.positionAt(e.offset), d.positionAt(e.offset + e.length)), e.content); | ||
}); | ||
} | ||
format: (document, range, options) => (0, format_1.format)(document, options, range), | ||
sort: (document, options) => (0, sort_1.sort)(document, options) | ||
}; | ||
@@ -91,0 +81,0 @@ } |
import { JSONWorkerContribution, JSONPath, Segment, CompletionsCollector } from './jsonContributions'; | ||
import { JSONSchema } from './jsonSchema'; | ||
import { Range, Position, DocumentUri, MarkupContent, MarkupKind, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, SelectionRange, Diagnostic, DiagnosticSeverity, CompletionItem, CompletionItemKind, CompletionList, CompletionItemTag, InsertTextFormat, SymbolInformation, SymbolKind, DocumentSymbol, Location, Hover, MarkedString, FormattingOptions as LSPFormattingOptions, DefinitionLink, CodeActionContext, Command, CodeAction, DocumentHighlight, DocumentLink, WorkspaceEdit, TextEdit, CodeActionKind, TextDocumentEdit, VersionedTextDocumentIdentifier, DocumentHighlightKind } from 'vscode-languageserver-types'; | ||
import { TextDocument } from 'vscode-languageserver-textdocument'; | ||
export { TextDocument, Range, Position, DocumentUri, MarkupContent, MarkupKind, JSONSchema, JSONWorkerContribution, JSONPath, Segment, CompletionsCollector, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, SelectionRange, Diagnostic, DiagnosticSeverity, CompletionItem, CompletionItemKind, CompletionList, CompletionItemTag, InsertTextFormat, DefinitionLink, SymbolInformation, SymbolKind, DocumentSymbol, Location, Hover, MarkedString, CodeActionContext, Command, CodeAction, DocumentHighlight, DocumentLink, WorkspaceEdit, TextEdit, CodeActionKind, TextDocumentEdit, VersionedTextDocumentIdentifier, DocumentHighlightKind }; | ||
import { TextDocument, TextDocumentContentChangeEvent } from 'vscode-languageserver-textdocument'; | ||
export { TextDocument, TextDocumentContentChangeEvent, Range, Position, DocumentUri, MarkupContent, MarkupKind, JSONSchema, JSONWorkerContribution, JSONPath, Segment, CompletionsCollector, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, SelectionRange, Diagnostic, DiagnosticSeverity, CompletionItem, CompletionItemKind, CompletionList, CompletionItemTag, InsertTextFormat, DefinitionLink, SymbolInformation, SymbolKind, DocumentSymbol, Location, Hover, MarkedString, CodeActionContext, Command, CodeAction, DocumentHighlight, DocumentLink, WorkspaceEdit, TextEdit, CodeActionKind, TextDocumentEdit, VersionedTextDocumentIdentifier, DocumentHighlightKind }; | ||
/** | ||
@@ -298,1 +298,4 @@ * Error codes used by diagnostics | ||
} | ||
export interface SortOptions extends LSPFormattingOptions { | ||
insertFinalNewline?: boolean; | ||
} |
@@ -702,3 +702,3 @@ /*--------------------------------------------------------------------------------------------- | ||
getInsertTextForValue(value, separatorAfter) { | ||
var text = JSON.stringify(value, null, '\t'); | ||
const text = JSON.stringify(value, null, '\t'); | ||
if (text === '{}') { | ||
@@ -821,3 +821,3 @@ return '{$1}' + separatorAfter; | ||
if (nValueProposals === 0) { | ||
var type = Array.isArray(propertySchema.type) ? propertySchema.type[0] : propertySchema.type; | ||
let type = Array.isArray(propertySchema.type) ? propertySchema.type[0] : propertySchema.type; | ||
if (!type) { | ||
@@ -862,4 +862,4 @@ if (propertySchema.properties) { | ||
getCurrentWord(document, offset) { | ||
var i = offset - 1; | ||
var text = document.getText(); | ||
let i = offset - 1; | ||
const text = document.getText(); | ||
while (i >= 0 && ' \t\n\r\v":{[,]}'.indexOf(text.charAt(i)) === -1) { | ||
@@ -866,0 +866,0 @@ i--; |
@@ -11,3 +11,3 @@ /*--------------------------------------------------------------------------------------------- | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "../parser/jsonParser", "../utils/strings", "../utils/colors", "../jsonLanguageTypes"], factory); | ||
define(["require", "exports", "../parser/jsonParser", "../utils/strings", "../utils/colors", "@vscode/l10n", "../jsonLanguageTypes"], factory); | ||
} | ||
@@ -21,2 +21,3 @@ })(function (require, exports) { | ||
const colors_1 = require("../utils/colors"); | ||
const l10n = require("@vscode/l10n"); | ||
const jsonLanguageTypes_1 = require("../jsonLanguageTypes"); | ||
@@ -43,3 +44,3 @@ class JSONDocumentSymbols { | ||
const location = jsonLanguageTypes_1.Location.create(document.uri, getRange(document, item)); | ||
result.push({ name: Parser.getNodeValue(property.valueNode), kind: jsonLanguageTypes_1.SymbolKind.Function, location: location }); | ||
result.push({ name: getName(property.valueNode), kind: jsonLanguageTypes_1.SymbolKind.Function, location: location }); | ||
limit--; | ||
@@ -118,3 +119,3 @@ if (limit <= 0) { | ||
const selectionRange = getRange(document, property.keyNode); | ||
result.push({ name: Parser.getNodeValue(property.valueNode), kind: jsonLanguageTypes_1.SymbolKind.Function, range, selectionRange }); | ||
result.push({ name: getName(property.valueNode), kind: jsonLanguageTypes_1.SymbolKind.Function, range, selectionRange }); | ||
limit--; | ||
@@ -285,2 +286,5 @@ if (limit <= 0) { | ||
} | ||
function getName(node) { | ||
return Parser.getNodeValue(node) || l10n.t('<empty>'); | ||
} | ||
}); |
@@ -43,3 +43,3 @@ /*--------------------------------------------------------------------------------------------- | ||
const hoverRange = jsonLanguageTypes_1.Range.create(document.positionAt(hoverRangeNode.offset), document.positionAt(hoverRangeNode.offset + hoverRangeNode.length)); | ||
var createHover = (contents) => { | ||
const createHover = (contents) => { | ||
const result = { | ||
@@ -46,0 +46,0 @@ contents: contents, |
@@ -33,3 +33,3 @@ /*--------------------------------------------------------------------------------------------- | ||
} | ||
var i, key; | ||
let i, key; | ||
if (Array.isArray(one)) { | ||
@@ -46,3 +46,3 @@ if (one.length !== other.length) { | ||
else { | ||
var oneKeys = []; | ||
const oneKeys = []; | ||
for (key in one) { | ||
@@ -52,3 +52,3 @@ oneKeys.push(key); | ||
oneKeys.sort(); | ||
var otherKeys = []; | ||
const otherKeys = []; | ||
for (key in other) { | ||
@@ -55,0 +55,0 @@ otherKeys.push(key); |
@@ -50,3 +50,3 @@ /*--------------------------------------------------------------------------------------------- | ||
function repeat(value, count) { | ||
var s = ''; | ||
let s = ''; | ||
while (count > 0) { | ||
@@ -53,0 +53,0 @@ if ((count & 1) === 1) { |
{ | ||
"name": "vscode-json-languageservice", | ||
"version": "5.2.0", | ||
"version": "5.3.0", | ||
"description": "Language service for JSON", | ||
@@ -20,9 +20,9 @@ "main": "./lib/umd/jsonLanguageService.js", | ||
"@types/node": "16.x", | ||
"@typescript-eslint/eslint-plugin": "^5.48.2", | ||
"@typescript-eslint/parser": "^5.48.2", | ||
"eslint": "^8.32.0", | ||
"@typescript-eslint/eslint-plugin": "^5.52.0", | ||
"@typescript-eslint/parser": "^5.52.0", | ||
"eslint": "^8.34.0", | ||
"json-schema-test-suite": "https://github.com/json-schema-org/JSON-Schema-Test-Suite.git#69acf52990b004240839ae19b4bec8fb01d50876", | ||
"mocha": "^10.2.0", | ||
"rimraf": "^4.1.1", | ||
"typescript": "^4.9.4" | ||
"rimraf": "^4.1.2", | ||
"typescript": "^4.9.5" | ||
}, | ||
@@ -32,3 +32,3 @@ "dependencies": { | ||
"vscode-languageserver-textdocument": "^1.0.8", | ||
"vscode-languageserver-types": "^3.17.2", | ||
"vscode-languageserver-types": "^3.17.3", | ||
"vscode-uri": "^3.0.7", | ||
@@ -35,0 +35,0 @@ "@vscode/l10n": "^0.0.11" |
556537
57
11273