Skip to content

Commit

Permalink
Merge c927078 into 74f640a
Browse files Browse the repository at this point in the history
  • Loading branch information
JPinkney committed Sep 26, 2018
2 parents 74f640a + c927078 commit c950164
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 11 deletions.
13 changes: 11 additions & 2 deletions src/languageservice/services/yamlHover.ts
Expand Up @@ -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<Hover> {

if(!document){
this.promise.resolve(void 0);
if(!this.shouldHover || !document){
return this.promise.resolve(void 0);
}

let offset = document.offsetAt(position);
Expand Down
2 changes: 2 additions & 0 deletions src/languageservice/yamlLanguageService.ts
Expand Up @@ -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<String>; //Array of Custom Tags
Expand Down Expand Up @@ -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);
},
Expand Down
4 changes: 4 additions & 0 deletions src/server.ts
Expand Up @@ -176,6 +176,7 @@ interface Settings {
format: { enable: boolean; };
schemas: JSONSchemaSettings[];
validate: boolean;
hover: boolean;
customTags: Array<String>;
};
http: {
Expand All @@ -196,6 +197,7 @@ let formatterRegistration: Thenable<Disposable> = null;
let specificValidatorPaths = [];
let schemaConfigurationSettings = [];
let yamlShouldValidate = true;
let yamlShouldHover = true;
let schemaStoreSettings = [];
let customTags = [];

Expand All @@ -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 : [];

Expand Down Expand Up @@ -290,6 +293,7 @@ connection.onNotification(SchemaAssociationNotification.type, associations => {
function updateConfiguration() {
let languageSettings: LanguageSettings = {
validate: yamlShouldValidate,
hover: yamlShouldHover,
schemas: [],
customTags: customTags
};
Expand Down
7 changes: 4 additions & 3 deletions test/hover.test.ts
Expand Up @@ -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';
Expand All @@ -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 });
Expand Down
7 changes: 4 additions & 3 deletions test/hover2.test.ts
Expand Up @@ -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';
Expand All @@ -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 });
Expand Down
48 changes: 48 additions & 0 deletions 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);
});

});
});
});
7 changes: 4 additions & 3 deletions test/mulipleDocuments.test.ts
Expand Up @@ -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';
Expand All @@ -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 });
Expand Down

0 comments on commit c950164

Please sign in to comment.