Skip to content

Commit

Permalink
Merge branch 'main' into export-telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
msivasubramaniaan authored Dec 19, 2023
2 parents 17f6c23 + d354c58 commit 4212cc9
Show file tree
Hide file tree
Showing 19 changed files with 118 additions and 74 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@ This repository only contains the server implementation. Here are some known cli

- [Eclipse Che](https://www.eclipse.org/che/)
- [vscode-yaml](https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml) for VSCode
- [ide-yaml](https://atom.io/packages/ide-yaml) for Atom editor
- [coc-yaml](https://github.com/neoclide/coc-yaml) for [coc.nvim](https://github.com/neoclide/coc.nvim)
- [Eclipse Wild Web Developer](https://marketplace.eclipse.org/content/eclipse-wild-web-developer-web-development-eclipse-ide) for Eclipse IDE
- [lsp-mode](https://github.com/emacs-lsp/lsp-mode) for Emacs
Expand All @@ -388,6 +387,7 @@ This repository only contains the server implementation. Here are some known cli
- [monaco-yaml](https://monaco-yaml.js.org) for Monaco editor
- [Vim-EasyComplete](https://github.com/jayli/vim-easycomplete) for Vim/NeoVim
- [nova-yaml](https://github.com/robb-j/nova-yaml/) for Nova
- [volar-service-yaml](https://github.com/volarjs/services/tree/master/packages/yaml) for Volar

## Developer Support

Expand Down
4 changes: 2 additions & 2 deletions src/languageserver/handlers/languageHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,15 @@ export class LanguageHandlers {
return this.languageService.getCodeAction(textDocument, params);
}

codeLensHandler(params: CodeLensParams): Thenable<CodeLens[] | undefined> | CodeLens[] | undefined {
codeLensHandler(params: CodeLensParams): PromiseLike<CodeLens[] | undefined> | CodeLens[] | undefined {
const textDocument = this.yamlSettings.documents.get(params.textDocument.uri);
if (!textDocument) {
return;
}
return this.languageService.getCodeLens(textDocument);
}

codeLensResolveHandler(param: CodeLens): Thenable<CodeLens> | CodeLens {
codeLensResolveHandler(param: CodeLens): PromiseLike<CodeLens> | CodeLens {
return this.languageService.resolveCodeLens(param);
}

Expand Down
2 changes: 1 addition & 1 deletion src/languageservice/parser/jsonParser07.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ export class ValidationResult {
(problemType !== ProblemType.missingRequiredPropWarning || isArrayEqual(p.problemArgs, bestResult.problemArgs)) // missingProp is merged only with same problemArg
);
if (mergingResult) {
if (mergingResult.problemArgs.length) {
if (mergingResult.problemArgs?.length) {
mergingResult.problemArgs
.filter((p) => !bestResult.problemArgs.includes(p))
.forEach((p) => bestResult.problemArgs.push(p));
Expand Down
1 change: 0 additions & 1 deletion src/languageservice/parser/yamlParser07.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Copyright (c) Adam Voss. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';

import { Parser, Composer, Document, LineCounter, ParseOptions, DocumentOptions, SchemaOptions } from 'yaml';
import { YAMLDocument, SingleYAMLDocument } from './yaml-documents';
Expand Down
1 change: 0 additions & 1 deletion src/languageservice/services/documentSymbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';

import { SymbolInformation, DocumentSymbol } from 'vscode-languageserver-types';
import { YAMLSchemaService } from './yamlSchemaService';
Expand Down
2 changes: 1 addition & 1 deletion src/languageservice/services/modelineUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';

import { SingleYAMLDocument } from '../parser/yamlParser07';
import { JSONDocument } from '../parser/jsonParser07';

Expand Down
2 changes: 1 addition & 1 deletion src/languageservice/services/yamlCodeLens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class YamlCodeLens {

return result;
}
resolveCodeLens(param: CodeLens): Thenable<CodeLens> | CodeLens {
resolveCodeLens(param: CodeLens): PromiseLike<CodeLens> | CodeLens {
return param;
}
}
3 changes: 1 addition & 2 deletions src/languageservice/services/yamlFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Copyright (c) Adam Voss. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';

import { Range, Position, TextEdit, FormattingOptions } from 'vscode-languageserver-types';
import { CustomFormatterOptions, LanguageSettings } from '../yamlLanguageService';
Expand All @@ -21,7 +20,7 @@ export class YAMLFormatter {
}
}

public format(document: TextDocument, options: FormattingOptions & CustomFormatterOptions): TextEdit[] {
public format(document: TextDocument, options: Partial<FormattingOptions> & CustomFormatterOptions = {}): TextEdit[] {
if (!this.formatterEnabled) {
return [];
}
Expand Down
68 changes: 44 additions & 24 deletions src/languageservice/services/yamlHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';

import { Hover, MarkupContent, MarkupKind, Position, Range } from 'vscode-languageserver-types';
import { matchOffsetToDocument } from '../utils/arrUtils';
Expand All @@ -13,7 +12,7 @@ import { setKubernetesParserOption } from '../parser/isKubernetes';
import { TextDocument } from 'vscode-languageserver-textdocument';
import { yamlDocumentsCache } from '../parser/yaml-documents';
import { SingleYAMLDocument } from '../parser/yamlParser07';
import { getNodeValue, IApplicableSchema } from '../parser/jsonParser07';
import { IApplicableSchema } from '../parser/jsonParser07';
import { JSONSchema } from '../jsonSchema';
import { URI } from 'vscode-uri';
import * as path from 'path';
Expand Down Expand Up @@ -113,27 +112,31 @@ export class YAMLHover {

let title: string | undefined = undefined;
let markdownDescription: string | undefined = undefined;
let markdownEnumValueDescription: string | undefined = undefined;
let enumValue: string | undefined = undefined;
let markdownEnumDescriptions: string[] = [];
const markdownExamples: string[] = [];
const markdownEnums: markdownEnum[] = [];

matchingSchemas.every((s) => {
if ((s.node === node || (node.type === 'property' && node.valueNode === s.node)) && !s.inverted && s.schema) {
title = title || s.schema.title || s.schema.closestTitle;
markdownDescription = markdownDescription || s.schema.markdownDescription || toMarkdown(s.schema.description);
if (s.schema.enum) {
const idx = s.schema.enum.indexOf(getNodeValue(node));
if (s.schema.markdownEnumDescriptions) {
markdownEnumValueDescription = s.schema.markdownEnumDescriptions[idx];
markdownEnumDescriptions = s.schema.markdownEnumDescriptions;
} else if (s.schema.enumDescriptions) {
markdownEnumValueDescription = toMarkdown(s.schema.enumDescriptions[idx]);
markdownEnumDescriptions = s.schema.enumDescriptions.map(toMarkdown);
} else {
markdownEnumDescriptions = [];
}
if (markdownEnumValueDescription) {
enumValue = s.schema.enum[idx];
s.schema.enum.forEach((enumValue, idx) => {
if (typeof enumValue !== 'string') {
enumValue = JSON.stringify(enumValue);
}
}
markdownEnums.push({
value: enumValue,
description: markdownEnumDescriptions[idx],
});
});
}
if (s.schema.anyOf && isAllSchemasMatched(node, matchingSchemas, s.schema)) {
//if append title and description of all matched schemas on hover
Expand Down Expand Up @@ -163,28 +166,30 @@ export class YAMLHover {
result = '#### ' + toMarkdown(title);
}
if (markdownDescription) {
if (result.length > 0) {
result += '\n\n';
}
result = ensureLineBreak(result);
result += markdownDescription;
}
if (markdownEnumValueDescription) {
if (result.length > 0) {
result += '\n\n';
}
result += `\`${toMarkdownCodeBlock(enumValue)}\`: ${markdownEnumValueDescription}`;
if (markdownEnums.length !== 0) {
result = ensureLineBreak(result);
result += 'Allowed Values:\n\n';
markdownEnums.forEach((me) => {
if (me.description) {
result += `* \`${toMarkdownCodeBlock(me.value)}\`: ${me.description}\n`;
} else {
result += `* \`${toMarkdownCodeBlock(me.value)}\`\n`;
}
});
}
if (markdownExamples.length !== 0) {
if (result.length > 0) {
result += '\n\n';
}
result += 'Examples:';
result = ensureLineBreak(result);
result += 'Examples:\n\n';
markdownExamples.forEach((example) => {
result += `\n\n\`\`\`${example}\`\`\``;
result += `* \`\`\`${example}\`\`\`\n`;
});
}
if (result.length > 0 && schema.schema.url) {
result += `\n\nSource: [${getSchemaName(schema.schema)}](${schema.schema.url})`;
result = ensureLineBreak(result);
result += `Source: [${getSchemaName(schema.schema)}](${schema.schema.url})`;
}
return createHover(result);
}
Expand All @@ -193,6 +198,21 @@ export class YAMLHover {
}
}

interface markdownEnum {
value: string;
description: string;
}

function ensureLineBreak(content: string): string {
if (content.length === 0) {
return content;
}
if (!content.endsWith('\n')) {
content += '\n';
}
return content + '\n';
}

function getSchemaName(schema: JSONSchema): string {
let result = 'JSON Schema';
const urlString = schema.url;
Expand Down
13 changes: 6 additions & 7 deletions src/languageservice/services/yamlSchemaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';

import { JSONSchema, JSONSchemaMap, JSONSchemaRef } from '../jsonSchema';
import { SchemaPriority, SchemaRequestService, WorkspaceContextService } from '../yamlLanguageService';
Expand Down Expand Up @@ -242,7 +241,7 @@ export class YAMLSchemaService extends JSONSchemaService {
}

const toWalk: JSONSchema[] = [node];
const seen: JSONSchema[] = [];
const seen: Set<JSONSchema> = new Set();

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const openPromises: Promise<any>[] = [];
Expand Down Expand Up @@ -278,7 +277,7 @@ export class YAMLSchemaService extends JSONSchemaService {
}
};
const handleRef = (next: JSONSchema): void => {
const seenRefs = [];
const seenRefs = new Set();
while (next.$ref) {
const ref = next.$ref;
const segments = ref.split('#', 2);
Expand All @@ -289,9 +288,9 @@ export class YAMLSchemaService extends JSONSchemaService {
openPromises.push(resolveExternalLink(next, segments[0], segments[1], parentSchemaURL, parentSchemaDependencies));
return;
} else {
if (seenRefs.indexOf(ref) === -1) {
if (!seenRefs.has(ref)) {
merge(next, parentSchema, parentSchemaURL, segments[1]); // can set next.$ref again, use seenRefs to avoid circle
seenRefs.push(ref);
seenRefs.add(ref);
}
}
}
Expand Down Expand Up @@ -330,10 +329,10 @@ export class YAMLSchemaService extends JSONSchemaService {

while (toWalk.length) {
const next = toWalk.pop();
if (seen.indexOf(next) >= 0) {
if (seen.has(next)) {
continue;
}
seen.push(next);
seen.add(next);
handleRef(next);
}
return Promise.all(openPromises);
Expand Down
1 change: 0 additions & 1 deletion src/languageservice/services/yamlValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';

import { Diagnostic, Position } from 'vscode-languageserver-types';
import { LanguageSettings, Telemetry } from '../yamlLanguageService';
Expand Down
1 change: 0 additions & 1 deletion src/languageservice/utils/documentPositionCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';

import { Position } from 'vscode-languageserver-types';

Expand Down
1 change: 0 additions & 1 deletion src/languageservice/utils/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';

// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
export function equals(one: any, other: any): boolean {
Expand Down
1 change: 0 additions & 1 deletion src/languageservice/utils/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';

import { CharCode } from './charCode';

Expand Down
44 changes: 22 additions & 22 deletions src/languageservice/yamlLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,28 +176,28 @@ export interface CustomFormatterOptions {
}

export interface LanguageService {
configure(settings: LanguageSettings): void;
registerCustomSchemaProvider(schemaProvider: CustomSchemaProvider): void;
doComplete(document: TextDocument, position: Position, isKubernetes: boolean): Promise<CompletionList>;
doValidation(document: TextDocument, isKubernetes: boolean): Promise<Diagnostic[]>;
doHover(document: TextDocument, position: Position): Promise<Hover | null>;
findDocumentSymbols(document: TextDocument, context: DocumentSymbolsContext): SymbolInformation[];
findDocumentSymbols2(document: TextDocument, context: DocumentSymbolsContext): DocumentSymbol[];
findLinks(document: TextDocument): Promise<DocumentLink[]>;
resetSchema(uri: string): boolean;
doFormat(document: TextDocument, options: CustomFormatterOptions): TextEdit[];
doDefinition(document: TextDocument, params: DefinitionParams): DefinitionLink[] | undefined;
doDocumentOnTypeFormatting(document: TextDocument, params: DocumentOnTypeFormattingParams): TextEdit[] | undefined;
addSchema(schemaID: string, schema: JSONSchema): void;
deleteSchema(schemaID: string): void;
modifySchemaContent(schemaAdditions: SchemaAdditions): void;
deleteSchemaContent(schemaDeletions: SchemaDeletions): void;
deleteSchemasWhole(schemaDeletions: SchemaDeletionsAll): void;
getFoldingRanges(document: TextDocument, context: FoldingRangesContext): FoldingRange[] | null;
getSelectionRanges(document: TextDocument, positions: Position[]): SelectionRange[] | undefined;
getCodeAction(document: TextDocument, params: CodeActionParams): CodeAction[] | undefined;
getCodeLens(document: TextDocument): Thenable<CodeLens[] | undefined> | CodeLens[] | undefined;
resolveCodeLens(param: CodeLens): Thenable<CodeLens> | CodeLens;
configure: (settings: LanguageSettings) => void;
registerCustomSchemaProvider: (schemaProvider: CustomSchemaProvider) => void;
doComplete: (document: TextDocument, position: Position, isKubernetes: boolean) => Promise<CompletionList>;
doValidation: (document: TextDocument, isKubernetes: boolean) => Promise<Diagnostic[]>;
doHover: (document: TextDocument, position: Position) => Promise<Hover | null>;
findDocumentSymbols: (document: TextDocument, context?: DocumentSymbolsContext) => SymbolInformation[];
findDocumentSymbols2: (document: TextDocument, context?: DocumentSymbolsContext) => DocumentSymbol[];
findLinks: (document: TextDocument) => Promise<DocumentLink[]>;
resetSchema: (uri: string) => boolean;
doFormat: (document: TextDocument, options?: CustomFormatterOptions) => TextEdit[];
doDefinition: (document: TextDocument, params: DefinitionParams) => DefinitionLink[] | undefined;
doDocumentOnTypeFormatting: (document: TextDocument, params: DocumentOnTypeFormattingParams) => TextEdit[] | undefined;
addSchema: (schemaID: string, schema: JSONSchema) => void;
deleteSchema: (schemaID: string) => void;
modifySchemaContent: (schemaAdditions: SchemaAdditions) => void;
deleteSchemaContent: (schemaDeletions: SchemaDeletions) => void;
deleteSchemasWhole: (schemaDeletions: SchemaDeletionsAll) => void;
getFoldingRanges: (document: TextDocument, context: FoldingRangesContext) => FoldingRange[] | null;
getSelectionRanges: (document: TextDocument, positions: Position[]) => SelectionRange[] | undefined;
getCodeAction: (document: TextDocument, params: CodeActionParams) => CodeAction[] | undefined;
getCodeLens: (document: TextDocument) => PromiseLike<CodeLens[] | undefined> | CodeLens[] | undefined;
resolveCodeLens: (param: CodeLens) => PromiseLike<CodeLens> | CodeLens;
}

export function getLanguageService(params: {
Expand Down
1 change: 0 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';

import { createConnection, Connection, ProposedFeatures } from 'vscode-languageserver/node';
import * as nls from 'vscode-nls';
Expand Down
2 changes: 1 addition & 1 deletion src/yamlSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export interface JSONSchemaSettings {
export class SettingsState {
yamlConfigurationSettings: JSONSchemaSettings[] = undefined;
schemaAssociations: ISchemaAssociations | SchemaConfiguration[] | undefined = undefined;
formatterRegistration: Thenable<Disposable> = null;
formatterRegistration: PromiseLike<Disposable> = null;
specificValidatorPaths = [];
schemaConfigurationSettings = [];
yamlShouldValidate = true;
Expand Down
Loading

0 comments on commit 4212cc9

Please sign in to comment.