mirror of
https://github.com/danbulant/monaco-yaml
synced 2026-07-11 22:11:02 +00:00
commit
27349f9d15
31 changed files with 585 additions and 451 deletions
18
.vscode/launch.json
vendored
Normal file
18
.vscode/launch.json
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"name": "vscode-jest-tests",
|
||||||
|
"request": "launch",
|
||||||
|
"args": ["--runInBand"],
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"internalConsoleOptions": "neverOpen",
|
||||||
|
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
"watch": "tsc -p ./src --watch",
|
"watch": "tsc -p ./src --watch",
|
||||||
"prepublish": "rimraf ./out && rimraf ./release && yarn compile:umd && node ./scripts/bundle && mcopy ./src/monaco.d.ts ./release/monaco.d.ts",
|
"prepublish": "rimraf ./out && rimraf ./release && yarn compile:umd && node ./scripts/bundle && mcopy ./src/monaco.d.ts ./release/monaco.d.ts",
|
||||||
"lint": "prettier \"{src,test}/**/*.{json,scss,html,ts}\" --write",
|
"lint": "prettier \"{src,test}/**/*.{json,scss,html,ts}\" --write",
|
||||||
"test": "jest"
|
"test": "jest --verbose"
|
||||||
},
|
},
|
||||||
"author": "Kevin Decker <kpdecker@gmail.com> (http://incaseofstairs.com)",
|
"author": "Kevin Decker <kpdecker@gmail.com> (http://incaseofstairs.com)",
|
||||||
"maintainers": [
|
"maintainers": [
|
||||||
|
|
@ -51,14 +51,11 @@
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
"linters": {
|
"linters": {
|
||||||
"*.{json,scss,html}": [
|
"*.{json,scss,html,ts}": [
|
||||||
"prettier --write",
|
"prettier --write",
|
||||||
"git add"
|
"git add"
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
"ignore": [
|
|
||||||
"src/backend/vendor/**/*"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"husky": {
|
"husky": {
|
||||||
"hooks": {
|
"hooks": {
|
||||||
|
|
|
||||||
|
|
@ -142,6 +142,7 @@ export class NumberASTNodeImpl extends ASTNodeImpl implements NumberASTNode {
|
||||||
export class StringASTNodeImpl extends ASTNodeImpl implements StringASTNode {
|
export class StringASTNodeImpl extends ASTNodeImpl implements StringASTNode {
|
||||||
public type: 'string' = 'string';
|
public type: 'string' = 'string';
|
||||||
public value: string;
|
public value: string;
|
||||||
|
public isKey: boolean;
|
||||||
|
|
||||||
constructor(parent: ASTNode, offset: number, length?: number) {
|
constructor(parent: ASTNode, offset: number, length?: number) {
|
||||||
super(parent, offset, length);
|
super(parent, offset, length);
|
||||||
|
|
@ -213,7 +214,7 @@ export interface ISchemaCollector {
|
||||||
|
|
||||||
class SchemaCollector implements ISchemaCollector {
|
class SchemaCollector implements ISchemaCollector {
|
||||||
public schemas: IApplicableSchema[] = [];
|
public schemas: IApplicableSchema[] = [];
|
||||||
constructor(private focusOffset = -1, private exclude: ASTNode = null) { }
|
constructor(private focusOffset = -1, private exclude: ASTNode = null) {}
|
||||||
public add(schema: IApplicableSchema) {
|
public add(schema: IApplicableSchema) {
|
||||||
this.schemas.push(schema);
|
this.schemas.push(schema);
|
||||||
}
|
}
|
||||||
|
|
@ -237,9 +238,9 @@ class NoOpSchemaCollector implements ISchemaCollector {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static instance = new NoOpSchemaCollector();
|
public static instance = new NoOpSchemaCollector();
|
||||||
private constructor() { }
|
private constructor() {}
|
||||||
public add(schema: IApplicableSchema) { }
|
public add(schema: IApplicableSchema) {}
|
||||||
public merge(other: ISchemaCollector) { }
|
public merge(other: ISchemaCollector) {}
|
||||||
public include(node: ASTNode) {
|
public include(node: ASTNode) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -389,7 +390,7 @@ export class JSONDocument {
|
||||||
public root: ASTNode,
|
public root: ASTNode,
|
||||||
public readonly syntaxErrors: Diagnostic[] = [],
|
public readonly syntaxErrors: Diagnostic[] = [],
|
||||||
public readonly comments: Range[] = []
|
public readonly comments: Range[] = []
|
||||||
) { }
|
) {}
|
||||||
|
|
||||||
public getNodeFromOffset(
|
public getNodeFromOffset(
|
||||||
offset: number,
|
offset: number,
|
||||||
|
|
@ -1110,13 +1111,15 @@ function validate(
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'array': {
|
case 'array': {
|
||||||
propertyNode.valueNode.items.forEach((sequenceNode: ObjectASTNode) => {
|
propertyNode.valueNode.items.forEach(
|
||||||
|
(sequenceNode: ObjectASTNode) => {
|
||||||
sequenceNode.properties.forEach(propASTNode => {
|
sequenceNode.properties.forEach(propASTNode => {
|
||||||
const seqKey = propASTNode.keyNode.value;
|
const seqKey = propASTNode.keyNode.value;
|
||||||
seenKeys[seqKey] = propASTNode.valueNode;
|
seenKeys[seqKey] = propASTNode.valueNode;
|
||||||
unprocessedProperties.push(seqKey);
|
unprocessedProperties.push(seqKey);
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import {
|
||||||
StringASTNodeImpl,
|
StringASTNodeImpl,
|
||||||
} from './jsonParser';
|
} from './jsonParser';
|
||||||
import { parseYamlBoolean } from './scalar-type';
|
import { parseYamlBoolean } from './scalar-type';
|
||||||
|
import { DiagnosticSeverity } from 'vscode-languageserver-types';
|
||||||
|
|
||||||
function recursivelyBuildAst(parent: ASTNode, node: Yaml.YAMLNode): ASTNode {
|
function recursivelyBuildAst(parent: ASTNode, node: Yaml.YAMLNode): ASTNode {
|
||||||
if (!node) {
|
if (!node) {
|
||||||
|
|
@ -60,6 +61,8 @@ function recursivelyBuildAst(parent: ASTNode, node: Yaml.YAMLNode): ASTNode {
|
||||||
instance.endPosition - key.startPosition
|
instance.endPosition - key.startPosition
|
||||||
);
|
);
|
||||||
|
|
||||||
|
result.colonOffset = key.colonPosition;
|
||||||
|
|
||||||
// Technically, this is an arbitrary node in YAML
|
// Technically, this is an arbitrary node in YAML
|
||||||
// I doubt we would get a better string representation by parsing it
|
// I doubt we would get a better string representation by parsing it
|
||||||
const keyNode = new StringASTNodeImpl(
|
const keyNode = new StringASTNodeImpl(
|
||||||
|
|
@ -68,11 +71,12 @@ function recursivelyBuildAst(parent: ASTNode, node: Yaml.YAMLNode): ASTNode {
|
||||||
key.endPosition - key.startPosition
|
key.endPosition - key.startPosition
|
||||||
);
|
);
|
||||||
keyNode.value = key.value;
|
keyNode.value = key.value;
|
||||||
|
keyNode.isKey = true;
|
||||||
|
|
||||||
// TODO: calculate the correct NULL range.
|
// TODO: calculate the correct NULL range.
|
||||||
const valueNode = instance.value
|
const valueNode = instance.value
|
||||||
? recursivelyBuildAst(result, instance.value)
|
? recursivelyBuildAst(result, instance.value)
|
||||||
: new NullASTNodeImpl(parent, instance.endPosition);
|
: new NullASTNodeImpl(result, instance.endPosition);
|
||||||
|
|
||||||
result.keyNode = keyNode;
|
result.keyNode = keyNode;
|
||||||
result.valueNode = valueNode;
|
result.valueNode = valueNode;
|
||||||
|
|
@ -225,10 +229,15 @@ function recursivelyBuildAst(parent: ASTNode, node: Yaml.YAMLNode): ASTNode {
|
||||||
function convertError(e: Yaml.Error) {
|
function convertError(e: Yaml.Error) {
|
||||||
return {
|
return {
|
||||||
message: `${e.reason}`,
|
message: `${e.reason}`,
|
||||||
|
// TODO: YAML ast parser does not give a length for validation error.
|
||||||
location: {
|
location: {
|
||||||
offset: e.mark.position,
|
offset: e.mark.position,
|
||||||
code: ErrorCode.Undefined,
|
length: 0,
|
||||||
},
|
},
|
||||||
|
code: ErrorCode.Undefined,
|
||||||
|
severity: e.isWarning
|
||||||
|
? DiagnosticSeverity.Warning
|
||||||
|
: DiagnosticSeverity.Error,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -248,14 +257,18 @@ function createJSONDocument(
|
||||||
'Expected a YAML object, array or literal'
|
'Expected a YAML object, array or literal'
|
||||||
),
|
),
|
||||||
code: ErrorCode.Undefined,
|
code: ErrorCode.Undefined,
|
||||||
location: { start: yamlDoc.startPosition, end: yamlDoc.endPosition },
|
location: {
|
||||||
|
offset: yamlDoc.startPosition,
|
||||||
|
length: yamlDoc.endPosition - yamlDoc.startPosition,
|
||||||
|
},
|
||||||
|
severity: DiagnosticSeverity.Error,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const duplicateKeyReason = 'duplicate key';
|
const duplicateKeyReason = 'duplicate key';
|
||||||
|
|
||||||
// Patch ontop of yaml-ast-parser to disable duplicate key message on merge key
|
// Patch ontop of yaml-ast-parser to disable duplicate key message on merge key
|
||||||
const isDuplicateAndNotMergeKey = function (
|
const isDuplicateAndNotMergeKey = function(
|
||||||
error: Yaml.Error,
|
error: Yaml.Error,
|
||||||
yamlText: string
|
yamlText: string
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -556,7 +556,8 @@ export class JSONSchemaService implements IJSONSchemaService {
|
||||||
next.anyOf,
|
next.anyOf,
|
||||||
next.allOf,
|
next.allOf,
|
||||||
next.oneOf,
|
next.oneOf,
|
||||||
next.items as JSONSchema[]
|
next.items as JSONSchema[],
|
||||||
|
next.schemaSequence
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,22 +35,19 @@ import {
|
||||||
ClientCapabilities,
|
ClientCapabilities,
|
||||||
ObjectASTNode,
|
ObjectASTNode,
|
||||||
PropertyASTNode,
|
PropertyASTNode,
|
||||||
StringASTNode,
|
|
||||||
} from '../jsonLanguageTypes';
|
} from '../jsonLanguageTypes';
|
||||||
import { matchOffsetToDocument } from '../utils/arrUtils';
|
import { matchOffsetToDocument } from '../utils/arrUtils';
|
||||||
import { stringifyObject } from '../utils/json';
|
import { stringifyObject } from '../utils/json';
|
||||||
import { isDefined } from '../utils/objects';
|
import { isDefined } from '../utils/objects';
|
||||||
import { endsWith } from '../utils/strings';
|
import { endsWith } from '../utils/strings';
|
||||||
import { YAMLDocument } from '../yamlLanguageTypes';
|
import { YAMLDocument } from '../yamlLanguageTypes';
|
||||||
|
import { LanguageSettings } from '../yamlLanguageService';
|
||||||
const localize = nls.loadMessageBundle();
|
const localize = nls.loadMessageBundle();
|
||||||
|
|
||||||
// !! FIXME: this implementation is buggy
|
|
||||||
|
|
||||||
export class YAMLCompletion {
|
export class YAMLCompletion {
|
||||||
|
private completionEnabled = true;
|
||||||
private supportsMarkdown: boolean | undefined;
|
private supportsMarkdown: boolean | undefined;
|
||||||
|
|
||||||
private templateVarIdCounter = 0;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private schemaService: SchemaService.IJSONSchemaService,
|
private schemaService: SchemaService.IJSONSchemaService,
|
||||||
private contributions: JSONWorkerContribution[] = [],
|
private contributions: JSONWorkerContribution[] = [],
|
||||||
|
|
@ -60,6 +57,12 @@ export class YAMLCompletion {
|
||||||
this.contributions = contributions;
|
this.contributions = contributions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public configure(settings: LanguageSettings) {
|
||||||
|
if (settings) {
|
||||||
|
this.completionEnabled = settings.completion !== false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public doResolve(item: CompletionItem): Thenable<CompletionItem> {
|
public doResolve(item: CompletionItem): Thenable<CompletionItem> {
|
||||||
for (let i = this.contributions.length - 1; i >= 0; i--) {
|
for (let i = this.contributions.length - 1; i >= 0; i--) {
|
||||||
if (this.contributions[i].resolveCompletion) {
|
if (this.contributions[i].resolveCompletion) {
|
||||||
|
|
@ -88,7 +91,7 @@ export class YAMLCompletion {
|
||||||
|
|
||||||
const currentDocIndex = doc.documents.indexOf(currentDoc);
|
const currentDocIndex = doc.documents.indexOf(currentDoc);
|
||||||
|
|
||||||
if (currentDoc === null) {
|
if (currentDoc === null || !this.completionEnabled) {
|
||||||
return Promise.resolve(result);
|
return Promise.resolve(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,14 +15,20 @@ import {
|
||||||
} from 'vscode-languageserver-types';
|
} from 'vscode-languageserver-types';
|
||||||
import { EOL } from '../../fillers/os';
|
import { EOL } from '../../fillers/os';
|
||||||
import * as Yaml from '../../yaml-ast-parser/index';
|
import * as Yaml from '../../yaml-ast-parser/index';
|
||||||
|
import { LanguageSettings } from '../yamlLanguageService';
|
||||||
|
|
||||||
export function format(
|
export class YamlFormatter {
|
||||||
document: TextDocument,
|
private customTags: string[];
|
||||||
options: FormattingOptions,
|
|
||||||
customTags: String[]
|
configure(settings: LanguageSettings) {
|
||||||
): TextEdit[] {
|
if (settings) {
|
||||||
|
this.customTags = settings.customTags || [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
doFormat(document: TextDocument, options: FormattingOptions): TextEdit[] {
|
||||||
const text = document.getText();
|
const text = document.getText();
|
||||||
customTags = customTags || [];
|
const customTags = this.customTags || [];
|
||||||
|
|
||||||
const schemaWithAdditionalTags = jsyaml.Schema.create(
|
const schemaWithAdditionalTags = jsyaml.Schema.create(
|
||||||
customTags.map(tag => {
|
customTags.map(tag => {
|
||||||
|
|
@ -71,4 +77,5 @@ export function format(
|
||||||
newText
|
newText
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,22 @@ import {
|
||||||
} from 'vscode-languageserver-types';
|
} from 'vscode-languageserver-types';
|
||||||
import { matchOffsetToDocument } from '../utils/arrUtils';
|
import { matchOffsetToDocument } from '../utils/arrUtils';
|
||||||
import { YAMLDocument } from '../yamlLanguageTypes';
|
import { YAMLDocument } from '../yamlLanguageTypes';
|
||||||
|
import { LanguageSettings } from '../yamlLanguageService';
|
||||||
|
|
||||||
export class YAMLHover {
|
export class YAMLHover {
|
||||||
|
private shouldHover = true;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private schemaService: SchemaService.IJSONSchemaService,
|
private schemaService: SchemaService.IJSONSchemaService,
|
||||||
private contributions: JSONWorkerContribution[] = []
|
private contributions: JSONWorkerContribution[] = []
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
public configure(languageSettings: LanguageSettings) {
|
||||||
|
if (languageSettings) {
|
||||||
|
this.shouldHover = languageSettings.hover !== false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public doHover(
|
public doHover(
|
||||||
document: TextDocument,
|
document: TextDocument,
|
||||||
position: Position,
|
position: Position,
|
||||||
|
|
@ -33,11 +42,11 @@ export class YAMLHover {
|
||||||
): Thenable<Hover> {
|
): Thenable<Hover> {
|
||||||
const offset = document.offsetAt(position);
|
const offset = document.offsetAt(position);
|
||||||
const currentDoc = matchOffsetToDocument(offset, doc);
|
const currentDoc = matchOffsetToDocument(offset, doc);
|
||||||
if (currentDoc === null) {
|
if (currentDoc === null || !this.shouldHover) {
|
||||||
return Promise.resolve(void 0);
|
return Promise.resolve(void 0);
|
||||||
}
|
}
|
||||||
const currentDocIndex = doc.documents.indexOf(currentDoc);
|
|
||||||
let node = currentDoc.getNodeFromOffset(offset);
|
let node = currentDoc.getNodeFromOffset(offset);
|
||||||
|
const currentDocIndex = doc.documents.indexOf(currentDoc);
|
||||||
if (
|
if (
|
||||||
!node ||
|
!node ||
|
||||||
((node.type === 'object' || node.type === 'array') &&
|
((node.type === 'object' || node.type === 'array') &&
|
||||||
|
|
@ -85,8 +94,19 @@ export class YAMLHover {
|
||||||
.getSchemaForResource(document.uri, currentDoc)
|
.getSchemaForResource(document.uri, currentDoc)
|
||||||
.then(schema => {
|
.then(schema => {
|
||||||
if (schema) {
|
if (schema) {
|
||||||
|
let newSchema = schema;
|
||||||
|
if (
|
||||||
|
schema.schema &&
|
||||||
|
schema.schema.schemaSequence &&
|
||||||
|
schema.schema.schemaSequence[currentDocIndex]
|
||||||
|
) {
|
||||||
|
newSchema = new SchemaService.ResolvedSchema(
|
||||||
|
schema.schema.schemaSequence[currentDocIndex]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const matchingSchemas = currentDoc.getMatchingSchemas(
|
const matchingSchemas = currentDoc.getMatchingSchemas(
|
||||||
schema.schema,
|
newSchema.schema,
|
||||||
node.offset
|
node.offset
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,15 @@
|
||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import { DiagnosticSeverity, TextDocument } from 'vscode-languageserver-types';
|
import {
|
||||||
|
DiagnosticSeverity,
|
||||||
|
TextDocument,
|
||||||
|
Diagnostic,
|
||||||
|
} from 'vscode-languageserver-types';
|
||||||
import { LanguageSettings } from '../yamlLanguageService';
|
import { LanguageSettings } from '../yamlLanguageService';
|
||||||
import { YAMLDocument } from '../yamlLanguageTypes';
|
import { YAMLDocument } from '../yamlLanguageTypes';
|
||||||
import { JSONSchemaService, ResolvedSchema } from './jsonSchemaService';
|
import { JSONSchemaService, ResolvedSchema } from './jsonSchemaService';
|
||||||
|
import { Thenable } from '../jsonLanguageTypes';
|
||||||
|
|
||||||
export class YAMLValidation {
|
export class YAMLValidation {
|
||||||
private validationEnabled: boolean;
|
private validationEnabled: boolean;
|
||||||
|
|
@ -18,18 +23,21 @@ export class YAMLValidation {
|
||||||
|
|
||||||
public configure(raw: LanguageSettings) {
|
public configure(raw: LanguageSettings) {
|
||||||
if (raw) {
|
if (raw) {
|
||||||
this.validationEnabled = raw.validate;
|
this.validationEnabled = raw.validate !== false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public doValidation(textDocument: TextDocument, yamlDocument: YAMLDocument) {
|
public doValidation(
|
||||||
|
textDocument: TextDocument,
|
||||||
|
yamlDocument: YAMLDocument
|
||||||
|
): Thenable<Diagnostic[]> {
|
||||||
if (!this.validationEnabled) {
|
if (!this.validationEnabled) {
|
||||||
return Promise.resolve([]);
|
return Promise.resolve([]);
|
||||||
}
|
}
|
||||||
return this.jsonSchemaService
|
return this.jsonSchemaService
|
||||||
.getSchemaForResource(textDocument.uri)
|
.getSchemaForResource(textDocument.uri)
|
||||||
.then(function(schema) {
|
.then(function(schema) {
|
||||||
const diagnostics = [];
|
const diagnostics: Diagnostic[] = [];
|
||||||
const added = {};
|
const added = {};
|
||||||
let newSchema = schema;
|
let newSchema = schema;
|
||||||
if (schema) {
|
if (schema) {
|
||||||
|
|
@ -53,10 +61,13 @@ export class YAMLValidation {
|
||||||
const curDiagnostic = diagnostics[diag];
|
const curDiagnostic = diagnostics[diag];
|
||||||
currentDoc.errors.push({
|
currentDoc.errors.push({
|
||||||
location: {
|
location: {
|
||||||
start: curDiagnostic.range.start,
|
offset: textDocument.offsetAt(curDiagnostic.range.start),
|
||||||
end: curDiagnostic.range.end,
|
length:
|
||||||
|
textDocument.offsetAt(curDiagnostic.range.end) -
|
||||||
|
textDocument.offsetAt(curDiagnostic.range.start),
|
||||||
},
|
},
|
||||||
message: curDiagnostic.message,
|
message: curDiagnostic.message,
|
||||||
|
severity: curDiagnostic.severity,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
documentIndex++;
|
documentIndex++;
|
||||||
|
|
@ -87,23 +98,24 @@ export class YAMLValidation {
|
||||||
.forEach(function(error, idx) {
|
.forEach(function(error, idx) {
|
||||||
// remove duplicated messages
|
// remove duplicated messages
|
||||||
const signature =
|
const signature =
|
||||||
error.location.start +
|
error.location.offset +
|
||||||
' ' +
|
' ' +
|
||||||
error.location.end +
|
error.location.length +
|
||||||
' ' +
|
' ' +
|
||||||
error.message;
|
error.message;
|
||||||
if (!added[signature]) {
|
if (!added[signature]) {
|
||||||
added[signature] = true;
|
added[signature] = true;
|
||||||
const range = {
|
|
||||||
start: textDocument.positionAt(error.location.start),
|
|
||||||
end: textDocument.positionAt(error.location.end),
|
|
||||||
};
|
|
||||||
diagnostics.push({
|
diagnostics.push({
|
||||||
severity:
|
severity:
|
||||||
idx >= currentDoc.errors.length
|
idx >= currentDoc.errors.length
|
||||||
? DiagnosticSeverity.Warning
|
? DiagnosticSeverity.Warning
|
||||||
: DiagnosticSeverity.Error,
|
: DiagnosticSeverity.Error,
|
||||||
range,
|
range: {
|
||||||
|
start: textDocument.positionAt(error.location.offset),
|
||||||
|
end: textDocument.positionAt(
|
||||||
|
error.location.offset + error.location.length
|
||||||
|
),
|
||||||
|
},
|
||||||
message: error.message,
|
message: error.message,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ import {
|
||||||
JSONSchemaService,
|
JSONSchemaService,
|
||||||
} from './services/jsonSchemaService';
|
} from './services/jsonSchemaService';
|
||||||
import { YAMLCompletion } from './services/yamlCompletion';
|
import { YAMLCompletion } from './services/yamlCompletion';
|
||||||
import { format } from './services/yamlFormatter';
|
import { YamlFormatter } from './services/yamlFormatter';
|
||||||
import { YAMLHover } from './services/yamlHover';
|
import { YAMLHover } from './services/yamlHover';
|
||||||
import { YAMLValidation } from './services/yamlValidation';
|
import { YAMLValidation } from './services/yamlValidation';
|
||||||
import { YAMLDocument } from './yamlLanguageTypes';
|
import { YAMLDocument } from './yamlLanguageTypes';
|
||||||
|
|
@ -38,7 +38,7 @@ export interface LanguageSettings {
|
||||||
completion?: boolean; // Setting for whether we want to have completion results
|
completion?: boolean; // Setting for whether we want to have completion results
|
||||||
isKubernetes?: boolean; // If true then its validating against kubernetes
|
isKubernetes?: boolean; // If true then its validating against kubernetes
|
||||||
schemas?: any[]; // List of schemas,
|
schemas?: any[]; // List of schemas,
|
||||||
customTags?: String[]; // Array of Custom Tags
|
customTags?: string[]; // Array of Custom Tags
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Thenable<R> {
|
export interface Thenable<R> {
|
||||||
|
|
@ -134,6 +134,7 @@ export function getLanguageService(
|
||||||
const hover = new YAMLHover(schemaService, contributions);
|
const hover = new YAMLHover(schemaService, contributions);
|
||||||
const yamlDocumentSymbols = new YAMLDocumentSymbols(schemaService);
|
const yamlDocumentSymbols = new YAMLDocumentSymbols(schemaService);
|
||||||
const yamlValidation = new YAMLValidation(schemaService);
|
const yamlValidation = new YAMLValidation(schemaService);
|
||||||
|
const yamlFormatter = new YamlFormatter();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
configure: settings => {
|
configure: settings => {
|
||||||
|
|
@ -147,6 +148,11 @@ export function getLanguageService(
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
yamlValidation.configure(settings);
|
||||||
|
hover.configure(settings);
|
||||||
|
completer.configure(settings);
|
||||||
|
yamlFormatter.configure(settings);
|
||||||
},
|
},
|
||||||
registerCustomSchemaProvider: (schemaProvider: CustomSchemaProvider) => {
|
registerCustomSchemaProvider: (schemaProvider: CustomSchemaProvider) => {
|
||||||
schemaService.registerCustomSchemaProvider(schemaProvider);
|
schemaService.registerCustomSchemaProvider(schemaProvider);
|
||||||
|
|
@ -165,7 +171,7 @@ export function getLanguageService(
|
||||||
yamlDocumentSymbols
|
yamlDocumentSymbols
|
||||||
),
|
),
|
||||||
resetSchema: (uri: string) => schemaService.onResourceChange(uri),
|
resetSchema: (uri: string) => schemaService.onResourceChange(uri),
|
||||||
doFormat: format,
|
doFormat: yamlFormatter.doFormat.bind(yamlFormatter),
|
||||||
parseYAMLDocument: (document: TextDocument) =>
|
parseYAMLDocument: (document: TextDocument) =>
|
||||||
parseYAML(document.getText()),
|
parseYAML(document.getText()),
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
import { ASTNode } from './jsonLanguageTypes';
|
import { ASTNode } from './jsonLanguageTypes';
|
||||||
import { JSONDocument } from './parser/jsonParser';
|
import { JSONDocument, IProblem } from './parser/jsonParser';
|
||||||
|
import { getPosition } from './utils/documentPositionCalculator';
|
||||||
|
|
||||||
export class SingleYAMLDocument extends JSONDocument {
|
export class SingleYAMLDocument extends JSONDocument {
|
||||||
public lines;
|
public lines: number[];
|
||||||
public errors;
|
public errors: IProblem[];
|
||||||
public warnings;
|
public warnings: IProblem[];
|
||||||
|
|
||||||
constructor(lines: number[]) {
|
constructor(lines: number[]) {
|
||||||
super(null, []);
|
super(null, []);
|
||||||
|
|
@ -56,16 +57,21 @@ export class SingleYAMLDocument extends JSONDocument {
|
||||||
}
|
}
|
||||||
return currMinNode || foundNode;
|
return currMinNode || foundNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns a node at offset which will be used as a hint for completion
|
||||||
|
//
|
||||||
|
public getCompletionNodeFromOffset(offset: number): ASTNode {
|
||||||
|
if (!this.root) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class YAMLDocument {
|
export class YAMLDocument {
|
||||||
public documents: SingleYAMLDocument[];
|
public documents: SingleYAMLDocument[];
|
||||||
public errors;
|
|
||||||
public warnings;
|
|
||||||
|
|
||||||
constructor(documents: SingleYAMLDocument[]) {
|
constructor(documents: SingleYAMLDocument[]) {
|
||||||
this.documents = documents;
|
this.documents = documents;
|
||||||
this.errors = [];
|
|
||||||
this.warnings = [];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -492,11 +492,7 @@ function storeMappingPair(
|
||||||
});
|
});
|
||||||
|
|
||||||
_result.mappings.push(mapping);
|
_result.mappings.push(mapping);
|
||||||
_result.endPosition = valueNode
|
_result.endPosition = mapping.endPosition;
|
||||||
? valueNode.endPosition
|
|
||||||
: keyNode.endPosition + 1; // FIXME.workaround should be position of ':' indeed
|
|
||||||
// }
|
|
||||||
|
|
||||||
return _result;
|
return _result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -646,7 +642,8 @@ function readPlainScalar(state: State, nodeIndent, withinFlowCollection) {
|
||||||
_lineIndent,
|
_lineIndent,
|
||||||
_kind = state.kind,
|
_kind = state.kind,
|
||||||
_result = state.result,
|
_result = state.result,
|
||||||
ch;
|
ch,
|
||||||
|
_colonPosition = -1;
|
||||||
const state_result = ast.newScalar();
|
const state_result = ast.newScalar();
|
||||||
state_result.plainScalar = true;
|
state_result.plainScalar = true;
|
||||||
state.result = state_result;
|
state.result = state_result;
|
||||||
|
|
@ -694,6 +691,7 @@ function readPlainScalar(state: State, nodeIndent, withinFlowCollection) {
|
||||||
is_WS_OR_EOL(following) ||
|
is_WS_OR_EOL(following) ||
|
||||||
(withinFlowCollection && is_FLOW_INDICATOR(following))
|
(withinFlowCollection && is_FLOW_INDICATOR(following))
|
||||||
) {
|
) {
|
||||||
|
_colonPosition = state.position;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (0x23 /* # */ === ch) {
|
} else if (0x23 /* # */ === ch) {
|
||||||
|
|
@ -750,6 +748,7 @@ function readPlainScalar(state: State, nodeIndent, withinFlowCollection) {
|
||||||
state_result.startPosition,
|
state_result.startPosition,
|
||||||
state_result.endPosition
|
state_result.endPosition
|
||||||
);
|
);
|
||||||
|
state_result.colonPosition = _colonPosition;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ export interface YAMLNode extends YAMLDocument {
|
||||||
startPosition: number;
|
startPosition: number;
|
||||||
endPosition: number;
|
endPosition: number;
|
||||||
kind: Kind;
|
kind: Kind;
|
||||||
|
colonPosition?: number; // Nearest colon position.
|
||||||
anchorId?: string;
|
anchorId?: string;
|
||||||
valueObject?: any;
|
valueObject?: any;
|
||||||
parent: YAMLNode;
|
parent: YAMLNode;
|
||||||
|
|
@ -63,8 +64,7 @@ export interface YamlMap extends YAMLNode {
|
||||||
mappings: YAMLMapping[];
|
mappings: YAMLMapping[];
|
||||||
}
|
}
|
||||||
export function newMapping(key: YAMLScalar, value: YAMLNode): YAMLMapping {
|
export function newMapping(key: YAMLScalar, value: YAMLNode): YAMLMapping {
|
||||||
const end = value ? value.endPosition : key.endPosition + 1; // FIXME.workaround, end should be defied by position of ':'
|
const end = value ? value.endPosition : key.colonPosition + 1;
|
||||||
// console.log('key: ' + key.value + ' ' + key.startPosition + '..' + key.endPosition + ' ' + value + ' end: ' + end);
|
|
||||||
const node = {
|
const node = {
|
||||||
key,
|
key,
|
||||||
value,
|
value,
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@ import {
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
describe('Array Utils Tests', () => {
|
describe('Array Utils Tests', () => {
|
||||||
describe('Server - Array Utils', function () {
|
describe('Server - Array Utils', function() {
|
||||||
describe('removeDuplicates', function () {
|
describe('removeDuplicates', function() {
|
||||||
it('Remove one duplicate with property', () => {
|
it('Remove one duplicate with property', () => {
|
||||||
const obj1 = {
|
const obj1 = {
|
||||||
test_key: 'test_value',
|
test_key: 'test_value',
|
||||||
|
|
@ -69,7 +69,7 @@ describe('Array Utils Tests', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getLineOffsets', function () {
|
describe('getLineOffsets', function() {
|
||||||
it('No offset', () => {
|
it('No offset', () => {
|
||||||
const offsets = getLineOffsets('');
|
const offsets = getLineOffsets('');
|
||||||
assert.equal(offsets.length, 0);
|
assert.equal(offsets.length, 0);
|
||||||
|
|
@ -89,7 +89,7 @@ describe('Array Utils Tests', () => {
|
||||||
|
|
||||||
it('Multiple offsets', () => {
|
it('Multiple offsets', () => {
|
||||||
const offsets = getLineOffsets(
|
const offsets = getLineOffsets(
|
||||||
'first_offset\n second_offset\n third_offset',
|
'first_offset\n second_offset\n third_offset'
|
||||||
);
|
);
|
||||||
assert.equal(offsets.length, 3);
|
assert.equal(offsets.length, 3);
|
||||||
assert.equal(offsets[0], 0);
|
assert.equal(offsets[0], 0);
|
||||||
|
|
@ -98,7 +98,7 @@ describe('Array Utils Tests', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('removeDuplicatesObj', function () {
|
describe('removeDuplicatesObj', function() {
|
||||||
it('Remove one duplicate with property', () => {
|
it('Remove one duplicate with property', () => {
|
||||||
const obj1 = {
|
const obj1 = {
|
||||||
test_key: 'test_value',
|
test_key: 'test_value',
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ const assert = require('assert');
|
||||||
const languageService = getLanguageService(
|
const languageService = getLanguageService(
|
||||||
schemaRequestService,
|
schemaRequestService,
|
||||||
workspaceContext,
|
workspaceContext,
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const uri = 'http://json.schemastore.org/bowerrc';
|
const uri = 'http://json.schemastore.org/bowerrc';
|
||||||
|
|
@ -25,161 +25,160 @@ languageSettings.schemas.push({ uri, fileMatch });
|
||||||
languageService.configure(languageSettings);
|
languageService.configure(languageSettings);
|
||||||
|
|
||||||
describe('Auto Completion Tests', () => {
|
describe('Auto Completion Tests', () => {
|
||||||
describe('yamlCompletion with bowerrc', function () {
|
describe('yamlCompletion with bowerrc', function() {
|
||||||
describe('doComplete', function () {
|
describe('doComplete', function() {
|
||||||
function setup(content: string) {
|
function setup(content: string) {
|
||||||
return TextDocument.create(
|
return TextDocument.create(
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseSetup(content: string, position) {
|
function parseSetup(content: string, position) {
|
||||||
const testTextDocument = setup(content);
|
const testTextDocument = setup(content);
|
||||||
const yDoc = parseYAML(testTextDocument.getText());
|
|
||||||
return completionHelper(
|
return completionHelper(
|
||||||
testTextDocument,
|
testTextDocument,
|
||||||
testTextDocument.positionAt(position),
|
testTextDocument.positionAt(position)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
it('Autocomplete on root node without word', (done) => {
|
it('Autocomplete on root node without word', done => {
|
||||||
const content = '';
|
const content = '';
|
||||||
const completion = parseSetup(content, 0);
|
const completion = parseSetup(content, 0);
|
||||||
completion
|
completion
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.items.length, 0);
|
assert.notEqual(result.items.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete on root node with word', (done) => {
|
it('Autocomplete on root node with word', done => {
|
||||||
const content = 'analyt';
|
const content = 'analyt';
|
||||||
const completion = parseSetup(content, 6);
|
const completion = parseSetup(content, 6);
|
||||||
completion
|
completion
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.items.length, 0);
|
assert.notEqual(result.items.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete on default value (without value content)', (done) => {
|
it('Autocomplete on default value (without value content)', done => {
|
||||||
const content = 'directory: ';
|
const content = 'directory: ';
|
||||||
const completion = parseSetup(content, 12);
|
const completion = parseSetup(content, 12);
|
||||||
completion
|
completion
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.items.length).toEqual(0);
|
|
||||||
})
|
|
||||||
.then(done, done);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Autocomplete on default value (with value content)', (done) => {
|
|
||||||
const content = 'directory: bow';
|
|
||||||
const completion = parseSetup(content, 15);
|
|
||||||
completion
|
|
||||||
.then(function (result) {
|
|
||||||
assert.notEqual(result.items.length, 0);
|
|
||||||
})
|
|
||||||
.then(done, done);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Autocomplete on boolean value (without value content)', (done) => {
|
|
||||||
const content = 'analytics: ';
|
|
||||||
const completion = parseSetup(content, 11);
|
|
||||||
completion
|
|
||||||
.then(function (result) {
|
|
||||||
expect(result.items.length).toEqual(2);
|
|
||||||
})
|
|
||||||
.then(done, done);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Autocomplete on boolean value (with value content)', (done) => {
|
|
||||||
const content = 'analytics: fal';
|
|
||||||
const completion = parseSetup(content, 11);
|
|
||||||
completion
|
|
||||||
.then(function (result) {
|
|
||||||
assert.equal(result.items.length, 2);
|
|
||||||
})
|
|
||||||
.then(done, done);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Autocomplete on number value (without value content)', (done) => {
|
|
||||||
const content = 'timeout: ';
|
|
||||||
const completion = parseSetup(content, 9);
|
|
||||||
completion
|
|
||||||
.then(function (result) {
|
|
||||||
expect(result.items.length).toEqual(1);
|
expect(result.items.length).toEqual(1);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete on number value (with value content)', (done) => {
|
it('Autocomplete on default value (with value content)', done => {
|
||||||
|
const content = 'directory: bow';
|
||||||
|
const completion = parseSetup(content, 15);
|
||||||
|
completion
|
||||||
|
.then(function(result) {
|
||||||
|
assert.notEqual(result.items.length, 0);
|
||||||
|
})
|
||||||
|
.then(done, done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Autocomplete on boolean value (without value content)', done => {
|
||||||
|
const content = 'analytics: ';
|
||||||
|
const completion = parseSetup(content, 11);
|
||||||
|
completion
|
||||||
|
.then(function(result) {
|
||||||
|
expect(result.items.length).toEqual(2);
|
||||||
|
})
|
||||||
|
.then(done, done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Autocomplete on boolean value (with value content)', done => {
|
||||||
|
const content = 'analytics: fal';
|
||||||
|
const completion = parseSetup(content, 11);
|
||||||
|
completion
|
||||||
|
.then(function(result) {
|
||||||
|
assert.equal(result.items.length, 2);
|
||||||
|
})
|
||||||
|
.then(done, done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Autocomplete on number value (without value content)', done => {
|
||||||
|
const content = 'timeout: ';
|
||||||
|
const completion = parseSetup(content, 9);
|
||||||
|
completion
|
||||||
|
.then(function(result) {
|
||||||
|
expect(result.items.length).toEqual(1);
|
||||||
|
})
|
||||||
|
.then(done, done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Autocomplete on number value (with value content)', done => {
|
||||||
const content = 'timeout: 6';
|
const content = 'timeout: 6';
|
||||||
const completion = parseSetup(content, 10);
|
const completion = parseSetup(content, 10);
|
||||||
completion
|
completion
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.equal(result.items.length, 1);
|
assert.equal(result.items.length, 1);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete key in middle of file', (done) => {
|
it('Autocomplete key in middle of file', done => {
|
||||||
const content = 'scripts:\n post';
|
const content = 'scripts:\n post';
|
||||||
const completion = parseSetup(content, 11);
|
const completion = parseSetup(content, 11);
|
||||||
completion
|
completion
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.items.length, 0);
|
assert.notEqual(result.items.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete key in middle of file 2', (done) => {
|
it('Autocomplete key in middle of file 2', done => {
|
||||||
const content = 'scripts:\n postinstall: /test\n preinsta';
|
const content = 'scripts:\n postinstall: /test\n preinsta';
|
||||||
const completion = parseSetup(content, 31);
|
const completion = parseSetup(content, 31);
|
||||||
completion
|
completion
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.items.length, 0);
|
assert.notEqual(result.items.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete does not happen right after :', (done) => {
|
it('Autocomplete does not happen right after :', done => {
|
||||||
const content = 'analytics:';
|
const content = 'analytics:';
|
||||||
const completion = parseSetup(content, 9);
|
const completion = parseSetup(content, 9);
|
||||||
completion
|
completion
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.items.length, 0);
|
assert.notEqual(result.items.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete does not happen right after : under an object', (done) => {
|
it('Autocomplete does not happen right after : under an object', done => {
|
||||||
const content = 'scripts:\n postinstall:';
|
const content = 'scripts:\n postinstall:';
|
||||||
const completion = parseSetup(content, 21);
|
const completion = parseSetup(content, 21);
|
||||||
completion
|
completion
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.items.length, 0);
|
assert.notEqual(result.items.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete on multi yaml documents in a single file on root', (done) => {
|
it('Autocomplete on multi yaml documents in a single file on root', done => {
|
||||||
const content = `---\nanalytics: true\n...\n---\n...`;
|
const content = `---\nanalytics: true\n...\n---\n...`;
|
||||||
const completion = parseSetup(content, 28);
|
const completion = parseSetup(content, 28);
|
||||||
completion
|
completion
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.items.length, 0);
|
assert.notEqual(result.items.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete on multi yaml documents in a single file on scalar', (done) => {
|
it('Autocomplete on multi yaml documents in a single file on scalar', done => {
|
||||||
const content = `---\nanalytics: true\n...\n---\njson: \n...`;
|
const content = `---\nanalytics: true\n...\n---\njson: \n...`;
|
||||||
const completion = parseSetup(content, 34);
|
const completion = parseSetup(content, 34);
|
||||||
completion
|
completion
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.items.length, 0);
|
assert.notEqual(result.items.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ const assert = require('assert');
|
||||||
const languageService = getLanguageService(
|
const languageService = getLanguageService(
|
||||||
schemaRequestService,
|
schemaRequestService,
|
||||||
workspaceContext,
|
workspaceContext,
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const uri = 'http://json.schemastore.org/composer';
|
const uri = 'http://json.schemastore.org/composer';
|
||||||
|
|
@ -30,7 +30,7 @@ describe('Auto Completion Tests', () => {
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,13 +38,13 @@ describe('Auto Completion Tests', () => {
|
||||||
const testTextDocument = setup(content);
|
const testTextDocument = setup(content);
|
||||||
return completionHelper(
|
return completionHelper(
|
||||||
testTextDocument,
|
testTextDocument,
|
||||||
testTextDocument.positionAt(position),
|
testTextDocument.positionAt(position)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('yamlCompletion with composer', function() {
|
describe('yamlCompletion with composer', function() {
|
||||||
describe('doComplete', function() {
|
describe('doComplete', function() {
|
||||||
it('Array autocomplete without word', (done) => {
|
it('Array autocomplete without word', done => {
|
||||||
const content = 'authors:\n - ';
|
const content = 'authors:\n - ';
|
||||||
const completion = parseSetup(content, 14);
|
const completion = parseSetup(content, 14);
|
||||||
completion
|
completion
|
||||||
|
|
@ -54,7 +54,7 @@ describe('Auto Completion Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Array autocomplete without word on array symbol', (done) => {
|
it('Array autocomplete without word on array symbol', done => {
|
||||||
const content = 'authors:\n -';
|
const content = 'authors:\n -';
|
||||||
const completion = parseSetup(content, 13);
|
const completion = parseSetup(content, 13);
|
||||||
completion
|
completion
|
||||||
|
|
@ -64,7 +64,7 @@ describe('Auto Completion Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Array autocomplete without word on space before array symbol', (done) => {
|
it('Array autocomplete without word on space before array symbol', done => {
|
||||||
const content = 'authors:\n - name: test\n ';
|
const content = 'authors:\n - name: test\n ';
|
||||||
const completion = parseSetup(content, 24);
|
const completion = parseSetup(content, 24);
|
||||||
completion
|
completion
|
||||||
|
|
@ -74,7 +74,7 @@ describe('Auto Completion Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Array autocomplete with letter', (done) => {
|
it('Array autocomplete with letter', done => {
|
||||||
const content = 'authors:\n - n';
|
const content = 'authors:\n - n';
|
||||||
const completion = parseSetup(content, 14);
|
const completion = parseSetup(content, 14);
|
||||||
completion
|
completion
|
||||||
|
|
@ -84,7 +84,7 @@ describe('Auto Completion Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Array autocomplete without word (second item)', (done) => {
|
it('Array autocomplete without word (second item)', done => {
|
||||||
const content = 'authors:\n - name: test\n ';
|
const content = 'authors:\n - name: test\n ';
|
||||||
const completion = parseSetup(content, 32);
|
const completion = parseSetup(content, 32);
|
||||||
completion
|
completion
|
||||||
|
|
@ -94,7 +94,7 @@ describe('Auto Completion Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Array autocomplete with letter (second item)', (done) => {
|
it('Array autocomplete with letter (second item)', done => {
|
||||||
const content = 'authors:\n - name: test\n e';
|
const content = 'authors:\n - name: test\n e';
|
||||||
const completion = parseSetup(content, 27);
|
const completion = parseSetup(content, 27);
|
||||||
completion
|
completion
|
||||||
|
|
@ -104,7 +104,7 @@ describe('Auto Completion Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocompletion after array', (done) => {
|
it('Autocompletion after array', done => {
|
||||||
const content = 'authors:\n - name: test\n';
|
const content = 'authors:\n - name: test\n';
|
||||||
const completion = parseSetup(content, 24);
|
const completion = parseSetup(content, 24);
|
||||||
completion
|
completion
|
||||||
|
|
@ -114,7 +114,7 @@ describe('Auto Completion Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocompletion after array with depth', (done) => {
|
it('Autocompletion after array with depth', done => {
|
||||||
const content = 'archive:\n exclude:\n - test\n';
|
const content = 'archive:\n exclude:\n - test\n';
|
||||||
const completion = parseSetup(content, 29);
|
const completion = parseSetup(content, 29);
|
||||||
completion
|
completion
|
||||||
|
|
@ -124,7 +124,7 @@ describe('Auto Completion Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocompletion after array with depth', (done) => {
|
it('Autocompletion after array with depth', done => {
|
||||||
const content =
|
const content =
|
||||||
'autoload:\n classmap:\n - test\n exclude-from-classmap:\n - test\n ';
|
'autoload:\n classmap:\n - test\n exclude-from-classmap:\n - test\n ';
|
||||||
const completion = parseSetup(content, 70);
|
const completion = parseSetup(content, 70);
|
||||||
|
|
@ -137,7 +137,7 @@ describe('Auto Completion Tests', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Failure tests', function() {
|
describe('Failure tests', function() {
|
||||||
it('Autocompletion has no results on value when they are not available', (done) => {
|
it('Autocompletion has no results on value when they are not available', done => {
|
||||||
const content = 'time: ';
|
const content = 'time: ';
|
||||||
const completion = parseSetup(content, 6);
|
const completion = parseSetup(content, 6);
|
||||||
completion
|
completion
|
||||||
|
|
@ -147,7 +147,7 @@ describe('Auto Completion Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocompletion has no results on value when they are not available (with depth)', (done) => {
|
it('Autocompletion has no results on value when they are not available (with depth)', done => {
|
||||||
const content = 'archive:\n exclude:\n - test\n ';
|
const content = 'archive:\n exclude:\n - test\n ';
|
||||||
const completion = parseSetup(content, 33);
|
const completion = parseSetup(content, 33);
|
||||||
completion
|
completion
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ const assert = require('assert');
|
||||||
const languageService = getLanguageService(
|
const languageService = getLanguageService(
|
||||||
schemaRequestService,
|
schemaRequestService,
|
||||||
workspaceContext,
|
workspaceContext,
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const uri = 'http://json.schemastore.org/asmdef';
|
const uri = 'http://json.schemastore.org/asmdef';
|
||||||
|
|
@ -32,7 +32,7 @@ describe('Auto Completion Tests', () => {
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,11 +40,11 @@ describe('Auto Completion Tests', () => {
|
||||||
const testTextDocument = setup(content);
|
const testTextDocument = setup(content);
|
||||||
return completionHelper(
|
return completionHelper(
|
||||||
testTextDocument,
|
testTextDocument,
|
||||||
testTextDocument.positionAt(position),
|
testTextDocument.positionAt(position)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
it('Array of enum autocomplete without word on array symbol', (done) => {
|
it('Array of enum autocomplete without word on array symbol', done => {
|
||||||
const content = 'optionalUnityReferences:\n -';
|
const content = 'optionalUnityReferences:\n -';
|
||||||
const completion = parseSetup(content, 29);
|
const completion = parseSetup(content, 29);
|
||||||
completion
|
completion
|
||||||
|
|
@ -54,7 +54,7 @@ describe('Auto Completion Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Array of enum autocomplete without word', (done) => {
|
it('Array of enum autocomplete without word', done => {
|
||||||
const content = 'optionalUnityReferences:\n - ';
|
const content = 'optionalUnityReferences:\n - ';
|
||||||
const completion = parseSetup(content, 30);
|
const completion = parseSetup(content, 30);
|
||||||
completion
|
completion
|
||||||
|
|
@ -64,7 +64,7 @@ describe('Auto Completion Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Array of enum autocomplete with letter', (done) => {
|
it('Array of enum autocomplete with letter', done => {
|
||||||
const content = 'optionalUnityReferences:\n - T';
|
const content = 'optionalUnityReferences:\n - T';
|
||||||
const completion = parseSetup(content, 31);
|
const completion = parseSetup(content, 31);
|
||||||
completion
|
completion
|
||||||
|
|
|
||||||
|
|
@ -12,96 +12,117 @@ const assert = require('assert');
|
||||||
const languageService = getLanguageService(
|
const languageService = getLanguageService(
|
||||||
schemaRequestService,
|
schemaRequestService,
|
||||||
workspaceContext,
|
workspaceContext,
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function traverse(
|
||||||
|
rootSymbols: DocumentSymbol[],
|
||||||
|
fn: (doc: DocumentSymbol) => void
|
||||||
|
) {
|
||||||
|
if (!rootSymbols || rootSymbols.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
rootSymbols.forEach(symbol => {
|
||||||
|
fn(symbol);
|
||||||
|
traverse(symbol.children, fn);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function allNodes(rootSymbols: DocumentSymbol[]): DocumentSymbol[] {
|
||||||
|
const res: DocumentSymbol[] = [];
|
||||||
|
traverse(rootSymbols, doc => res.push(doc));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: this suite is outdated and should be updated.
|
// TODO: this suite is outdated and should be updated.
|
||||||
// https://github.com/Microsoft/vscode-json-languageservice/blob/master/src/test/documentSymbols.test.ts
|
// https://github.com/Microsoft/vscode-json-languageservice/blob/master/src/test/documentSymbols.test.ts
|
||||||
xdescribe('Document Symbols Tests', () => {
|
describe('Document Symbols Tests', () => {
|
||||||
describe('Document Symbols Tests', function() {
|
describe('Document Symbols Tests', function() {
|
||||||
function setup(content: string) {
|
function setup(content: string) {
|
||||||
return TextDocument.create(
|
return TextDocument.create(
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseSetup(content: string) {
|
function parseSetup(content: string) {
|
||||||
const testTextDocument = setup(content);
|
const testTextDocument = setup(content);
|
||||||
const jsonDocument = parseYAML(testTextDocument.getText());
|
const jsonDocument = parseYAML(testTextDocument.getText());
|
||||||
return languageService.findDocumentSymbols(
|
const rootSymbols = languageService.findDocumentSymbols(
|
||||||
testTextDocument,
|
testTextDocument,
|
||||||
jsonDocument,
|
jsonDocument
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return allNodes(rootSymbols);
|
||||||
}
|
}
|
||||||
|
|
||||||
it('Document is empty', (done) => {
|
it('Document is empty', done => {
|
||||||
const content = '';
|
const content = '';
|
||||||
const symbols = parseSetup(content);
|
const symbols = parseSetup(content);
|
||||||
assert.equal(symbols, null);
|
assert.equal(symbols.length, 0);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Simple document symbols', (done) => {
|
it('Simple document symbols', done => {
|
||||||
const content = 'cwd: test';
|
const content = 'cwd: test';
|
||||||
const symbols = parseSetup(content);
|
const symbols = parseSetup(content);
|
||||||
assert.equal(symbols.length, 1);
|
assert.equal(symbols.length, 1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Document Symbols with number', (done) => {
|
it('Document Symbols with number', done => {
|
||||||
const content = 'node1: 10000';
|
const content = 'node1: 10000';
|
||||||
const symbols = parseSetup(content);
|
const symbols = parseSetup(content);
|
||||||
assert.equal(symbols.length, 1);
|
assert.equal(symbols.length, 1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Document Symbols with boolean', (done) => {
|
it('Document Symbols with boolean', done => {
|
||||||
const content = 'node1: False';
|
const content = 'node1: False';
|
||||||
const symbols = parseSetup(content);
|
const symbols = parseSetup(content);
|
||||||
assert.equal(symbols.length, 1);
|
assert.equal(symbols.length, 1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Document Symbols with object', (done) => {
|
it('Document Symbols with object', done => {
|
||||||
const content = 'scripts:\n node1: test\n node2: test';
|
const content = 'scripts:\n node1: test\n node2: test';
|
||||||
const symbols = parseSetup(content);
|
const symbols = parseSetup(content);
|
||||||
assert.equal(symbols.length, 3);
|
assert.equal(symbols.length, 3);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Document Symbols with null', (done) => {
|
it('Document Symbols with null', done => {
|
||||||
const content = 'apiVersion: null';
|
const content = 'apiVersion: null';
|
||||||
const symbols = parseSetup(content);
|
const symbols = parseSetup(content);
|
||||||
assert.equal(symbols.length, 1);
|
assert.equal(symbols.length, 1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Document Symbols with array of strings', (done) => {
|
it('Document Symbols with array of strings', done => {
|
||||||
const content = 'items:\n - test\n - test';
|
const content = 'items:\n - test\n - test';
|
||||||
const symbols = parseSetup(content);
|
const symbols = parseSetup(content);
|
||||||
assert.equal(symbols.length, 1);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Document Symbols with array', (done) => {
|
|
||||||
const content = 'authors:\n - name: Josh\n - email: jp';
|
|
||||||
const symbols = parseSetup(content);
|
|
||||||
assert.equal(symbols.length, 3);
|
assert.equal(symbols.length, 3);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Document Symbols with object and array', (done) => {
|
it('Document Symbols with array', done => {
|
||||||
const content =
|
const content = 'authors:\n - name: Josh\n - email: jp';
|
||||||
'scripts:\n node1: test\n node2: test\nauthors:\n - name: Josh\n - email: jp';
|
|
||||||
const symbols = parseSetup(content);
|
const symbols = parseSetup(content);
|
||||||
assert.equal(symbols.length, 6);
|
assert.equal(symbols.length, 5);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Document Symbols with multi documents', (done) => {
|
it('Document Symbols with object and array', done => {
|
||||||
|
const content =
|
||||||
|
'scripts:\n node1: test\n node2: test\nauthors:\n - name: Josh\n - email: jp';
|
||||||
|
const symbols = parseSetup(content);
|
||||||
|
assert.equal(symbols.length, 8);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Document Symbols with multi documents', done => {
|
||||||
const content = '---\nanalytics: true\n...\n---\njson: test\n...';
|
const content = '---\nanalytics: true\n...\n---\njson: test\n...';
|
||||||
const symbols = parseSetup(content);
|
const symbols = parseSetup(content);
|
||||||
assert.equal(symbols.length, 2);
|
assert.equal(symbols.length, 2);
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ const assert = require('assert');
|
||||||
const languageService = getLanguageService(
|
const languageService = getLanguageService(
|
||||||
schemaRequestService,
|
schemaRequestService,
|
||||||
workspaceContext,
|
workspaceContext,
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const uri = 'http://json.schemastore.org/bowerrc';
|
const uri = 'http://json.schemastore.org/bowerrc';
|
||||||
|
|
@ -32,7 +32,7 @@ describe('Formatter Tests', () => {
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,18 +42,18 @@ describe('Formatter Tests', () => {
|
||||||
const testTextDocument = setup(content);
|
const testTextDocument = setup(content);
|
||||||
const edits = languageService.doFormat(
|
const edits = languageService.doFormat(
|
||||||
testTextDocument,
|
testTextDocument,
|
||||||
{} as FormattingOptions,
|
{} as FormattingOptions
|
||||||
);
|
);
|
||||||
assert.notEqual(edits.length, 0);
|
assert.notEqual(edits.length, 0);
|
||||||
assert.equal(edits[0].newText, 'cwd: test\n');
|
assert.equal(edits[0].newText, 'cwd: test\n');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Formatting works without custom tags', () => {
|
it('Formatting works with custom tags', () => {
|
||||||
const content = `cwd: !Test test`;
|
const content = `cwd: !Test test`;
|
||||||
const testTextDocument = setup(content);
|
const testTextDocument = setup(content);
|
||||||
const edits = languageService.doFormat(
|
const edits = languageService.doFormat(
|
||||||
testTextDocument,
|
testTextDocument,
|
||||||
{} as FormattingOptions,
|
{} as FormattingOptions
|
||||||
);
|
);
|
||||||
assert.notEqual(edits.length, 0);
|
assert.notEqual(edits.length, 0);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,17 @@
|
||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
import { TextDocument } from 'vscode-languageserver';
|
import { TextDocument } from 'vscode-languageserver';
|
||||||
import { parse as parseYAML } from '../src/languageservice/parser/yamlParser';
|
import { parse as parseYAML } from '../src/languageservice/parser/yamlParser';
|
||||||
import { getLanguageService, LanguageSettings } from '../src/languageservice/yamlLanguageService';
|
import {
|
||||||
|
getLanguageService,
|
||||||
|
LanguageSettings,
|
||||||
|
} from '../src/languageservice/yamlLanguageService';
|
||||||
import { schemaRequestService, workspaceContext } from './testHelper';
|
import { schemaRequestService, workspaceContext } from './testHelper';
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
const languageService = getLanguageService(
|
const languageService = getLanguageService(
|
||||||
schemaRequestService,
|
schemaRequestService,
|
||||||
workspaceContext,
|
workspaceContext,
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const uri = 'http://json.schemastore.org/bowerrc';
|
const uri = 'http://json.schemastore.org/bowerrc';
|
||||||
|
|
@ -24,14 +27,14 @@ languageSettings.schemas.push({ uri, fileMatch });
|
||||||
languageService.configure(languageSettings);
|
languageService.configure(languageSettings);
|
||||||
|
|
||||||
describe('Hover Tests', () => {
|
describe('Hover Tests', () => {
|
||||||
describe('Yaml Hover with bowerrc', function () {
|
describe('Yaml Hover with bowerrc', function() {
|
||||||
describe('doComplete', function () {
|
describe('doComplete', function() {
|
||||||
function setup(content: string) {
|
function setup(content: string) {
|
||||||
return TextDocument.create(
|
return TextDocument.create(
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,81 +44,81 @@ describe('Hover Tests', () => {
|
||||||
return languageService.doHover(
|
return languageService.doHover(
|
||||||
testTextDocument,
|
testTextDocument,
|
||||||
testTextDocument.positionAt(position),
|
testTextDocument.positionAt(position),
|
||||||
jsonDocument,
|
jsonDocument
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
it('Hover on key on root', (done) => {
|
it('Hover on key on root', done => {
|
||||||
const content = 'cwd: test';
|
const content = 'cwd: test';
|
||||||
const hover = parseSetup(content, 1);
|
const hover = parseSetup(content, 1);
|
||||||
hover
|
hover
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.contents.length, 0);
|
assert.notEqual(result.contents.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Hover on value on root', (done) => {
|
it('Hover on value on root', done => {
|
||||||
const content = 'cwd: test';
|
const content = 'cwd: test';
|
||||||
const hover = parseSetup(content, 6);
|
const hover = parseSetup(content, 6);
|
||||||
hover
|
hover
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.contents.length, 0);
|
assert.notEqual(result.contents.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Hover on key with depth', (done) => {
|
it('Hover on key with depth', done => {
|
||||||
const content = 'scripts:\n postinstall: test';
|
const content = 'scripts:\n postinstall: test';
|
||||||
const hover = parseSetup(content, 15);
|
const hover = parseSetup(content, 15);
|
||||||
hover
|
hover
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.contents.length, 0);
|
assert.notEqual(result.contents.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Hover on value with depth', (done) => {
|
it('Hover on value with depth', done => {
|
||||||
const content = 'scripts:\n postinstall: test';
|
const content = 'scripts:\n postinstall: test';
|
||||||
const hover = parseSetup(content, 26);
|
const hover = parseSetup(content, 26);
|
||||||
hover
|
hover
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.contents.length, 0);
|
assert.notEqual(result.contents.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Hover works on both root node and child nodes works', (done) => {
|
it('Hover works on both root node and child nodes works', done => {
|
||||||
const content = 'scripts:\n postinstall: test';
|
const content = 'scripts:\n postinstall: test';
|
||||||
|
|
||||||
const firstHover = parseSetup(content, 3);
|
const firstHover = parseSetup(content, 3);
|
||||||
firstHover.then(function (result) {
|
firstHover.then(function(result) {
|
||||||
assert.notEqual(result.contents.length, 0);
|
assert.notEqual(result.contents.length, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
const secondHover = parseSetup(content, 15);
|
const secondHover = parseSetup(content, 15);
|
||||||
secondHover
|
secondHover
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.contents.length, 0);
|
assert.notEqual(result.contents.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Hover does not show results when there isnt description field', (done) => {
|
it('Hover does not show results when there isnt description field', done => {
|
||||||
const content = 'analytics: true';
|
const content = 'analytics: true';
|
||||||
const hover = parseSetup(content, 3);
|
const hover = parseSetup(content, 3);
|
||||||
hover
|
hover
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.contents.length, 0);
|
assert.notEqual(result.contents.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Hover on multi document', (done) => {
|
it('Hover on multi document', done => {
|
||||||
const content = '---\nanalytics: true\n...\n---\njson: test\n...';
|
const content = '---\nanalytics: true\n...\n---\njson: test\n...';
|
||||||
const hover = parseSetup(content, 30);
|
const hover = parseSetup(content, 30);
|
||||||
hover
|
hover
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.contents.length, 0);
|
assert.notEqual(result.contents.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ const assert = require('assert');
|
||||||
const languageService = getLanguageService(
|
const languageService = getLanguageService(
|
||||||
schemaRequestService,
|
schemaRequestService,
|
||||||
workspaceContext,
|
workspaceContext,
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const uri = 'http://json.schemastore.org/composer';
|
const uri = 'http://json.schemastore.org/composer';
|
||||||
|
|
@ -34,7 +34,7 @@ describe('Hover Tests', () => {
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,11 +44,11 @@ describe('Hover Tests', () => {
|
||||||
return languageService.doHover(
|
return languageService.doHover(
|
||||||
testTextDocument,
|
testTextDocument,
|
||||||
testTextDocument.positionAt(position),
|
testTextDocument.positionAt(position),
|
||||||
jsonDocument,
|
jsonDocument
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
it('Hover works on array nodes', (done) => {
|
it('Hover works on array nodes', done => {
|
||||||
const content = 'authors:\n - name: Josh';
|
const content = 'authors:\n - name: Josh';
|
||||||
const hover = parseSetup(content, 14);
|
const hover = parseSetup(content, 14);
|
||||||
hover
|
hover
|
||||||
|
|
@ -58,7 +58,7 @@ describe('Hover Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Hover works on array nodes 2', (done) => {
|
it('Hover works on array nodes 2', done => {
|
||||||
const content = 'authors:\n - name: Josh\n - email: jp';
|
const content = 'authors:\n - name: Josh\n - email: jp';
|
||||||
const hover = parseSetup(content, 28);
|
const hover = parseSetup(content, 28);
|
||||||
hover
|
hover
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,17 @@
|
||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
import { TextDocument } from 'vscode-languageserver';
|
import { TextDocument } from 'vscode-languageserver';
|
||||||
import { parse as parseYAML } from '../src/languageservice/parser/yamlParser';
|
import { parse as parseYAML } from '../src/languageservice/parser/yamlParser';
|
||||||
import { getLanguageService, LanguageSettings } from '../src/languageservice/yamlLanguageService';
|
import {
|
||||||
|
getLanguageService,
|
||||||
|
LanguageSettings,
|
||||||
|
} from '../src/languageservice/yamlLanguageService';
|
||||||
import { schemaRequestService, workspaceContext } from './testHelper';
|
import { schemaRequestService, workspaceContext } from './testHelper';
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
const languageService = getLanguageService(
|
const languageService = getLanguageService(
|
||||||
schemaRequestService,
|
schemaRequestService,
|
||||||
workspaceContext,
|
workspaceContext,
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const uri = 'http://json.schemastore.org/bowerrc';
|
const uri = 'http://json.schemastore.org/bowerrc';
|
||||||
|
|
@ -24,14 +27,14 @@ languageSettings.schemas.push({ uri, fileMatch });
|
||||||
languageService.configure(languageSettings);
|
languageService.configure(languageSettings);
|
||||||
|
|
||||||
describe('Hover Setting Tests', () => {
|
describe('Hover Setting Tests', () => {
|
||||||
describe('Yaml Hover with bowerrc', function () {
|
describe('Yaml Hover with bowerrc', function() {
|
||||||
describe('doComplete', function () {
|
describe('doComplete', function() {
|
||||||
function setup(content: string) {
|
function setup(content: string) {
|
||||||
return TextDocument.create(
|
return TextDocument.create(
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,16 +44,16 @@ describe('Hover Setting Tests', () => {
|
||||||
return languageService.doHover(
|
return languageService.doHover(
|
||||||
testTextDocument,
|
testTextDocument,
|
||||||
testTextDocument.positionAt(position),
|
testTextDocument.positionAt(position),
|
||||||
jsonDocument,
|
jsonDocument
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
it('Hover should not return anything', (done) => {
|
it('Hover should not return anything', done => {
|
||||||
const content = 'cwd: test';
|
const content = 'cwd: test';
|
||||||
const hover = parseSetup(content, 1);
|
const hover = parseSetup(content, 1);
|
||||||
hover
|
hover
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result, undefined);
|
assert.equal(result, undefined);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ const assert = require('assert');
|
||||||
const languageService = getLanguageService(
|
const languageService = getLanguageService(
|
||||||
schemaRequestService,
|
schemaRequestService,
|
||||||
workspaceContext,
|
workspaceContext,
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const uri =
|
const uri =
|
||||||
|
|
@ -34,7 +34,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,7 +46,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
|
|
||||||
// Validating basic nodes
|
// Validating basic nodes
|
||||||
describe('Test that validation does not throw errors', function() {
|
describe('Test that validation does not throw errors', function() {
|
||||||
it('Basic test', (done) => {
|
it('Basic test', done => {
|
||||||
const content = `apiVersion: v1`;
|
const content = `apiVersion: v1`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -56,7 +56,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Basic test on nodes with children', (done) => {
|
it('Basic test on nodes with children', done => {
|
||||||
const content = `metadata:\n name: hello`;
|
const content = `metadata:\n name: hello`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -66,7 +66,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Advanced test on nodes with children', (done) => {
|
it('Advanced test on nodes with children', done => {
|
||||||
const content = `apiVersion: v1\nmetadata:\n name: test1`;
|
const content = `apiVersion: v1\nmetadata:\n name: test1`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -76,7 +76,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Type string validates under children', (done) => {
|
it('Type string validates under children', done => {
|
||||||
const content = `apiVersion: v1\nkind: Pod\nmetadata:\n resourceVersion: test`;
|
const content = `apiVersion: v1\nkind: Pod\nmetadata:\n resourceVersion: test`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -87,7 +87,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Type tests', function() {
|
describe('Type tests', function() {
|
||||||
it('Type String does not error on valid node', (done) => {
|
it('Type String does not error on valid node', done => {
|
||||||
const content = `apiVersion: v1`;
|
const content = `apiVersion: v1`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -97,7 +97,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Type Boolean does not error on valid node', (done) => {
|
it('Type Boolean does not error on valid node', done => {
|
||||||
const content = `readOnlyRootFilesystem: false`;
|
const content = `readOnlyRootFilesystem: false`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -107,7 +107,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Type Number does not error on valid node', (done) => {
|
it('Type Number does not error on valid node', done => {
|
||||||
const content = `generation: 5`;
|
const content = `generation: 5`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -117,7 +117,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Type Object does not error on valid node', (done) => {
|
it('Type Object does not error on valid node', done => {
|
||||||
const content = `metadata:\n clusterName: tes`;
|
const content = `metadata:\n clusterName: tes`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -127,7 +127,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Type Array does not error on valid node', (done) => {
|
it('Type Array does not error on valid node', done => {
|
||||||
const content = `items:\n - apiVersion: v1`;
|
const content = `items:\n - apiVersion: v1`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -140,7 +140,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Test that validation DOES throw errors', function() {
|
describe('Test that validation DOES throw errors', function() {
|
||||||
it('Error when theres no value for a node', (done) => {
|
it('Error when theres no value for a node', done => {
|
||||||
const content = `apiVersion:`;
|
const content = `apiVersion:`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -150,7 +150,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Error on incorrect value type (number)', (done) => {
|
it('Error on incorrect value type (number)', done => {
|
||||||
const content = `apiVersion: 1000`;
|
const content = `apiVersion: 1000`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -160,7 +160,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Error on incorrect value type (boolean)', (done) => {
|
it('Error on incorrect value type (boolean)', done => {
|
||||||
const content = `apiVersion: False`;
|
const content = `apiVersion: False`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -170,7 +170,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Error on incorrect value type (string)', (done) => {
|
it('Error on incorrect value type (string)', done => {
|
||||||
const content = `isNonResourceURL: hello_world`;
|
const content = `isNonResourceURL: hello_world`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -180,7 +180,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Error on incorrect value type (object)', (done) => {
|
it('Error on incorrect value type (object)', done => {
|
||||||
const content = `apiVersion: v1\nkind: Pod\nmetadata:\n name: False`;
|
const content = `apiVersion: v1\nkind: Pod\nmetadata:\n name: False`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -190,7 +190,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Error on incorrect value type in multiple yaml documents', (done) => {
|
it('Error on incorrect value type in multiple yaml documents', done => {
|
||||||
const content = `---\napiVersion: v1\n...\n---\napiVersion: False\n...`;
|
const content = `---\napiVersion: v1\n...\n---\napiVersion: False\n...`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -200,7 +200,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Property error message should be "Unexpected property {$property_name}" when property is not allowed ', (done) => {
|
it('Property error message should be "Unexpected property {$property_name}" when property is not allowed ', done => {
|
||||||
const content = `unknown_node: test`;
|
const content = `unknown_node: test`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -220,7 +220,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -229,11 +229,11 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
const yDoc = parseYAML(testTextDocument.getText());
|
const yDoc = parseYAML(testTextDocument.getText());
|
||||||
return completionHelper(
|
return completionHelper(
|
||||||
testTextDocument,
|
testTextDocument,
|
||||||
testTextDocument.positionAt(position),
|
testTextDocument.positionAt(position)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
it('Autocomplete on root node without word', (done) => {
|
it('Autocomplete on root node without word', done => {
|
||||||
const content = '';
|
const content = '';
|
||||||
const completion = parseSetup(content, 0);
|
const completion = parseSetup(content, 0);
|
||||||
completion
|
completion
|
||||||
|
|
@ -243,7 +243,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete on root node with word', (done) => {
|
it('Autocomplete on root node with word', done => {
|
||||||
const content = 'api';
|
const content = 'api';
|
||||||
const completion = parseSetup(content, 6);
|
const completion = parseSetup(content, 6);
|
||||||
completion
|
completion
|
||||||
|
|
@ -253,7 +253,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete on default value (without value content)', (done) => {
|
it('Autocomplete on default value (without value content)', done => {
|
||||||
const content = 'apiVersion: ';
|
const content = 'apiVersion: ';
|
||||||
const completion = parseSetup(content, 10);
|
const completion = parseSetup(content, 10);
|
||||||
completion
|
completion
|
||||||
|
|
@ -263,7 +263,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete on default value (with value content)', (done) => {
|
it('Autocomplete on default value (with value content)', done => {
|
||||||
const content = 'apiVersion: v1\nkind: Bin';
|
const content = 'apiVersion: v1\nkind: Bin';
|
||||||
const completion = parseSetup(content, 19);
|
const completion = parseSetup(content, 19);
|
||||||
completion
|
completion
|
||||||
|
|
@ -273,7 +273,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete on boolean value (without value content)', (done) => {
|
it('Autocomplete on boolean value (without value content)', done => {
|
||||||
const content = 'isNonResourceURL: ';
|
const content = 'isNonResourceURL: ';
|
||||||
const completion = parseSetup(content, 18);
|
const completion = parseSetup(content, 18);
|
||||||
completion
|
completion
|
||||||
|
|
@ -283,7 +283,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete on boolean value (with value content)', (done) => {
|
it('Autocomplete on boolean value (with value content)', done => {
|
||||||
const content = 'isNonResourceURL: fal';
|
const content = 'isNonResourceURL: fal';
|
||||||
const completion = parseSetup(content, 21);
|
const completion = parseSetup(content, 21);
|
||||||
completion
|
completion
|
||||||
|
|
@ -293,7 +293,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete key in middle of file', (done) => {
|
it('Autocomplete key in middle of file', done => {
|
||||||
const content = 'metadata:\n nam';
|
const content = 'metadata:\n nam';
|
||||||
const completion = parseSetup(content, 14);
|
const completion = parseSetup(content, 14);
|
||||||
completion
|
completion
|
||||||
|
|
@ -303,7 +303,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete key in middle of file 2', (done) => {
|
it('Autocomplete key in middle of file 2', done => {
|
||||||
const content = 'metadata:\n name: test\n cluster';
|
const content = 'metadata:\n name: test\n cluster';
|
||||||
const completion = parseSetup(content, 31);
|
const completion = parseSetup(content, 31);
|
||||||
completion
|
completion
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ function toFsPath(str): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
const uri = toFsPath(
|
const uri = toFsPath(
|
||||||
path.join(__dirname, './fixtures/customMultipleSchemaSequences.json'),
|
path.join(__dirname, './fixtures/customMultipleSchemaSequences.json')
|
||||||
);
|
);
|
||||||
const languageSettings: LanguageSettings = {
|
const languageSettings: LanguageSettings = {
|
||||||
schemas: [],
|
schemas: [],
|
||||||
|
|
@ -50,13 +50,13 @@ languageService.configure(languageSettings);
|
||||||
|
|
||||||
describe('Multiple Documents Validation Tests', () => {
|
describe('Multiple Documents Validation Tests', () => {
|
||||||
// Tests for validator
|
// Tests for validator
|
||||||
describe('Multiple Documents Validation', function () {
|
describe('Multiple Documents Validation', function() {
|
||||||
function setup(content: string) {
|
function setup(content: string) {
|
||||||
return TextDocument.create(
|
return TextDocument.create(
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,7 +64,7 @@ describe('Multiple Documents Validation Tests', () => {
|
||||||
const testTextDocument = setup(content);
|
const testTextDocument = setup(content);
|
||||||
const yDoc = parseYAML(
|
const yDoc = parseYAML(
|
||||||
testTextDocument.getText(),
|
testTextDocument.getText(),
|
||||||
languageSettings.customTags,
|
languageSettings.customTags
|
||||||
);
|
);
|
||||||
return languageService.doValidation(testTextDocument, yDoc);
|
return languageService.doValidation(testTextDocument, yDoc);
|
||||||
}
|
}
|
||||||
|
|
@ -75,11 +75,11 @@ describe('Multiple Documents Validation Tests', () => {
|
||||||
return languageService.doHover(
|
return languageService.doHover(
|
||||||
testTextDocument,
|
testTextDocument,
|
||||||
testTextDocument.positionAt(position),
|
testTextDocument.positionAt(position),
|
||||||
jsonDocument,
|
jsonDocument
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
it('Should validate multiple documents', (done) => {
|
it('Should validate multiple documents', done => {
|
||||||
const content = `
|
const content = `
|
||||||
name: jack
|
name: jack
|
||||||
age: 22
|
age: 22
|
||||||
|
|
@ -88,56 +88,56 @@ analytics: true
|
||||||
`;
|
`;
|
||||||
const validator = validatorSetup(content);
|
const validator = validatorSetup(content);
|
||||||
validator
|
validator
|
||||||
.then((result) => {
|
.then(result => {
|
||||||
assert.equal(result.length, 0);
|
assert.equal(result.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should find errors in both documents', (done) => {
|
it('Should find errors in both documents', done => {
|
||||||
const content = `name1: jack
|
const content = `name1: jack
|
||||||
age: asd
|
age: asd
|
||||||
---
|
---
|
||||||
cwd: False`;
|
cwd: False`;
|
||||||
const validator = validatorSetup(content);
|
const validator = validatorSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.equal(result.length, 3);
|
assert.equal(result.length, 3);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should find errors in first document', (done) => {
|
it('Should find errors in first document', done => {
|
||||||
const content = `name: jack
|
const content = `name: jack
|
||||||
age: age
|
age: age
|
||||||
---
|
---
|
||||||
analytics: true`;
|
analytics: true`;
|
||||||
const validator = validatorSetup(content);
|
const validator = validatorSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.equal(result.length, 1);
|
assert.equal(result.length, 1);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should find errors in second document', (done) => {
|
it('Should find errors in second document', done => {
|
||||||
const content = `name: jack
|
const content = `name: jack
|
||||||
age: 22
|
age: 22
|
||||||
---
|
---
|
||||||
cwd: False`;
|
cwd: False`;
|
||||||
const validator = validatorSetup(content);
|
const validator = validatorSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.equal(result.length, 1);
|
assert.equal(result.length, 1);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should hover in first document', (done) => {
|
it('Should hover in first document', done => {
|
||||||
const content = `name: jack\nage: 22\n---\ncwd: False`;
|
const content = `name: jack\nage: 22\n---\ncwd: False`;
|
||||||
const hover = hoverSetup(content, 1 + content.indexOf('age'));
|
const hover = hoverSetup(content, 1 + content.indexOf('age'));
|
||||||
hover
|
hover
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.contents.length, 0);
|
assert.notEqual(result.contents.length, 0);
|
||||||
assert.equal(result.contents[0], 'The age of this person');
|
assert.equal(result.contents[0], 'The age of this person');
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ const fixtureDocuments = {
|
||||||
'http://schema.management.azure.com/schemas/2015-08-01/Microsoft.Compute.json':
|
'http://schema.management.azure.com/schemas/2015-08-01/Microsoft.Compute.json':
|
||||||
'Microsoft.Compute.json',
|
'Microsoft.Compute.json',
|
||||||
};
|
};
|
||||||
const requestServiceMock = function (uri: string): Promise<string> {
|
const requestServiceMock = function(uri: string): Promise<string> {
|
||||||
if (uri.length && uri[uri.length - 1] === '#') {
|
if (uri.length && uri[uri.length - 1] === '#') {
|
||||||
uri = uri.substr(0, uri.length - 1);
|
uri = uri.substr(0, uri.length - 1);
|
||||||
}
|
}
|
||||||
|
|
@ -48,10 +48,10 @@ const workspaceContext = {
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('JSON Schema', () => {
|
describe('JSON Schema', () => {
|
||||||
test('Resolving $refs', function (testDone) {
|
test('Resolving $refs', function(testDone) {
|
||||||
const service = new SchemaService.JSONSchemaService(
|
const service = new SchemaService.JSONSchemaService(
|
||||||
requestServiceMock,
|
requestServiceMock,
|
||||||
workspaceContext,
|
workspaceContext
|
||||||
);
|
);
|
||||||
service.setSchemaContributions({
|
service.setSchemaContributions({
|
||||||
schemas: {
|
schemas: {
|
||||||
|
|
@ -74,7 +74,7 @@ describe('JSON Schema', () => {
|
||||||
|
|
||||||
service
|
service
|
||||||
.getResolvedSchema('https://myschemastore/main')
|
.getResolvedSchema('https://myschemastore/main')
|
||||||
.then((solvedSchema) => {
|
.then(solvedSchema => {
|
||||||
assert.deepEqual(solvedSchema.schema.properties.child, {
|
assert.deepEqual(solvedSchema.schema.properties.child, {
|
||||||
id: 'https://myschemastore/child',
|
id: 'https://myschemastore/child',
|
||||||
type: 'bool',
|
type: 'bool',
|
||||||
|
|
@ -83,16 +83,16 @@ describe('JSON Schema', () => {
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
() => testDone(),
|
() => testDone(),
|
||||||
(error) => {
|
error => {
|
||||||
testDone(error);
|
testDone(error);
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Resolving $refs 2', function (testDone) {
|
test('Resolving $refs 2', function(testDone) {
|
||||||
const service = new SchemaService.JSONSchemaService(
|
const service = new SchemaService.JSONSchemaService(
|
||||||
requestServiceMock,
|
requestServiceMock,
|
||||||
workspaceContext,
|
workspaceContext
|
||||||
);
|
);
|
||||||
service.setSchemaContributions({
|
service.setSchemaContributions({
|
||||||
schemas: {
|
schemas: {
|
||||||
|
|
@ -121,7 +121,7 @@ describe('JSON Schema', () => {
|
||||||
|
|
||||||
service
|
service
|
||||||
.getResolvedSchema('http://json.schemastore.org/swagger-2.0')
|
.getResolvedSchema('http://json.schemastore.org/swagger-2.0')
|
||||||
.then((fs) => {
|
.then(fs => {
|
||||||
assert.deepEqual(fs.schema.properties.responseValue, {
|
assert.deepEqual(fs.schema.properties.responseValue, {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
required: ['$ref'],
|
required: ['$ref'],
|
||||||
|
|
@ -130,16 +130,16 @@ describe('JSON Schema', () => {
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
() => testDone(),
|
() => testDone(),
|
||||||
(error) => {
|
error => {
|
||||||
testDone(error);
|
testDone(error);
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Resolving $refs 3', function (testDone) {
|
test('Resolving $refs 3', function(testDone) {
|
||||||
const service = new SchemaService.JSONSchemaService(
|
const service = new SchemaService.JSONSchemaService(
|
||||||
requestServiceMock,
|
requestServiceMock,
|
||||||
workspaceContext,
|
workspaceContext
|
||||||
);
|
);
|
||||||
service.setSchemaContributions({
|
service.setSchemaContributions({
|
||||||
schemas: {
|
schemas: {
|
||||||
|
|
@ -172,7 +172,7 @@ describe('JSON Schema', () => {
|
||||||
|
|
||||||
service
|
service
|
||||||
.getResolvedSchema('https://myschemastore/main/schema1.json')
|
.getResolvedSchema('https://myschemastore/main/schema1.json')
|
||||||
.then((fs) => {
|
.then(fs => {
|
||||||
assert.deepEqual(fs.schema.properties.p1, {
|
assert.deepEqual(fs.schema.properties.p1, {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
enum: ['object'],
|
enum: ['object'],
|
||||||
|
|
@ -188,16 +188,16 @@ describe('JSON Schema', () => {
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
() => testDone(),
|
() => testDone(),
|
||||||
(error) => {
|
error => {
|
||||||
testDone(error);
|
testDone(error);
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('FileSchema', function (testDone) {
|
test('FileSchema', function(testDone) {
|
||||||
const service = new SchemaService.JSONSchemaService(
|
const service = new SchemaService.JSONSchemaService(
|
||||||
requestServiceMock,
|
requestServiceMock,
|
||||||
workspaceContext,
|
workspaceContext
|
||||||
);
|
);
|
||||||
|
|
||||||
service.setSchemaContributions({
|
service.setSchemaContributions({
|
||||||
|
|
@ -222,22 +222,22 @@ describe('JSON Schema', () => {
|
||||||
|
|
||||||
service
|
service
|
||||||
.getResolvedSchema('main')
|
.getResolvedSchema('main')
|
||||||
.then((fs) => {
|
.then(fs => {
|
||||||
const section = fs.getSection(['child', 'grandchild']);
|
const section = fs.getSection(['child', 'grandchild']);
|
||||||
assert.equal(section.description, 'Meaning of Life');
|
assert.equal(section.description, 'Meaning of Life');
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
() => testDone(),
|
() => testDone(),
|
||||||
(error) => {
|
error => {
|
||||||
testDone(error);
|
testDone(error);
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Array FileSchema', function (testDone) {
|
test('Array FileSchema', function(testDone) {
|
||||||
const service = new SchemaService.JSONSchemaService(
|
const service = new SchemaService.JSONSchemaService(
|
||||||
requestServiceMock,
|
requestServiceMock,
|
||||||
workspaceContext,
|
workspaceContext
|
||||||
);
|
);
|
||||||
|
|
||||||
service.setSchemaContributions({
|
service.setSchemaContributions({
|
||||||
|
|
@ -265,22 +265,22 @@ describe('JSON Schema', () => {
|
||||||
|
|
||||||
service
|
service
|
||||||
.getResolvedSchema('main')
|
.getResolvedSchema('main')
|
||||||
.then((fs) => {
|
.then(fs => {
|
||||||
const section = fs.getSection(['child', '0', 'grandchild']);
|
const section = fs.getSection(['child', '0', 'grandchild']);
|
||||||
assert.equal(section.description, 'Meaning of Life');
|
assert.equal(section.description, 'Meaning of Life');
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
() => testDone(),
|
() => testDone(),
|
||||||
(error) => {
|
error => {
|
||||||
testDone(error);
|
testDone(error);
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Missing subschema', function (testDone) {
|
test('Missing subschema', function(testDone) {
|
||||||
const service = new SchemaService.JSONSchemaService(
|
const service = new SchemaService.JSONSchemaService(
|
||||||
requestServiceMock,
|
requestServiceMock,
|
||||||
workspaceContext,
|
workspaceContext
|
||||||
);
|
);
|
||||||
|
|
||||||
service.setSchemaContributions({
|
service.setSchemaContributions({
|
||||||
|
|
@ -299,22 +299,22 @@ describe('JSON Schema', () => {
|
||||||
|
|
||||||
service
|
service
|
||||||
.getResolvedSchema('main')
|
.getResolvedSchema('main')
|
||||||
.then((fs) => {
|
.then(fs => {
|
||||||
const section = fs.getSection(['child', 'grandchild']);
|
const section = fs.getSection(['child', 'grandchild']);
|
||||||
assert.strictEqual(section, null);
|
assert.strictEqual(section, null);
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
() => testDone(),
|
() => testDone(),
|
||||||
(error) => {
|
error => {
|
||||||
testDone(error);
|
testDone(error);
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Preloaded Schema', function (testDone) {
|
test('Preloaded Schema', function(testDone) {
|
||||||
const service = new SchemaService.JSONSchemaService(
|
const service = new SchemaService.JSONSchemaService(
|
||||||
requestServiceMock,
|
requestServiceMock,
|
||||||
workspaceContext,
|
workspaceContext
|
||||||
);
|
);
|
||||||
const id = 'https://myschemastore/test1';
|
const id = 'https://myschemastore/test1';
|
||||||
const schema: JsonSchema.JSONSchema = {
|
const schema: JsonSchema.JSONSchema = {
|
||||||
|
|
@ -336,53 +336,53 @@ describe('JSON Schema', () => {
|
||||||
|
|
||||||
service
|
service
|
||||||
.getSchemaForResource('test.json')
|
.getSchemaForResource('test.json')
|
||||||
.then((schema) => {
|
.then(schema => {
|
||||||
const section = schema.getSection(['child', 'grandchild']);
|
const section = schema.getSection(['child', 'grandchild']);
|
||||||
assert.equal(section.description, 'Meaning of Life');
|
assert.equal(section.description, 'Meaning of Life');
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
() => testDone(),
|
() => testDone(),
|
||||||
(error) => {
|
error => {
|
||||||
testDone(error);
|
testDone(error);
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Null Schema', function (testDone) {
|
test('Null Schema', function(testDone) {
|
||||||
const service = new SchemaService.JSONSchemaService(
|
const service = new SchemaService.JSONSchemaService(
|
||||||
requestServiceMock,
|
requestServiceMock,
|
||||||
workspaceContext,
|
workspaceContext
|
||||||
);
|
);
|
||||||
|
|
||||||
service
|
service
|
||||||
.getSchemaForResource('test.json')
|
.getSchemaForResource('test.json')
|
||||||
.then((schema) => {
|
.then(schema => {
|
||||||
assert.equal(schema, null);
|
assert.equal(schema, null);
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
() => testDone(),
|
() => testDone(),
|
||||||
(error) => {
|
error => {
|
||||||
testDone(error);
|
testDone(error);
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Schema not found', function (testDone) {
|
test('Schema not found', function(testDone) {
|
||||||
const service = new SchemaService.JSONSchemaService(
|
const service = new SchemaService.JSONSchemaService(
|
||||||
requestServiceMock,
|
requestServiceMock,
|
||||||
workspaceContext,
|
workspaceContext
|
||||||
);
|
);
|
||||||
|
|
||||||
service
|
service
|
||||||
.loadSchema('test.json')
|
.loadSchema('test.json')
|
||||||
.then((schema) => {
|
.then(schema => {
|
||||||
assert.notEqual(schema.errors.length, 0);
|
assert.notEqual(schema.errors.length, 0);
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
() => testDone(),
|
() => testDone(),
|
||||||
(error) => {
|
error => {
|
||||||
testDone(error);
|
testDone(error);
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ const assert = require('assert');
|
||||||
const languageService = getLanguageService(
|
const languageService = getLanguageService(
|
||||||
schemaRequestService,
|
schemaRequestService,
|
||||||
workspaceContext,
|
workspaceContext,
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const uri = 'SchemaDoesNotExist';
|
const uri = 'SchemaDoesNotExist';
|
||||||
|
|
@ -32,7 +32,7 @@ describe('Validation Tests', () => {
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,14 +40,14 @@ describe('Validation Tests', () => {
|
||||||
const testTextDocument = setup(content);
|
const testTextDocument = setup(content);
|
||||||
const yDoc = parseYAML(
|
const yDoc = parseYAML(
|
||||||
testTextDocument.getText(),
|
testTextDocument.getText(),
|
||||||
languageSettings.customTags,
|
languageSettings.customTags
|
||||||
);
|
);
|
||||||
return languageService.doValidation(testTextDocument, yDoc);
|
return languageService.doValidation(testTextDocument, yDoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validating basic nodes
|
// Validating basic nodes
|
||||||
describe('Test that validation throws error when schema is not found', function() {
|
describe('Test that validation throws error when schema is not found', function() {
|
||||||
it('Basic test', (done) => {
|
it('Basic test', done => {
|
||||||
const content = `testing: true`;
|
const content = `testing: true`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ const assert = require('assert');
|
||||||
const languageService = getLanguageService(
|
const languageService = getLanguageService(
|
||||||
schemaRequestService,
|
schemaRequestService,
|
||||||
workspaceContext,
|
workspaceContext,
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const uri = 'http://json.schemastore.org/bowerrc';
|
const uri = 'http://json.schemastore.org/bowerrc';
|
||||||
|
|
@ -28,13 +28,13 @@ languageService.configure(languageSettings);
|
||||||
|
|
||||||
describe('Validation Tests', () => {
|
describe('Validation Tests', () => {
|
||||||
// Tests for validator
|
// Tests for validator
|
||||||
describe('Validation', function () {
|
describe('Validation', function() {
|
||||||
function setup(content: string) {
|
function setup(content: string) {
|
||||||
return TextDocument.create(
|
return TextDocument.create(
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,154 +42,154 @@ describe('Validation Tests', () => {
|
||||||
const testTextDocument = setup(content);
|
const testTextDocument = setup(content);
|
||||||
const yDoc = parseYAML(
|
const yDoc = parseYAML(
|
||||||
testTextDocument.getText(),
|
testTextDocument.getText(),
|
||||||
languageSettings.customTags,
|
languageSettings.customTags
|
||||||
);
|
);
|
||||||
return languageService.doValidation(testTextDocument, yDoc);
|
return languageService.doValidation(testTextDocument, yDoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validating basic nodes
|
// Validating basic nodes
|
||||||
describe('Test that validation does not throw errors', function () {
|
describe('Test that validation does not throw errors', function() {
|
||||||
it('Basic test', (done) => {
|
it('Basic test', done => {
|
||||||
const content = `analytics: true`;
|
const content = `analytics: true`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Test that boolean value in quotations is not interpreted as boolean i.e. it errors', (done) => {
|
it('Test that boolean value in quotations is not interpreted as boolean i.e. it errors', done => {
|
||||||
const content = `analytics: "no"`;
|
const content = `analytics: "no"`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.length, 0);
|
assert.notEqual(result.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Test that boolean value without quotations is valid', (done) => {
|
it('Test that boolean value without quotations is valid', done => {
|
||||||
const content = `analytics: no`;
|
const content = `analytics: no`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Test that boolean is valid when inside strings', (done) => {
|
it('Test that boolean is valid when inside strings', done => {
|
||||||
const content = `cwd: "no"`;
|
const content = `cwd: "no"`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Test that boolean is invalid when no strings present and schema wants string', (done) => {
|
it('Test that boolean is invalid when no strings present and schema wants string', done => {
|
||||||
const content = `cwd: no`;
|
const content = `cwd: no`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.length, 0);
|
assert.notEqual(result.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Basic test', (done) => {
|
it('Basic test', done => {
|
||||||
const content = `analytics: true`;
|
const content = `analytics: true`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Basic test on nodes with children', (done) => {
|
it('Basic test on nodes with children', done => {
|
||||||
const content = `scripts:\n preinstall: test1\n postinstall: test2`;
|
const content = `scripts:\n preinstall: test1\n postinstall: test2`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Advanced test on nodes with children', (done) => {
|
it('Advanced test on nodes with children', done => {
|
||||||
const content = `analytics: true\ncwd: this\nscripts:\n preinstall: test1\n postinstall: test2`;
|
const content = `analytics: true\ncwd: this\nscripts:\n preinstall: test1\n postinstall: test2`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Type string validates under children', (done) => {
|
it('Type string validates under children', done => {
|
||||||
const content = `registry:\n register: http://test_url.com`;
|
const content = `registry:\n register: http://test_url.com`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Include with value should not error', (done) => {
|
it('Include with value should not error', done => {
|
||||||
const content = `customize: !include customize.yaml`;
|
const content = `customize: !include customize.yaml`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Null scalar value should be treated as null', (done) => {
|
it('Null scalar value should be treated as null', done => {
|
||||||
const content = `cwd: Null`;
|
const content = `cwd: Null`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(1);
|
expect(result.length).toEqual(1);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Anchor should not not error', (done) => {
|
it('Anchor should not not error', done => {
|
||||||
const content = `default: &DEFAULT\n name: Anchor\nanchor_test:\n <<: *DEFAULT`;
|
const content = `default: &DEFAULT\n name: Anchor\nanchor_test:\n <<: *DEFAULT`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Anchor with multiple references should not not error', (done) => {
|
it('Anchor with multiple references should not not error', done => {
|
||||||
const content = `default: &DEFAULT\n name: Anchor\nanchor_test:\n <<: *DEFAULT\nanchor_test2:\n <<: *DEFAULT`;
|
const content = `default: &DEFAULT\n name: Anchor\nanchor_test:\n <<: *DEFAULT\nanchor_test2:\n <<: *DEFAULT`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Multiple Anchor in array of references should not not error', (done) => {
|
it('Multiple Anchor in array of references should not not error', done => {
|
||||||
const content = `default: &DEFAULT\n name: Anchor\ncustomname: &CUSTOMNAME\n custom_name: Anchor\nanchor_test:\n <<: [*DEFAULT, *CUSTOMNAME]`;
|
const content = `default: &DEFAULT\n name: Anchor\ncustomname: &CUSTOMNAME\n custom_name: Anchor\nanchor_test:\n <<: [*DEFAULT, *CUSTOMNAME]`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Multiple Anchors being referenced in same level at same time', (done) => {
|
it('Multiple Anchors being referenced in same level at same time', done => {
|
||||||
const content = `
|
const content = `
|
||||||
default: &DEFAULT
|
default: &DEFAULT
|
||||||
name: Anchor
|
name: Anchor
|
||||||
|
|
@ -201,87 +201,87 @@ describe('Validation Tests', () => {
|
||||||
`;
|
`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Custom Tags without type', (done) => {
|
it('Custom Tags without type', done => {
|
||||||
const content = `analytics: !Test false`;
|
const content = `analytics: !Test false`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Custom Tags with type', (done) => {
|
it('Custom Tags with type', done => {
|
||||||
const content = `resolvers: !Ref\n - test`;
|
const content = `resolvers: !Ref\n - test`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Type tests', function () {
|
describe('Type tests', function() {
|
||||||
it('Type String does not error on valid node', (done) => {
|
it('Type String does not error on valid node', done => {
|
||||||
const content = `cwd: this`;
|
const content = `cwd: this`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Type Boolean does not error on valid node', (done) => {
|
it('Type Boolean does not error on valid node', done => {
|
||||||
const content = `analytics: true`;
|
const content = `analytics: true`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Type Number does not error on valid node', (done) => {
|
it('Type Number does not error on valid node', done => {
|
||||||
const content = `timeout: 60000`;
|
const content = `timeout: 60000`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Type Object does not error on valid node', (done) => {
|
it('Type Object does not error on valid node', done => {
|
||||||
const content = `registry:\n search: http://test_url.com`;
|
const content = `registry:\n search: http://test_url.com`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Type Array does not error on valid node', (done) => {
|
it('Type Array does not error on valid node', done => {
|
||||||
const content = `resolvers:\n - test\n - test\n - test`;
|
const content = `resolvers:\n - test\n - test\n - test`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Do not error when there are multiple types in schema and theyre valid', (done) => {
|
it('Do not error when there are multiple types in schema and theyre valid', done => {
|
||||||
const content = `license: MIT`;
|
const content = `license: MIT`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator.then(function (result) {
|
validator.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
|
|
@ -289,82 +289,82 @@ describe('Validation Tests', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Test that validation DOES throw errors', function () {
|
describe('Test that validation DOES throw errors', function() {
|
||||||
it('Error when theres a finished untyped item', (done) => {
|
it('Error when theres a finished untyped item', done => {
|
||||||
const content = `cwd: hello\nan`;
|
const content = `cwd: hello\nan`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.length, 0);
|
assert.notEqual(result.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Error when theres no value for a node', (done) => {
|
it('Error when theres no value for a node', done => {
|
||||||
const content = `cwd:`;
|
const content = `cwd:`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.length, 0);
|
assert.notEqual(result.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Error on incorrect value type (number)', (done) => {
|
it('Error on incorrect value type (number)', done => {
|
||||||
const content = `cwd: 100000`;
|
const content = `cwd: 100000`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.length, 0);
|
assert.notEqual(result.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Error on incorrect value type (boolean)', (done) => {
|
it('Error on incorrect value type (boolean)', done => {
|
||||||
const content = `cwd: False`;
|
const content = `cwd: False`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.length, 0);
|
assert.notEqual(result.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Error on incorrect value type (string)', (done) => {
|
it('Error on incorrect value type (string)', done => {
|
||||||
const content = `analytics: hello`;
|
const content = `analytics: hello`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.length, 0);
|
assert.notEqual(result.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Error on incorrect value type (object)', (done) => {
|
it('Error on incorrect value type (object)', done => {
|
||||||
const content = `scripts: test`;
|
const content = `scripts: test`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.length, 0);
|
assert.notEqual(result.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Error on incorrect value type (array)', (done) => {
|
it('Error on incorrect value type (array)', done => {
|
||||||
const content = `resolvers: test`;
|
const content = `resolvers: test`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.length, 0);
|
assert.notEqual(result.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Include without value should error', (done) => {
|
it('Include without value should error', done => {
|
||||||
const content = `customize: !include`;
|
const content = `customize: !include`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(1);
|
expect(result.length).toEqual(1);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ import URI from '../src/languageservice/utils/uri';
|
||||||
|
|
||||||
namespace VSCodeContentRequest {
|
namespace VSCodeContentRequest {
|
||||||
export const type: RequestType<{}, {}, {}, {}> = new RequestType(
|
export const type: RequestType<{}, {}, {}, {}> = new RequestType(
|
||||||
'vscode/content',
|
'vscode/content'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -28,7 +28,7 @@ let connection: IConnection = null;
|
||||||
if (process.argv.indexOf('--stdio') === -1) {
|
if (process.argv.indexOf('--stdio') === -1) {
|
||||||
connection = createConnection(
|
connection = createConnection(
|
||||||
new IPCMessageReader(process),
|
new IPCMessageReader(process),
|
||||||
new IPCMessageWriter(process),
|
new IPCMessageWriter(process)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
connection = createConnection();
|
connection = createConnection();
|
||||||
|
|
@ -50,7 +50,7 @@ connection.onInitialize(
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
export let workspaceContext = {
|
export let workspaceContext = {
|
||||||
|
|
@ -69,24 +69,24 @@ export let schemaRequestService = (uri: string): Thenable<string> => {
|
||||||
});
|
});
|
||||||
} else if (Strings.startsWith(uri, 'vscode://')) {
|
} else if (Strings.startsWith(uri, 'vscode://')) {
|
||||||
return connection.sendRequest(VSCodeContentRequest.type, uri).then(
|
return connection.sendRequest(VSCodeContentRequest.type, uri).then(
|
||||||
(responseText) => {
|
responseText => {
|
||||||
return responseText;
|
return responseText;
|
||||||
},
|
},
|
||||||
(error) => {
|
error => {
|
||||||
return error.message;
|
return error.message;
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return xhr({ url: uri, followRedirects: 5 }).then(
|
return xhr({ url: uri, followRedirects: 5 }).then(
|
||||||
(response) => {
|
response => {
|
||||||
return response.responseText;
|
return response.responseText;
|
||||||
},
|
},
|
||||||
(error: XHRResponse) => {
|
(error: XHRResponse) => {
|
||||||
return Promise.reject(
|
return Promise.reject(
|
||||||
error.responseText ||
|
error.responseText ||
|
||||||
getErrorStatusDescription(error.status) ||
|
getErrorStatusDescription(error.status) ||
|
||||||
error.toString(),
|
error.toString()
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"lib": ["es2016"],
|
"lib": ["es2016"],
|
||||||
"outDir": "./out/server",
|
|
||||||
"downlevelIteration": true
|
"downlevelIteration": true
|
||||||
},
|
},
|
||||||
"exclude": ["node_modules", "out"]
|
"exclude": ["node_modules", "out"]
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ describe('URI Tests', () => {
|
||||||
'www.foo.com',
|
'www.foo.com',
|
||||||
'/bar.html',
|
'/bar.html',
|
||||||
'name=hello',
|
'name=hello',
|
||||||
'123',
|
'123'
|
||||||
);
|
);
|
||||||
assert.equal(result.authority, 'www.foo.com');
|
assert.equal(result.authority, 'www.foo.com');
|
||||||
assert.equal(result.fragment, '123');
|
assert.equal(result.fragment, '123');
|
||||||
|
|
@ -69,14 +69,14 @@ describe('URI Tests', () => {
|
||||||
describe('URI toString', function() {
|
describe('URI toString', function() {
|
||||||
it('toString with encoding', () => {
|
it('toString with encoding', () => {
|
||||||
const result = URI.parse(
|
const result = URI.parse(
|
||||||
'http://www.foo.com:8080/bar.html?name=hello#123',
|
'http://www.foo.com:8080/bar.html?name=hello#123'
|
||||||
).toString();
|
).toString();
|
||||||
assert.equal('http://www.foo.com:8080/bar.html?name%3Dhello#123', result);
|
assert.equal('http://www.foo.com:8080/bar.html?name%3Dhello#123', result);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('toString without encoding', () => {
|
it('toString without encoding', () => {
|
||||||
const result = URI.parse(
|
const result = URI.parse(
|
||||||
'http://www.foo.com/bar.html?name=hello#123',
|
'http://www.foo.com/bar.html?name=hello#123'
|
||||||
).toString(true);
|
).toString(true);
|
||||||
assert.equal('http://www.foo.com/bar.html?name=hello#123', result);
|
assert.equal('http://www.foo.com/bar.html?name=hello#123', result);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
24
test/yamlDocument.test.ts
Normal file
24
test/yamlDocument.test.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
import { TextDocument } from 'vscode-languageserver';
|
||||||
|
import { parse as parseYAML } from '../src/languageservice/parser/yamlParser';
|
||||||
|
|
||||||
|
describe('SingleYAMLDocument tests', () => {
|
||||||
|
function setup(content: string) {
|
||||||
|
return (offset: number) => {
|
||||||
|
const yamlDocs = parseYAML(content);
|
||||||
|
|
||||||
|
// Should be one doc only
|
||||||
|
expect(yamlDocs.documents.length).toBe(1);
|
||||||
|
return yamlDocs.documents[0].getCompletionNodeFromOffset(offset);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('getCompletionNodeFromOffset for simple null value mapping', () => {
|
||||||
|
const content = 'a : \n ';
|
||||||
|
const parseSetup = setup(content);
|
||||||
|
it('within value of `a`', () => {
|
||||||
|
const node = parseSetup(1);
|
||||||
|
expect(node.value).toBe('a');
|
||||||
|
expect(node.type).toBe('string');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue