diff --git a/.vscode/launch.json b/.vscode/launch.json index 1b4c56b14..e4f816d53 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,8 @@ "sourceMaps": true, "outFiles": ["${workspaceRoot}/out/server/**/*.ts"], "protocol": "inspector", - "trace": true + "trace": true, + "preLaunchTask": "watch typescript", }, // A launch configuration that compiles the server and runs mocha unit tests { diff --git a/src/languageservice/services/yamlHover.ts b/src/languageservice/services/yamlHover.ts index 8320719a2..9ad870cd6 100644 --- a/src/languageservice/services/yamlHover.ts +++ b/src/languageservice/services/yamlHover.ts @@ -5,7 +5,7 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; -import { Hover, MarkupContent, Position, Range } from 'vscode-languageserver-types'; +import { Hover, MarkupContent, MarkupKind, Position, Range } from 'vscode-languageserver-types'; import { matchOffsetToDocument } from '../utils/arrUtils'; import { LanguageSettings } from '../yamlLanguageService'; import { YAMLSchemaService } from './yamlSchemaService'; @@ -23,6 +23,7 @@ import { ASTNode } from 'vscode-json-languageservice'; export class YAMLHover { private shouldHover: boolean; + private indentation: string; private schemaService: YAMLSchemaService; constructor(schemaService: YAMLSchemaService, private readonly telemetry: Telemetry) { @@ -33,6 +34,7 @@ export class YAMLHover { configure(languageSettings: LanguageSettings): void { if (languageSettings) { this.shouldHover = languageSettings.hover; + this.indentation = languageSettings.indentation; } } @@ -86,9 +88,10 @@ export class YAMLHover { ); const createHover = (contents: string): Hover => { + const regex = new RegExp(this.indentation, 'g'); const markupContent: MarkupContent = { - kind: 'markdown', - value: contents, + kind: MarkupKind.Markdown, + value: contents.replace(regex, ' '), }; const result: Hover = { contents: markupContent, diff --git a/test/hover.test.ts b/test/hover.test.ts index b4293ac6c..e01b90c02 100644 --- a/test/hover.test.ts +++ b/test/hover.test.ts @@ -20,10 +20,13 @@ describe('Hover Tests', () => { let telemetry: TestTelemetry; before(() => { - languageSettingsSetup = new ServiceSetup().withHover().withSchemaFileMatch({ - uri: 'http://google.com', - fileMatch: ['bad-schema.yaml'], - }); + languageSettingsSetup = new ServiceSetup() + .withHover() + .withIndentation(' ') + .withSchemaFileMatch({ + uri: 'http://google.com', + fileMatch: ['bad-schema.yaml'], + }); const { languageService: langService, languageHandler: langHandler, @@ -510,6 +513,28 @@ users: ); }); + it('hover on value and its description has multiline, indentationa and special string', async () => { + //https://github.com/redhat-developer/vscode-yaml/issues/886 + languageService.addSchema(SCHEMA_ID, { + type: 'object', + title: 'Person', + properties: { + firstName: { + type: 'string', + description: 'At the top level my_var is shown properly.\n\n Issue with my_var2\n here my_var3', + }, + }, + }); + const content = 'fi|r|stName: '; // len: 12, pos: 1 + const result = await parseSetup(content); + + assert.strictEqual(MarkupContent.is(result.contents), true); + assert.strictEqual( + (result.contents as MarkupContent).value, + `#### Person\n\nAt the top level my\\_var is shown properly\\.\n\n  Issue with my\\_var2\n\n   here my\\_var3\n\nSource: [${SCHEMA_ID}](file:///${SCHEMA_ID})` + ); + }); + it('Hover works on examples', async () => { languageService.addSchema(SCHEMA_ID, { type: 'object', diff --git a/test/integration.test.ts b/test/integration.test.ts index 3499086aa..e34fe40f3 100644 --- a/test/integration.test.ts +++ b/test/integration.test.ts @@ -22,6 +22,7 @@ describe('Kubernetes Integration Tests', () => { const fileMatch = ['*.yml', '*.yaml']; languageSettingsSetup = new ServiceSetup() .withHover() + .withIndentation(' ') .withValidate() .withCompletion() .withSchemaFileMatch({ @@ -318,8 +319,8 @@ describe('Kubernetes Integration Tests', () => { it('Hover on incomplete kubernetes document', async () => { const content = 'apiVersion: v1\nmetadata:\n name: test\nkind: Deployment\nspec:\n '; const hover = await parseSetup(content, 58); - assert.strictEqual(MarkupContent.is(hover.contents), true); - assert.strictEqual((hover.contents as MarkupContent).value, ''); + assert.strictEqual(MarkupContent.is(hover?.contents), true); + assert.strictEqual((hover?.contents as MarkupContent).value, ''); }); }); }); diff --git a/test/multipleDocuments.test.ts b/test/multipleDocuments.test.ts index 67a3230ac..1e1fd20b9 100644 --- a/test/multipleDocuments.test.ts +++ b/test/multipleDocuments.test.ts @@ -29,6 +29,7 @@ describe('Multiple Documents Validation Tests', () => { const fileMatch = ['*.yml', '*.yaml']; languageSettingsSetup = new ServiceSetup() .withHover() + .withIndentation(' ') .withValidate() .withSchemaFileMatch({ fileMatch,