Skip to content

Commit

Permalink
Merge pull request #102 from pengx17/chore/style-fixes
Browse files Browse the repository at this point in the history
Chore/style fixes
  • Loading branch information
JPinkney committed Nov 15, 2018
2 parents 9351ef5 + f7175c3 commit 7af01f5
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 46 deletions.
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -30,7 +30,7 @@
"dependencies": {
"js-yaml": "^3.12.0",
"jsonc-parser": "^1.0.3",
"prettier": "^1.14.3",
"prettier": "^1.15.2",
"request-light": "^0.2.3",
"vscode-json-languageservice": "3.0.12",
"vscode-languageserver": "^4.0.0",
Expand All @@ -42,8 +42,9 @@
"devDependencies": {
"@types/mocha": "2.2.48",
"@types/node": "^9.4.7",
"mocha": "5.0.4",
"@types/prettier": "^1.13.2",
"coveralls": "^3.0.0",
"mocha": "5.0.4",
"mocha-lcov-reporter": "^1.3.0",
"nyc": "^11.6.0",
"source-map-support": "^0.5.4",
Expand Down
16 changes: 8 additions & 8 deletions src/languageservice/parser/jsonParser.ts
Expand Up @@ -5,7 +5,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';

import Json = require('jsonc-parser');
import * as Json from 'jsonc-parser';
import { JSONSchema } from '../jsonSchema';
import * as objects from '../utils/objects';

Expand Down Expand Up @@ -119,7 +119,7 @@ export class ASTNode {
collector.push(item);
}
}
return node;
return node;
};
let foundNode = findNode(this);
return collector.length;
Expand Down Expand Up @@ -158,7 +158,7 @@ export class ASTNode {
if (!matchingSchemas.include(this)) {
return;
}

if (Array.isArray(schema.type)) {
if ((<string[]>schema.type).indexOf(this.type) === -1) {
validationResult.problems.push({
Expand Down Expand Up @@ -540,7 +540,7 @@ export class StringASTNode extends ASTNode {
});
}
}

}
}

Expand Down Expand Up @@ -650,7 +650,7 @@ export class ObjectASTNode extends ASTNode {
let seenKeys: { [key: string]: ASTNode } = Object.create(null);
let unprocessedProperties: string[] = [];
this.properties.forEach((node) => {

let key = node.key.value;

//Replace the merge key with the actual values of what the node value points to in seen keys
Expand Down Expand Up @@ -683,7 +683,7 @@ export class ObjectASTNode extends ASTNode {
seenKeys[key] = node.value;
unprocessedProperties.push(key);
}

});

if (Array.isArray(schema.required)) {
Expand Down Expand Up @@ -771,7 +771,7 @@ export class ObjectASTNode extends ASTNode {
}
});
}
}
}

if (schema.maxProperties) {
if (this.properties.length > schema.maxProperties) {
Expand Down Expand Up @@ -835,7 +835,7 @@ export interface ISchemaCollector {
schemas: IApplicableSchema[];
add(schema: IApplicableSchema): void;
merge(other: ISchemaCollector): void;
include(node: ASTNode): void;
include(node: ASTNode): boolean;
newSub(): ISchemaCollector;
}

Expand Down
11 changes: 4 additions & 7 deletions src/languageservice/services/documentSymbols.ts
Expand Up @@ -5,12 +5,9 @@
*--------------------------------------------------------------------------------------------*/
'use strict';

import Parser = require('../parser/jsonParser');
import Strings = require('../utils/strings');
import * as Parser from '../parser/jsonParser';

import { SymbolInformation, SymbolKind, TextDocument, Range, Location } from 'vscode-languageserver-types';
import { Thenable } from "../yamlLanguageService";
import { IJSONSchemaService } from "./jsonSchemaService";

export class YAMLDocumentSymbols {

Expand All @@ -19,15 +16,15 @@ export class YAMLDocumentSymbols {
if(!doc || doc["documents"].length === 0){
return null;
}

let collectOutlineEntries = (result: SymbolInformation[], node: Parser.ASTNode, containerName: string): SymbolInformation[] => {
if (node.type === 'array') {
(<Parser.ArrayASTNode>node).items.forEach((node: Parser.ASTNode) => {
collectOutlineEntries(result, node, containerName);
});
} else if (node.type === 'object') {
let objectNode = <Parser.ObjectASTNode>node;

objectNode.properties.forEach((property: Parser.PropertyASTNode) => {
let location = Location.create(document.uri, Range.create(document.positionAt(property.start), document.positionAt(property.end)));
let valueNode = property.value;
Expand All @@ -49,7 +46,7 @@ export class YAMLDocumentSymbols {
results = results.concat(result);
}
}

return results;
}

Expand Down
4 changes: 2 additions & 2 deletions src/languageservice/services/jsonSchemaService.ts
Expand Up @@ -5,10 +5,10 @@
*--------------------------------------------------------------------------------------------*/
'use strict';

import Json = require('jsonc-parser');
import * as Json from 'jsonc-parser';
import {JSONSchema, JSONSchemaMap} from '../jsonSchema';
import URI from 'vscode-uri';
import Strings = require('../utils/strings');
import * as Strings from '../utils/strings';
import {SchemaRequestService, WorkspaceContextService, PromiseConstructor, Thenable} from '../yamlLanguageService';


Expand Down
30 changes: 15 additions & 15 deletions src/languageservice/services/yamlCompletion.ts
Expand Up @@ -6,9 +6,9 @@
'use strict';


import Parser = require('../parser/jsonParser');
import Json = require('jsonc-parser');
import SchemaService = require('./jsonSchemaService');
import * as Parser from '../parser/jsonParser';
import * as Json from 'jsonc-parser';
import * as SchemaService from './jsonSchemaService';
import { JSONSchema } from '../jsonSchema';
import { JSONWorkerContribution, CompletionsCollector } from '../jsonContributions';
import { PromiseConstructor, Thenable } from 'vscode-json-languageservice';
Expand Down Expand Up @@ -66,12 +66,12 @@ export class YAMLCompletion {
if (!this.completion) {
return Promise.resolve(result);
}

let offset = document.offsetAt(position);
if(document.getText()[offset] === ":"){
return Promise.resolve(result);
}

let currentDoc = matchOffsetToDocument(offset, doc);
if(currentDoc === null){
return Promise.resolve(result);
Expand Down Expand Up @@ -134,7 +134,7 @@ export class YAMLCompletion {
if(!schema){
return Promise.resolve(result);
}
let newSchema = schema;
let newSchema = schema;
if (schema.schema && schema.schema.schemaSequence && schema.schema.schemaSequence[currentDocIndex]) {
newSchema = new SchemaService.ResolvedSchema(schema.schema.schemaSequence[currentDocIndex]);
}
Expand Down Expand Up @@ -178,7 +178,7 @@ export class YAMLCompletion {
if (newSchema) {
// property proposals with schema
this.getPropertyCompletions(newSchema, currentDoc, node, addValue, collector, separatorAfter);
}
}

let location = node.getPath();
this.contributions.forEach((contribution) => {
Expand All @@ -192,7 +192,7 @@ export class YAMLCompletion {
kind: CompletionItemKind.Property,
label: this.getLabelForValue(currentWord),
insertText: this.getInsertTextForProperty(currentWord, null, false, separatorAfter),
insertTextFormat: InsertTextFormat.Snippet,
insertTextFormat: InsertTextFormat.Snippet,
documentation: ''
});
}
Expand All @@ -201,7 +201,7 @@ export class YAMLCompletion {
// proposals for values
if (newSchema) {
this.getValueCompletions(newSchema, currentDoc, node, offset, document, collector);
}
}
if (this.contributions.length > 0) {
this.getContributedValueCompletions(currentDoc, node, offset, document, collector, collectionPromises);
}
Expand Down Expand Up @@ -242,15 +242,15 @@ export class YAMLCompletion {
if (node.type === 'object' && node.parent && node.parent.type === 'array' && s.schema.type !== 'object') {
this.addSchemaValueCompletions(s.schema, collector, separatorAfter)
}
}
}
});
}

private getValueCompletions(schema: SchemaService.ResolvedSchema, doc, node: Parser.ASTNode, offset: number, document: TextDocument, collector: CompletionsCollector): void {
let offsetForSeparator = offset;
let parentKey: string = null;
let valueNode: Parser.ASTNode = null;

if (node && (node.type === 'string' || node.type === 'number' || node.type === 'boolean')) {
offsetForSeparator = node.end;
valueNode = node;
Expand All @@ -259,7 +259,7 @@ export class YAMLCompletion {

if(node && node.type === 'null'){
let nodeParent = node.parent;

/*
* This is going to be an object for some reason and we need to find the property
* Its an issue with the null node
Expand All @@ -278,7 +278,7 @@ export class YAMLCompletion {
this.addSchemaValueCompletions(schema.schema, collector, "");
return;
}

if ((node.type === 'property') && offset > (<Parser.PropertyASTNode>node).colonOffset) {
let propertyNode = <Parser.PropertyASTNode>node;
let valueNode = propertyNode.value;
Expand Down Expand Up @@ -353,7 +353,7 @@ export class YAMLCompletion {
}
}

private getCustomTagValueCompletions(collector: CompletionsCollector) {
private getCustomTagValueCompletions(collector: CompletionsCollector) {
this.customTags.forEach((customTagItem) => {
let tagItemSplit = customTagItem.split(" ");
if(tagItemSplit && tagItemSplit[0]){
Expand Down Expand Up @@ -533,7 +533,7 @@ export class YAMLCompletion {
}

private getInsertTextForPlainText(text: string): string {
return text.replace(/[\\\$\}]/g, '\\$&'); // escape $, \ and }
return text.replace(/[\\\$\}]/g, '\\$&'); // escape $, \ and }
}

private getInsertTextForValue(value: any, separatorAfter: string): string {
Expand Down
4 changes: 2 additions & 2 deletions src/languageservice/services/yamlFormatter.ts
Expand Up @@ -7,12 +7,12 @@

import { TextDocument, Range, Position, TextEdit } from 'vscode-languageserver-types';
import { CustomFormatterOptions } from '../yamlLanguageService';
const prettier = require("prettier");
import * as prettier from 'prettier';

export function format(document: TextDocument, options: CustomFormatterOptions): TextEdit[] {
const text = document.getText();

const formatted = prettier.format(text, Object.assign(options, { parser: "yaml" }));
const formatted = prettier.format(text, Object.assign(options, { parser: "yaml" as prettier.BuiltInParserName }));

return [TextEdit.replace(Range.create(Position.create(0, 0), document.positionAt(text.length)), formatted)];
}
8 changes: 4 additions & 4 deletions src/languageservice/services/yamlHover.ts
Expand Up @@ -6,8 +6,8 @@
'use strict';


import Parser = require('../parser/jsonParser');
import SchemaService = require('./jsonSchemaService');
import * as Parser from '../parser/jsonParser';
import * as SchemaService from './jsonSchemaService';
import {JSONWorkerContribution} from '../jsonContributions';
import {PromiseConstructor, Thenable} from 'vscode-json-languageservice';

Expand Down Expand Up @@ -61,7 +61,7 @@ export class YAMLHover {
node = propertyNode.value;
if (!node) {
return this.promise.resolve(void 0);
}
}
}
}

Expand All @@ -86,7 +86,7 @@ export class YAMLHover {

return this.schemaService.getSchemaForResource(document.uri).then((schema) => {
if (schema) {
let newSchema = schema;
let newSchema = schema;
if (schema.schema && schema.schema.schemaSequence && schema.schema.schemaSequence[currentDocIndex]) {
newSchema = new SchemaService.ResolvedSchema(schema.schema.schemaSequence[currentDocIndex]);
}
Expand Down
6 changes: 2 additions & 4 deletions src/languageservice/utils/errorHandler.ts
Expand Up @@ -2,12 +2,10 @@
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { DiagnosticSeverity } from "vscode-languageserver/lib/main";

export class ErrorHandler {
private errorResultsList;
private textDocument;

constructor(textDocument){
this.errorResultsList = [];
this.textDocument = textDocument;
Expand All @@ -22,7 +20,7 @@ export class ErrorHandler {
},
message: errorMessage
});

}

public getErrorResultsList(){
Expand Down
3 changes: 1 addition & 2 deletions src/languageservice/yamlLanguageService.ts
Expand Up @@ -5,11 +5,10 @@
*--------------------------------------------------------------------------------------------*/

import { JSONSchemaService, CustomSchemaProvider } from './services/jsonSchemaService'
import { TextDocument, Position, CompletionList, FormattingOptions, Diagnostic } from 'vscode-languageserver-types';
import { TextDocument, Position, CompletionList, Diagnostic } from 'vscode-languageserver-types';
import { JSONSchema } from './jsonSchema';
import { YAMLDocumentSymbols } from './services/documentSymbols';
import { YAMLCompletion } from "./services/yamlCompletion";
import { JSONDocument } from 'vscode-json-languageservice';
import { YAMLHover } from "./services/yamlHover";
import { YAMLValidation } from "./services/yamlValidation";
import { format } from './services/yamlFormatter';
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Expand Up @@ -10,6 +10,11 @@
version "9.6.30"
resolved "https://registry.yarnpkg.com/@types/node/-/node-9.6.30.tgz#1ecf83eaf7ac2d0dada7a9d61a1e4e7a6183ac06"

"@types/prettier@^1.13.2":
version "1.13.2"
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-1.13.2.tgz#ffe96278e712a8d4e467e367a338b05e22872646"
integrity sha512-k6MCN8WuDiCj6O+UJsVMbrreZxkbrhQbO02oDj6yuRu8UAkp0MDdEcDKif8/gBKuJbT84kkO+VHQAqXkumEklg==

agent-base@4, agent-base@^4.1.0:
version "4.2.1"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-4.2.1.tgz#d89e5999f797875674c07d87f260fc41e83e8ca9"
Expand Down Expand Up @@ -1474,6 +1479,11 @@ posix-character-classes@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab"

prettier@^1.15.2:
version "1.15.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.15.2.tgz#d31abe22afa4351efa14c7f8b94b58bb7452205e"
integrity sha512-YgPLFFA0CdKL4Eg2IHtUSjzj/BWgszDHiNQAe0VAIBse34148whfdzLagRL+QiKS+YfK5ftB6X4v/MBw8yCoug==

pseudomap@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"
Expand Down

0 comments on commit 7af01f5

Please sign in to comment.