diff --git a/src/languageservice/services/yamlHover.ts b/src/languageservice/services/yamlHover.ts index 9ca9ecb8a..18276d166 100644 --- a/src/languageservice/services/yamlHover.ts +++ b/src/languageservice/services/yamlHover.ts @@ -13,23 +13,32 @@ import {PromiseConstructor, Thenable} from 'vscode-json-languageservice'; import {Hover, TextDocument, Position, Range, MarkedString} from 'vscode-languageserver-types'; import { matchOffsetToDocument } from '../utils/arrUtils'; +import { LanguageSettings } from '../yamlLanguageService'; export class YAMLHover { private schemaService: SchemaService.IJSONSchemaService; private contributions: JSONWorkerContribution[]; private promise: PromiseConstructor; + private shouldHover: boolean; constructor(schemaService: SchemaService.IJSONSchemaService, contributions: JSONWorkerContribution[] = [], promiseConstructor: PromiseConstructor) { this.schemaService = schemaService; this.contributions = contributions; this.promise = promiseConstructor || Promise; + this.shouldHover = true; + } + + public configure(languageSettings: LanguageSettings){ + if(languageSettings){ + this.shouldHover = languageSettings.hover; + } } public doHover(document: TextDocument, position: Position, doc): Thenable { - if(!document){ - this.promise.resolve(void 0); + if(!this.shouldHover || !document){ + return this.promise.resolve(void 0); } let offset = document.offsetAt(position); diff --git a/src/languageservice/yamlLanguageService.ts b/src/languageservice/yamlLanguageService.ts index e565c8884..c082690b6 100644 --- a/src/languageservice/yamlLanguageService.ts +++ b/src/languageservice/yamlLanguageService.ts @@ -15,6 +15,7 @@ import { format } from './services/yamlFormatter'; export interface LanguageSettings { validate?: boolean; //Setting for whether we want to validate the schema + hover?: boolean; //Setting for whether we want to have hover results isKubernetes?: boolean; //If true then its validating against kubernetes schemas?: any[]; //List of schemas, customTags?: Array; //Array of Custom Tags @@ -120,6 +121,7 @@ export function getLanguageService(schemaRequestService, workspaceContext, contr }); } yamlValidation.configure(settings); + hover.configure(settings); let customTagsSetting = settings && settings["customTags"] ? settings["customTags"] : []; completer.configure(customTagsSetting); }, diff --git a/src/server.ts b/src/server.ts index fe686144f..8f17aa634 100755 --- a/src/server.ts +++ b/src/server.ts @@ -176,6 +176,7 @@ interface Settings { format: { enable: boolean; }; schemas: JSONSchemaSettings[]; validate: boolean; + hover: boolean; customTags: Array; }; http: { @@ -196,6 +197,7 @@ let formatterRegistration: Thenable = null; let specificValidatorPaths = []; let schemaConfigurationSettings = []; let yamlShouldValidate = true; +let yamlShouldHover = true; let schemaStoreSettings = []; let customTags = []; @@ -206,6 +208,7 @@ connection.onDidChangeConfiguration((change) => { specificValidatorPaths = []; yamlConfigurationSettings = settings.yaml && settings.yaml.schemas; yamlShouldValidate = settings.yaml && settings.yaml.validate; + yamlShouldHover = settings.yaml && settings.yaml.hover; schemaConfigurationSettings = []; customTags = settings.yaml && settings.yaml.customTags ? settings.yaml.customTags : []; @@ -290,6 +293,7 @@ connection.onNotification(SchemaAssociationNotification.type, associations => { function updateConfiguration() { let languageSettings: LanguageSettings = { validate: yamlShouldValidate, + hover: yamlShouldHover, schemas: [], customTags: customTags }; diff --git a/test/hover.test.ts b/test/hover.test.ts index dc931928c..8d8210212 100644 --- a/test/hover.test.ts +++ b/test/hover.test.ts @@ -10,7 +10,7 @@ import { RequestType } from 'vscode-languageserver'; import { xhr, XHRResponse, configure as configureHttpRequests, getErrorStatusDescription } from 'request-light'; -import {getLanguageService} from '../src/languageservice/yamlLanguageService' +import {getLanguageService, LanguageSettings} from '../src/languageservice/yamlLanguageService' import Strings = require( '../src/languageservice/utils/strings'); import URI from '../src/languageservice/utils/uri'; import * as URL from 'url'; @@ -26,8 +26,9 @@ let languageService = getLanguageService(schemaRequestService, workspaceContext, let schemaService = new JSONSchemaService(schemaRequestService, workspaceContext); let uri = 'http://json.schemastore.org/bowerrc'; -let languageSettings = { - schemas: [] +let languageSettings: LanguageSettings = { + schemas: [], + hover: true }; let fileMatch = ["*.yml", "*.yaml"]; languageSettings.schemas.push({ uri, fileMatch: fileMatch }); diff --git a/test/hover2.test.ts b/test/hover2.test.ts index 35a904c6b..e9c002e81 100644 --- a/test/hover2.test.ts +++ b/test/hover2.test.ts @@ -10,7 +10,7 @@ import { RequestType } from 'vscode-languageserver'; import { xhr, XHRResponse, configure as configureHttpRequests, getErrorStatusDescription } from 'request-light'; -import {getLanguageService} from '../src/languageservice/yamlLanguageService' +import {getLanguageService, LanguageSettings} from '../src/languageservice/yamlLanguageService' import Strings = require( '../src/languageservice/utils/strings'); import URI from '../src/languageservice/utils/uri'; import * as URL from 'url'; @@ -26,8 +26,9 @@ let languageService = getLanguageService(schemaRequestService, workspaceContext, let schemaService = new JSONSchemaService(schemaRequestService, workspaceContext); let uri = 'http://json.schemastore.org/composer'; -let languageSettings = { - schemas: [] +let languageSettings: LanguageSettings = { + schemas: [], + hover: true }; let fileMatch = ["*.yml", "*.yaml"]; languageSettings.schemas.push({ uri, fileMatch: fileMatch }); diff --git a/test/hover3.test.ts b/test/hover3.test.ts new file mode 100644 index 000000000..d818c3a21 --- /dev/null +++ b/test/hover3.test.ts @@ -0,0 +1,48 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Red Hat. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +import { TextDocument } from 'vscode-languageserver'; +import {getLanguageService, LanguageSettings} from '../src/languageservice/yamlLanguageService' +import {schemaRequestService, workspaceContext} from './testHelper'; +import { parse as parseYAML } from '../src/languageservice/parser/yamlParser'; +var assert = require('assert'); + +let languageService = getLanguageService(schemaRequestService, workspaceContext, [], null); + +let uri = 'http://json.schemastore.org/bowerrc'; +let languageSettings: LanguageSettings = { + schemas: [], + hover: false +}; +let fileMatch = ["*.yml", "*.yaml"]; +languageSettings.schemas.push({ uri, fileMatch: fileMatch }); +languageService.configure(languageSettings); + +suite("Hover Setting Tests", () => { + + describe('Yaml Hover with bowerrc', function(){ + + describe('doComplete', function(){ + + function setup(content: string){ + return TextDocument.create("file://~/Desktop/vscode-k8s/test.yaml", "yaml", 0, content); + } + + function parseSetup(content: string, position){ + let testTextDocument = setup(content); + let jsonDocument = parseYAML(testTextDocument.getText()); + return languageService.doHover(testTextDocument, testTextDocument.positionAt(position), jsonDocument); + } + + it('Hover should not return anything', (done) => { + let content = "cwd: test"; + let hover = parseSetup(content, 1); + hover.then(function(result){ + assert.equal(result, undefined); + }).then(done, done); + }); + + }); + }); +}); \ No newline at end of file diff --git a/test/mulipleDocuments.test.ts b/test/mulipleDocuments.test.ts index 381ff1a6f..e9fb76b0c 100644 --- a/test/mulipleDocuments.test.ts +++ b/test/mulipleDocuments.test.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import { TextDocument } from 'vscode-languageserver'; -import {getLanguageService} from '../src/languageservice/yamlLanguageService' +import {getLanguageService, LanguageSettings} from '../src/languageservice/yamlLanguageService' import path = require('path'); import {schemaRequestService, workspaceContext} from './testHelper'; import { parse as parseYAML } from '../src/languageservice/parser/yamlParser'; @@ -27,10 +27,11 @@ function toFsPath(str): string { } let uri = toFsPath(path.join(__dirname, './fixtures/customMultipleSchemaSequences.json')); -let languageSettings = { +let languageSettings: LanguageSettings = { schemas: [], validate: true, - customTags: [] + customTags: [], + hover: true }; let fileMatch = ["*.yml", "*.yaml"]; languageSettings.schemas.push({ uri, fileMatch: fileMatch });