From eefe7cbc1ebadcac6bb9523028d52610d2bf6b27 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Wed, 24 Jun 2026 09:50:33 +0200 Subject: [PATCH] Sort imports This change enforces some ESLint rules to ensure consistent import sorting. The `import-x/first` rule ensures all imports are on top of the file. The `import-x/order` rule forces a consistent order of import statements. Imports are grouped by Node.js builtins, external dependencies, and relative imports. Type imports are sorted before values. Within each group, the statements are alphabetized. The `sort-imports` rule sorts the imported members. The `import/newline-after-import` rule enforces a newline after the last import. --- eslint.config.mjs | 12 ++++ .../handlers/languageHandlers.ts | 21 +++--- .../handlers/notificationHandlers.ts | 6 +- .../handlers/requestHandlers.ts | 4 +- .../handlers/schemaSelectionHandlers.ts | 6 +- .../handlers/settingsHandlers.ts | 17 +++-- .../handlers/validationHandlers.ts | 6 +- .../handlers/workspaceHandlers.ts | 3 +- src/languageserver/telemetry.ts | 4 +- src/languageservice/jsonLanguageTypes.ts | 62 ++++++++-------- src/languageservice/parser/ast-converter.ts | 17 +++-- .../parser/custom-tag-provider.ts | 5 +- src/languageservice/parser/isKubernetes.ts | 4 +- src/languageservice/parser/jsonDocument.ts | 16 +++-- .../parser/schemaValidation/baseValidator.ts | 27 +++---- .../schemaValidation/draft04Validator.ts | 3 +- .../schemaValidation/draft07Validator.ts | 3 +- .../schemaValidation/draft2019Validator.ts | 12 ++-- .../schemaValidation/draft2020Validator.ts | 12 ++-- .../schemaValidation/validatorFactory.ts | 3 +- src/languageservice/parser/yaml-documents.ts | 13 ++-- src/languageservice/parser/yamlParser07.ts | 10 +-- .../services/documentSymbols.ts | 11 +-- src/languageservice/services/dollarUtils.ts | 2 +- src/languageservice/services/k8sSchemaUtil.ts | 6 +- src/languageservice/services/modelineUtil.ts | 3 +- .../services/schemaRequestHandler.ts | 10 ++- .../services/validation/map-key-order.ts | 8 ++- .../services/validation/types.ts | 1 + .../services/validation/unused-anchors.ts | 13 ++-- .../services/validation/yaml-style.ts | 8 ++- .../services/yamlCodeActions.ts | 30 ++++---- src/languageservice/services/yamlCodeLens.ts | 9 ++- src/languageservice/services/yamlCommands.ts | 5 +- .../services/yamlCompletion.ts | 41 ++++++----- .../services/yamlDefinition.ts | 5 +- src/languageservice/services/yamlFolding.ts | 9 ++- src/languageservice/services/yamlFormatter.ts | 10 +-- src/languageservice/services/yamlHover.ts | 24 ++++--- src/languageservice/services/yamlLinks.ts | 11 +-- .../services/yamlOnTypeFormatting.ts | 2 + src/languageservice/services/yamlRename.ts | 15 ++-- .../services/yamlSchemaService.ts | 1 + .../services/yamlSelectionRanges.ts | 7 +- .../services/yamlValidation.ts | 23 +++--- src/languageservice/utils/arrUtils.ts | 2 +- .../utils/block-string-rewriter.ts | 1 + .../utils/flow-style-rewriter.ts | 3 +- .../utils/indentationGuesser.ts | 3 +- src/languageservice/utils/parseUtils.ts | 1 + src/languageservice/utils/paths.ts | 2 + src/languageservice/utils/schemaUrls.ts | 10 ++- src/languageservice/utils/schemaUtils.ts | 4 +- src/languageservice/utils/textBuffer.ts | 1 + src/languageservice/utils/yamlAstUtils.ts | 4 +- src/languageservice/yamlLanguageService.ts | 70 ++++++++++--------- src/nodeTranslationSetup.ts | 8 ++- src/requestTypes.ts | 3 +- src/server.ts | 7 +- src/webworker/yamlServerMain.ts | 4 +- src/yamlServerInit.ts | 9 ++- src/yamlSettings.ts | 13 ++-- test/arrUtils.test.ts | 3 +- test/astUtils.test.ts | 9 ++- test/autoCompletion.test.ts | 20 +++--- test/autoCompletionFix.test.ts | 16 +++-- test/bundlel10n.test.ts | 7 +- test/code-action-schema.test.ts | 19 ++--- test/customTags.test.ts | 13 ++-- test/defaultSnippets.test.ts | 14 ++-- test/diagnostic-filter.test.ts | 6 +- test/documentSymbols.test.ts | 20 +++--- test/findLinks.test.ts | 11 +-- test/flow-style-rewriter.test.ts | 3 +- test/formatter.test.ts | 8 ++- test/hover.test.ts | 18 +++-- test/integration.test.ts | 14 ++-- test/invalid-metaschema.test.ts | 4 +- test/multipleDocuments.test.ts | 20 +++--- test/objects.test.ts | 3 +- test/paths.test.ts | 6 +- test/schema.test.ts | 40 ++++++----- test/schema2019Validation.test.ts | 17 +++-- test/schema2020Validation.test.ts | 17 +++-- test/schemaRequestHandler.test.ts | 12 ++-- test/schemaSelectionHandlers.test.ts | 8 ++- test/schemaValidation.test.ts | 42 ++++++----- test/settingsHandlers.test.ts | 9 ++- test/strings.test.ts | 4 +- test/telemetry.test.ts | 10 +-- test/textBuffer.test.ts | 6 +- test/utils/serviceSetup.ts | 2 +- test/utils/testHelper.ts | 18 +++-- test/utils/testsTypes.ts | 16 +++-- test/utils/verifyError.ts | 4 +- test/yaml-documents.test.ts | 12 ++-- test/yamlCodeActions.test.ts | 13 ++-- test/yamlCodeLens.test.ts | 25 ++++--- test/yamlCommands.test.ts | 10 +-- test/yamlDefinition.test.ts | 8 ++- test/yamlFolding.test.ts | 6 +- test/yamlLanguageService.test.ts | 7 +- test/yamlOnTypeFormatting.test.ts | 6 +- test/yamlParser.test.ts | 9 ++- test/yamlRename.test.ts | 8 ++- test/yamlSchema.test.ts | 6 +- test/yamlSchemaService.test.ts | 15 ++-- test/yamlSelectionRanges.test.ts | 4 +- test/yamlValidation.test.ts | 9 ++- 109 files changed, 744 insertions(+), 478 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 6ef471dec..be9d1b7cf 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -33,10 +33,22 @@ export default defineConfig( }, }, rules: { + 'sort-imports': ['error', { ignoreDeclarationSort: true }], '@typescript-eslint/consistent-type-imports': 'error', '@typescript-eslint/no-use-before-define': ['error', { functions: false, classes: false }], '@typescript-eslint/explicit-function-return-type': ['error', { allowExpressions: true }], 'import-x/consistent-type-specifier-style': ['error', 'prefer-top-level'], + 'import-x/first': 'error', + 'import-x/newline-after-import': 'error', + 'import-x/order': [ + 'error', + { + alphabetize: { order: 'asc' }, + groups: ['type', 'builtin', 'external', ['parent', 'sibling', 'index']], + 'newlines-between': 'always', + sortTypesGroup: true, + }, + ], }, }, { diff --git a/src/languageserver/handlers/languageHandlers.ts b/src/languageserver/handlers/languageHandlers.ts index 1d4ed68bd..3f117dc81 100644 --- a/src/languageserver/handlers/languageHandlers.ts +++ b/src/languageserver/handlers/languageHandlers.ts @@ -6,19 +6,20 @@ import type { Connection } from 'vscode-languageserver'; import type { CodeActionParams, + CodeLensParams, + DefinitionParams, DidChangeWatchedFilesParams, DocumentFormattingParams, DocumentLinkParams, DocumentOnTypeFormattingParams, DocumentSymbolParams, FoldingRangeParams, - SelectionRangeParams, - TextDocumentPositionParams, - CodeLensParams, - DefinitionParams, PrepareRenameParams, RenameParams, + SelectionRangeParams, + TextDocumentPositionParams, } from 'vscode-languageserver-protocol'; +import type { TextDocument } from 'vscode-languageserver-textdocument'; import type { CodeAction, CodeLens, @@ -26,21 +27,23 @@ import type { DefinitionLink, DocumentLink, DocumentSymbol, - Hover, FoldingRange, + Hover, Range, SelectionRange, SymbolInformation, TextEdit, WorkspaceEdit, } from 'vscode-languageserver-types'; -import { isKubernetesAssociatedDocument } from '../../languageservice/parser/isKubernetes'; + +import type { ValidationHandler } from './validationHandlers'; import type { LanguageService } from '../../languageservice/yamlLanguageService'; import type { SettingsState } from '../../yamlSettings'; -import type { ValidationHandler } from './validationHandlers'; -import { ResultLimitReachedNotification } from '../../requestTypes'; + import * as path from 'path'; -import type { TextDocument } from 'vscode-languageserver-textdocument'; + +import { isKubernetesAssociatedDocument } from '../../languageservice/parser/isKubernetes'; +import { ResultLimitReachedNotification } from '../../requestTypes'; export class LanguageHandlers { private languageService: LanguageService; diff --git a/src/languageserver/handlers/notificationHandlers.ts b/src/languageserver/handlers/notificationHandlers.ts index 998b10083..51e2e4662 100644 --- a/src/languageserver/handlers/notificationHandlers.ts +++ b/src/languageserver/handlers/notificationHandlers.ts @@ -3,8 +3,12 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import type { Connection } from 'vscode-languageserver'; + +import type { SettingsHandler } from './settingsHandlers'; import type { CustomSchemaProvider } from '../../languageservice/services/yamlSchemaService'; import type { LanguageService, SchemaConfiguration } from '../../languageservice/yamlLanguageService'; +import type { SettingsState } from '../../yamlSettings'; + import { CustomSchemaRequest, DynamicCustomSchemaRequestRegistration, @@ -12,8 +16,6 @@ import { SchemaSelectionRequests, VSCodeContentRequestRegistration, } from '../../requestTypes'; -import type { SettingsState } from '../../yamlSettings'; -import type { SettingsHandler } from './settingsHandlers'; export class NotificationHandlers { private languageService: LanguageService; diff --git a/src/languageserver/handlers/requestHandlers.ts b/src/languageserver/handlers/requestHandlers.ts index 4bacdea03..f0ede779d 100644 --- a/src/languageserver/handlers/requestHandlers.ts +++ b/src/languageserver/handlers/requestHandlers.ts @@ -3,9 +3,11 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import type { Connection } from 'vscode-languageserver'; + import type { SchemaAdditions, SchemaDeletions, SchemaDeletionsAll } from '../../languageservice/services/yamlSchemaService'; -import { MODIFICATION_ACTIONS } from '../../languageservice/services/yamlSchemaService'; import type { LanguageService } from '../../languageservice/yamlLanguageService'; + +import { MODIFICATION_ACTIONS } from '../../languageservice/services/yamlSchemaService'; import { SchemaModificationNotification } from '../../requestTypes'; export class RequestHandlers { diff --git a/src/languageserver/handlers/schemaSelectionHandlers.ts b/src/languageserver/handlers/schemaSelectionHandlers.ts index d041c0e76..714b6cb45 100644 --- a/src/languageserver/handlers/schemaSelectionHandlers.ts +++ b/src/languageserver/handlers/schemaSelectionHandlers.ts @@ -4,11 +4,13 @@ *--------------------------------------------------------------------------------------------*/ import type { Connection } from 'vscode-languageserver/node'; + import type { JSONSchema } from '../../languageservice/jsonSchema'; -import { yamlDocumentsCache } from '../../languageservice/parser/yaml-documents'; import type { YAMLSchemaService } from '../../languageservice/services/yamlSchemaService'; -import type { SettingsState } from '../../yamlSettings'; import type { JSONSchemaDescription, JSONSchemaDescriptionExt } from '../../requestTypes'; +import type { SettingsState } from '../../yamlSettings'; + +import { yamlDocumentsCache } from '../../languageservice/parser/yaml-documents'; import { SchemaSelectionRequests } from '../../requestTypes'; export class JSONSchemaSelection { diff --git a/src/languageserver/handlers/settingsHandlers.ts b/src/languageserver/handlers/settingsHandlers.ts index 8fd67bbee..96f78d8ed 100644 --- a/src/languageserver/handlers/settingsHandlers.ts +++ b/src/languageserver/handlers/settingsHandlers.ts @@ -2,19 +2,22 @@ * Copyright (c) Red Hat, Inc. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { configure as configureHttpRequests, xhr } from 'request-light'; import type { Connection } from 'vscode-languageserver'; + +import type { ValidationHandler } from './validationHandlers'; +import type { Telemetry } from '../../languageservice/telemetry'; +import type { LanguageService, LanguageSettings, SchemasSettings } from '../../languageservice/yamlLanguageService'; +import type { Settings, SettingsState } from '../../yamlSettings'; + +import { configure as configureHttpRequests, xhr } from 'request-light'; import { DidChangeConfigurationNotification, DocumentFormattingRequest } from 'vscode-languageserver'; import { CodeLensRefreshRequest } from 'vscode-languageserver-protocol'; -import { isRelativePath, relativeToAbsolutePath } from '../../languageservice/utils/paths'; -import { checkSchemaURI, EMPTY_SCHEMA_URL, isKubernetes, JSON_SCHEMASTORE_URL } from '../../languageservice/utils/schemaUrls'; + import { equals } from '../../languageservice/utils/objects'; -import type { LanguageService, LanguageSettings, SchemasSettings } from '../../languageservice/yamlLanguageService'; +import { isRelativePath, relativeToAbsolutePath } from '../../languageservice/utils/paths'; +import { EMPTY_SCHEMA_URL, JSON_SCHEMASTORE_URL, checkSchemaURI, isKubernetes } from '../../languageservice/utils/schemaUrls'; import { SchemaPriority } from '../../languageservice/yamlLanguageService'; import { SchemaSelectionRequests } from '../../requestTypes'; -import type { Settings, SettingsState } from '../../yamlSettings'; -import type { Telemetry } from '../../languageservice/telemetry'; -import type { ValidationHandler } from './validationHandlers'; export class SettingsHandler { private schemaSettings: SchemasSettings[] | undefined; diff --git a/src/languageserver/handlers/validationHandlers.ts b/src/languageserver/handlers/validationHandlers.ts index 644901ab4..eff58551e 100644 --- a/src/languageserver/handlers/validationHandlers.ts +++ b/src/languageserver/handlers/validationHandlers.ts @@ -5,11 +5,13 @@ import type { Connection } from 'vscode-languageserver'; import type { TextDocument } from 'vscode-languageserver-textdocument'; import type { Diagnostic } from 'vscode-languageserver-types'; -import { isKubernetesAssociatedDocument } from '../../languageservice/parser/isKubernetes'; -import { removeDuplicatesObj } from '../../languageservice/utils/arrUtils'; + import type { LanguageService } from '../../languageservice/yamlLanguageService'; import type { SettingsState } from '../../yamlSettings'; +import { isKubernetesAssociatedDocument } from '../../languageservice/parser/isKubernetes'; +import { removeDuplicatesObj } from '../../languageservice/utils/arrUtils'; + export class ValidationHandler { private languageService: LanguageService; private yamlSettings: SettingsState; diff --git a/src/languageserver/handlers/workspaceHandlers.ts b/src/languageserver/handlers/workspaceHandlers.ts index abb95e8f1..f67e73da5 100644 --- a/src/languageserver/handlers/workspaceHandlers.ts +++ b/src/languageserver/handlers/workspaceHandlers.ts @@ -3,7 +3,8 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import type { ExecuteCommandParams, Connection } from 'vscode-languageserver'; +import type { Connection, ExecuteCommandParams } from 'vscode-languageserver'; + import type { CommandExecutor } from '../commandExecutor'; export class WorkspaceHandlers { diff --git a/src/languageserver/telemetry.ts b/src/languageserver/telemetry.ts index a28e88143..69da8d019 100644 --- a/src/languageserver/telemetry.ts +++ b/src/languageserver/telemetry.ts @@ -4,7 +4,9 @@ *--------------------------------------------------------------------------------------------*/ import type { Connection } from 'vscode-languageserver'; -import type { TelemetryEvent, Telemetry } from '../languageservice/telemetry'; + +import type { Telemetry, TelemetryEvent } from '../languageservice/telemetry'; + import { convertErrorToTelemetryMsg } from '../languageservice/utils/objects'; export class TelemetryImpl implements Telemetry { diff --git a/src/languageservice/jsonLanguageTypes.ts b/src/languageservice/jsonLanguageTypes.ts index 0532e21e8..7da0b92dc 100644 --- a/src/languageservice/jsonLanguageTypes.ts +++ b/src/languageservice/jsonLanguageTypes.ts @@ -6,49 +6,53 @@ // Forked from vscode-json-languageservice@6.0.0-next.1 // Source: https://github.com/microsoft/vscode-json-languageservice/blob/810471bbb462bb6b87351c2232e209a3bb4062ca/src/jsonLanguageTypes.ts -import { JSONSchema } from './jsonSchema'; import type { FormattingOptions as LSPFormattingOptions } from 'vscode-languageserver-types'; +import type { Node, Pair } from 'yaml'; + +import type { CustomTagReturnType } from './utils/customTags'; + +import { TextDocument, TextDocumentContentChangeEvent } from 'vscode-languageserver-textdocument'; import { - Range, - Position, - DocumentUri, - MarkupContent, - MarkupKind, + CodeAction, + CodeActionContext, + CodeActionKind, Color, ColorInformation, ColorPresentation, - FoldingRange, - FoldingRangeKind, - SelectionRange, - Diagnostic, - DiagnosticSeverity, + Command, CompletionItem, CompletionItemKind, - CompletionList, CompletionItemTag, - InsertTextFormat, - SymbolInformation, - SymbolKind, - DocumentSymbol, - Location, - Hover, - MarkedString, + CompletionList, DefinitionLink, - CodeActionContext, - Command, - CodeAction, + Diagnostic, + DiagnosticSeverity, DocumentHighlight, + DocumentHighlightKind, DocumentLink, - WorkspaceEdit, - TextEdit, - CodeActionKind, + DocumentSymbol, + DocumentUri, + FoldingRange, + FoldingRangeKind, + Hover, + InsertTextFormat, + Location, + MarkedString, + MarkupContent, + MarkupKind, + Position, + Range, + SelectionRange, + SymbolInformation, + SymbolKind, TextDocumentEdit, + TextEdit, VersionedTextDocumentIdentifier, - DocumentHighlightKind, + WorkspaceEdit, } from 'vscode-languageserver-types'; -import { TextDocument, TextDocumentContentChangeEvent } from 'vscode-languageserver-textdocument'; -import type { Node, Pair } from 'yaml'; -import type { CustomTagReturnType } from './utils/customTags'; + +import { JSONSchema } from './jsonSchema'; + export { TextDocument, TextDocumentContentChangeEvent, diff --git a/src/languageservice/parser/ast-converter.ts b/src/languageservice/parser/ast-converter.ts index 7c9dfa561..a3b253c93 100644 --- a/src/languageservice/parser/ast-converter.ts +++ b/src/languageservice/parser/ast-converter.ts @@ -3,19 +3,22 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import type { Node, Scalar, YAMLMap, Pair, YAMLSeq, Alias, Document, LineCounter } from 'yaml'; -import { isScalar, isMap, isPair, isSeq, isNode, isAlias } from 'yaml'; +import type { Alias, Document, LineCounter, Node, Pair, Scalar, YAMLMap, YAMLSeq } from 'yaml'; + import type { ASTNode, YamlNode } from '../jsonLanguageTypes'; -import { getCustomTagReturnType } from '../utils/customTags'; + +import { isAlias, isMap, isNode, isPair, isScalar, isSeq } from 'yaml'; + import { + ArrayASTNodeImpl, + BooleanASTNodeImpl, NullASTNodeImpl, + NumberASTNodeImpl, + ObjectASTNodeImpl, PropertyASTNodeImpl, StringASTNodeImpl, - ObjectASTNodeImpl, - NumberASTNodeImpl, - ArrayASTNodeImpl, - BooleanASTNodeImpl, } from './jsonDocument'; +import { getCustomTagReturnType } from '../utils/customTags'; type NodeRange = [number, number, number]; diff --git a/src/languageservice/parser/custom-tag-provider.ts b/src/languageservice/parser/custom-tag-provider.ts index 275e3d6f0..7dd7c653c 100644 --- a/src/languageservice/parser/custom-tag-provider.ts +++ b/src/languageservice/parser/custom-tag-provider.ts @@ -1,6 +1,9 @@ import type { Tags, YAMLMap, YAMLSeq } from 'yaml'; -import { isSeq, isMap, Scalar } from 'yaml'; + import type { CustomTagInputType, CustomTagReturnType } from '../utils/customTags'; + +import { Scalar, isMap, isSeq } from 'yaml'; + import { parseCustomTag, setCustomTagReturnType } from '../utils/customTags'; class CommonTagImpl { diff --git a/src/languageservice/parser/isKubernetes.ts b/src/languageservice/parser/isKubernetes.ts index ebd9de8b5..1a9c50d2f 100644 --- a/src/languageservice/parser/isKubernetes.ts +++ b/src/languageservice/parser/isKubernetes.ts @@ -3,9 +3,11 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import type { TextDocument } from 'vscode-languageserver-textdocument'; -import { FilePatternAssociation } from '../utils/filePatternAssociation'; + import type * as Parser from './jsonDocument'; +import { FilePatternAssociation } from '../utils/filePatternAssociation'; + export function setKubernetesParserOption(jsonDocuments: Parser.JSONDocument[], option: boolean): void { for (const jsonDoc of jsonDocuments) { jsonDoc.isKubernetes = option; diff --git a/src/languageservice/parser/jsonDocument.ts b/src/languageservice/parser/jsonDocument.ts index bb566f6ce..e5b12eed3 100644 --- a/src/languageservice/parser/jsonDocument.ts +++ b/src/languageservice/parser/jsonDocument.ts @@ -3,23 +3,25 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import type { JSONSchema } from '../jsonSchema'; +import type { TextDocument } from 'vscode-languageserver-textdocument'; +import type { Diagnostic, Range } from 'vscode-languageserver-types'; +import type { Node, Pair } from 'yaml'; + import type { ASTNode, - ObjectASTNode, ArrayASTNode, BooleanASTNode, - NumberASTNode, - StringASTNode, NullASTNode, + NumberASTNode, + ObjectASTNode, PropertyASTNode, + StringASTNode, YamlNode, } from '../jsonLanguageTypes'; +import type { JSONSchema } from '../jsonSchema'; import type { CustomTagReturnType } from '../utils/customTags'; -import type { Diagnostic, Range } from 'vscode-languageserver-types'; -import type { TextDocument } from 'vscode-languageserver-textdocument'; -import type { Node, Pair } from 'yaml'; import type { IApplicableSchema } from './schemaValidation/baseValidator'; + import { findNodeAtOffset } from '../utils/astNodeUtils'; import { getValidator } from './schemaValidation/validatorFactory'; diff --git a/src/languageservice/parser/schemaValidation/baseValidator.ts b/src/languageservice/parser/schemaValidation/baseValidator.ts index 485b0c409..b4760c5d2 100644 --- a/src/languageservice/parser/schemaValidation/baseValidator.ts +++ b/src/languageservice/parser/schemaValidation/baseValidator.ts @@ -4,29 +4,32 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import type { JSONSchema, JSONSchemaRef } from '../../jsonSchema'; +import type { TextDocument } from 'vscode-languageserver-textdocument'; + import type { ASTNode, ArrayASTNode, NumberASTNode, ObjectASTNode, PropertyASTNode, - StringASTNode, SchemaDraft, + StringASTNode, } from '../../jsonLanguageTypes'; -import { equals, isBoolean, isDefined, isIterable, isNumber, isString } from '../../utils/objects'; -import { getSchemaTypeName } from '../../utils/schemaUtils'; -import { isArrayEqual } from '../../utils/arrUtils'; -import { safeCreateUnicodeRegExp } from '../../utils/strings'; -import { FilePatternAssociation } from '../../utils/filePatternAssociation'; -import { floatSafeRemainder } from '../../utils/math'; -import { ErrorCode } from '../../jsonLanguageTypes'; +import type { JSONSchema, JSONSchemaRef } from '../../jsonSchema'; + import * as l10n from '@vscode/l10n'; -import { URI } from 'vscode-uri'; import { Diagnostic, DiagnosticSeverity, Range } from 'vscode-languageserver-types'; -import type { TextDocument } from 'vscode-languageserver-textdocument'; -import { contains, getNodeValue } from '../../utils/astNodeUtils'; +import { URI } from 'vscode-uri'; + import { getValidator } from './validatorFactory'; +import { ErrorCode } from '../../jsonLanguageTypes'; +import { isArrayEqual } from '../../utils/arrUtils'; +import { contains, getNodeValue } from '../../utils/astNodeUtils'; +import { FilePatternAssociation } from '../../utils/filePatternAssociation'; +import { floatSafeRemainder } from '../../utils/math'; +import { equals, isBoolean, isDefined, isIterable, isNumber, isString } from '../../utils/objects'; +import { getSchemaTypeName } from '../../utils/schemaUtils'; +import { safeCreateUnicodeRegExp } from '../../utils/strings'; export const YAML_SOURCE = 'YAML'; const YAML_SCHEMA_PREFIX = 'yaml-schema: '; diff --git a/src/languageservice/parser/schemaValidation/draft04Validator.ts b/src/languageservice/parser/schemaValidation/draft04Validator.ts index 2c67bf329..fdb8537c3 100644 --- a/src/languageservice/parser/schemaValidation/draft04Validator.ts +++ b/src/languageservice/parser/schemaValidation/draft04Validator.ts @@ -4,9 +4,10 @@ *--------------------------------------------------------------------------------------------*/ import type { JSONSchema } from '../../jsonSchema'; + +import { BaseValidator } from './baseValidator'; import { SchemaDraft } from '../../jsonLanguageTypes'; import { isBoolean, isNumber } from '../../utils/objects'; -import { BaseValidator } from './baseValidator'; export class Draft04Validator extends BaseValidator { protected override getCurrentSchemaDraft(): SchemaDraft { diff --git a/src/languageservice/parser/schemaValidation/draft07Validator.ts b/src/languageservice/parser/schemaValidation/draft07Validator.ts index 73d5b3d2c..30da07d50 100644 --- a/src/languageservice/parser/schemaValidation/draft07Validator.ts +++ b/src/languageservice/parser/schemaValidation/draft07Validator.ts @@ -4,9 +4,10 @@ *--------------------------------------------------------------------------------------------*/ import type { JSONSchema } from '../../jsonSchema'; + +import { BaseValidator } from './baseValidator'; import { SchemaDraft } from '../../jsonLanguageTypes'; import { isNumber } from '../../utils/objects'; -import { BaseValidator } from './baseValidator'; export class Draft07Validator extends BaseValidator { protected override getCurrentSchemaDraft(): SchemaDraft { diff --git a/src/languageservice/parser/schemaValidation/draft2019Validator.ts b/src/languageservice/parser/schemaValidation/draft2019Validator.ts index 14d84ff16..114f73cec 100644 --- a/src/languageservice/parser/schemaValidation/draft2019Validator.ts +++ b/src/languageservice/parser/schemaValidation/draft2019Validator.ts @@ -3,15 +3,17 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import type { JSONSchema, JSONSchemaRef } from '../../jsonSchema'; -import { ErrorCode, SchemaDraft } from '../../jsonLanguageTypes'; +import type { ISchemaCollector, Options } from './baseValidator'; import type { ASTNode, ArrayASTNode, ObjectASTNode } from '../../jsonLanguageTypes'; -import { isNumber } from '../../utils/objects'; +import type { JSONSchema, JSONSchemaRef } from '../../jsonSchema'; + import * as l10n from '@vscode/l10n'; import { DiagnosticSeverity } from 'vscode-languageserver-types'; -import { Draft07Validator } from './draft07Validator'; + import { ValidationResult, asSchema } from './baseValidator'; -import type { ISchemaCollector, Options } from './baseValidator'; +import { Draft07Validator } from './draft07Validator'; +import { ErrorCode, SchemaDraft } from '../../jsonLanguageTypes'; +import { isNumber } from '../../utils/objects'; export class Draft2019Validator extends Draft07Validator { protected override getCurrentSchemaDraft(): SchemaDraft { diff --git a/src/languageservice/parser/schemaValidation/draft2020Validator.ts b/src/languageservice/parser/schemaValidation/draft2020Validator.ts index 36d02fa00..bd128c8b0 100644 --- a/src/languageservice/parser/schemaValidation/draft2020Validator.ts +++ b/src/languageservice/parser/schemaValidation/draft2020Validator.ts @@ -3,15 +3,17 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import type { JSONSchema, JSONSchemaRef } from '../../jsonSchema'; -import { SchemaDraft } from '../../jsonLanguageTypes'; +import type { ISchemaCollector, Options } from './baseValidator'; import type { ASTNode, ArrayASTNode } from '../../jsonLanguageTypes'; -import { isNumber } from '../../utils/objects'; +import type { JSONSchema, JSONSchemaRef } from '../../jsonSchema'; + import * as l10n from '@vscode/l10n'; import { DiagnosticSeverity } from 'vscode-languageserver-types'; -import { Draft2019Validator } from './draft2019Validator'; -import type { ISchemaCollector, Options } from './baseValidator'; + import { ValidationResult, asSchema } from './baseValidator'; +import { Draft2019Validator } from './draft2019Validator'; +import { SchemaDraft } from '../../jsonLanguageTypes'; +import { isNumber } from '../../utils/objects'; export class Draft2020Validator extends Draft2019Validator { protected override getCurrentSchemaDraft(): SchemaDraft { diff --git a/src/languageservice/parser/schemaValidation/validatorFactory.ts b/src/languageservice/parser/schemaValidation/validatorFactory.ts index e59c1ddc8..0e281d61c 100644 --- a/src/languageservice/parser/schemaValidation/validatorFactory.ts +++ b/src/languageservice/parser/schemaValidation/validatorFactory.ts @@ -3,12 +3,13 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { SchemaDraft } from '../../jsonLanguageTypes'; import type { BaseValidator } from './baseValidator'; + import { Draft04Validator } from './draft04Validator'; import { Draft07Validator } from './draft07Validator'; import { Draft2019Validator } from './draft2019Validator'; import { Draft2020Validator } from './draft2020Validator'; +import { SchemaDraft } from '../../jsonLanguageTypes'; export function getValidator(schemaDraft: SchemaDraft): BaseValidator { switch (schemaDraft) { diff --git a/src/languageservice/parser/yaml-documents.ts b/src/languageservice/parser/yaml-documents.ts index f93b3f499..33f0002e7 100644 --- a/src/languageservice/parser/yaml-documents.ts +++ b/src/languageservice/parser/yaml-documents.ts @@ -4,19 +4,22 @@ *--------------------------------------------------------------------------------------------*/ import type { TextDocument } from 'vscode-languageserver-textdocument'; -import { JSONDocument } from './jsonDocument'; import type { CST, Document, LineCounter, Node, YAMLError } from 'yaml'; -import { isNode, isPair, isScalar, visit } from 'yaml'; + import type { ASTNode, YamlNode } from '../jsonLanguageTypes'; import type { ParserOptions } from './yamlParser07'; +import type { YAMLDocDiagnostic } from '../utils/parseUtils'; +import type { TextBuffer } from '../utils/textBuffer'; + +import { isNode, isPair, isScalar, visit } from 'yaml'; + +import { JSONDocument } from './jsonDocument'; import { defaultOptions, parse as parseYAML } from './yamlParser07'; import { ErrorCode } from '../jsonLanguageTypes'; import { convertAST } from './ast-converter'; -import type { YAMLDocDiagnostic } from '../utils/parseUtils'; import { isArrayEqual } from '../utils/arrUtils'; -import { getParent } from '../utils/yamlAstUtils'; -import type { TextBuffer } from '../utils/textBuffer'; import { getIndentation } from '../utils/strings'; +import { getParent } from '../utils/yamlAstUtils'; /** * These documents are collected into a final YAMLDocument diff --git a/src/languageservice/parser/yamlParser07.ts b/src/languageservice/parser/yamlParser07.ts index b8307304c..b1c4bb80a 100644 --- a/src/languageservice/parser/yamlParser07.ts +++ b/src/languageservice/parser/yamlParser07.ts @@ -4,11 +4,13 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import type { Document, ParseOptions, DocumentOptions, SchemaOptions } from 'yaml'; -import { Parser, Composer, LineCounter } from 'yaml'; -import { YAMLDocument, SingleYAMLDocument } from './yaml-documents'; -import { getCustomTags } from './custom-tag-provider'; import type { TextDocument } from 'vscode-languageserver-textdocument'; +import type { Document, DocumentOptions, ParseOptions, SchemaOptions } from 'yaml'; + +import { Composer, LineCounter, Parser } from 'yaml'; + +import { getCustomTags } from './custom-tag-provider'; +import { SingleYAMLDocument, YAMLDocument } from './yaml-documents'; import { TextBuffer } from '../utils/textBuffer'; export { YAMLDocument, SingleYAMLDocument }; diff --git a/src/languageservice/services/documentSymbols.ts b/src/languageservice/services/documentSymbols.ts index 185d2009d..8bc04bbc5 100644 --- a/src/languageservice/services/documentSymbols.ts +++ b/src/languageservice/services/documentSymbols.ts @@ -4,14 +4,17 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { Location, Range, SymbolKind } from 'vscode-languageserver-types'; -import type { DocumentSymbol, SymbolInformation } from 'vscode-languageserver-types'; -import type { DocumentSymbolsContext, ASTNode, PropertyASTNode } from '../jsonLanguageTypes'; import type { TextDocument } from 'vscode-languageserver-textdocument'; -import { yamlDocumentsCache } from '../parser/yaml-documents'; +import type { DocumentSymbol, SymbolInformation } from 'vscode-languageserver-types'; + +import type { ASTNode, DocumentSymbolsContext, PropertyASTNode } from '../jsonLanguageTypes'; import type { Telemetry } from '../telemetry'; + +import { Location, Range, SymbolKind } from 'vscode-languageserver-types'; import { isMap, isSeq } from 'yaml'; +import { yamlDocumentsCache } from '../parser/yaml-documents'; + export class YAMLDocumentSymbols { constructor(private readonly telemetry?: Telemetry) {} diff --git a/src/languageservice/services/dollarUtils.ts b/src/languageservice/services/dollarUtils.ts index 8adff1469..d270a2caa 100644 --- a/src/languageservice/services/dollarUtils.ts +++ b/src/languageservice/services/dollarUtils.ts @@ -3,8 +3,8 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { SingleYAMLDocument } from '../parser/yamlParser07'; import { JSONDocument } from '../parser/jsonDocument'; +import { SingleYAMLDocument } from '../parser/yamlParser07'; /** * Retrieve schema if declared by `$schema`. diff --git a/src/languageservice/services/k8sSchemaUtil.ts b/src/languageservice/services/k8sSchemaUtil.ts index 11ef5e921..46a413b76 100644 --- a/src/languageservice/services/k8sSchemaUtil.ts +++ b/src/languageservice/services/k8sSchemaUtil.ts @@ -1,8 +1,8 @@ -import type { JSONDocument } from '../parser/jsonDocument'; -import { SingleYAMLDocument } from '../parser/yamlParser07'; - import type { ResolvedSchema } from './yamlSchemaService'; import type { JSONSchema } from '../jsonSchema'; +import type { JSONDocument } from '../parser/jsonDocument'; + +import { SingleYAMLDocument } from '../parser/yamlParser07'; /** * Attempt to retrieve the schema for a given YAML document based on the Kubernetes GroupVersionKind (GVK). diff --git a/src/languageservice/services/modelineUtil.ts b/src/languageservice/services/modelineUtil.ts index 97cf1e945..7785c7911 100644 --- a/src/languageservice/services/modelineUtil.ts +++ b/src/languageservice/services/modelineUtil.ts @@ -3,9 +3,10 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { SingleYAMLDocument } from '../parser/yamlParser07'; import type { JSONDocument } from '../parser/jsonDocument'; +import { SingleYAMLDocument } from '../parser/yamlParser07'; + /** * Retrieve schema if declared as modeline. * Public for testing purpose, not part of the API. diff --git a/src/languageservice/services/schemaRequestHandler.ts b/src/languageservice/services/schemaRequestHandler.ts index 2da2739b7..9e34a3387 100644 --- a/src/languageservice/services/schemaRequestHandler.ts +++ b/src/languageservice/services/schemaRequestHandler.ts @@ -1,12 +1,16 @@ +import type { Connection, WorkspaceFolder } from 'vscode-languageserver'; + +import type { WorkspaceContextService } from '../yamlLanguageService'; + import { join } from 'path'; -import { getErrorStatusDescription, xhr } from 'request-light'; import * as URL from 'url'; -import type { Connection, WorkspaceFolder } from 'vscode-languageserver'; + +import { getErrorStatusDescription, xhr } from 'request-light'; import { RequestType } from 'vscode-languageserver'; import { URI } from 'vscode-uri'; + import { CustomSchemaContentRequest, VSCodeContentRequest } from '../../requestTypes'; import { isRelativePath, relativeToAbsolutePath } from '../utils/paths'; -import type { WorkspaceContextService } from '../yamlLanguageService'; export interface FileSystem { readFile(fsPath: string, encoding?: string): Promise; diff --git a/src/languageservice/services/validation/map-key-order.ts b/src/languageservice/services/validation/map-key-order.ts index 71f80630a..3fc153bca 100644 --- a/src/languageservice/services/validation/map-key-order.ts +++ b/src/languageservice/services/validation/map-key-order.ts @@ -4,11 +4,13 @@ *--------------------------------------------------------------------------------------------*/ import type { TextDocument } from 'vscode-languageserver-textdocument'; -import { Diagnostic, DiagnosticSeverity, Range } from 'vscode-languageserver-types'; import type { CST, Node, Pair } from 'yaml'; -import { isMap, visit } from 'yaml'; -import type { SingleYAMLDocument } from '../../parser/yaml-documents'; + import type { AdditionalValidator } from './types'; +import type { SingleYAMLDocument } from '../../parser/yaml-documents'; + +import { Diagnostic, DiagnosticSeverity, Range } from 'vscode-languageserver-types'; +import { isMap, visit } from 'yaml'; export class MapKeyOrderValidator implements AdditionalValidator { validate(document: TextDocument, yamlDoc: SingleYAMLDocument): Diagnostic[] { diff --git a/src/languageservice/services/validation/types.ts b/src/languageservice/services/validation/types.ts index 9ad2d38ee..038308f7b 100644 --- a/src/languageservice/services/validation/types.ts +++ b/src/languageservice/services/validation/types.ts @@ -5,6 +5,7 @@ import type { TextDocument } from 'vscode-languageserver-textdocument'; import type { Diagnostic } from 'vscode-languageserver-types'; + import type { SingleYAMLDocument } from '../../parser/yaml-documents'; export interface AdditionalValidator { diff --git a/src/languageservice/services/validation/unused-anchors.ts b/src/languageservice/services/validation/unused-anchors.ts index da5a91046..068edc0a8 100644 --- a/src/languageservice/services/validation/unused-anchors.ts +++ b/src/languageservice/services/validation/unused-anchors.ts @@ -4,14 +4,17 @@ *--------------------------------------------------------------------------------------------*/ import type { TextDocument } from 'vscode-languageserver-textdocument'; -import { Diagnostic, DiagnosticSeverity, DiagnosticTag, Range } from 'vscode-languageserver-types'; -import type { Node, Scalar, YAMLMap, YAMLSeq, Pair } from 'yaml'; -import { isAlias, isCollection, isNode, isScalar, visit, CST } from 'yaml'; +import type { Node, Pair, Scalar, YAMLMap, YAMLSeq } from 'yaml'; + +import type { AdditionalValidator } from './types'; import type { YamlNode } from '../../jsonLanguageTypes'; import type { SingleYAMLDocument } from '../../parser/yaml-documents'; -import type { AdditionalValidator } from './types'; -import { isCollectionItem } from '../../utils/yamlAstUtils'; + import * as l10n from '@vscode/l10n'; +import { Diagnostic, DiagnosticSeverity, DiagnosticTag, Range } from 'vscode-languageserver-types'; +import { CST, isAlias, isCollection, isNode, isScalar, visit } from 'yaml'; + +import { isCollectionItem } from '../../utils/yamlAstUtils'; export class UnusedAnchorsValidator implements AdditionalValidator { validate(document: TextDocument, yamlDoc: SingleYAMLDocument): Diagnostic[] { diff --git a/src/languageservice/services/validation/yaml-style.ts b/src/languageservice/services/validation/yaml-style.ts index 255c72834..830134e39 100644 --- a/src/languageservice/services/validation/yaml-style.ts +++ b/src/languageservice/services/validation/yaml-style.ts @@ -1,11 +1,13 @@ import type { TextDocument } from 'vscode-languageserver-textdocument'; -import { Diagnostic, DiagnosticSeverity, Range } from 'vscode-languageserver-types'; import type { CST } from 'yaml'; -import { isMap, isSeq, visit } from 'yaml'; + +import type { AdditionalValidator } from './types'; import type { SingleYAMLDocument } from '../../parser/yaml-documents'; import type { LanguageSettings } from '../../yamlLanguageService'; -import type { AdditionalValidator } from './types'; + import * as l10n from '@vscode/l10n'; +import { Diagnostic, DiagnosticSeverity, Range } from 'vscode-languageserver-types'; +import { isMap, isSeq, visit } from 'yaml'; export class YAMLStyleValidator implements AdditionalValidator { private forbidSequence: boolean; diff --git a/src/languageservice/services/yamlCodeActions.ts b/src/languageservice/services/yamlCodeActions.ts index 036c706c3..6ae1b0730 100644 --- a/src/languageservice/services/yamlCodeActions.ts +++ b/src/languageservice/services/yamlCodeActions.ts @@ -3,30 +3,30 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as l10n from '@vscode/l10n'; -import * as path from 'path'; -import { ErrorCode } from '../jsonLanguageTypes'; -import type { Diagnostic, WorkspaceEdit } from 'vscode-languageserver-types'; -import { CodeAction, CodeActionKind, Command, Position, Range, TextEdit } from 'vscode-languageserver-types'; import type { ClientCapabilities, CodeActionParams } from 'vscode-languageserver-protocol'; import type { TextDocument } from 'vscode-languageserver-textdocument'; - +import type { Diagnostic, WorkspaceEdit } from 'vscode-languageserver-types'; import type { Scalar, YAMLMap } from 'yaml'; -import { CST, isMap, isSeq, isScalar, visit } from 'yaml'; -import { YamlCommands } from '../../commands'; -import { TextBuffer } from '../utils/textBuffer'; -import { toYamlStringScalar } from '../utils/yamlScalar'; +import type { ASTNode } from '../jsonLanguageTypes'; import type { LanguageSettings } from '../yamlLanguageService'; + +import * as path from 'path'; + +import * as l10n from '@vscode/l10n'; +import { CodeAction, CodeActionKind, Command, Position, Range, TextEdit } from 'vscode-languageserver-types'; +import { CST, isMap, isScalar, isSeq, visit } from 'yaml'; + +import { YamlCommands } from '../../commands'; +import { ErrorCode } from '../jsonLanguageTypes'; import { YAML_SOURCE } from '../parser/schemaValidation/baseValidator'; -import { getFirstNonWhitespaceCharacterAfterOffset } from '../utils/strings'; -import { matchOffsetToDocument } from '../utils/arrUtils'; import { yamlDocumentsCache } from '../parser/yaml-documents'; - +import { matchOffsetToDocument } from '../utils/arrUtils'; import { BlockStringRewriter } from '../utils/block-string-rewriter'; import { FlowStyleRewriter } from '../utils/flow-style-rewriter'; - -import type { ASTNode } from '../jsonLanguageTypes'; +import { getFirstNonWhitespaceCharacterAfterOffset } from '../utils/strings'; +import { TextBuffer } from '../utils/textBuffer'; +import { toYamlStringScalar } from '../utils/yamlScalar'; interface YamlDiagnosticData { schemaUri: string[]; diff --git a/src/languageservice/services/yamlCodeLens.ts b/src/languageservice/services/yamlCodeLens.ts index 8dcf12c5f..603a1805b 100644 --- a/src/languageservice/services/yamlCodeLens.ts +++ b/src/languageservice/services/yamlCodeLens.ts @@ -4,12 +4,15 @@ *--------------------------------------------------------------------------------------------*/ import type { TextDocument } from 'vscode-languageserver-textdocument'; -import { CodeLens, Range } from 'vscode-languageserver-types'; -import { YamlCommands } from '../../commands'; -import { yamlDocumentsCache } from '../parser/yaml-documents'; + import type { YAMLSchemaService } from './yamlSchemaService'; import type { JSONSchema } from '../jsonSchema'; import type { Telemetry } from '../telemetry'; + +import { CodeLens, Range } from 'vscode-languageserver-types'; + +import { YamlCommands } from '../../commands'; +import { yamlDocumentsCache } from '../parser/yaml-documents'; import { getSchemaUrls } from '../utils/schemaUrls'; import { getSchemaTitle } from '../utils/schemaUtils'; diff --git a/src/languageservice/services/yamlCommands.ts b/src/languageservice/services/yamlCommands.ts index efdee7682..e6383f31d 100644 --- a/src/languageservice/services/yamlCommands.ts +++ b/src/languageservice/services/yamlCommands.ts @@ -4,10 +4,13 @@ *--------------------------------------------------------------------------------------------*/ import type { Connection } from 'vscode-languageserver'; -import { YamlCommands } from '../../commands'; + import type { CommandExecutor } from '../../languageserver/commandExecutor'; + import { URI } from 'vscode-uri'; +import { YamlCommands } from '../../commands'; + export function registerCommands(commandExecutor: CommandExecutor, connection: Connection): void { commandExecutor.registerCommand(YamlCommands.JUMP_TO_SCHEMA, async (uri: string) => { if (!uri) { diff --git a/src/languageservice/services/yamlCompletion.ts b/src/languageservice/services/yamlCompletion.ts index b258cbe2d..5c943f283 100644 --- a/src/languageservice/services/yamlCompletion.ts +++ b/src/languageservice/services/yamlCompletion.ts @@ -3,9 +3,22 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import type { TextDocument } from 'vscode-languageserver-textdocument'; import type { ClientCapabilities } from 'vscode-languageserver'; +import type { TextDocument } from 'vscode-languageserver-textdocument'; import type { MarkupContent } from 'vscode-languageserver-types'; +import type { Node, Pair, YAMLMap, YAMLSeq } from 'yaml'; + +import type { JSONSchema, JSONSchemaRef } from '../jsonSchema'; +import type { ResolvedSchema, YAMLSchemaService } from './yamlSchemaService'; +import type { SettingsState } from '../../yamlSettings'; +import type { YamlNode } from '../jsonLanguageTypes'; +import type { SingleYAMLDocument, YamlDocuments } from '../parser/yaml-documents'; +import type { YamlVersion } from '../parser/yamlParser07'; +import type { Telemetry } from '../telemetry'; +import type { StringifySettings } from '../utils/json'; +import type { LanguageSettings } from '../yamlLanguageService'; + +import * as l10n from '@vscode/l10n'; import { CompletionItem as CompletionItemBase, CompletionItemKind, @@ -17,30 +30,20 @@ import { Range, TextEdit, } from 'vscode-languageserver-types'; -import type { Node, YAMLMap, YAMLSeq, Pair } from 'yaml'; -import { isPair, isScalar, isMap, isSeq, isNode } from 'yaml'; -import { parseCustomTag } from '../utils/customTags'; -import type { Telemetry } from '../telemetry'; -import type { SingleYAMLDocument, YamlDocuments } from '../parser/yaml-documents'; -import type { YamlVersion } from '../parser/yamlParser07'; +import { isMap, isNode, isPair, isScalar, isSeq } from 'yaml'; + +import { isModeline } from './modelineUtil'; +import { setKubernetesParserOption } from '../parser/isKubernetes'; +import { asSchema } from '../parser/schemaValidation/baseValidator'; import { matchOffsetToDocument } from '../utils/arrUtils'; +import { parseCustomTag } from '../utils/customTags'; import { guessIndentation } from '../utils/indentationGuesser'; -import { TextBuffer } from '../utils/textBuffer'; -import type { LanguageSettings } from '../yamlLanguageService'; -import type { ResolvedSchema, YAMLSchemaService } from './yamlSchemaService'; -import type { JSONSchema, JSONSchemaRef } from '../jsonSchema'; -import type { StringifySettings } from '../utils/json'; import { stringifyObject } from '../utils/json'; import { isDefined, isString } from '../utils/objects'; -import { setKubernetesParserOption } from '../parser/isKubernetes'; -import { asSchema } from '../parser/schemaValidation/baseValidator'; -import { indexOf, isInComment, isMapContainsEmptyPair } from '../utils/yamlAstUtils'; -import { isModeline } from './modelineUtil'; import { getSchemaTypeName, isAnyOfAllOfOneOfType, isPrimitiveType } from '../utils/schemaUtils'; -import type { YamlNode } from '../jsonLanguageTypes'; -import type { SettingsState } from '../../yamlSettings'; +import { TextBuffer } from '../utils/textBuffer'; +import { indexOf, isInComment, isMapContainsEmptyPair } from '../utils/yamlAstUtils'; import { toYamlStringScalar } from '../utils/yamlScalar'; -import * as l10n from '@vscode/l10n'; const parentCompletionKind = CompletionItemKind.Class; diff --git a/src/languageservice/services/yamlDefinition.ts b/src/languageservice/services/yamlDefinition.ts index d7d3bc49f..64ac4fd25 100644 --- a/src/languageservice/services/yamlDefinition.ts +++ b/src/languageservice/services/yamlDefinition.ts @@ -6,9 +6,12 @@ import type { DefinitionParams } from 'vscode-languageserver-protocol'; import type { TextDocument } from 'vscode-languageserver-textdocument'; import type { DefinitionLink } from 'vscode-languageserver-types'; + +import type { Telemetry } from '../telemetry'; + import { LocationLink, Range } from 'vscode-languageserver-types'; import { isAlias } from 'yaml'; -import type { Telemetry } from '../telemetry'; + import { yamlDocumentsCache } from '../parser/yaml-documents'; import { matchOffsetToDocument } from '../utils/arrUtils'; import { TextBuffer } from '../utils/textBuffer'; diff --git a/src/languageservice/services/yamlFolding.ts b/src/languageservice/services/yamlFolding.ts index d9c19c718..d77926c95 100644 --- a/src/languageservice/services/yamlFolding.ts +++ b/src/languageservice/services/yamlFolding.ts @@ -2,11 +2,14 @@ * Copyright (c) Red Hat, Inc. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { FoldingRange, Range } from 'vscode-languageserver-types'; -import type { FoldingRangesContext } from '../yamlTypes'; +import type { TextDocument } from 'vscode-languageserver-textdocument'; + import type { ASTNode } from '../jsonLanguageTypes'; +import type { FoldingRangesContext } from '../yamlTypes'; + +import { FoldingRange, Range } from 'vscode-languageserver-types'; + import { yamlDocumentsCache } from '../parser/yaml-documents'; -import type { TextDocument } from 'vscode-languageserver-textdocument'; export function getFoldingRanges(document: TextDocument, context: FoldingRangesContext): FoldingRange[] | undefined { if (!document) { diff --git a/src/languageservice/services/yamlFormatter.ts b/src/languageservice/services/yamlFormatter.ts index f980d98f4..b8771064c 100644 --- a/src/languageservice/services/yamlFormatter.ts +++ b/src/languageservice/services/yamlFormatter.ts @@ -4,14 +4,16 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import type { Options } from 'prettier'; +import type { TextDocument } from 'vscode-languageserver-textdocument'; import type { FormattingOptions } from 'vscode-languageserver-types'; -import { Range, Position, TextEdit } from 'vscode-languageserver-types'; + import type { CustomFormatterOptions, LanguageSettings } from '../yamlLanguageService'; -import type { Options } from 'prettier'; -import * as yamlPlugin from 'prettier/plugins/yaml'; + import * as estreePlugin from 'prettier/plugins/estree'; +import * as yamlPlugin from 'prettier/plugins/yaml'; import { format } from 'prettier/standalone'; -import type { TextDocument } from 'vscode-languageserver-textdocument'; +import { Position, Range, TextEdit } from 'vscode-languageserver-types'; export class YAMLFormatter { private formatterEnabled = true; diff --git a/src/languageservice/services/yamlHover.ts b/src/languageservice/services/yamlHover.ts index bf74361e4..a0b0f7e71 100644 --- a/src/languageservice/services/yamlHover.ts +++ b/src/languageservice/services/yamlHover.ts @@ -4,27 +4,31 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as l10n from '@vscode/l10n'; -import * as path from 'path'; import type { TextDocument } from 'vscode-languageserver-textdocument'; import type { Hover, MarkupContent, Position } from 'vscode-languageserver-types'; -import { MarkupKind, Range } from 'vscode-languageserver-types'; -import { URI } from 'vscode-uri'; import type { Node } from 'yaml'; -import { isAlias, isMap, isSeq, stringify as stringifyYAML } from 'yaml'; + import type { ASTNode, ObjectASTNode, PropertyASTNode } from '../jsonLanguageTypes'; import type { JSONSchema } from '../jsonSchema'; -import { setKubernetesParserOption } from '../parser/isKubernetes'; -import { getNodeValue } from '../utils/astNodeUtils'; import type { IApplicableSchema } from '../parser/schemaValidation/baseValidator'; -import { yamlDocumentsCache } from '../parser/yaml-documents'; import type { SingleYAMLDocument } from '../parser/yamlParser07'; import type { Telemetry } from '../telemetry'; -import { matchOffsetToDocument } from '../utils/arrUtils'; -import { toYamlStringScalar } from '../utils/yamlScalar'; import type { LanguageSettings } from '../yamlLanguageService'; import type { YAMLSchemaService } from './yamlSchemaService'; +import * as path from 'path'; + +import * as l10n from '@vscode/l10n'; +import { MarkupKind, Range } from 'vscode-languageserver-types'; +import { URI } from 'vscode-uri'; +import { isAlias, isMap, isSeq, stringify as stringifyYAML } from 'yaml'; + +import { setKubernetesParserOption } from '../parser/isKubernetes'; +import { yamlDocumentsCache } from '../parser/yaml-documents'; +import { matchOffsetToDocument } from '../utils/arrUtils'; +import { getNodeValue } from '../utils/astNodeUtils'; +import { toYamlStringScalar } from '../utils/yamlScalar'; + export class YAMLHover { private shouldHover: boolean; private shouldHoverAnchor: boolean; diff --git a/src/languageservice/services/yamlLinks.ts b/src/languageservice/services/yamlLinks.ts index f92fc0028..4cbfcb4cd 100644 --- a/src/languageservice/services/yamlLinks.ts +++ b/src/languageservice/services/yamlLinks.ts @@ -3,13 +3,16 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import type { DocumentLink } from 'vscode-languageserver-types'; -import { Range } from 'vscode-languageserver-types'; import type { TextDocument } from 'vscode-languageserver-textdocument'; -import type { Telemetry } from '../telemetry'; -import { yamlDocumentsCache } from '../parser/yaml-documents'; +import type { DocumentLink } from 'vscode-languageserver-types'; + import type { ASTNode, PropertyASTNode } from '../jsonLanguageTypes'; import type { JSONDocument } from '../parser/jsonDocument'; +import type { Telemetry } from '../telemetry'; + +import { Range } from 'vscode-languageserver-types'; + +import { yamlDocumentsCache } from '../parser/yaml-documents'; export class YamlLinks { constructor(private readonly telemetry?: Telemetry) {} diff --git a/src/languageservice/services/yamlOnTypeFormatting.ts b/src/languageservice/services/yamlOnTypeFormatting.ts index 27f80dcda..09f2e1b27 100644 --- a/src/languageservice/services/yamlOnTypeFormatting.ts +++ b/src/languageservice/services/yamlOnTypeFormatting.ts @@ -5,7 +5,9 @@ import type { DocumentOnTypeFormattingParams } from 'vscode-languageserver'; import type { TextDocument } from 'vscode-languageserver-textdocument'; + import { Position, Range, TextEdit } from 'vscode-languageserver-types'; + import { TextBuffer } from '../utils/textBuffer'; export function doDocumentOnTypeFormatting( diff --git a/src/languageservice/services/yamlRename.ts b/src/languageservice/services/yamlRename.ts index df633208b..047d0e281 100644 --- a/src/languageservice/services/yamlRename.ts +++ b/src/languageservice/services/yamlRename.ts @@ -3,19 +3,22 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import type { PrepareRenameParams, RenameParams } from 'vscode-languageserver-protocol'; import type { TextDocument } from 'vscode-languageserver-textdocument'; import type { Position, WorkspaceEdit } from 'vscode-languageserver-types'; +import type { Node } from 'yaml'; + +import type { SingleYAMLDocument } from '../parser/yamlParser07'; +import type { Telemetry } from '../telemetry'; + +import { ErrorCodes, ResponseError } from 'vscode-languageserver-protocol'; import { Range, TextEdit } from 'vscode-languageserver-types'; +import { CST, isAlias, isCollection, isScalar, visit } from 'yaml'; + import { yamlDocumentsCache } from '../parser/yaml-documents'; import { matchOffsetToDocument } from '../utils/arrUtils'; import { TextBuffer } from '../utils/textBuffer'; -import type { Telemetry } from '../telemetry'; -import type { Node } from 'yaml'; -import { CST, isAlias, isCollection, isScalar, visit } from 'yaml'; -import type { SingleYAMLDocument } from '../parser/yamlParser07'; import { isCollectionItem } from '../utils/yamlAstUtils'; -import type { PrepareRenameParams, RenameParams } from 'vscode-languageserver-protocol'; -import { ResponseError, ErrorCodes } from 'vscode-languageserver-protocol'; interface RenameTarget { anchorNode: Node; diff --git a/src/languageservice/services/yamlSchemaService.ts b/src/languageservice/services/yamlSchemaService.ts index 618cf5d6a..7aa79f84c 100644 --- a/src/languageservice/services/yamlSchemaService.ts +++ b/src/languageservice/services/yamlSchemaService.ts @@ -18,6 +18,7 @@ import type { SchemaRequestService, WorkspaceContextService } from '../yamlLangu import type { SchemaVersions } from '../yamlTypes'; import * as path from 'path'; + import * as l10n from '@vscode/l10n'; import Ajv from 'ajv'; import Ajv2019 from 'ajv/dist/2019'; diff --git a/src/languageservice/services/yamlSelectionRanges.ts b/src/languageservice/services/yamlSelectionRanges.ts index 2b6c2c14d..6c4442ab8 100644 --- a/src/languageservice/services/yamlSelectionRanges.ts +++ b/src/languageservice/services/yamlSelectionRanges.ts @@ -1,8 +1,11 @@ +import type { TextDocument } from 'vscode-languageserver-textdocument'; import type { Position, Range } from 'vscode-languageserver-types'; + +import type { ASTNode } from '../jsonLanguageTypes'; + import { SelectionRange } from 'vscode-languageserver-types'; + import { yamlDocumentsCache } from '../parser/yaml-documents'; -import type { TextDocument } from 'vscode-languageserver-textdocument'; -import type { ASTNode } from '../jsonLanguageTypes'; export function getSelectionRanges(document: TextDocument, positions: Position[]): SelectionRange[] { const doc = yamlDocumentsCache.getYamlDocument(document); diff --git a/src/languageservice/services/yamlValidation.ts b/src/languageservice/services/yamlValidation.ts index 7592f96d5..2371ace55 100644 --- a/src/languageservice/services/yamlValidation.ts +++ b/src/languageservice/services/yamlValidation.ts @@ -4,25 +4,28 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { Diagnostic, DiagnosticSeverity, Position, Range } from 'vscode-languageserver-types'; +import type { TextDocument } from 'vscode-languageserver-textdocument'; import type { DiagnosticRelatedInformation } from 'vscode-languageserver-types'; + +import type { ErrorCode } from '../jsonLanguageTypes'; +import type { SingleYAMLDocument, YamlVersion } from '../parser/yamlParser07'; +import type { Telemetry } from '../telemetry'; import type { LanguageSettings } from '../yamlLanguageService'; -import type { YamlVersion, SingleYAMLDocument } from '../parser/yamlParser07'; +import type { AdditionalValidator } from './validation/types'; import type { YAMLSchemaService } from './yamlSchemaService'; import type { YAMLDocDiagnostic } from '../utils/parseUtils'; -import type { TextDocument } from 'vscode-languageserver-textdocument'; + +import { Diagnostic, DiagnosticSeverity, Position, Range } from 'vscode-languageserver-types'; + +import { getSchemaFromModeline } from './modelineUtil'; import { YAML_SOURCE } from '../parser/schemaValidation/baseValidator'; -import { TextBuffer } from '../utils/textBuffer'; -import { filterSuppressedDiagnostics } from '../utils/diagnostic-filter'; import { yamlDocumentsCache } from '../parser/yaml-documents'; -import type { Telemetry } from '../telemetry'; -import type { AdditionalValidator } from './validation/types'; +import { filterSuppressedDiagnostics } from '../utils/diagnostic-filter'; +import { TextBuffer } from '../utils/textBuffer'; +import { MapKeyOrderValidator } from './validation/map-key-order'; import { UnusedAnchorsValidator } from './validation/unused-anchors'; import { YAMLStyleValidator } from './validation/yaml-style'; -import { MapKeyOrderValidator } from './validation/map-key-order'; -import { getSchemaFromModeline } from './modelineUtil'; import { isKubernetes as isKubernetesSchemaURI } from '../utils/schemaUrls'; -import type { ErrorCode } from '../jsonLanguageTypes'; /** * Convert a YAMLDocDiagnostic to a language server Diagnostic diff --git a/src/languageservice/utils/arrUtils.ts b/src/languageservice/utils/arrUtils.ts index 6180eaade..9fe7719ed 100644 --- a/src/languageservice/utils/arrUtils.ts +++ b/src/languageservice/utils/arrUtils.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import type { YAMLDocument, SingleYAMLDocument } from '../parser/yamlParser07'; +import type { SingleYAMLDocument, YAMLDocument } from '../parser/yamlParser07'; export function getLineOffsets(textDocString: string): number[] { const lineOffsets: number[] = []; diff --git a/src/languageservice/utils/block-string-rewriter.ts b/src/languageservice/utils/block-string-rewriter.ts index 4b999d5b5..88ee3d6ed 100644 --- a/src/languageservice/utils/block-string-rewriter.ts +++ b/src/languageservice/utils/block-string-rewriter.ts @@ -3,6 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import type { Scalar } from 'yaml'; + import { CST } from 'yaml'; export class BlockStringRewriter { diff --git a/src/languageservice/utils/flow-style-rewriter.ts b/src/languageservice/utils/flow-style-rewriter.ts index db872ce2b..e84c0a871 100644 --- a/src/languageservice/utils/flow-style-rewriter.ts +++ b/src/languageservice/utils/flow-style-rewriter.ts @@ -1,6 +1,7 @@ -import { CST, visit } from 'yaml'; import type { ASTNode } from '../jsonLanguageTypes'; +import { CST, visit } from 'yaml'; + export class FlowStyleRewriter { constructor(private readonly indentation: string) {} diff --git a/src/languageservice/utils/indentationGuesser.ts b/src/languageservice/utils/indentationGuesser.ts index 3cca1955f..714eb2c2e 100644 --- a/src/languageservice/utils/indentationGuesser.ts +++ b/src/languageservice/utils/indentationGuesser.ts @@ -5,9 +5,10 @@ //copied from https://github.com/Microsoft/vscode/blob/015c3afe96966df50c15a7d66be2ab0ef1dc5f49/src/vs/editor/common/model/indentationGuesser.ts -import { CharCode } from './charCode'; import type { TextBuffer } from './textBuffer'; +import { CharCode } from './charCode'; + class SpacesDiffResult { public spacesDiff = 0; public looksLikeAlignment = false; diff --git a/src/languageservice/utils/parseUtils.ts b/src/languageservice/utils/parseUtils.ts index a4b0fb7c3..57b94a0f9 100644 --- a/src/languageservice/utils/parseUtils.ts +++ b/src/languageservice/utils/parseUtils.ts @@ -1,4 +1,5 @@ import type { ErrorCode } from '../jsonLanguageTypes'; + export const DUPLICATE_KEY_REASON = 'duplicate key'; /** diff --git a/src/languageservice/utils/paths.ts b/src/languageservice/utils/paths.ts index d9945954c..39e4c650a 100644 --- a/src/languageservice/utils/paths.ts +++ b/src/languageservice/utils/paths.ts @@ -1,5 +1,7 @@ import type { WorkspaceFolder, WorkspaceFoldersChangeEvent } from 'vscode-languageserver-protocol'; + import { join, normalize, sep } from 'path'; + import { URI } from 'vscode-uri'; export const isRelativePath = (path: string): boolean => { diff --git a/src/languageservice/utils/schemaUrls.ts b/src/languageservice/utils/schemaUrls.ts index bc7fa836b..fd775d07f 100644 --- a/src/languageservice/utils/schemaUrls.ts +++ b/src/languageservice/utils/schemaUrls.ts @@ -1,8 +1,12 @@ import type { WorkspaceFolder } from 'vscode-languageserver-protocol'; -import { URI } from 'vscode-uri'; -import * as path from 'path'; -import type { Telemetry } from '../telemetry'; + import type { JSONSchema, JSONSchemaRef } from '../jsonSchema'; +import type { Telemetry } from '../telemetry'; + +import * as path from 'path'; + +import { URI } from 'vscode-uri'; + import { isBoolean } from './objects'; import { isRelativePath, relativeToAbsolutePath } from './paths'; diff --git a/src/languageservice/utils/schemaUtils.ts b/src/languageservice/utils/schemaUtils.ts index c1a4c6306..7cd79653b 100644 --- a/src/languageservice/utils/schemaUtils.ts +++ b/src/languageservice/utils/schemaUtils.ts @@ -1,7 +1,9 @@ -import { URI } from 'vscode-uri'; import type { JSONSchema } from '../jsonSchema'; + import * as path from 'path'; +import { URI } from 'vscode-uri'; + export function getSchemaTypeName(schema: JSONSchema): string { const closestTitleWithType = schema.type && schema.closestTitle; if (schema.title) { diff --git a/src/languageservice/utils/textBuffer.ts b/src/languageservice/utils/textBuffer.ts index f7f363a2e..17b968e29 100644 --- a/src/languageservice/utils/textBuffer.ts +++ b/src/languageservice/utils/textBuffer.ts @@ -5,6 +5,7 @@ import type { TextDocument } from 'vscode-languageserver-textdocument'; import type { Position } from 'vscode-languageserver-types'; + import { Range } from 'vscode-languageserver-types'; interface FullTextDocument { diff --git a/src/languageservice/utils/yamlAstUtils.ts b/src/languageservice/utils/yamlAstUtils.ts index 6bd6c5418..f951ab9af 100644 --- a/src/languageservice/utils/yamlAstUtils.ts +++ b/src/languageservice/utils/yamlAstUtils.ts @@ -4,9 +4,11 @@ *--------------------------------------------------------------------------------------------*/ import type { CST, Document, Node, YAMLMap, YAMLSeq } from 'yaml'; -import { isDocument, isScalar, visit } from 'yaml'; + import type { YamlNode } from '../jsonLanguageTypes'; +import { isDocument, isScalar, visit } from 'yaml'; + type Visitor = (item: CST.SourceToken, path: CST.VisitPath) => number | symbol | Visitor | void; export function getParent(doc: Document, nodeToFind: YamlNode): YamlNode | undefined { diff --git a/src/languageservice/yamlLanguageService.ts b/src/languageservice/yamlLanguageService.ts index 56bfab7af..ce0bd9e65 100644 --- a/src/languageservice/yamlLanguageService.ts +++ b/src/languageservice/yamlLanguageService.ts @@ -4,56 +4,58 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import type { CustomSchemaProvider, SchemaAdditions, SchemaDeletions, SchemaDeletionsAll } from './services/yamlSchemaService'; -import { YAMLSchemaService } from './services/yamlSchemaService'; import type { - Position, + ClientCapabilities, + CodeActionParams, + Connection, + DefinitionParams, + DocumentOnTypeFormattingParams, + PrepareRenameParams, + RenameParams, +} from 'vscode-languageserver'; +import type { TextDocument } from 'vscode-languageserver-textdocument'; +import type { CodeAction, + CodeLens, CompletionList, + DefinitionLink, Diagnostic, - Hover, - SymbolInformation, + DocumentLink, DocumentSymbol, FoldingRange, - TextEdit, - DocumentLink, - CodeLens, - DefinitionLink, - SelectionRange, + Hover, + Position, Range, + SelectionRange, + SymbolInformation, + TextEdit, WorkspaceEdit, } from 'vscode-languageserver-types'; -import type { JSONSchema } from './jsonSchema'; -import { YAMLDocumentSymbols } from './services/documentSymbols'; -import { YAMLHover } from './services/yamlHover'; -import { YAMLValidation } from './services/yamlValidation'; -import { YAMLFormatter } from './services/yamlFormatter'; + import type { DocumentSymbolsContext } from './jsonLanguageTypes'; -import { YamlLinks } from './services/yamlLinks'; -import type { - ClientCapabilities, - CodeActionParams, - Connection, - DocumentOnTypeFormattingParams, - DefinitionParams, - PrepareRenameParams, - RenameParams, -} from 'vscode-languageserver'; -import type { TextDocument } from 'vscode-languageserver-textdocument'; -import { getFoldingRanges } from './services/yamlFolding'; +import type { JSONSchema } from './jsonSchema'; +import type { Telemetry } from './telemetry'; +import type { SettingsState } from '../yamlSettings'; +import type { YamlVersion } from './parser/yamlParser07'; +import type { CustomSchemaProvider, SchemaAdditions, SchemaDeletions, SchemaDeletionsAll } from './services/yamlSchemaService'; import type { FoldingRangesContext, SchemaVersions } from './yamlTypes'; + +import { yamlDocumentsCache } from './parser/yaml-documents'; +import { YAMLDocumentSymbols } from './services/documentSymbols'; import { YamlCodeActions } from './services/yamlCodeActions'; -import { doDocumentOnTypeFormatting } from './services/yamlOnTypeFormatting'; import { YamlCodeLens } from './services/yamlCodeLens'; -import type { Telemetry } from './telemetry'; -import type { YamlVersion } from './parser/yamlParser07'; import { YamlCompletion } from './services/yamlCompletion'; -import { yamlDocumentsCache } from './parser/yaml-documents'; -import type { SettingsState } from '../yamlSettings'; -import { JSONSchemaSelection } from '../languageserver/handlers/schemaSelectionHandlers'; import { YamlDefinition } from './services/yamlDefinition'; -import { getSelectionRanges } from './services/yamlSelectionRanges'; +import { getFoldingRanges } from './services/yamlFolding'; +import { YAMLFormatter } from './services/yamlFormatter'; +import { YAMLHover } from './services/yamlHover'; +import { YamlLinks } from './services/yamlLinks'; +import { doDocumentOnTypeFormatting } from './services/yamlOnTypeFormatting'; import { YamlRename } from './services/yamlRename'; +import { YAMLSchemaService } from './services/yamlSchemaService'; +import { getSelectionRanges } from './services/yamlSelectionRanges'; +import { YAMLValidation } from './services/yamlValidation'; +import { JSONSchemaSelection } from '../languageserver/handlers/schemaSelectionHandlers'; export enum SchemaPriority { SchemaStore = 1, diff --git a/src/nodeTranslationSetup.ts b/src/nodeTranslationSetup.ts index 25d5ef773..47921bc1e 100644 --- a/src/nodeTranslationSetup.ts +++ b/src/nodeTranslationSetup.ts @@ -2,11 +2,13 @@ * Copyright (c) IBM Corp. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as path from 'path'; +import type { InitializeParams } from 'vscode-languageserver'; + import { existsSync } from 'fs'; -import { URI } from 'vscode-uri'; +import * as path from 'path'; + import * as l10n from '@vscode/l10n'; -import type { InitializeParams } from 'vscode-languageserver'; +import { URI } from 'vscode-uri'; /** * Loads translations from the filesystem based on the configured locale and the folder of translations provided in the initialization parameters. diff --git a/src/requestTypes.ts b/src/requestTypes.ts index 4e4087ad2..8d364fe1c 100644 --- a/src/requestTypes.ts +++ b/src/requestTypes.ts @@ -1,9 +1,10 @@ /* eslint-disable @typescript-eslint/no-namespace */ -import { NotificationType, RequestType } from 'vscode-languageserver'; import type { SchemaAdditions, SchemaDeletions } from './languageservice/services/yamlSchemaService'; import type { SchemaConfiguration } from './languageservice/yamlLanguageService'; import type { SchemaVersions } from './languageservice/yamlTypes'; +import { NotificationType, RequestType } from 'vscode-languageserver'; + export type ISchemaAssociations = Record; export interface JSONSchemaDescription { diff --git a/src/server.ts b/src/server.ts index 86cb855ba..f93e48f3c 100644 --- a/src/server.ts +++ b/src/server.ts @@ -5,9 +5,12 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { promises as fs } from 'fs'; import type { Connection } from 'vscode-languageserver/node'; -import { createConnection, ProposedFeatures } from 'vscode-languageserver/node'; + +import { promises as fs } from 'fs'; + +import { ProposedFeatures, createConnection } from 'vscode-languageserver/node'; + import { TelemetryImpl } from './languageserver/telemetry'; import { schemaRequestHandler, workspaceContext } from './languageservice/services/schemaRequestHandler'; import { convertErrorToTelemetryMsg } from './languageservice/utils/objects'; diff --git a/src/webworker/yamlServerMain.ts b/src/webworker/yamlServerMain.ts index 0e2c5ae40..9d4b38074 100644 --- a/src/webworker/yamlServerMain.ts +++ b/src/webworker/yamlServerMain.ts @@ -3,10 +3,12 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as l10n from '@vscode/l10n'; import type { Connection } from 'vscode-languageserver'; + +import * as l10n from '@vscode/l10n'; import { RequestType } from 'vscode-languageserver'; import { BrowserMessageReader, BrowserMessageWriter, createConnection } from 'vscode-languageserver/browser'; + import { TelemetryImpl } from '../languageserver/telemetry'; import { schemaRequestHandler, workspaceContext } from '../languageservice/services/schemaRequestHandler'; import { YAMLServerInit } from '../yamlServerInit'; diff --git a/src/yamlServerInit.ts b/src/yamlServerInit.ts index e4edc9181..95bfde5bc 100644 --- a/src/yamlServerInit.ts +++ b/src/yamlServerInit.ts @@ -1,6 +1,12 @@ import type { Connection, InitializeParams, InitializeResult } from 'vscode-languageserver'; + +import type { Telemetry } from './languageservice/telemetry'; +import type { LanguageService, SchemaRequestService, WorkspaceContextService } from './languageservice/yamlLanguageService'; +import type { SettingsState } from './yamlSettings'; + import { TextDocumentSyncKind } from 'vscode-languageserver'; import { URI } from 'vscode-uri'; + import { YamlCommands } from './commands'; import { commandExecutor } from './languageserver/commandExecutor'; import { LanguageHandlers } from './languageserver/handlers/languageHandlers'; @@ -10,11 +16,8 @@ import { SettingsHandler } from './languageserver/handlers/settingsHandlers'; import { ValidationHandler } from './languageserver/handlers/validationHandlers'; import { WorkspaceHandlers } from './languageserver/handlers/workspaceHandlers'; import { registerCommands } from './languageservice/services/yamlCommands'; -import type { Telemetry } from './languageservice/telemetry'; import { workspaceFoldersChanged } from './languageservice/utils/paths'; -import type { LanguageService, SchemaRequestService, WorkspaceContextService } from './languageservice/yamlLanguageService'; import { getLanguageService as getCustomLanguageService } from './languageservice/yamlLanguageService'; -import type { SettingsState } from './yamlSettings'; export class YAMLServerInit { languageService: LanguageService; diff --git a/src/yamlSettings.ts b/src/yamlSettings.ts index 912878a0e..847f5e4b2 100644 --- a/src/yamlSettings.ts +++ b/src/yamlSettings.ts @@ -1,12 +1,15 @@ -import type { Disposable, ClientCapabilities, WorkspaceFolder } from 'vscode-languageserver'; -import { TextDocuments } from 'vscode-languageserver'; -import type { CustomFormatterOptions, SchemaConfiguration } from './languageservice/yamlLanguageService'; -import type { ISchemaAssociations } from './requestTypes'; +import type { ClientCapabilities, Disposable, WorkspaceFolder } from 'vscode-languageserver'; import type { URI } from 'vscode-uri'; + import type { JSONSchema } from './languageservice/jsonSchema'; +import type { YamlVersion } from './languageservice/parser/yamlParser07'; +import type { CustomFormatterOptions, SchemaConfiguration } from './languageservice/yamlLanguageService'; +import type { ISchemaAssociations } from './requestTypes'; + +import { TextDocuments } from 'vscode-languageserver'; import { TextDocument } from 'vscode-languageserver-textdocument'; + import { CRD_CATALOG_URL, JSON_SCHEMASTORE_URL } from './languageservice/utils/schemaUrls'; -import type { YamlVersion } from './languageservice/parser/yamlParser07'; // Client settings interface to grab settings relevant for the language server export interface Settings { diff --git a/test/arrUtils.test.ts b/test/arrUtils.test.ts index 9f926f966..e8fc85370 100644 --- a/test/arrUtils.test.ts +++ b/test/arrUtils.test.ts @@ -2,9 +2,10 @@ * Copyright (c) Red Hat. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { getLineOffsets, removeDuplicatesObj } from '../src/languageservice/utils/arrUtils'; import assert from 'assert'; +import { getLineOffsets, removeDuplicatesObj } from '../src/languageservice/utils/arrUtils'; + describe('Array Utils Tests', () => { describe('Server - Array Utils', function () { describe('getLineOffsets', function () { diff --git a/test/astUtils.test.ts b/test/astUtils.test.ts index 28859ed7d..2ea27efad 100644 --- a/test/astUtils.test.ts +++ b/test/astUtils.test.ts @@ -3,13 +3,16 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as chai from 'chai'; import type { Pair, YAMLSeq } from 'yaml'; + +import * as chai from 'chai'; import { isPair, isSeq } from 'yaml'; + +import { setupTextDocument } from './utils/testHelper'; import { YamlDocuments } from '../src/languageservice/parser/yaml-documents'; -import { getParent, isInComment } from '../src/languageservice/utils/yamlAstUtils'; import { TextBuffer } from '../src/languageservice/utils/textBuffer'; -import { setupTextDocument } from './utils/testHelper'; +import { getParent, isInComment } from '../src/languageservice/utils/yamlAstUtils'; + const expect = chai.expect; describe('AST Utils Tests', () => { diff --git a/test/autoCompletion.test.ts b/test/autoCompletion.test.ts index f8ab0b2c4..50af67209 100644 --- a/test/autoCompletion.test.ts +++ b/test/autoCompletion.test.ts @@ -3,19 +3,23 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import type { CompletionList, MarkupContent } from 'vscode-languageserver-types'; + +import type { LanguageService } from '../src'; import type { TestCustomSchemaProvider } from './utils/testHelper'; -import { caretPosition, SCHEMA_ID, setupLanguageService, setupSchemaIDTextDocument, toFsPath } from './utils/testHelper'; +import type { LanguageHandlers } from '../src/languageserver/handlers/languageHandlers'; +import type { SettingsState } from '../src/yamlSettings'; + import assert from 'assert'; import * as path from 'path'; -import { createExpectedCompletion } from './utils/verifyError'; -import { ServiceSetup } from './utils/serviceSetup'; -import type { CompletionList, MarkupContent } from 'vscode-languageserver-types'; -import { CompletionItemKind, InsertTextFormat, MarkupKind, Position } from 'vscode-languageserver-types'; + import { expect } from 'chai'; -import type { SettingsState } from '../src/yamlSettings'; +import { CompletionItemKind, InsertTextFormat, MarkupKind, Position } from 'vscode-languageserver-types'; + +import { ServiceSetup } from './utils/serviceSetup'; +import { SCHEMA_ID, caretPosition, setupLanguageService, setupSchemaIDTextDocument, toFsPath } from './utils/testHelper'; +import { createExpectedCompletion } from './utils/verifyError'; import { TextDocumentTestManager } from '../src/yamlSettings'; -import type { LanguageService } from '../src'; -import type { LanguageHandlers } from '../src/languageserver/handlers/languageHandlers'; describe('Auto Completion Tests', () => { let languageSettingsSetup: ServiceSetup; diff --git a/test/autoCompletionFix.test.ts b/test/autoCompletionFix.test.ts index fd3a821cd..803c6345e 100644 --- a/test/autoCompletionFix.test.ts +++ b/test/autoCompletionFix.test.ts @@ -4,18 +4,22 @@ *--------------------------------------------------------------------------------------------*/ import type { CompletionList } from 'vscode-languageserver-types'; -import { CompletionItemKind, InsertTextFormat, Position, Range } from 'vscode-languageserver-types'; + import type { LanguageHandlers } from '../src/languageserver/handlers/languageHandlers'; import type { LanguageService } from '../src/languageservice/yamlLanguageService'; import type { SettingsState } from '../src/yamlSettings'; -import { TextDocumentTestManager } from '../src/yamlSettings'; -import { ServiceSetup } from './utils/serviceSetup'; +import type { JSONSchema } from './../src/languageservice/jsonSchema'; import type { TestCustomSchemaProvider } from './utils/testHelper'; -import { caretPosition, SCHEMA_ID, setupLanguageService, setupSchemaIDTextDocument } from './utils/testHelper'; + +import * as path from 'path'; + import { expect } from 'chai'; +import { CompletionItemKind, InsertTextFormat, Position, Range } from 'vscode-languageserver-types'; + +import { TextDocumentTestManager } from '../src/yamlSettings'; +import { ServiceSetup } from './utils/serviceSetup'; +import { SCHEMA_ID, caretPosition, setupLanguageService, setupSchemaIDTextDocument } from './utils/testHelper'; import { createExpectedCompletion } from './utils/verifyError'; -import * as path from 'path'; -import type { JSONSchema } from './../src/languageservice/jsonSchema'; describe('Auto Completion Fix Tests', () => { let languageSettingsSetup: ServiceSetup; diff --git a/test/bundlel10n.test.ts b/test/bundlel10n.test.ts index 4506c1641..5a089dbd9 100644 --- a/test/bundlel10n.test.ts +++ b/test/bundlel10n.test.ts @@ -2,11 +2,14 @@ * Copyright (c) Red Hat. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as l10n from '@vscode/l10n'; +import type { Connection } from 'vscode-languageserver/node'; + import assert from 'assert'; import * as path from 'path'; -import type { Connection } from 'vscode-languageserver/node'; + +import * as l10n from '@vscode/l10n'; import { createConnection } from 'vscode-languageserver/node'; + import { schemaRequestHandler, workspaceContext } from '../src/languageservice/services/schemaRequestHandler'; import { setupl10nBundle } from '../src/nodeTranslationSetup'; import { YAMLServerInit } from '../src/yamlServerInit'; diff --git a/test/code-action-schema.test.ts b/test/code-action-schema.test.ts index c440ee055..42b5868cc 100644 --- a/test/code-action-schema.test.ts +++ b/test/code-action-schema.test.ts @@ -2,17 +2,20 @@ * Copyright (c) Red Hat. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import type { TestCustomSchemaProvider } from './utils/testHelper'; -import { SCHEMA_ID, setupLanguageService, setupSchemaIDTextDocument, TEST_URI } from './utils/testHelper'; -import { ServiceSetup } from './utils/serviceSetup'; import type { CodeActionParams } from 'vscode-languageserver'; -import { TextDocumentIdentifier, CodeActionContext, TextEdit, Range } from 'vscode-languageserver'; -import { expect } from 'chai'; -import type { SettingsState } from '../src/yamlSettings'; -import { TextDocumentTestManager } from '../src/yamlSettings'; +import type { TextDocument } from 'vscode-languageserver-textdocument'; + +import type { TestCustomSchemaProvider } from './utils/testHelper'; import type { ValidationHandler } from '../src/languageserver/handlers/validationHandlers'; +import type { SettingsState } from '../src/yamlSettings'; + +import { expect } from 'chai'; +import { CodeActionContext, Range, TextDocumentIdentifier, TextEdit } from 'vscode-languageserver'; + +import { ServiceSetup } from './utils/serviceSetup'; +import { SCHEMA_ID, TEST_URI, setupLanguageService, setupSchemaIDTextDocument } from './utils/testHelper'; import { YamlCodeActions } from '../src/languageservice/services/yamlCodeActions'; -import type { TextDocument } from 'vscode-languageserver-textdocument'; +import { TextDocumentTestManager } from '../src/yamlSettings'; describe('Schema Errors Code Action Tests', () => { let languageSettingsSetup: ServiceSetup; diff --git a/test/customTags.test.ts b/test/customTags.test.ts index fe4f70aaf..ebcc3aeb5 100644 --- a/test/customTags.test.ts +++ b/test/customTags.test.ts @@ -2,13 +2,16 @@ * Copyright (c) Red Hat. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { setupLanguageService, setupTextDocument } from './utils/testHelper'; -import { ServiceSetup } from './utils/serviceSetup'; -import { createExpectedError } from './utils/verifyError'; -import assert from 'assert'; import type { Diagnostic } from 'vscode-languageserver-types'; -import type { LanguageService } from '../src/languageservice/yamlLanguageService'; + import type { ValidationHandler } from '../src/languageserver/handlers/validationHandlers'; +import type { LanguageService } from '../src/languageservice/yamlLanguageService'; + +import assert from 'assert'; + +import { ServiceSetup } from './utils/serviceSetup'; +import { setupLanguageService, setupTextDocument } from './utils/testHelper'; +import { createExpectedError } from './utils/verifyError'; // Defines a Mocha test describe to group tests of similar kind together describe('Custom Tag tests Tests', () => { diff --git a/test/defaultSnippets.test.ts b/test/defaultSnippets.test.ts index 610c85303..6efbb60ff 100644 --- a/test/defaultSnippets.test.ts +++ b/test/defaultSnippets.test.ts @@ -2,15 +2,19 @@ * Copyright (c) Red Hat. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { toFsPath, setupSchemaIDTextDocument, setupLanguageService, caretPosition } from './utils/testHelper'; +import type { CompletionList, TextEdit } from 'vscode-languageserver-types'; + +import type { LanguageHandlers } from '../src/languageserver/handlers/languageHandlers'; +import type { SettingsState } from '../src/yamlSettings'; + import assert from 'assert'; import * as path from 'path'; + +import { expect } from 'chai'; + import { ServiceSetup } from './utils/serviceSetup'; -import type { LanguageHandlers } from '../src/languageserver/handlers/languageHandlers'; -import type { SettingsState } from '../src/yamlSettings'; +import { caretPosition, setupLanguageService, setupSchemaIDTextDocument, toFsPath } from './utils/testHelper'; import { TextDocumentTestManager } from '../src/yamlSettings'; -import type { CompletionList, TextEdit } from 'vscode-languageserver-types'; -import { expect } from 'chai'; describe('Default Snippet Tests', () => { let languageHandler: LanguageHandlers; diff --git a/test/diagnostic-filter.test.ts b/test/diagnostic-filter.test.ts index 395385ac7..ae4a76075 100644 --- a/test/diagnostic-filter.test.ts +++ b/test/diagnostic-filter.test.ts @@ -3,11 +3,13 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { expect } from 'chai'; import type { GetLineText } from '../src/languageservice/utils/diagnostic-filter'; + +import { expect } from 'chai'; + import { - filterSuppressedDiagnostics, YAML_DISABLE_PATTERN, + filterSuppressedDiagnostics, parseDisableSpecifiers, shouldSuppressDiagnostic, } from '../src/languageservice/utils/diagnostic-filter'; diff --git a/test/documentSymbols.test.ts b/test/documentSymbols.test.ts index a6ce3bb16..71dbd249e 100644 --- a/test/documentSymbols.test.ts +++ b/test/documentSymbols.test.ts @@ -2,19 +2,23 @@ * Copyright (c) Red Hat. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { setupLanguageService, setupTextDocument, TEST_URI } from './utils/testHelper'; +import type { DocumentSymbol, SymbolInformation } from 'vscode-languageserver-types'; + +import type { LanguageHandlers } from '../src/languageserver/handlers/languageHandlers'; +import type { SettingsState } from '../src/yamlSettings'; + +import assert from 'assert'; + +import { SymbolKind } from 'vscode-languageserver-types'; + +import { ServiceSetup } from './utils/serviceSetup'; +import { TEST_URI, setupLanguageService, setupTextDocument } from './utils/testHelper'; import { - createExpectedSymbolInformation, createExpectedDocumentSymbol, createExpectedDocumentSymbolNoDetail, + createExpectedSymbolInformation, } from './utils/verifyError'; -import type { DocumentSymbol, SymbolInformation } from 'vscode-languageserver-types'; -import { SymbolKind } from 'vscode-languageserver-types'; -import assert from 'assert'; -import { ServiceSetup } from './utils/serviceSetup'; -import type { SettingsState } from '../src/yamlSettings'; import { TextDocumentTestManager } from '../src/yamlSettings'; -import type { LanguageHandlers } from '../src/languageserver/handlers/languageHandlers'; describe('Document Symbols Tests', () => { let languageHandler: LanguageHandlers; diff --git a/test/findLinks.test.ts b/test/findLinks.test.ts index 4f6651f54..35c419491 100644 --- a/test/findLinks.test.ts +++ b/test/findLinks.test.ts @@ -2,13 +2,16 @@ * Copyright (c) Red Hat. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { setupLanguageService, setupTextDocument } from './utils/testHelper'; -import assert from 'assert'; -import { ServiceSetup } from './utils/serviceSetup'; import type { DocumentLink } from 'vscode-languageserver-types'; + +import type { LanguageHandlers } from '../src/languageserver/handlers/languageHandlers'; import type { SettingsState } from '../src/yamlSettings'; + +import assert from 'assert'; + +import { ServiceSetup } from './utils/serviceSetup'; +import { setupLanguageService, setupTextDocument } from './utils/testHelper'; import { TextDocumentTestManager } from '../src/yamlSettings'; -import type { LanguageHandlers } from '../src/languageserver/handlers/languageHandlers'; describe('Find Links Tests', () => { let languageHandler: LanguageHandlers; diff --git a/test/flow-style-rewriter.test.ts b/test/flow-style-rewriter.test.ts index 7cc773755..4dac8b01f 100644 --- a/test/flow-style-rewriter.test.ts +++ b/test/flow-style-rewriter.test.ts @@ -1,7 +1,8 @@ import { expect } from 'chai'; + +import { setupTextDocument } from './utils/testHelper'; import { YamlDocuments } from '../src/languageservice/parser/yaml-documents'; import { FlowStyleRewriter } from '../src/languageservice/utils/flow-style-rewriter'; -import { setupTextDocument } from './utils/testHelper'; describe('Flow style rewriter', () => { let writer: FlowStyleRewriter; diff --git a/test/formatter.test.ts b/test/formatter.test.ts index 545be44b3..0f89bbccb 100644 --- a/test/formatter.test.ts +++ b/test/formatter.test.ts @@ -2,12 +2,16 @@ * Copyright (c) Red Hat. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import assert from 'assert'; -import * as sinon from 'sinon'; import type { FormattingOptions, TextEdit } from 'vscode-languageserver-types'; + import type { CustomFormatterOptions } from '../src'; import type { LanguageHandlers } from '../src/languageserver/handlers/languageHandlers'; import type { SettingsState } from '../src/yamlSettings'; + +import assert from 'assert'; + +import * as sinon from 'sinon'; + import { TextDocumentTestManager } from '../src/yamlSettings'; import { ServiceSetup } from './utils/serviceSetup'; import { setupLanguageService, setupTextDocument } from './utils/testHelper'; diff --git a/test/hover.test.ts b/test/hover.test.ts index 8fa16f855..1cd4034f9 100644 --- a/test/hover.test.ts +++ b/test/hover.test.ts @@ -2,18 +2,22 @@ * Copyright (c) Red Hat. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { ServiceSetup } from './utils/serviceSetup'; -import type { TestCustomSchemaProvider } from './utils/testHelper'; -import { caretPosition, SCHEMA_ID, setupLanguageService, setupSchemaIDTextDocument } from './utils/testHelper'; -import assert from 'assert'; import type { Hover } from 'vscode-languageserver-types'; -import { MarkupContent, Position } from 'vscode-languageserver-types'; + +import type { TestCustomSchemaProvider } from './utils/testHelper'; import type { LanguageHandlers } from '../src/languageserver/handlers/languageHandlers'; import type { SettingsState } from '../src/yamlSettings'; -import { TextDocumentTestManager } from '../src/yamlSettings'; -import { expect } from 'chai'; import type { TestTelemetry } from './utils/testsTypes'; +import assert from 'assert'; + +import { expect } from 'chai'; +import { MarkupContent, Position } from 'vscode-languageserver-types'; + +import { SCHEMA_ID, caretPosition, setupLanguageService, setupSchemaIDTextDocument } from './utils/testHelper'; +import { TextDocumentTestManager } from '../src/yamlSettings'; +import { ServiceSetup } from './utils/serviceSetup'; + describe('Hover Tests', () => { let languageSettingsSetup: ServiceSetup; let languageHandler: LanguageHandlers; diff --git a/test/integration.test.ts b/test/integration.test.ts index ab8f52d1c..6fbee8088 100644 --- a/test/integration.test.ts +++ b/test/integration.test.ts @@ -2,15 +2,19 @@ * Copyright (c) Red Hat. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { setupLanguageService, setupTextDocument } from './utils/testHelper'; +import type { CompletionList, Diagnostic, Hover } from 'vscode-languageserver-types'; + +import type { LanguageHandlers } from '../src/languageserver/handlers/languageHandlers'; +import type { ValidationHandler } from '../src/languageserver/handlers/validationHandlers'; +import type { SettingsState } from '../src/yamlSettings'; + import assert from 'assert'; -import type { Diagnostic, CompletionList, Hover } from 'vscode-languageserver-types'; + import { MarkupContent } from 'vscode-languageserver-types'; + import { ServiceSetup } from './utils/serviceSetup'; -import type { LanguageHandlers } from '../src/languageserver/handlers/languageHandlers'; -import type { SettingsState } from '../src/yamlSettings'; import { TextDocumentTestManager } from '../src/yamlSettings'; -import type { ValidationHandler } from '../src/languageserver/handlers/validationHandlers'; +import { setupLanguageService, setupTextDocument } from './utils/testHelper'; // Defines a Mocha test describe to group tests of similar kind together describe('Kubernetes Integration Tests', () => { diff --git a/test/invalid-metaschema.test.ts b/test/invalid-metaschema.test.ts index e584ea9cf..29697d751 100644 --- a/test/invalid-metaschema.test.ts +++ b/test/invalid-metaschema.test.ts @@ -2,9 +2,11 @@ * Copyright (c) IBM Corp. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import type { Connection, RemoteClient } from 'vscode-languageserver/node'; + import { assert } from 'chai'; import * as sinon from 'sinon'; -import type { Connection, RemoteClient } from 'vscode-languageserver/node'; + import { JSONSchemaSelection } from '../src/languageserver/handlers/schemaSelectionHandlers'; import { YAMLSchemaService } from '../src/languageservice/services/yamlSchemaService'; import { SettingsState, TextDocumentTestManager } from '../src/yamlSettings'; diff --git a/test/multipleDocuments.test.ts b/test/multipleDocuments.test.ts index 4af4ae814..876cd5437 100644 --- a/test/multipleDocuments.test.ts +++ b/test/multipleDocuments.test.ts @@ -2,17 +2,21 @@ * Copyright (c) Red Hat. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as path from 'path'; -import { setupLanguageService, setupTextDocument, toFsPath } from './utils/testHelper'; -import assert from 'assert'; -import { ServiceSetup } from './utils/serviceSetup'; import type { Diagnostic, Hover } from 'vscode-languageserver-types'; -import { MarkupContent } from 'vscode-languageserver-types'; + +import type { LanguageHandlers } from '../src/languageserver/handlers/languageHandlers'; +import type { ValidationHandler } from '../src/languageserver/handlers/validationHandlers'; +import type { LanguageService } from '../src/languageservice/yamlLanguageService'; import type { SettingsState } from '../src/yamlSettings'; + +import assert from 'assert'; +import * as path from 'path'; + +import { MarkupContent } from 'vscode-languageserver-types'; + +import { ServiceSetup } from './utils/serviceSetup'; +import { setupLanguageService, setupTextDocument, toFsPath } from './utils/testHelper'; import { TextDocumentTestManager } from '../src/yamlSettings'; -import type { LanguageService } from '../src/languageservice/yamlLanguageService'; -import type { ValidationHandler } from '../src/languageserver/handlers/validationHandlers'; -import type { LanguageHandlers } from '../src/languageserver/handlers/languageHandlers'; /** * Setup the schema we are going to use with the language settings diff --git a/test/objects.test.ts b/test/objects.test.ts index 121ebe87a..194e19dad 100644 --- a/test/objects.test.ts +++ b/test/objects.test.ts @@ -2,9 +2,10 @@ * Copyright (c) Red Hat. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { equals, convertErrorToTelemetryMsg } from '../src/languageservice/utils/objects'; import assert from 'assert'; +import { convertErrorToTelemetryMsg, equals } from '../src/languageservice/utils/objects'; + describe('Object Equals Tests', () => { describe('Equals', function () { it('Both are null', () => { diff --git a/test/paths.test.ts b/test/paths.test.ts index 3071994b7..3c2e13fb6 100644 --- a/test/paths.test.ts +++ b/test/paths.test.ts @@ -1,10 +1,12 @@ -import assert from 'assert'; import type { WorkspaceFolder } from 'vscode-languageserver-protocol'; + +import assert from 'assert'; import { join } from 'path'; -import { relativeToAbsolutePath, isRelativePath, workspaceFoldersChanged } from '../src/languageservice/utils/paths'; import { URI } from 'vscode-uri'; +import { isRelativePath, relativeToAbsolutePath, workspaceFoldersChanged } from '../src/languageservice/utils/paths'; + class TestWorkspace { folders: WorkspaceFolder[]; root: URI; diff --git a/test/schema.test.ts b/test/schema.test.ts index 063c326c7..7a1fde133 100644 --- a/test/schema.test.ts +++ b/test/schema.test.ts @@ -1,27 +1,31 @@ -import assert from 'assert'; -import * as parser from '../src/languageservice/parser/yamlParser07'; -import * as SchemaService from '../src/languageservice/services/yamlSchemaService'; -import type * as JsonSchema from '../src/languageservice/jsonSchema'; -import * as url from 'url'; -import * as path from 'path'; -import { xhr } from 'request-light'; -import type { SchemaDeletions } from '../src/languageservice/services/yamlSchemaService'; -import { MODIFICATION_ACTIONS } from '../src/languageservice/services/yamlSchemaService'; -import { EMPTY_SCHEMA_URL, DEFAULT_KUBERNETES_SCHEMA_VERSION } from '../src/languageservice/utils/schemaUrls'; -import { expect } from 'chai'; -import { ServiceSetup } from './utils/serviceSetup'; -import type { TestCustomSchemaProvider } from './utils/testHelper'; -import { SCHEMA_ID, setupLanguageService, setupSchemaIDTextDocument, setupTextDocument, TEST_URI } from './utils/testHelper'; +import type { Diagnostic, MarkupContent } from 'vscode-languageserver-types'; + import type { LanguageService } from '../src'; -import { SchemaPriority } from '../src'; +import type { TestCustomSchemaProvider } from './utils/testHelper'; import type { ValidationHandler } from '../src/languageserver/handlers/validationHandlers'; +import type * as JsonSchema from '../src/languageservice/jsonSchema'; +import type { SchemaDeletions } from '../src/languageservice/services/yamlSchemaService'; import type { SettingsState } from '../src/yamlSettings'; -import { TextDocumentTestManager } from '../src/yamlSettings'; -import type { Diagnostic, MarkupContent } from 'vscode-languageserver-types'; + +import assert from 'assert'; +import * as path from 'path'; +import * as url from 'url'; + +import { expect } from 'chai'; +import { xhr } from 'request-light'; import { Position } from 'vscode-languageserver-types'; import { LineCounter } from 'yaml'; -import { getSchemaFromModeline } from '../src/languageservice/services/modelineUtil'; + +import { SchemaPriority } from '../src'; +import { ServiceSetup } from './utils/serviceSetup'; +import { SCHEMA_ID, TEST_URI, setupLanguageService, setupSchemaIDTextDocument, setupTextDocument } from './utils/testHelper'; +import * as parser from '../src/languageservice/parser/yamlParser07'; import { getGroupVersionKindFromDocument } from '../src/languageservice/services/k8sSchemaUtil'; +import { getSchemaFromModeline } from '../src/languageservice/services/modelineUtil'; +import * as SchemaService from '../src/languageservice/services/yamlSchemaService'; +import { MODIFICATION_ACTIONS } from '../src/languageservice/services/yamlSchemaService'; +import { DEFAULT_KUBERNETES_SCHEMA_VERSION, EMPTY_SCHEMA_URL } from '../src/languageservice/utils/schemaUrls'; +import { TextDocumentTestManager } from '../src/yamlSettings'; const KUBERNETES_SCHEMA_URL = `https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/${DEFAULT_KUBERNETES_SCHEMA_VERSION}-standalone-strict/all.json`; diff --git a/test/schema2019Validation.test.ts b/test/schema2019Validation.test.ts index 3ef1105a5..e76236185 100644 --- a/test/schema2019Validation.test.ts +++ b/test/schema2019Validation.test.ts @@ -2,16 +2,19 @@ * Copyright (c) IBM Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import type { TestCustomSchemaProvider } from './utils/testHelper'; -import { SCHEMA_ID, setupLanguageService, setupSchemaIDTextDocument } from './utils/testHelper'; -import { ServiceSetup } from './utils/serviceSetup'; import type { Diagnostic } from 'vscode-languageserver-types'; -import { expect } from 'chai'; -import type { SettingsState } from '../src/yamlSettings'; -import { TextDocumentTestManager } from '../src/yamlSettings'; + +import type { TestCustomSchemaProvider } from './utils/testHelper'; import type { ValidationHandler } from '../src/languageserver/handlers/validationHandlers'; -import { DEFAULT_KUBERNETES_SCHEMA_VERSION } from '../src/languageservice/utils/schemaUrls'; import type { JSONSchema } from '../src/languageservice/jsonSchema'; +import type { SettingsState } from '../src/yamlSettings'; + +import { expect } from 'chai'; + +import { ServiceSetup } from './utils/serviceSetup'; +import { SCHEMA_ID, setupLanguageService, setupSchemaIDTextDocument } from './utils/testHelper'; +import { DEFAULT_KUBERNETES_SCHEMA_VERSION } from '../src/languageservice/utils/schemaUrls'; +import { TextDocumentTestManager } from '../src/yamlSettings'; describe('Validation Tests', () => { let languageSettingsSetup: ServiceSetup; diff --git a/test/schema2020Validation.test.ts b/test/schema2020Validation.test.ts index d49060272..df29cc0f5 100644 --- a/test/schema2020Validation.test.ts +++ b/test/schema2020Validation.test.ts @@ -2,16 +2,19 @@ * Copyright (c) IBM Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import type { TestCustomSchemaProvider } from './utils/testHelper'; -import { SCHEMA_ID, setupLanguageService, setupSchemaIDTextDocument } from './utils/testHelper'; -import { ServiceSetup } from './utils/serviceSetup'; import type { Diagnostic } from 'vscode-languageserver-types'; -import { expect } from 'chai'; -import type { SettingsState } from '../src/yamlSettings'; -import { TextDocumentTestManager } from '../src/yamlSettings'; + +import type { TestCustomSchemaProvider } from './utils/testHelper'; import type { ValidationHandler } from '../src/languageserver/handlers/validationHandlers'; -import { DEFAULT_KUBERNETES_SCHEMA_VERSION } from '../src/languageservice/utils/schemaUrls'; import type { JSONSchema } from '../src/languageservice/jsonSchema'; +import type { SettingsState } from '../src/yamlSettings'; + +import { expect } from 'chai'; + +import { ServiceSetup } from './utils/serviceSetup'; +import { SCHEMA_ID, setupLanguageService, setupSchemaIDTextDocument } from './utils/testHelper'; +import { DEFAULT_KUBERNETES_SCHEMA_VERSION } from '../src/languageservice/utils/schemaUrls'; +import { TextDocumentTestManager } from '../src/yamlSettings'; describe('Validation Tests', () => { let languageSettingsSetup: ServiceSetup; diff --git a/test/schemaRequestHandler.test.ts b/test/schemaRequestHandler.test.ts index a0e5939f8..6c7abe1a8 100644 --- a/test/schemaRequestHandler.test.ts +++ b/test/schemaRequestHandler.test.ts @@ -3,18 +3,20 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { schemaRequestHandler } from '../src/languageservice/services/schemaRequestHandler'; -import * as sinon from 'sinon'; -import * as request from 'request-light'; import type { XHRResponse } from 'request-light'; import type { Connection } from 'vscode-languageserver'; -import { URI } from 'vscode-uri'; + import * as chai from 'chai'; +import * as request from 'request-light'; +import * as sinon from 'sinon'; import sinonChai from 'sinon-chai'; +import { URI } from 'vscode-uri'; + +import { testFileSystem } from './utils/testHelper'; +import { schemaRequestHandler } from '../src/languageservice/services/schemaRequestHandler'; const expect = chai.expect; chai.use(sinonChai); -import { testFileSystem } from './utils/testHelper'; describe('Schema Request Handler Tests', () => { describe('schemaRequestHandler', () => { diff --git a/test/schemaSelectionHandlers.test.ts b/test/schemaSelectionHandlers.test.ts index 1e5827084..dfb429903 100644 --- a/test/schemaSelectionHandlers.test.ts +++ b/test/schemaSelectionHandlers.test.ts @@ -2,14 +2,16 @@ * Copyright (c) Red Hat, Inc. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as sinon from 'sinon'; +import type { Connection, RemoteClient } from 'vscode-languageserver/node'; + import * as chai from 'chai'; +import * as sinon from 'sinon'; import sinonChai from 'sinon-chai'; + import { JSONSchemaSelection } from '../src/languageserver/handlers/schemaSelectionHandlers'; import { YAMLSchemaService } from '../src/languageservice/services/yamlSchemaService'; -import type { Connection, RemoteClient } from 'vscode-languageserver/node'; -import { SettingsState, TextDocumentTestManager } from '../src/yamlSettings'; import { SchemaSelectionRequests } from '../src/requestTypes'; +import { SettingsState, TextDocumentTestManager } from '../src/yamlSettings'; import { SCHEMA_ID, setupSchemaIDTextDocument } from './utils/testHelper'; const expect = chai.expect; diff --git a/test/schemaValidation.test.ts b/test/schemaValidation.test.ts index 7ed7e37fe..69f5e6a62 100644 --- a/test/schemaValidation.test.ts +++ b/test/schemaValidation.test.ts @@ -2,34 +2,38 @@ * Copyright (c) Red Hat. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import type { Diagnostic } from 'vscode-languageserver-types'; + import type { TestCustomSchemaProvider } from './utils/testHelper'; -import { SCHEMA_ID, setupLanguageService, setupSchemaIDTextDocument } from './utils/testHelper'; -import { createDiagnosticWithData, createExpectedError } from './utils/verifyError'; -import { ServiceSetup } from './utils/serviceSetup'; +import type { TestTelemetry } from './utils/testsTypes'; +import type { ValidationHandler } from '../src/languageserver/handlers/validationHandlers'; +import type { JSONSchema } from '../src/languageservice/jsonSchema'; +import type { IProblem } from '../src/languageservice/parser/schemaValidation/baseValidator'; +import type { LanguageService } from '../src/languageservice/yamlLanguageService'; +import type { SettingsState } from '../src/yamlSettings'; + +import assert from 'assert'; +import * as path from 'path'; + +import { expect } from 'chai'; +import { DiagnosticSeverity, Position } from 'vscode-languageserver-types'; + import { - StringTypeError, - BooleanTypeError, ArrayTypeError, - IncludeWithoutValueError, BlockMappingEntryError, + BooleanTypeError, DuplicateKeyError, - propertyIsNotAllowed, + IncludeWithoutValueError, MissingRequiredPropWarning, + StringTypeError, + propertyIsNotAllowed, } from './utils/errorMessages'; -import assert from 'assert'; -import * as path from 'path'; -import type { Diagnostic } from 'vscode-languageserver-types'; -import { DiagnosticSeverity, Position } from 'vscode-languageserver-types'; -import { expect } from 'chai'; -import type { SettingsState } from '../src/yamlSettings'; -import { TextDocumentTestManager } from '../src/yamlSettings'; -import type { ValidationHandler } from '../src/languageserver/handlers/validationHandlers'; -import type { LanguageService } from '../src/languageservice/yamlLanguageService'; -import type { IProblem } from '../src/languageservice/parser/schemaValidation/baseValidator'; -import type { JSONSchema } from '../src/languageservice/jsonSchema'; -import type { TestTelemetry } from './utils/testsTypes'; +import { ServiceSetup } from './utils/serviceSetup'; +import { SCHEMA_ID, setupLanguageService, setupSchemaIDTextDocument } from './utils/testHelper'; +import { createDiagnosticWithData, createExpectedError } from './utils/verifyError'; import { ErrorCode } from '../src/languageservice/jsonLanguageTypes'; import { DEFAULT_KUBERNETES_SCHEMA_VERSION } from '../src/languageservice/utils/schemaUrls'; +import { TextDocumentTestManager } from '../src/yamlSettings'; const KUBERNETES_SCHEMA_URL = `https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/${DEFAULT_KUBERNETES_SCHEMA_VERSION}-standalone-strict/all.json`; diff --git a/test/settingsHandlers.test.ts b/test/settingsHandlers.test.ts index 71ac4754c..766409133 100644 --- a/test/settingsHandlers.test.ts +++ b/test/settingsHandlers.test.ts @@ -3,19 +3,22 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import type { Connection, RemoteClient, RemoteWorkspace } from 'vscode-languageserver'; + +import type { LanguageService, LanguageSettings, SchemaConfiguration } from '../src'; +import type { Telemetry } from '../src/languageservice/telemetry'; + import * as chai from 'chai'; import * as request from 'request-light'; import * as sinon from 'sinon'; import sinonChai from 'sinon-chai'; -import type { Connection, RemoteClient, RemoteWorkspace } from 'vscode-languageserver'; import { CodeLensRefreshRequest } from 'vscode-languageserver-protocol'; import { URI } from 'vscode-uri'; -import type { LanguageService, LanguageSettings, SchemaConfiguration } from '../src'; + import { SchemaPriority } from '../src'; import { SettingsHandler } from '../src/languageserver/handlers/settingsHandlers'; import { ValidationHandler } from '../src/languageserver/handlers/validationHandlers'; import { EMPTY_SCHEMA_URL } from '../src/languageservice/utils/schemaUrls'; -import type { Telemetry } from '../src/languageservice/telemetry'; import { SettingsState } from '../src/yamlSettings'; import { TestCustomSchemaProvider, setupLanguageService, setupSchemaIDTextDocument, setupTextDocument } from './utils/testHelper'; import { TestWorkspace } from './utils/testsTypes'; diff --git a/test/strings.test.ts b/test/strings.test.ts index fc5be71b4..95033e634 100644 --- a/test/strings.test.ts +++ b/test/strings.test.ts @@ -2,10 +2,12 @@ * Copyright (c) Red Hat. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { startsWith, endsWith, convertSimple2RegExp, safeCreateUnicodeRegExp } from '../src/languageservice/utils/strings'; import assert from 'assert'; + import { expect } from 'chai'; +import { convertSimple2RegExp, endsWith, safeCreateUnicodeRegExp, startsWith } from '../src/languageservice/utils/strings'; + describe('String Tests', () => { describe('startsWith', function () { it('String with different lengths', () => { diff --git a/test/telemetry.test.ts b/test/telemetry.test.ts index 879f59075..77afd8497 100644 --- a/test/telemetry.test.ts +++ b/test/telemetry.test.ts @@ -2,13 +2,15 @@ * Copyright (c) Red Hat. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import type { Connection } from 'vscode-languageserver'; + +import * as chai from 'chai'; import * as sinon from 'sinon'; import sinonChai from 'sinon-chai'; -import * as chai from 'chai'; -import { checkSchemaURI } from '../src/languageservice/utils/schemaUrls'; -import { TelemetryImpl } from '../src/languageserver/telemetry'; import { URI } from 'vscode-uri'; -import type { Connection } from 'vscode-languageserver'; + +import { TelemetryImpl } from '../src/languageserver/telemetry'; +import { checkSchemaURI } from '../src/languageservice/utils/schemaUrls'; const expect = chai.expect; chai.use(sinonChai); diff --git a/test/textBuffer.test.ts b/test/textBuffer.test.ts index 385644484..f6dab8f8e 100644 --- a/test/textBuffer.test.ts +++ b/test/textBuffer.test.ts @@ -3,10 +3,12 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { TextBuffer } from '../src/languageservice/utils/textBuffer'; -import { TextDocument } from 'vscode-languageserver-textdocument'; import assert from 'assert'; +import { TextDocument } from 'vscode-languageserver-textdocument'; + +import { TextBuffer } from '../src/languageservice/utils/textBuffer'; + describe('TextBuffer', () => { it('getLineLength should return actual line length', () => { const buffer = new TextBuffer(TextDocument.create('file://foo/bar', 'yaml', 1, 'Foo\nbar')); diff --git a/test/utils/serviceSetup.ts b/test/utils/serviceSetup.ts index ac8333c8a..3fa2df7a5 100644 --- a/test/utils/serviceSetup.ts +++ b/test/utils/serviceSetup.ts @@ -2,8 +2,8 @@ * Copyright (c) Red Hat. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import type { LanguageSettings, SchemasSettings } from '../../src/languageservice/yamlLanguageService'; import type { YamlVersion } from '../../src/languageservice/parser/yamlParser07'; +import type { LanguageSettings, SchemasSettings } from '../../src/languageservice/yamlLanguageService'; export class ServiceSetup { /* diff --git a/test/utils/testHelper.ts b/test/utils/testHelper.ts index b74492441..93077b65d 100644 --- a/test/utils/testHelper.ts +++ b/test/utils/testHelper.ts @@ -2,22 +2,26 @@ * Copyright (c) Red Hat. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { promises as fs } from 'fs'; -import { ClientCapabilities } from '../../src/languageservice/jsonLanguageTypes'; -import { TextDocument } from 'vscode-languageserver-textdocument'; import type { Connection, ClientCapabilities as LSPClientCapabilities } from 'vscode-languageserver/node'; -import { createConnection } from 'vscode-languageserver/node'; + import type { LanguageService, LanguageSettings } from '../../src'; import type { LanguageHandlers } from '../../src/languageserver/handlers/languageHandlers'; import type { ValidationHandler } from '../../src/languageserver/handlers/validationHandlers'; import type { JSONSchema } from '../../src/languageservice/jsonSchema'; -import { yamlDocumentsCache } from '../../src/languageservice/parser/yaml-documents'; import type { FileSystem } from '../../src/languageservice/services/schemaRequestHandler'; + +import { promises as fs } from 'fs'; +import * as path from 'path'; + +import { createConnection } from 'vscode-languageserver/node'; +import { TextDocument } from 'vscode-languageserver-textdocument'; + +import { TestTelemetry } from './testsTypes'; +import { ClientCapabilities } from '../../src/languageservice/jsonLanguageTypes'; +import { yamlDocumentsCache } from '../../src/languageservice/parser/yaml-documents'; import { schemaRequestHandler, workspaceContext } from '../../src/languageservice/services/schemaRequestHandler'; import { YAMLServerInit } from '../../src/yamlServerInit'; import { SettingsState } from '../../src/yamlSettings'; -import { TestTelemetry } from './testsTypes'; -import * as path from 'path'; export function toFsPath(str: unknown): string { if (typeof str !== 'string') { diff --git a/test/utils/testsTypes.ts b/test/utils/testsTypes.ts index b580f9a45..442d6fc2b 100644 --- a/test/utils/testsTypes.ts +++ b/test/utils/testsTypes.ts @@ -4,23 +4,25 @@ *--------------------------------------------------------------------------------------------*/ import type { Disposable, Event, NotificationHandler, RequestHandler } from 'vscode-jsonrpc'; +import type { Connection, RemoteWorkspace } from 'vscode-languageserver'; import type { ApplyWorkspaceEditParams, - WorkspaceEdit, ApplyWorkspaceEditResponse, + ClientCapabilities, ConfigurationItem, - WorkspaceFolder, - WorkspaceFoldersChangeEvent, CreateFilesParams, - RenameFilesParams, DeleteFilesParams, - ClientCapabilities, + RenameFilesParams, ServerCapabilities, + WorkspaceEdit, + WorkspaceFolder, + WorkspaceFoldersChangeEvent, } from 'vscode-languageserver-protocol'; -import type { Connection, RemoteWorkspace } from 'vscode-languageserver'; -import { TelemetryImpl } from '../../src/languageserver/telemetry'; + import type { TelemetryEvent } from '../../src/languageservice/telemetry'; +import { TelemetryImpl } from '../../src/languageserver/telemetry'; + /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-unused-vars */ export class TestWorkspace implements RemoteWorkspace { diff --git a/test/utils/verifyError.ts b/test/utils/verifyError.ts index ef0f10cb9..d4c388ae3 100644 --- a/test/utils/verifyError.ts +++ b/test/utils/verifyError.ts @@ -7,10 +7,12 @@ import type { CompletionItem, CompletionItemKind, InsertTextFormat, - SymbolKind, SymbolInformation, + SymbolKind, } from 'vscode-languageserver-types'; + import { Diagnostic, DiagnosticSeverity, DiagnosticTag, DocumentSymbol, Range } from 'vscode-languageserver-types'; + import { ErrorCode } from '../../src/languageservice/jsonLanguageTypes'; export function createExpectedError( diff --git a/test/yaml-documents.test.ts b/test/yaml-documents.test.ts index 2c3a80c9a..465e0d2ac 100644 --- a/test/yaml-documents.test.ts +++ b/test/yaml-documents.test.ts @@ -3,15 +3,17 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import type { Pair, Scalar, YAMLMap, YAMLSeq } from 'yaml'; + +import * as chai from 'chai'; import * as sinon from 'sinon'; import sinonChai from 'sinon-chai'; -import * as chai from 'chai'; -import { YamlDocuments } from '../src/languageservice/parser/yaml-documents'; -import { setupTextDocument } from './utils/testHelper'; -import * as yamlParser from '../src/languageservice/parser/yamlParser07'; import { TextDocument } from 'vscode-languageserver-textdocument'; -import type { Pair, Scalar, YAMLMap, YAMLSeq } from 'yaml'; import { isMap, isScalar, isSeq } from 'yaml'; + +import { setupTextDocument } from './utils/testHelper'; +import { YamlDocuments } from '../src/languageservice/parser/yaml-documents'; +import * as yamlParser from '../src/languageservice/parser/yamlParser07'; import { TextBuffer } from '../src/languageservice/utils/textBuffer'; const expect = chai.expect; diff --git a/test/yamlCodeActions.test.ts b/test/yamlCodeActions.test.ts index 675ac1758..a53aeefea 100644 --- a/test/yamlCodeActions.test.ts +++ b/test/yamlCodeActions.test.ts @@ -3,10 +3,13 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import type { ClientCapabilities, CodeActionParams } from 'vscode-languageserver'; + +import type { LanguageSettings } from '../src'; + +import * as chai from 'chai'; import * as sinon from 'sinon'; import sinonChai from 'sinon-chai'; -import * as chai from 'chai'; -import { YamlCodeActions } from '../src/languageservice/services/yamlCodeActions'; import { CodeAction, CodeActionContext, @@ -18,12 +21,12 @@ import { TextEdit, WorkspaceEdit, } from 'vscode-languageserver-types'; -import type { ClientCapabilities, CodeActionParams } from 'vscode-languageserver'; -import { setupTextDocument, TEST_URI } from './utils/testHelper'; + +import { TEST_URI, setupTextDocument } from './utils/testHelper'; import { createDiagnosticWithData, createExpectedError, createUnusedAnchorDiagnostic } from './utils/verifyError'; import { YamlCommands } from '../src/commands'; -import type { LanguageSettings } from '../src'; import { ErrorCode } from '../src/languageservice/jsonLanguageTypes'; +import { YamlCodeActions } from '../src/languageservice/services/yamlCodeActions'; const expect = chai.expect; chai.use(sinonChai); diff --git a/test/yamlCodeLens.test.ts b/test/yamlCodeLens.test.ts index ce15db85e..fd0098b4e 100644 --- a/test/yamlCodeLens.test.ts +++ b/test/yamlCodeLens.test.ts @@ -2,22 +2,25 @@ * Copyright (c) Red Hat, Inc. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import type { Connection } from 'vscode-languageserver'; +import type { Command } from 'vscode-languageserver-protocol'; + +import type { ValidationHandler } from '../src/languageserver/handlers/validationHandlers'; +import type { JSONSchema } from '../src/languageservice/jsonSchema'; +import type { Telemetry } from '../src/languageservice/telemetry'; +import type { LanguageService } from '../src/languageservice/yamlLanguageService'; + +import * as chai from 'chai'; import * as sinon from 'sinon'; import sinonChai from 'sinon-chai'; -import * as chai from 'chai'; -import { YamlCodeLens } from '../src/languageservice/services/yamlCodeLens'; -import { YAMLSchemaService } from '../src/languageservice/services/yamlSchemaService'; -import { setupTextDocument } from './utils/testHelper'; -import type { JSONSchema } from '../src/languageservice/jsonSchema'; -import type { Command } from 'vscode-languageserver-protocol'; import { CodeLens, Range } from 'vscode-languageserver-protocol'; -import type { Connection } from 'vscode-languageserver'; + +import { setupTextDocument } from './utils/testHelper'; import { YamlCommands } from '../src/commands'; -import { TelemetryImpl } from '../src/languageserver/telemetry'; -import type { Telemetry } from '../src/languageservice/telemetry'; import { LanguageHandlers } from '../src/languageserver/handlers/languageHandlers'; -import type { ValidationHandler } from '../src/languageserver/handlers/validationHandlers'; -import type { LanguageService } from '../src/languageservice/yamlLanguageService'; +import { TelemetryImpl } from '../src/languageserver/telemetry'; +import { YamlCodeLens } from '../src/languageservice/services/yamlCodeLens'; +import { YAMLSchemaService } from '../src/languageservice/services/yamlSchemaService'; import { SettingsState, TextDocumentTestManager } from '../src/yamlSettings'; const expect = chai.expect; diff --git a/test/yamlCommands.test.ts b/test/yamlCommands.test.ts index ee784e0e9..46ee202c8 100644 --- a/test/yamlCommands.test.ts +++ b/test/yamlCommands.test.ts @@ -3,14 +3,16 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import type { Connection } from 'vscode-languageserver'; + +import * as chai from 'chai'; import * as sinon from 'sinon'; import sinonChai from 'sinon-chai'; -import * as chai from 'chai'; -import { registerCommands } from '../src/languageservice/services/yamlCommands'; -import { commandExecutor } from '../src/languageserver/commandExecutor'; -import type { Connection } from 'vscode-languageserver'; import { URI } from 'vscode-uri'; +import { commandExecutor } from '../src/languageserver/commandExecutor'; +import { registerCommands } from '../src/languageservice/services/yamlCommands'; + const expect = chai.expect; chai.use(sinonChai); diff --git a/test/yamlDefinition.test.ts b/test/yamlDefinition.test.ts index 18a7136bb..852766a41 100644 --- a/test/yamlDefinition.test.ts +++ b/test/yamlDefinition.test.ts @@ -3,11 +3,13 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { setupTextDocument, TEST_URI } from './utils/testHelper'; +import type { Telemetry } from '../src/languageservice/telemetry'; + import { expect } from 'chai'; -import { YamlDefinition } from '../src/languageservice/services/yamlDefinition'; import { LocationLink, Position, Range } from 'vscode-languageserver-types'; -import type { Telemetry } from '../src/languageservice/telemetry'; + +import { TEST_URI, setupTextDocument } from './utils/testHelper'; +import { YamlDefinition } from '../src/languageservice/services/yamlDefinition'; describe('YAML Definition', () => { it('should not provide definition for non anchor node', () => { diff --git a/test/yamlFolding.test.ts b/test/yamlFolding.test.ts index fee416a74..ecf0a66a0 100644 --- a/test/yamlFolding.test.ts +++ b/test/yamlFolding.test.ts @@ -3,11 +3,13 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import type { FoldingRangesContext } from '../src/languageservice/yamlTypes'; + import { expect } from 'chai'; import { FoldingRange } from 'vscode-languageserver-types'; + +import { TEST_URI, setupTextDocument } from './utils/testHelper'; import { getFoldingRanges } from '../src/languageservice/services/yamlFolding'; -import type { FoldingRangesContext } from '../src/languageservice/yamlTypes'; -import { setupTextDocument, TEST_URI } from './utils/testHelper'; const context: FoldingRangesContext = { rangeLimit: 10_0000 }; diff --git a/test/yamlLanguageService.test.ts b/test/yamlLanguageService.test.ts index 1e31d8db6..eb9dc51cf 100644 --- a/test/yamlLanguageService.test.ts +++ b/test/yamlLanguageService.test.ts @@ -2,12 +2,15 @@ * Copyright (c) Red Hat, Inc. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { assert } from 'chai'; import type { Position, TextDocument } from 'vscode-languageserver-textdocument'; + import type { LanguageService, SchemaRequestService, WorkspaceContextService } from '../src'; + +import { assert } from 'chai'; + import { getLanguageService } from '../src'; -import { workspaceContext } from '../src/languageservice/services/schemaRequestHandler'; import { caretPosition, setupSchemaIDTextDocument } from './utils/testHelper'; +import { workspaceContext } from '../src/languageservice/services/schemaRequestHandler'; /** * Builds a simple schema request service diff --git a/test/yamlOnTypeFormatting.test.ts b/test/yamlOnTypeFormatting.test.ts index e42ea779e..e042c6769 100644 --- a/test/yamlOnTypeFormatting.test.ts +++ b/test/yamlOnTypeFormatting.test.ts @@ -2,11 +2,13 @@ * Copyright (c) Red Hat, Inc. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { expect } from 'chai'; import type { DocumentOnTypeFormattingParams } from 'vscode-languageserver-protocol'; + +import { expect } from 'chai'; import { FormattingOptions, Position, Range, TextEdit } from 'vscode-languageserver-types'; -import { doDocumentOnTypeFormatting } from '../src/languageservice/services/yamlOnTypeFormatting'; + import { setupTextDocument } from './utils/testHelper'; +import { doDocumentOnTypeFormatting } from '../src/languageservice/services/yamlOnTypeFormatting'; function createParams(position: Position): DocumentOnTypeFormattingParams { return { diff --git a/test/yamlParser.test.ts b/test/yamlParser.test.ts index 940820fc6..cb93c0074 100644 --- a/test/yamlParser.test.ts +++ b/test/yamlParser.test.ts @@ -2,12 +2,15 @@ * Copyright (c) Red Hat. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import assert from 'assert'; -import { expect } from 'chai'; import type { ArrayASTNode, ObjectASTNode, PropertyASTNode } from '../src/languageservice/jsonLanguageTypes'; import type { YAMLDocument } from './../src/languageservice/parser/yamlParser07'; -import { parse } from './../src/languageservice/parser/yamlParser07'; + +import assert from 'assert'; + +import { expect } from 'chai'; + import { aliasDepth } from '../src/languageservice/parser/ast-converter'; +import { parse } from './../src/languageservice/parser/yamlParser07'; describe('YAML parser', () => { describe('YAML parser', function () { diff --git a/test/yamlRename.test.ts b/test/yamlRename.test.ts index 248e1fe2b..e439f7c28 100644 --- a/test/yamlRename.test.ts +++ b/test/yamlRename.test.ts @@ -1,8 +1,10 @@ -import { expect } from 'chai'; +import type { TextDocument } from 'vscode-languageserver-textdocument'; import type { TextEdit } from 'vscode-languageserver-types'; + +import { expect } from 'chai'; import { Position } from 'vscode-languageserver-types'; -import { setupLanguageService, setupTextDocument, TEST_URI } from './utils/testHelper'; -import type { TextDocument } from 'vscode-languageserver-textdocument'; + +import { TEST_URI, setupLanguageService, setupTextDocument } from './utils/testHelper'; function applyEdits(document: TextDocument, edits: TextEdit[]): string { const sorted = [...edits].sort((a, b) => document.offsetAt(b.range.start) - document.offsetAt(a.range.start)); diff --git a/test/yamlSchema.test.ts b/test/yamlSchema.test.ts index 97c9b6e37..0336047d3 100644 --- a/test/yamlSchema.test.ts +++ b/test/yamlSchema.test.ts @@ -2,12 +2,14 @@ * Copyright (c) Red Hat. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as SchemaService from '../src/languageservice/services/yamlSchemaService'; import * as url from 'url'; -import * as sinon from 'sinon'; + import * as chai from 'chai'; +import * as sinon from 'sinon'; import sinonChai from 'sinon-chai'; +import * as SchemaService from '../src/languageservice/services/yamlSchemaService'; + const expect = chai.expect; chai.use(sinonChai); diff --git a/test/yamlSchemaService.test.ts b/test/yamlSchemaService.test.ts index 4909446d3..779e24538 100644 --- a/test/yamlSchemaService.test.ts +++ b/test/yamlSchemaService.test.ts @@ -2,16 +2,19 @@ * Copyright (c) Red Hat. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as sinon from 'sinon'; -import * as chai from 'chai'; -import sinonChai from 'sinon-chai'; +import type { JSONSchema } from '../src/languageservice/jsonSchema'; + import * as path from 'path'; import * as url from 'url'; -import * as SchemaService from '../src/languageservice/services/yamlSchemaService'; + +import * as chai from 'chai'; +import * as sinon from 'sinon'; +import sinonChai from 'sinon-chai'; + import { parse } from '../src/languageservice/parser/yamlParser07'; -import { SettingsState } from '../src/yamlSettings'; +import * as SchemaService from '../src/languageservice/services/yamlSchemaService'; import { DEFAULT_KUBERNETES_SCHEMA_VERSION, getSchemaUrls } from '../src/languageservice/utils/schemaUrls'; -import type { JSONSchema } from '../src/languageservice/jsonSchema'; +import { SettingsState } from '../src/yamlSettings'; const BASE_KUBERNETES_SCHEMA_URL = `https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/${DEFAULT_KUBERNETES_SCHEMA_VERSION}-standalone-strict/`; const KUBERNETES_SCHEMA_URL = BASE_KUBERNETES_SCHEMA_URL + 'all.json'; diff --git a/test/yamlSelectionRanges.test.ts b/test/yamlSelectionRanges.test.ts index 625f82ad8..37e344517 100644 --- a/test/yamlSelectionRanges.test.ts +++ b/test/yamlSelectionRanges.test.ts @@ -1,5 +1,7 @@ -import { expect } from 'chai'; import type { Position, Range, SelectionRange } from 'vscode-languageserver-types'; + +import { expect } from 'chai'; + import { setupTextDocument } from './utils/testHelper'; import { getSelectionRanges } from '../src/languageservice/services/yamlSelectionRanges'; diff --git a/test/yamlValidation.test.ts b/test/yamlValidation.test.ts index fbf710f48..e59327ba8 100644 --- a/test/yamlValidation.test.ts +++ b/test/yamlValidation.test.ts @@ -3,14 +3,17 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import type { Diagnostic } from 'vscode-languageserver-types'; -import { DiagnosticSeverity } from 'vscode-languageserver-types'; + import type { ValidationHandler } from '../src/languageserver/handlers/validationHandlers'; import type { SettingsState } from '../src/yamlSettings'; + +import { expect } from 'chai'; +import * as sinon from 'sinon'; +import { DiagnosticSeverity } from 'vscode-languageserver-types'; + import { TextDocumentTestManager } from '../src/yamlSettings'; import { ServiceSetup } from './utils/serviceSetup'; import { setupLanguageService, setupSchemaIDTextDocument } from './utils/testHelper'; -import { expect } from 'chai'; -import * as sinon from 'sinon'; import { createExpectedError, createUnusedAnchorDiagnostic } from './utils/verifyError'; type ValidationHandlerWithConnection = {