diff --git a/src/example/sample.ts b/src/example/sample.ts index 3f936450..b45e4aac 100644 --- a/src/example/sample.ts +++ b/src/example/sample.ts @@ -1,6 +1,6 @@ -import { getLanguageService, JSONSchema, SchemaRequestService, TextDocument, MatchingSchema } from '../jsonLanguageService'; +import { getLanguageService, TextDocument } from '../jsonLanguageService'; async function main() { const jsonContentUri = 'foo://server/example.data.json'; @@ -58,4 +58,3 @@ async function main() { } main(); - diff --git a/src/jsonContributions.ts b/src/jsonContributions.ts index ac70b942..fe5be120 100644 --- a/src/jsonContributions.ts +++ b/src/jsonContributions.ts @@ -2,14 +2,14 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { Thenable, MarkedString, CompletionItem } from './jsonLanguageService'; +import { MarkedString, CompletionItem } from './jsonLanguageService'; export interface JSONWorkerContribution { - getInfoContribution(uri: string, location: JSONPath): Thenable; - collectPropertyCompletions(uri: string, location: JSONPath, currentWord: string, addValue: boolean, isLast: boolean, result: CompletionsCollector): Thenable; - collectValueCompletions(uri: string, location: JSONPath, propertyKey: string, result: CompletionsCollector): Thenable; - collectDefaultCompletions(uri: string, result: CompletionsCollector): Thenable; - resolveCompletion?(item: CompletionItem): Thenable; + getInfoContribution(uri: string, location: JSONPath): PromiseLike; + collectPropertyCompletions(uri: string, location: JSONPath, currentWord: string, addValue: boolean, isLast: boolean, result: CompletionsCollector): PromiseLike; + collectValueCompletions(uri: string, location: JSONPath, propertyKey: string, result: CompletionsCollector): PromiseLike; + collectDefaultCompletions(uri: string, result: CompletionsCollector): PromiseLike; + resolveCompletion?(item: CompletionItem): PromiseLike; } export type Segment = string | number; export type JSONPath = Segment[]; diff --git a/src/jsonLanguageService.ts b/src/jsonLanguageService.ts index 1e2e54fa..b5a9ef4a 100644 --- a/src/jsonLanguageService.ts +++ b/src/jsonLanguageService.ts @@ -17,7 +17,6 @@ import { sort } from './utils/sort'; import { format } from './utils/format'; import { - Thenable, ASTNode, Color, ColorInformation, ColorPresentation, LanguageServiceParams, LanguageSettings, DocumentLanguageSettings, @@ -37,23 +36,23 @@ export * from './jsonLanguageTypes'; export interface LanguageService { configure(settings: LanguageSettings): void; - doValidation(document: TextDocument, jsonDocument: JSONDocument, documentSettings?: DocumentLanguageSettings, schema?: JSONSchema): Thenable; + doValidation(document: TextDocument, jsonDocument: JSONDocument, documentSettings?: DocumentLanguageSettings, schema?: JSONSchema): PromiseLike; parseJSONDocument(document: TextDocument): JSONDocument; newJSONDocument(rootNode: ASTNode, syntaxDiagnostics?: Diagnostic[]): JSONDocument; resetSchema(uri: string): boolean; - getMatchingSchemas(document: TextDocument, jsonDocument: JSONDocument, schema?: JSONSchema): Thenable; + getMatchingSchemas(document: TextDocument, jsonDocument: JSONDocument, schema?: JSONSchema): PromiseLike; getLanguageStatus(document: TextDocument, jsonDocument: JSONDocument): JSONLanguageStatus; - doResolve(item: CompletionItem): Thenable; - doComplete(document: TextDocument, position: Position, doc: JSONDocument): Thenable; + doResolve(item: CompletionItem): PromiseLike; + doComplete(document: TextDocument, position: Position, doc: JSONDocument): PromiseLike; findDocumentSymbols(document: TextDocument, doc: JSONDocument, context?: DocumentSymbolsContext): SymbolInformation[]; findDocumentSymbols2(document: TextDocument, doc: JSONDocument, context?: DocumentSymbolsContext): DocumentSymbol[]; - findDocumentColors(document: TextDocument, doc: JSONDocument, context?: DocumentColorsContext): Thenable; + findDocumentColors(document: TextDocument, doc: JSONDocument, context?: DocumentColorsContext): PromiseLike; getColorPresentations(document: TextDocument, doc: JSONDocument, color: Color, range: Range): ColorPresentation[]; - doHover(document: TextDocument, position: Position, doc: JSONDocument): Thenable; + doHover(document: TextDocument, position: Position, doc: JSONDocument): PromiseLike; getFoldingRanges(document: TextDocument, context?: FoldingRangesContext): FoldingRange[]; getSelectionRanges(document: TextDocument, positions: Position[], doc: JSONDocument): SelectionRange[]; - findDefinition(document: TextDocument, position: Position, doc: JSONDocument): Thenable; - findLinks(document: TextDocument, doc: JSONDocument): Thenable; + findDefinition(document: TextDocument, position: Position, doc: JSONDocument): PromiseLike; + findLinks(document: TextDocument, doc: JSONDocument): PromiseLike; format(document: TextDocument, range: Range, options: FormattingOptions): TextEdit[]; sort(document: TextDocument, options: SortOptions): TextEdit[]; } diff --git a/src/jsonLanguageTypes.ts b/src/jsonLanguageTypes.ts index 7f4ae6f1..568c97f0 100644 --- a/src/jsonLanguageTypes.ts +++ b/src/jsonLanguageTypes.ts @@ -206,7 +206,7 @@ export interface WorkspaceContextService { * In case of an error, returns a rejected promise with a displayable error string. */ export interface SchemaRequestService { - (uri: string): Thenable; + (uri: string): PromiseLike; } export interface PromiseConstructor { @@ -216,7 +216,7 @@ export interface PromiseConstructor { * a resolve callback used resolve the promise with a value or the result of another promise, * and a reject callback used to reject the promise with a provided reason or error. */ - new (executor: (resolve: (value?: T | Thenable) => void, reject: (reason?: any) => void) => void): Thenable; + new (executor: (resolve: (value?: T | PromiseLike) => void, reject: (reason?: any) => void) => void): PromiseLike; /** * Creates a Promise that is resolved with an array of results when all of the provided Promises @@ -224,33 +224,29 @@ export interface PromiseConstructor { * @param values An array of Promises. * @returns A new Promise. */ - all(values: Array>): Thenable; + all(values: Array>): PromiseLike; /** * Creates a new rejected promise for the provided reason. * @param reason The reason the promise was rejected. * @returns A new rejected Promise. */ - reject(reason: any): Thenable; + reject(reason: any): PromiseLike; /** * Creates a new resolved promise for the provided value. * @param value A promise. * @returns A promise whose internal state matches the provided promise. */ - resolve(value: T | Thenable): Thenable; + resolve(value: T | PromiseLike): PromiseLike; } -export interface Thenable { - /** - * Attaches callbacks for the resolution and/or rejection of the Promise. - * @param onfulfilled The callback to execute when the Promise is resolved. - * @param onrejected The callback to execute when the Promise is rejected. - * @returns A Promise for the completion of which ever callback is executed. - */ - then(onfulfilled?: (value: R) => TResult | Thenable, onrejected?: (reason: any) => TResult | Thenable): Thenable; - then(onfulfilled?: (value: R) => TResult | Thenable, onrejected?: (reason: any) => void): Thenable; -} +/** + * A deprecated alias of {@link PromiseLike} + * + * @deprecated + */ +export interface Thenable extends PromiseLike {} export interface LanguageServiceParams { /** diff --git a/src/services/jsonCompletion.ts b/src/services/jsonCompletion.ts index 90d4c9fc..fe42793f 100644 --- a/src/services/jsonCompletion.ts +++ b/src/services/jsonCompletion.ts @@ -12,7 +12,7 @@ import { stringifyObject } from '../utils/json'; import { endsWith, extendedRegExp } from '../utils/strings'; import { isDefined } from '../utils/objects'; import { - PromiseConstructor, Thenable, + PromiseConstructor, ASTNode, ObjectASTNode, ArrayASTNode, PropertyASTNode, ClientCapabilities, TextDocument, CompletionItem, CompletionItemKind, CompletionList, Position, Range, TextEdit, InsertTextFormat, MarkupContent, MarkupKind @@ -36,7 +36,7 @@ export class JSONCompletion { private clientCapabilities: ClientCapabilities = {}) { } - public doResolve(item: CompletionItem): Thenable { + public doResolve(item: CompletionItem): PromiseLike { for (let i = this.contributions.length - 1; i >= 0; i--) { const resolveCompletion = this.contributions[i].resolveCompletion; if (resolveCompletion) { @@ -49,7 +49,7 @@ export class JSONCompletion { return this.promiseConstructor.resolve(item); } - public doComplete(document: TextDocument, position: Position, doc: Parser.JSONDocument): Thenable { + public doComplete(document: TextDocument, position: Position, doc: Parser.JSONDocument): PromiseLike { const result: CompletionList = { items: [], @@ -130,7 +130,7 @@ export class JSONCompletion { }; return this.schemaService.getSchemaForResource(document.uri, doc).then((schema) => { - const collectionPromises: Thenable[] = []; + const collectionPromises: PromiseLike[] = []; let addValue = true; let currentKey = ''; @@ -512,7 +512,7 @@ export class JSONCompletion { } - private getContributedValueCompletions(doc: Parser.JSONDocument, node: ASTNode | undefined, offset: number, document: TextDocument, collector: CompletionsCollector, collectionPromises: Thenable[]) { + private getContributedValueCompletions(doc: Parser.JSONDocument, node: ASTNode | undefined, offset: number, document: TextDocument, collector: CompletionsCollector, collectionPromises: PromiseLike[]) { if (!node) { this.contributions.forEach((contribution) => { const collectPromise = contribution.collectDefaultCompletions(document.uri, collector); diff --git a/src/services/jsonDocumentSymbols.ts b/src/services/jsonDocumentSymbols.ts index 1338ff51..e3b752ca 100644 --- a/src/services/jsonDocumentSymbols.ts +++ b/src/services/jsonDocumentSymbols.ts @@ -9,7 +9,7 @@ import { colorFromHex } from '../utils/colors'; import * as l10n from '@vscode/l10n'; import { - TextDocument, Thenable, ColorInformation, ColorPresentation, Color, ASTNode, PropertyASTNode, DocumentSymbolsContext, Range, TextEdit, + TextDocument, ColorInformation, ColorPresentation, Color, ASTNode, PropertyASTNode, DocumentSymbolsContext, Range, TextEdit, SymbolInformation, SymbolKind, DocumentSymbol, Location } from "../jsonLanguageTypes"; @@ -236,7 +236,7 @@ export class JSONDocumentSymbols { return undefined; } - public findDocumentColors(document: TextDocument, doc: Parser.JSONDocument, context?: DocumentSymbolsContext): Thenable { + public findDocumentColors(document: TextDocument, doc: Parser.JSONDocument, context?: DocumentSymbolsContext): PromiseLike { return this.schemaService.getSchemaForResource(document.uri, doc).then(schema => { const result: ColorInformation[] = []; if (schema) { diff --git a/src/services/jsonHover.ts b/src/services/jsonHover.ts index e68f945b..11d2fe14 100644 --- a/src/services/jsonHover.ts +++ b/src/services/jsonHover.ts @@ -6,7 +6,7 @@ import * as Parser from '../parser/jsonParser'; import * as SchemaService from './jsonSchemaService'; import { JSONWorkerContribution } from '../jsonContributions'; -import { TextDocument, PromiseConstructor, Thenable, Position, Range, Hover, MarkedString } from '../jsonLanguageTypes'; +import { TextDocument, PromiseConstructor, Position, Range, Hover, MarkedString } from '../jsonLanguageTypes'; export class JSONHover { @@ -20,7 +20,7 @@ export class JSONHover { this.promise = promiseConstructor || Promise; } - public doHover(document: TextDocument, position: Position, doc: Parser.JSONDocument): Thenable { + public doHover(document: TextDocument, position: Position, doc: Parser.JSONDocument): PromiseLike { const offset = document.offsetAt(position); let node = doc.getNodeFromOffset(offset); @@ -125,4 +125,4 @@ function toMarkdownCodeBlock(content: string) { return '`` ' + content + ' ``'; } return content; -} \ No newline at end of file +} diff --git a/src/services/jsonLinks.ts b/src/services/jsonLinks.ts index 3a73e4ff..51d29364 100644 --- a/src/services/jsonLinks.ts +++ b/src/services/jsonLinks.ts @@ -4,10 +4,10 @@ *--------------------------------------------------------------------------------------------*/ import { DocumentLink } from 'vscode-languageserver-types'; -import { TextDocument, ASTNode, PropertyASTNode, Range, Thenable } from '../jsonLanguageTypes'; +import { TextDocument, ASTNode, PropertyASTNode, Range } from '../jsonLanguageTypes'; import { JSONDocument } from '../parser/jsonParser'; -export function findLinks(document: TextDocument, doc: JSONDocument): Thenable { +export function findLinks(document: TextDocument, doc: JSONDocument): PromiseLike { const links: DocumentLink[] = []; doc.visit(node => { if (node.type === "property" && node.keyNode.value === "$ref" && node.valueNode?.type === 'string') { diff --git a/src/services/jsonSchemaService.ts b/src/services/jsonSchemaService.ts index 93869dfa..7b84ee3e 100644 --- a/src/services/jsonSchemaService.ts +++ b/src/services/jsonSchemaService.ts @@ -8,7 +8,7 @@ import { JSONSchema, JSONSchemaMap, JSONSchemaRef } from '../jsonSchema'; import { URI } from 'vscode-uri'; import * as Strings from '../utils/strings'; import * as Parser from '../parser/jsonParser'; -import { SchemaRequestService, WorkspaceContextService, PromiseConstructor, Thenable, MatchingSchema, TextDocument, SchemaConfiguration } from '../jsonLanguageTypes'; +import { SchemaRequestService, WorkspaceContextService, PromiseConstructor, MatchingSchema, TextDocument, SchemaConfiguration } from '../jsonLanguageTypes'; import * as l10n from '@vscode/l10n'; import { createRegex } from '../utils/glob'; @@ -34,7 +34,7 @@ export interface IJSONSchemaService { /** * Looks up the appropriate schema for the given URI */ - getSchemaForResource(resource: string, document?: Parser.JSONDocument): Thenable; + getSchemaForResource(resource: string, document?: Parser.JSONDocument): PromiseLike; /** * Returns all registered schema ids @@ -62,12 +62,12 @@ export interface ISchemaHandle { /** * The schema from the file, with potential $ref references */ - getUnresolvedSchema(): Thenable; + getUnresolvedSchema(): PromiseLike; /** * The schema from the file, with references resolved */ - getResolvedSchema(): Thenable; + getResolvedSchema(): PromiseLike; } const BANG = '!'; @@ -138,8 +138,8 @@ class SchemaHandle implements ISchemaHandle { public readonly uri: string; public readonly dependencies: SchemaDependencies; public anchors: Map | undefined; - private resolvedSchema: Thenable | undefined; - private unresolvedSchema: Thenable | undefined; + private resolvedSchema: PromiseLike | undefined; + private unresolvedSchema: PromiseLike | undefined; private readonly service: JSONSchemaService; constructor(service: JSONSchemaService, uri: string, unresolvedSchemaContent?: JSONSchema) { @@ -152,14 +152,14 @@ class SchemaHandle implements ISchemaHandle { } } - public getUnresolvedSchema(): Thenable { + public getUnresolvedSchema(): PromiseLike { if (!this.unresolvedSchema) { this.unresolvedSchema = this.service.loadSchema(this.uri); } return this.unresolvedSchema; } - public getResolvedSchema(): Thenable { + public getResolvedSchema(): PromiseLike { if (!this.resolvedSchema) { this.resolvedSchema = this.getUnresolvedSchema().then(unresolved => { return this.service.resolveSchemaContent(unresolved, this); @@ -256,7 +256,7 @@ export class JSONSchemaService implements IJSONSchemaService { private requestService: SchemaRequestService | undefined; private promiseConstructor: PromiseConstructor; - private cachedSchemaForResource: { resource: string; resolvedSchema: Thenable } | undefined; + private cachedSchemaForResource: { resource: string; resolvedSchema: PromiseLike } | undefined; constructor(requestService?: SchemaRequestService, contextService?: WorkspaceContextService, promiseConstructor?: PromiseConstructor) { this.contextService = contextService; @@ -376,7 +376,7 @@ export class JSONSchemaService implements IJSONSchemaService { } } - public getResolvedSchema(schemaId: string): Thenable { + public getResolvedSchema(schemaId: string): PromiseLike { const id = normalizeId(schemaId); const schemaHandle = this.schemasById[id]; if (schemaHandle) { @@ -385,7 +385,7 @@ export class JSONSchemaService implements IJSONSchemaService { return this.promise.resolve(undefined); } - public loadSchema(url: string): Thenable { + public loadSchema(url: string): PromiseLike { if (!this.requestService) { const errorMessage = l10n.t('Unable to load schema from \'{0}\'. No schema request service available', toDisplayString(url)); return this.promise.resolve(new UnresolvedSchema({}, [errorMessage])); @@ -428,7 +428,7 @@ export class JSONSchemaService implements IJSONSchemaService { ); } - public resolveSchemaContent(schemaToResolve: UnresolvedSchema, handle: SchemaHandle): Thenable { + public resolveSchemaContent(schemaToResolve: UnresolvedSchema, handle: SchemaHandle): PromiseLike { const resolveErrors: string[] = schemaToResolve.errors.slice(0); const schema = schemaToResolve.schema; @@ -489,7 +489,7 @@ export class JSONSchemaService implements IJSONSchemaService { } }; - const resolveExternalLink = (node: JSONSchema, uri: string, refSegment: string | undefined, parentHandle: SchemaHandle): Thenable => { + const resolveExternalLink = (node: JSONSchema, uri: string, refSegment: string | undefined, parentHandle: SchemaHandle): PromiseLike => { if (contextService && !/^[A-Za-z][A-Za-z0-9+\-.+]*:\/\/.*/.test(uri)) { uri = contextService.resolveRelativePath(uri, parentHandle.uri); } @@ -506,8 +506,8 @@ export class JSONSchemaService implements IJSONSchemaService { }); }; - const resolveRefs = (node: JSONSchema, parentSchema: JSONSchema, parentHandle: SchemaHandle): Thenable => { - const openPromises: Thenable[] = []; + const resolveRefs = (node: JSONSchema, parentSchema: JSONSchema, parentHandle: SchemaHandle): PromiseLike => { + const openPromises: PromiseLike[] = []; this.traverseNodes(node, next => { const seenRefs = new Set(); @@ -674,7 +674,7 @@ export class JSONSchemaService implements IJSONSchemaService { return this.getAssociatedSchemas(resource); } - public getSchemaForResource(resource: string, document?: Parser.JSONDocument): Thenable { + public getSchemaForResource(resource: string, document?: Parser.JSONDocument): PromiseLike { if (document) { // first use $schema if present let schemeId = this.getSchemaFromProperty(resource, document); @@ -704,7 +704,7 @@ export class JSONSchemaService implements IJSONSchemaService { } } - public getMatchingSchemas(document: TextDocument, jsonDocument: Parser.JSONDocument, schema?: JSONSchema): Thenable { + public getMatchingSchemas(document: TextDocument, jsonDocument: Parser.JSONDocument, schema?: JSONSchema): PromiseLike { if (schema) { const id = schema.id || ('schemaservice://untitled/matchingSchemas/' + idCounter++); const handle = this.addSchemaHandle(id, schema); diff --git a/src/services/jsonValidation.ts b/src/services/jsonValidation.ts index 1ce1983c..876e27e0 100644 --- a/src/services/jsonValidation.ts +++ b/src/services/jsonValidation.ts @@ -3,10 +3,10 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { JSONSchemaService, ResolvedSchema, UnresolvedSchema } from './jsonSchemaService'; +import { JSONSchemaService, ResolvedSchema } from './jsonSchemaService'; import { JSONDocument } from '../parser/jsonParser'; -import { TextDocument, ErrorCode, PromiseConstructor, Thenable, LanguageSettings, DocumentLanguageSettings, SeverityLevel, Diagnostic, DiagnosticSeverity, Range, JSONLanguageStatus } from '../jsonLanguageTypes'; +import { TextDocument, ErrorCode, PromiseConstructor, LanguageSettings, DocumentLanguageSettings, SeverityLevel, Diagnostic, DiagnosticSeverity, Range, JSONLanguageStatus } from '../jsonLanguageTypes'; import * as l10n from '@vscode/l10n'; import { JSONSchemaRef, JSONSchema } from '../jsonSchema'; import { isBoolean } from '../utils/objects'; @@ -32,7 +32,7 @@ export class JSONValidation { } } - public doValidation(textDocument: TextDocument, jsonDocument: JSONDocument, documentSettings?: DocumentLanguageSettings, schema?: JSONSchema): Thenable { + public doValidation(textDocument: TextDocument, jsonDocument: JSONDocument, documentSettings?: DocumentLanguageSettings, schema?: JSONSchema): PromiseLike { if (!this.validationEnabled) { return this.promise.resolve([]); } @@ -170,4 +170,4 @@ function toDiagnosticSeverity(severityLevel: SeverityLevel | undefined): Diagnos case 'ignore': return undefined; } return undefined; -} \ No newline at end of file +} diff --git a/src/test/documentSymbols.test.ts b/src/test/documentSymbols.test.ts index 743bcdc3..a63659de 100644 --- a/src/test/documentSymbols.test.ts +++ b/src/test/documentSymbols.test.ts @@ -7,7 +7,7 @@ import * as assert from 'assert'; import * as JsonSchema from '../jsonSchema'; import { - Thenable, getLanguageService, + getLanguageService, ClientCapabilities, DocumentSymbolsContext, TextDocument, Color, SymbolInformation, SymbolKind, Range, Position, TextEdit, DocumentSymbol } from "../jsonLanguageService"; @@ -37,7 +37,7 @@ suite('JSON Document Symbols', () => { return ls.findDocumentSymbols2(document, jsonDoc, context); } - function assertColors(value: string, schema: JsonSchema.JSONSchema, expectedOffsets: number[], expectedColors: Color[]): Thenable { + function assertColors(value: string, schema: JsonSchema.JSONSchema, expectedOffsets: number[], expectedColors: Color[]): PromiseLike { const uri = 'test://test.json'; const schemaUri = "http://myschemastore/test1"; @@ -298,4 +298,4 @@ suite('JSON Document Symbols', () => { assertColorPresentations(colorFrom256RGB(77, 33, 111, 0.5), '#4d216f80'); }); -}); \ No newline at end of file +}); diff --git a/src/test/hover.test.ts b/src/test/hover.test.ts index 5d4582e2..b0b62587 100644 --- a/src/test/hover.test.ts +++ b/src/test/hover.test.ts @@ -5,7 +5,7 @@ import * as assert from 'assert'; -import { Hover, Position, MarkedString, TextDocument, getLanguageService, JSONSchema, JSONWorkerContribution, LanguageServiceParams } from '../jsonLanguageService'; +import { Hover, Position, MarkedString, TextDocument, getLanguageService, JSONSchema, LanguageServiceParams } from '../jsonLanguageService'; suite('JSON Hover', () => { @@ -184,4 +184,4 @@ suite('JSON Hover', () => { assert.deepEqual(result.contents, ['test://test.json: prop1/0']); }); -}); \ No newline at end of file +}); diff --git a/src/utils/sort.ts b/src/utils/sort.ts index 83ef1745..5beeb4e3 100644 --- a/src/utils/sort.ts +++ b/src/utils/sort.ts @@ -3,8 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -// import { TextEdit} from 'vscode-languageserver-textdocument'; -import { createScanner, SyntaxKind, JSONScanner, FormattingOptions as JPFormattingOptions } from 'jsonc-parser'; +import { createScanner, SyntaxKind, JSONScanner } from 'jsonc-parser'; import { TextDocument, TextEdit, FormattingOptions, Position, Range, TextDocumentContentChangeEvent, SortOptions } from '../jsonLanguageTypes'; import { format } from './format'; import { PropertyTree, Container } from './propertyTree'; @@ -425,4 +424,4 @@ class SortingRange { this.beginningLineNumber = beginningLineNumber; this.propertyTreeArray = propertyTreeArray; } -} \ No newline at end of file +}