Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with registerContributor API #177

Merged
merged 4 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions src/languageservice/services/documentSymbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
import { parse as parseYAML } from '../parser/yamlParser07';

import { SymbolInformation, TextDocument, DocumentSymbol } from 'vscode-languageserver-types';
import { LanguageService } from 'vscode-json-languageservice';
import { JSONSchemaService } from './jsonSchemaService';
import { JSONDocumentSymbols } from 'vscode-json-languageservice/lib/umd/services/jsonDocumentSymbols';

export class YAMLDocumentSymbols {

private jsonLanguageService: LanguageService;
private jsonDocumentSymbols;

constructor(jsonLanguageService: LanguageService) {
this.jsonLanguageService = jsonLanguageService;
constructor(schemaService: JSONSchemaService) {
this.jsonDocumentSymbols = new JSONDocumentSymbols(schemaService);
}

public findDocumentSymbols(document: TextDocument): SymbolInformation[] {
Expand All @@ -28,7 +29,7 @@ export class YAMLDocumentSymbols {
let results = [];
for (const yamlDoc of doc['documents']) {
if (yamlDoc.root) {
results = results.concat(this.jsonLanguageService.findDocumentSymbols(document, yamlDoc));
results = results.concat(this.jsonDocumentSymbols.findDocumentSymbols(document, yamlDoc));
}
}

Expand All @@ -44,7 +45,7 @@ export class YAMLDocumentSymbols {
let results = [];
for (const yamlDoc of doc['documents']) {
if (yamlDoc.root) {
results = results.concat(this.jsonLanguageService.findDocumentSymbols2(document, yamlDoc));
results = results.concat(this.jsonDocumentSymbols.findDocumentSymbols2(document, yamlDoc));
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/languageservice/services/jsonSchemaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export interface IJSONSchemaService {
/**
* Looks up the appropriate schema for the given URI
*/
getSchemaForResource(resource: string): Thenable<ResolvedSchema>;
// tslint:disable-next-line: no-any
getSchemaForResource(resource: string, document?: any): Thenable<ResolvedSchema>;

/**
* Returns all registered schema ids
Expand Down Expand Up @@ -527,7 +528,7 @@ export class JSONSchemaService implements IJSONSchemaService {
return resolveRefs(schema, schema, schemaURL).then(_ => new ResolvedSchema(schema, resolveErrors));
}

public getSchemaForResource(resource: string ): Thenable<ResolvedSchema> {
public getSchemaForResource(resource: string, doc = undefined): Thenable<ResolvedSchema> {
const resolveSchema = () => {
// check for matching file names, last to first
for (let i = this.filePatternAssociations.length - 1; i >= 0; i--) {
Expand All @@ -545,8 +546,8 @@ export class JSONSchemaService implements IJSONSchemaService {
return resolveSchema();
}

this.loadSchema(schemaUri)
.then(unsolvedSchema => this.resolveSchemaContent(unsolvedSchema, schemaUri))
return this.loadSchema(schemaUri)
.then(unsolvedSchema => this.resolveSchemaContent(unsolvedSchema, schemaUri));
})
.then(schema => schema, err => resolveSchema());
} else {
Expand Down
10 changes: 6 additions & 4 deletions src/languageservice/services/yamlHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ import { Hover, TextDocument, Position } from 'vscode-languageserver-types';
import { matchOffsetToDocument2 } from '../utils/arrUtils';
import { LanguageSettings } from '../yamlLanguageService';
import { parse as parseYAML } from '../parser/yamlParser07';
import { JSONSchemaService } from './jsonSchemaService';
import { JSONHover } from 'vscode-json-languageservice/lib/umd/services/jsonHover';

export class YAMLHover {

private promise: PromiseConstructor;
private shouldHover: boolean;
private jsonLanguageService: LanguageService;
private jsonHover;

constructor(promiseConstructor: PromiseConstructor, jsonLanguageService: LanguageService) {
constructor(schemaService: JSONSchemaService, promiseConstructor: PromiseConstructor) {
this.promise = promiseConstructor || Promise;
this.shouldHover = true;
this.jsonLanguageService = jsonLanguageService;
this.jsonHover = new JSONHover(schemaService, [], Promise);
}

public configure(languageSettings: LanguageSettings) {
Expand All @@ -41,6 +43,6 @@ export class YAMLHover {
return this.promise.resolve(void 0);
}

return this.jsonLanguageService.doHover(document, position, currentDoc);
return this.jsonHover.doHover(document, position, currentDoc);
}
}
14 changes: 8 additions & 6 deletions src/languageservice/services/yamlValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@

import { Diagnostic, TextDocument } from 'vscode-languageserver-types';
import { PromiseConstructor, LanguageSettings } from '../yamlLanguageService';
import { LanguageService } from 'vscode-json-languageservice';
import { parse as parseYAML, YAMLDocument } from '../parser/yamlParser07';
import { SingleYAMLDocument } from '../parser/yamlParser04';
import { JSONSchemaService } from './jsonSchemaService';
import { JSONValidation } from 'vscode-json-languageservice/lib/umd/services/jsonValidation';

export class YAMLValidation {

private promise: PromiseConstructor;
private validationEnabled: boolean;
private jsonLanguageService: LanguageService;
private customTags: String[];
private jsonValidation;

private MATCHES_MULTIPLE = 'Matches multiple schemas when only one must validate.';

public constructor(promiseConstructor: PromiseConstructor, jsonLanguageService: LanguageService) {
this.promise = promiseConstructor;
public constructor(schemaService: JSONSchemaService, promiseConstructor: PromiseConstructor) {
this.promise = promiseConstructor || Promise;
this.validationEnabled = true;
this.jsonLanguageService = jsonLanguageService;
this.jsonValidation = new JSONValidation(schemaService, this.promise);
}

public configure(settings: LanguageSettings) {
Expand All @@ -42,7 +43,8 @@ export class YAMLValidation {
const validationResult: Diagnostic[] = [];
for (const currentYAMLDoc of yamlDocument.documents) {
currentYAMLDoc.isKubernetes = isKubernetes;
const validation = await this.jsonLanguageService.doValidation(textDocument, currentYAMLDoc);

const validation = await this.jsonValidation.doValidation(textDocument, currentYAMLDoc);
const syd = currentYAMLDoc as unknown as SingleYAMLDocument;
if (syd.errors.length > 0) {
validationResult.push(...syd.errors);
Expand Down
17 changes: 4 additions & 13 deletions src/languageservice/yamlLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,16 @@ export function getLanguageService(schemaRequestService: SchemaRequestService,
contributions: JSONWorkerContribution[],
promiseConstructor?: PromiseConstructor ): LanguageService {
const promise = promiseConstructor || Promise;
const jsonLanguageService = getJSONLanguageService({
schemaRequestService,
workspaceContext
});

const schemaService = new JSONSchemaService(schemaRequestService, workspaceContext);
const completer = new YAMLCompletion(schemaService, contributions, promise);
const hover = new YAMLHover(promise, jsonLanguageService);
const yamlDocumentSymbols = new YAMLDocumentSymbols(jsonLanguageService);
const yamlValidation = new YAMLValidation(promise, jsonLanguageService);
const hover = new YAMLHover(schemaService, promise);
const yamlDocumentSymbols = new YAMLDocumentSymbols(schemaService);
const yamlValidation = new YAMLValidation(schemaService, promise);
const formatter = new YAMLFormatter();

return {
configure: settings => {
jsonLanguageService.configure(settings);
schemaService.clearExternalSchemas();
if (settings.schemas) {
settings.schemas.forEach(settings => {
Expand All @@ -161,11 +156,7 @@ export function getLanguageService(schemaRequestService: SchemaRequestService,
doHover: hover.doHover.bind(hover),
findDocumentSymbols: yamlDocumentSymbols.findDocumentSymbols.bind(yamlDocumentSymbols),
findDocumentSymbols2: yamlDocumentSymbols.findHierarchicalDocumentSymbols.bind(yamlDocumentSymbols),
resetSchema: (uri: string) => {
jsonLanguageService.resetSchema(uri);
return schemaService.onResourceChange(uri);
},

resetSchema: (uri: string) => schemaService.onResourceChange(uri),
doFormat: formatter.format.bind(formatter)
};
}