From 55ffa3ff6176f1b287f31e7408189aace51e09cc Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Wed, 6 Sep 2023 13:45:55 +0200 Subject: [PATCH 1/3] Export Telemetry type This is used by `monaco-yaml`. --- src/languageservice/yamlLanguageService.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/languageservice/yamlLanguageService.ts b/src/languageservice/yamlLanguageService.ts index 6fd1153d..82e809f2 100644 --- a/src/languageservice/yamlLanguageService.ts +++ b/src/languageservice/yamlLanguageService.ts @@ -55,6 +55,8 @@ import { JSONSchemaSelection } from '../languageserver/handlers/schemaSelectionH import { YamlDefinition } from './services/yamlDefinition'; import { getSelectionRanges } from './services/yamlSelectionRanges'; +export { type Telemetry }; + export enum SchemaPriority { SchemaStore = 1, SchemaAssociation = 2, From 8fb05d74dc78678944e2a073a48ea3e329e0030c Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Sat, 7 Oct 2023 18:25:50 +0200 Subject: [PATCH 2/3] Move Telemetry and TelemetryEvent into yamlLanguageService --- .../handlers/settingsHandlers.ts | 3 +-- src/languageserver/telemetry.ts | 2 +- .../services/documentSymbols.ts | 2 +- src/languageservice/services/yamlCodeLens.ts | 2 +- .../services/yamlCompletion.ts | 2 +- .../services/yamlDefinition.ts | 2 +- src/languageservice/services/yamlHover.ts | 3 +-- src/languageservice/services/yamlLinks.ts | 2 +- .../services/yamlValidation.ts | 3 +-- src/languageservice/telemetry.ts | 24 ------------------- src/languageservice/utils/schemaUrls.ts | 2 +- src/languageservice/yamlLanguageService.ts | 21 ++++++++++++++-- src/yamlServerInit.ts | 2 +- test/settingsHandlers.test.ts | 2 +- test/utils/testsTypes.ts | 2 +- test/yamlCodeLens.test.ts | 2 +- test/yamlDefinition.test.ts | 2 +- 17 files changed, 34 insertions(+), 44 deletions(-) delete mode 100644 src/languageservice/telemetry.ts diff --git a/src/languageserver/handlers/settingsHandlers.ts b/src/languageserver/handlers/settingsHandlers.ts index 95ddba77..a15da6f7 100644 --- a/src/languageserver/handlers/settingsHandlers.ts +++ b/src/languageserver/handlers/settingsHandlers.ts @@ -7,10 +7,9 @@ import { Connection, DidChangeConfigurationNotification, DocumentFormattingReque import { convertErrorToTelemetryMsg } from '../../languageservice/utils/objects'; import { isRelativePath, relativeToAbsolutePath } from '../../languageservice/utils/paths'; import { checkSchemaURI, JSON_SCHEMASTORE_URL, KUBERNETES_SCHEMA_URL } from '../../languageservice/utils/schemaUrls'; -import { LanguageService, LanguageSettings, SchemaPriority } from '../../languageservice/yamlLanguageService'; +import { LanguageService, LanguageSettings, SchemaPriority, Telemetry } from '../../languageservice/yamlLanguageService'; import { SchemaSelectionRequests } from '../../requestTypes'; import { Settings, SettingsState } from '../../yamlSettings'; -import { Telemetry } from '../../languageservice/telemetry'; import { ValidationHandler } from './validationHandlers'; export class SettingsHandler { diff --git a/src/languageserver/telemetry.ts b/src/languageserver/telemetry.ts index b18979ff..c69650ae 100644 --- a/src/languageserver/telemetry.ts +++ b/src/languageserver/telemetry.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { Connection } from 'vscode-languageserver'; -import { TelemetryEvent, Telemetry } from '../languageservice/telemetry'; +import { TelemetryEvent, Telemetry } from '../languageservice/yamlLanguageService'; export class TelemetryImpl implements Telemetry { constructor(private readonly connection: Connection) {} diff --git a/src/languageservice/services/documentSymbols.ts b/src/languageservice/services/documentSymbols.ts index 6aa631d6..940bfda7 100644 --- a/src/languageservice/services/documentSymbols.ts +++ b/src/languageservice/services/documentSymbols.ts @@ -11,7 +11,7 @@ import { JSONDocumentSymbols } from 'vscode-json-languageservice/lib/umd/service import { DocumentSymbolsContext } from 'vscode-json-languageservice/lib/umd/jsonLanguageTypes'; import { TextDocument } from 'vscode-languageserver-textdocument'; import { yamlDocumentsCache } from '../parser/yaml-documents'; -import { Telemetry } from '../telemetry'; +import { Telemetry } from '../yamlLanguageService'; import { isMap, isSeq, Node } from 'yaml'; import { convertErrorToTelemetryMsg } from '../utils/objects'; diff --git a/src/languageservice/services/yamlCodeLens.ts b/src/languageservice/services/yamlCodeLens.ts index 7157ccf8..1ece64e6 100644 --- a/src/languageservice/services/yamlCodeLens.ts +++ b/src/languageservice/services/yamlCodeLens.ts @@ -9,7 +9,7 @@ import { YamlCommands } from '../../commands'; import { yamlDocumentsCache } from '../parser/yaml-documents'; import { YAMLSchemaService } from './yamlSchemaService'; import { JSONSchema } from '../jsonSchema'; -import { Telemetry } from '../telemetry'; +import { Telemetry } from '../yamlLanguageService'; import { getSchemaUrls } from '../utils/schemaUrls'; import { convertErrorToTelemetryMsg } from '../utils/objects'; import { getSchemaTitle } from '../utils/schemaUtils'; diff --git a/src/languageservice/services/yamlCompletion.ts b/src/languageservice/services/yamlCompletion.ts index 99e061f0..bc04b4bd 100644 --- a/src/languageservice/services/yamlCompletion.ts +++ b/src/languageservice/services/yamlCompletion.ts @@ -18,7 +18,7 @@ import { TextEdit, } from 'vscode-languageserver-types'; import { Node, isPair, isScalar, isMap, YAMLMap, isSeq, YAMLSeq, isNode, Pair } from 'yaml'; -import { Telemetry } from '../telemetry'; +import { Telemetry } from '../yamlLanguageService'; import { SingleYAMLDocument, YamlDocuments } from '../parser/yaml-documents'; import { YamlVersion } from '../parser/yamlParser07'; import { filterInvalidCustomTags, matchOffsetToDocument } from '../utils/arrUtils'; diff --git a/src/languageservice/services/yamlDefinition.ts b/src/languageservice/services/yamlDefinition.ts index b2f1b975..ca469da9 100644 --- a/src/languageservice/services/yamlDefinition.ts +++ b/src/languageservice/services/yamlDefinition.ts @@ -7,7 +7,7 @@ import { DefinitionParams } from 'vscode-languageserver-protocol'; import { TextDocument } from 'vscode-languageserver-textdocument'; import { DefinitionLink, LocationLink, Range } from 'vscode-languageserver-types'; import { isAlias } from 'yaml'; -import { Telemetry } from '../telemetry'; +import { Telemetry } from '../yamlLanguageService'; import { yamlDocumentsCache } from '../parser/yaml-documents'; import { matchOffsetToDocument } from '../utils/arrUtils'; import { convertErrorToTelemetryMsg } from '../utils/objects'; diff --git a/src/languageservice/services/yamlHover.ts b/src/languageservice/services/yamlHover.ts index 3e7cc8a5..6ee59e10 100644 --- a/src/languageservice/services/yamlHover.ts +++ b/src/languageservice/services/yamlHover.ts @@ -7,7 +7,7 @@ import { Hover, MarkupContent, MarkupKind, Position, Range } from 'vscode-languageserver-types'; import { matchOffsetToDocument } from '../utils/arrUtils'; -import { LanguageSettings } from '../yamlLanguageService'; +import { LanguageSettings, Telemetry } from '../yamlLanguageService'; import { YAMLSchemaService } from './yamlSchemaService'; import { setKubernetesParserOption } from '../parser/isKubernetes'; import { TextDocument } from 'vscode-languageserver-textdocument'; @@ -17,7 +17,6 @@ import { getNodeValue, IApplicableSchema } from '../parser/jsonParser07'; import { JSONSchema } from '../jsonSchema'; import { URI } from 'vscode-uri'; import * as path from 'path'; -import { Telemetry } from '../telemetry'; import { convertErrorToTelemetryMsg } from '../utils/objects'; import { ASTNode } from 'vscode-json-languageservice'; diff --git a/src/languageservice/services/yamlLinks.ts b/src/languageservice/services/yamlLinks.ts index fe22e455..5175895a 100644 --- a/src/languageservice/services/yamlLinks.ts +++ b/src/languageservice/services/yamlLinks.ts @@ -5,7 +5,7 @@ import { findLinks as JSONFindLinks } from 'vscode-json-languageservice/lib/umd/services/jsonLinks'; import { DocumentLink } from 'vscode-languageserver-types'; import { TextDocument } from 'vscode-languageserver-textdocument'; -import { Telemetry } from '../telemetry'; +import { Telemetry } from '../yamlLanguageService'; import { yamlDocumentsCache } from '../parser/yaml-documents'; import { convertErrorToTelemetryMsg } from '../utils/objects'; diff --git a/src/languageservice/services/yamlValidation.ts b/src/languageservice/services/yamlValidation.ts index 8ba3f023..64deb40c 100644 --- a/src/languageservice/services/yamlValidation.ts +++ b/src/languageservice/services/yamlValidation.ts @@ -6,7 +6,7 @@ 'use strict'; import { Diagnostic, Position } from 'vscode-languageserver-types'; -import { LanguageSettings } from '../yamlLanguageService'; +import { LanguageSettings, Telemetry } from '../yamlLanguageService'; import { YAMLDocument, YamlVersion, SingleYAMLDocument } from '../parser/yamlParser07'; import { YAMLSchemaService } from './yamlSchemaService'; import { YAMLDocDiagnostic } from '../utils/parseUtils'; @@ -16,7 +16,6 @@ import { YAML_SOURCE } from '../parser/jsonParser07'; import { TextBuffer } from '../utils/textBuffer'; import { yamlDocumentsCache } from '../parser/yaml-documents'; import { convertErrorToTelemetryMsg } from '../utils/objects'; -import { Telemetry } from '../telemetry'; import { AdditionalValidator } from './validation/types'; import { UnusedAnchorsValidator } from './validation/unused-anchors'; import { YAMLStyleValidator } from './validation/yaml-style'; diff --git a/src/languageservice/telemetry.ts b/src/languageservice/telemetry.ts deleted file mode 100644 index c5c71426..00000000 --- a/src/languageservice/telemetry.ts +++ /dev/null @@ -1,24 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Red Hat, Inc. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -/** - * Due to LSP limitation this object must be JSON serializable - */ -export interface TelemetryEvent { - name: string; - type?: string; - properties?: unknown; - measures?: unknown; - traits?: unknown; - context?: unknown; -} - -export interface Telemetry { - send(event: TelemetryEvent): void; - - sendError(name: string, properties: unknown): void; - - sendTrack(name: string, properties: unknown): void; -} diff --git a/src/languageservice/utils/schemaUrls.ts b/src/languageservice/utils/schemaUrls.ts index ff474e10..63b5ad85 100644 --- a/src/languageservice/utils/schemaUrls.ts +++ b/src/languageservice/utils/schemaUrls.ts @@ -1,6 +1,6 @@ import { WorkspaceFolder } from 'vscode-languageserver-protocol'; import { URI } from 'vscode-uri'; -import { Telemetry } from '../telemetry'; +import { Telemetry } from '../yamlLanguageService'; import { JSONSchema, JSONSchemaRef } from '../jsonSchema'; import { isBoolean } from './objects'; import { isRelativePath, relativeToAbsolutePath } from './paths'; diff --git a/src/languageservice/yamlLanguageService.ts b/src/languageservice/yamlLanguageService.ts index 82e809f2..a5b70b33 100644 --- a/src/languageservice/yamlLanguageService.ts +++ b/src/languageservice/yamlLanguageService.ts @@ -46,7 +46,6 @@ import { FoldingRangesContext, SchemaVersions } from './yamlTypes'; import { YamlCodeActions } from './services/yamlCodeActions'; import { doDocumentOnTypeFormatting } from './services/yamlOnTypeFormatting'; import { YamlCodeLens } from './services/yamlCodeLens'; -import { Telemetry } from './telemetry'; import { YamlVersion } from './parser/yamlParser07'; import { YamlCompletion } from './services/yamlCompletion'; import { yamlDocumentsCache } from './parser/yaml-documents'; @@ -55,7 +54,25 @@ import { JSONSchemaSelection } from '../languageserver/handlers/schemaSelectionH import { YamlDefinition } from './services/yamlDefinition'; import { getSelectionRanges } from './services/yamlSelectionRanges'; -export { type Telemetry }; +/** + * Due to LSP limitation this object must be JSON serializable + */ +export interface TelemetryEvent { + name: string; + type?: string; + properties?: unknown; + measures?: unknown; + traits?: unknown; + context?: unknown; +} + +export interface Telemetry { + send(event: TelemetryEvent): void; + + sendError(name: string, properties: unknown): void; + + sendTrack(name: string, properties: unknown): void; +} export enum SchemaPriority { SchemaStore = 1, diff --git a/src/yamlServerInit.ts b/src/yamlServerInit.ts index 9640e48d..92cc7256 100644 --- a/src/yamlServerInit.ts +++ b/src/yamlServerInit.ts @@ -4,6 +4,7 @@ import { LanguageService, SchemaRequestService, WorkspaceContextService, + Telemetry, } from './languageservice/yamlLanguageService'; import { workspaceFoldersChanged } from './languageservice/utils/paths'; import { URI } from 'vscode-uri'; @@ -16,7 +17,6 @@ import { SettingsHandler } from './languageserver/handlers/settingsHandlers'; import { YamlCommands } from './commands'; import { WorkspaceHandlers } from './languageserver/handlers/workspaceHandlers'; import { commandExecutor } from './languageserver/commandExecutor'; -import { Telemetry } from './languageservice/telemetry'; import { registerCommands } from './languageservice/services/yamlCommands'; export class YAMLServerInit { diff --git a/test/settingsHandlers.test.ts b/test/settingsHandlers.test.ts index 1438aad3..31e9f483 100644 --- a/test/settingsHandlers.test.ts +++ b/test/settingsHandlers.test.ts @@ -11,7 +11,7 @@ import { Connection, RemoteClient, RemoteWorkspace } from 'vscode-languageserver import { LanguageService, LanguageSettings, SchemaConfiguration, SchemaPriority } from '../src'; import { SettingsHandler } from '../src/languageserver/handlers/settingsHandlers'; import { ValidationHandler } from '../src/languageserver/handlers/validationHandlers'; -import { Telemetry } from '../src/languageservice/telemetry'; +import { Telemetry } from '../src/languageservice/yamlLanguageService'; import { SettingsState } from '../src/yamlSettings'; import { setupLanguageService } from './utils/testHelper'; import { TestWorkspace } from './utils/testsTypes'; diff --git a/test/utils/testsTypes.ts b/test/utils/testsTypes.ts index 6dbd78bd..3a33b47b 100644 --- a/test/utils/testsTypes.ts +++ b/test/utils/testsTypes.ts @@ -17,7 +17,7 @@ import { } from 'vscode-languageserver-protocol'; import { Connection, RemoteWorkspace } from 'vscode-languageserver'; import { TelemetryImpl } from '../../src/languageserver/telemetry'; -import { TelemetryEvent } from '../../src/languageservice/telemetry'; +import { TelemetryEvent } from '../../src/languageservice/yamlLanguageService'; /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-unused-vars */ diff --git a/test/yamlCodeLens.test.ts b/test/yamlCodeLens.test.ts index 9619ad51..4a013946 100644 --- a/test/yamlCodeLens.test.ts +++ b/test/yamlCodeLens.test.ts @@ -12,7 +12,7 @@ import { JSONSchema } from '../src/languageservice/jsonSchema'; import { CodeLens, Command, Range } from 'vscode-languageserver-protocol'; import { YamlCommands } from '../src/commands'; import { TelemetryImpl } from '../src/languageserver/telemetry'; -import { Telemetry } from '../src/languageservice/telemetry'; +import { Telemetry } from '../src/languageservice/yamlLanguageService'; const expect = chai.expect; chai.use(sinonChai); diff --git a/test/yamlDefinition.test.ts b/test/yamlDefinition.test.ts index 9a80dca8..59c83f0e 100644 --- a/test/yamlDefinition.test.ts +++ b/test/yamlDefinition.test.ts @@ -7,7 +7,7 @@ import { setupTextDocument, TEST_URI } from './utils/testHelper'; import { expect } from 'chai'; import { YamlDefinition } from '../src/languageservice/services/yamlDefinition'; import { LocationLink, Position, Range } from 'vscode-languageserver-types'; -import { Telemetry } from '../src/languageservice/telemetry'; +import { Telemetry } from '../src/languageservice/yamlLanguageService'; describe('YAML Definition', () => { it('should not provide definition for non anchor node', () => { From 17f6c23d68832fe1d0f4062048379e8eec336c23 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Sat, 7 Oct 2023 18:29:28 +0200 Subject: [PATCH 3/3] Fix ESLint issue --- src/languageservice/services/yamlCompletion.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/languageservice/services/yamlCompletion.ts b/src/languageservice/services/yamlCompletion.ts index bc04b4bd..5ede1d94 100644 --- a/src/languageservice/services/yamlCompletion.ts +++ b/src/languageservice/services/yamlCompletion.ts @@ -18,13 +18,12 @@ import { TextEdit, } from 'vscode-languageserver-types'; import { Node, isPair, isScalar, isMap, YAMLMap, isSeq, YAMLSeq, isNode, Pair } from 'yaml'; -import { Telemetry } from '../yamlLanguageService'; +import { Telemetry, LanguageSettings } from '../yamlLanguageService'; import { SingleYAMLDocument, YamlDocuments } from '../parser/yaml-documents'; import { YamlVersion } from '../parser/yamlParser07'; import { filterInvalidCustomTags, matchOffsetToDocument } from '../utils/arrUtils'; import { guessIndentation } from '../utils/indentationGuesser'; import { TextBuffer } from '../utils/textBuffer'; -import { LanguageSettings } from '../yamlLanguageService'; import { YAMLSchemaService } from './yamlSchemaService'; import { ResolvedSchema } from 'vscode-json-languageservice/lib/umd/services/jsonSchemaService'; import { JSONSchema, JSONSchemaRef } from '../jsonSchema';