From 8dd16a36b72d1e5cc67ea3b7e45b6af2c94aff58 Mon Sep 17 00:00:00 2001 From: jpinkney Date: Thu, 22 Jun 2017 11:58:10 -0400 Subject: [PATCH 1/4] Added the ability for travis ci to run the test suites --- client/package.json | 3 ++- client/test/extension.test.ts | 11 ++++++----- server/test/autoCompletion.test.ts | 2 +- server/test/schemaToMappingTransformer.test.ts | 2 +- server/test/schemaValidation.test.ts | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/client/package.json b/client/package.json index 1152a17e..cda76cf4 100755 --- a/client/package.json +++ b/client/package.json @@ -52,7 +52,8 @@ "vscode:prepublish": "tsc -p ./", "compile": "tsc -watch -p ./", "update-vscode": "node ./node_modules/vscode/bin/install", - "postinstall": "node ./node_modules/vscode/bin/install" + "postinstall": "node ./node_modules/vscode/bin/install", + "test": "mocha --ui tdd out/test/extension.test.js && mocha --ui tdd server/test/*.test.js" }, "devDependencies": { "@types/mocha": "^2.2.33", diff --git a/client/test/extension.test.ts b/client/test/extension.test.ts index 1cec6f47..960e23a5 100755 --- a/client/test/extension.test.ts +++ b/client/test/extension.test.ts @@ -13,10 +13,11 @@ import * as myExtension from '../src/extension'; // Defines a Mocha test suite to group tests of similar kind together suite("Extension Tests", () => { - - // Defines a Mocha unit test - test("Something 1", () => { - assert.equal(-1, [1, 2, 3].indexOf(5)); - assert.equal(-1, [1, 2, 3].indexOf(0)); + describe('Client - Setup Tests', function(){ + // Defines a Mocha unit test + it("Basic client setup test", () => { + assert.equal(-1, [1, 2, 3].indexOf(5)); + assert.equal(-1, [1, 2, 3].indexOf(0)); + }); }); }); \ No newline at end of file diff --git a/server/test/autoCompletion.test.ts b/server/test/autoCompletion.test.ts index e979e9ed..0137a77c 100644 --- a/server/test/autoCompletion.test.ts +++ b/server/test/autoCompletion.test.ts @@ -33,7 +33,7 @@ schemaService.getResolvedSchema(schemaService.getRegisteredSchemaIds()[0]).then( suite("Auto Completion Tests", () => { - describe('Auto Completion - yamlCompletion', function(){ + describe('Server - Auto Completion - yamlCompletion', function(){ describe('doComplete', function(){ it('Autocomplete on root node without word', (done) => { diff --git a/server/test/schemaToMappingTransformer.test.ts b/server/test/schemaToMappingTransformer.test.ts index fa647d08..2fa272f1 100644 --- a/server/test/schemaToMappingTransformer.test.ts +++ b/server/test/schemaToMappingTransformer.test.ts @@ -31,7 +31,7 @@ var assert = require('assert'); schemaService.getResolvedSchema(schemaService.getRegisteredSchemaIds()[0]).then(schema =>{ suite("Schema Transformation Tests", () => { - describe('Schema Tranformation - schemaToMappingTransformer', function(){ + describe('Server - Schema Tranformation - schemaToMappingTransformer', function(){ let schemaTransformer = new SchemaToMappingTransformer(schema.schema); diff --git a/server/test/schemaValidation.test.ts b/server/test/schemaValidation.test.ts index edff8fd0..d33b6cea 100644 --- a/server/test/schemaValidation.test.ts +++ b/server/test/schemaValidation.test.ts @@ -32,7 +32,7 @@ var assert = require('assert'); suite("Validation Tests", () => { // Tests for validator - describe('Validation - schemaValidation and schemaValidator files', function() { + describe('Server - Validation - schemaValidation and schemaValidator files', function() { describe('traverseBackToLocation', function() { //Validating basic nodes From b7516fd43f9161f1377a2e91e8151e75dc08d7fa Mon Sep 17 00:00:00 2001 From: jpinkney Date: Thu, 22 Jun 2017 14:42:15 -0400 Subject: [PATCH 2/4] Added document symbols feature --- server/package.json | 1 + .../src/languageService/utils/astServices.ts | 32 ++++++++++++++++++- server/src/server.ts | 30 +++++++++++++++-- 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/server/package.json b/server/package.json index bdf0430b..166e16d4 100755 --- a/server/package.json +++ b/server/package.json @@ -14,6 +14,7 @@ "mocha": "^3.4.2", "request-light": "^0.2.0", "triesearch": "^1.0.2", + "vscode-json-languageservice": "^2.0.10", "vscode-languageserver": "^3.1.0", "vscode-nls": "^2.0.2", "vscode-uri": "1.0.0", diff --git a/server/src/languageService/utils/astServices.ts b/server/src/languageService/utils/astServices.ts index ee8730b7..7e1102ba 100644 --- a/server/src/languageService/utils/astServices.ts +++ b/server/src/languageService/utils/astServices.ts @@ -38,6 +38,7 @@ export function traverse ( node: YAMLNode, visitor:ASTVisitor){ break } } + export class ASTVisitor{ public visit(node: YAMLNode) : boolean { return true; @@ -85,4 +86,33 @@ export function generateChildren(node){ }); return [].concat([], yamlSeqNodeList); } - } \ No newline at end of file + } + +export function traverseForSymbols(node: YAMLNode){ + if(!node) return; + switch(node.kind){ + case Kind.SCALAR: + let scalar = node; + return [{type: 0, value: scalar}]; + case Kind.SEQ: + let seq = node; + let seqList = []; + seq.items.forEach(item=>{ + seqList.push(traverseForSymbols(item)); + }); + return seqList.concat({kind: 9, value: seq.key}); + case Kind.MAPPING: + let mapping = node; + return traverseForSymbols(mapping.value).concat({kind: 9, value: mapping.key}); + case Kind.MAP: + let map = node; + let mapList = []; + map.mappings.forEach(mapping=>{ + mapList.push(traverseForSymbols(mapping)); + }); + return mapList; + case Kind.ANCHOR_REF: + let anchor = node; + return traverseForSymbols(anchor.value).concat({kind: 9, value: anchor.key}); + } +} \ No newline at end of file diff --git a/server/src/server.ts b/server/src/server.ts index a9ad84a7..a985c044 100755 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -5,16 +5,17 @@ import { createConnection, IConnection, TextDocumentSyncKind, TextDocuments, TextDocument, Diagnostic, DiagnosticSeverity, InitializeParams, InitializeResult, TextDocumentPositionParams, - CompletionItem, CompletionItemKind, RequestType + CompletionItem, CompletionItemKind, RequestType, Location, Range, Position } from 'vscode-languageserver'; import { xhr, XHRResponse, configure as configureHttpRequests, getErrorStatusDescription } from 'request-light'; -import {load as yamlLoader, YAMLDocument, YAMLException} from 'yaml-ast-parser-beta'; +import {load as yamlLoader, YAMLDocument, YAMLException, YAMLNode, Kind} from 'yaml-ast-parser-beta'; import {getLanguageService} from './languageService/yamlLanguageService' import Strings = require( './languageService/utils/strings'); import URI from './languageService/utils/uri'; import * as URL from 'url'; import fs = require('fs'); import {snippitAutocompletor} from './SnippitSupport/snippit'; +import {traverseForSymbols} from './languageService/utils/astServices'; var glob = require('glob'); namespace VSCodeContentRequest { @@ -47,6 +48,7 @@ connection.onInitialize((params): InitializeResult => { workspaceRoot = params.rootPath; return { capabilities: { + documentSymbolProvider: true, // Tell the client that the server works in FULL text document sync mode textDocumentSync: TextDocumentSyncKind.Full, // Tell the client that the server support code complete @@ -246,6 +248,30 @@ connection.onCompletionResolve((item: CompletionItem): CompletionItem => { return item; }); +connection.onDocumentSymbol(params => { + let doc = documents.get(params.textDocument.uri); + let yamlDoc:YAMLDocument = yamlLoader(doc.getText(),{}); + let symbols = traverseForSymbols(yamlDoc); + let flattenedSymbols = flatten(symbols); + let documentSymbols = []; + flattenedSymbols.forEach(obj => { + if(obj !== null && obj !== undefined && obj.value){ + documentSymbols.push({ + name: obj.value.value, + kind: obj.kind, + location: Location.create(params.textDocument.uri, Range.create(doc.positionAt(obj.value.startPosition), doc.positionAt(obj.value.endPosition))) + }); + } + }); + + return documentSymbols; + +}); + +const flatten = arr => arr.reduce( + (a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), [] +); + function getLineOffsets(textDocString: String): number[] { let lineOffsets: number[] = []; From d4232671b03c3929bd292492171afdba43fd7c71 Mon Sep 17 00:00:00 2001 From: jpinkney Date: Tue, 27 Jun 2017 11:50:52 -0400 Subject: [PATCH 3/4] Changed all references of snippit to snippet --- server/.vscode/{snippits.ts => snippets.ts} | 2 +- .../snippit.ts => SnippetSupport/snippet.ts} | 18 +++++++++--------- .../languageService/services/yamlCompletion.ts | 6 +++--- server/src/server.ts | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) rename server/.vscode/{snippits.ts => snippets.ts} (98%) rename server/src/{SnippitSupport/snippit.ts => SnippetSupport/snippet.ts} (62%) diff --git a/server/.vscode/snippits.ts b/server/.vscode/snippets.ts similarity index 98% rename from server/.vscode/snippits.ts rename to server/.vscode/snippets.ts index da503f7b..958bcc61 100644 --- a/server/.vscode/snippits.ts +++ b/server/.vscode/snippets.ts @@ -1,4 +1,4 @@ -export let snippits = { +export let snippets = { "deployment": { "prefix": "deployment", "body": [ diff --git a/server/src/SnippitSupport/snippit.ts b/server/src/SnippetSupport/snippet.ts similarity index 62% rename from server/src/SnippitSupport/snippit.ts rename to server/src/SnippetSupport/snippet.ts index 7a4947f5..c0d5441c 100644 --- a/server/src/SnippitSupport/snippit.ts +++ b/server/src/SnippetSupport/snippet.ts @@ -1,5 +1,5 @@ -import { snippits } from "../../.vscode/snippits"; +import { snippets } from "../../.vscode/snippets"; import { IPCMessageReader, IPCMessageWriter, createConnection, IConnection, TextDocumentSyncKind, @@ -8,23 +8,23 @@ import { CompletionItem, CompletionItemKind, RequestType } from 'vscode-languageserver'; -export class snippitAutocompletor { +export class snippetAutocompletor { private textDocument; constructor(textDoc){ this.textDocument = textDoc; } - public provideSnippitAutocompletor(){ + public provideSnippetAutocompletor(){ let items = []; - Object.keys(snippits).forEach(snip => { - let item = CompletionItem.create(snippits[snip]["prefix"]); + Object.keys(snippets).forEach(snip => { + let item = CompletionItem.create(snippets[snip]["prefix"]); item.kind = CompletionItemKind.Snippet; - item.insertText = snippits[snip]["body"].join("\n").replace(/\$\{TM_FILENAME\}/g, this.uriToName(this.textDocument.uri)); + item.insertText = snippets[snip]["body"].join("\n").replace(/\$\{TM_FILENAME\}/g, this.uriToName(this.textDocument.uri)); item.detail = "vscode-k8s"; - item.sortText = snippits[snip]["prefix"].substring(0, 5); - item.filterText = snippits[snip]["prefix"].substring(0, 5); - item.documentation = snippits[snip]["description"]; + item.sortText = snippets[snip]["prefix"].substring(0, 5); + item.filterText = snippets[snip]["prefix"].substring(0, 5); + item.documentation = snippets[snip]["description"]; items.push(item); }); return items; diff --git a/server/src/languageService/services/yamlCompletion.ts b/server/src/languageService/services/yamlCompletion.ts index 5496459f..8b29b4d1 100644 --- a/server/src/languageService/services/yamlCompletion.ts +++ b/server/src/languageService/services/yamlCompletion.ts @@ -6,7 +6,7 @@ import {IJSONSchemaService} from './jsonSchemaService'; import {YAMLSChemaValidator} from './schemaValidator'; import {traverse} from '../utils/astServices'; import {AutoCompleter} from './autoCompleter'; -import {snippitAutocompletor} from '../../SnippitSupport/snippit'; +import {snippetAutocompletor} from '../../SnippetSupport/snippet'; export class YamlCompletion { private schemaService: IJSONSchemaService; @@ -48,8 +48,8 @@ export class YamlCompletion { } - let snip = new snippitAutocompletor(document); - snip.provideSnippitAutocompletor().forEach(compItem => { + let snip = new snippetAutocompletor(document); + snip.provideSnippetAutocompletor().forEach(compItem => { result.items.push(compItem); }); diff --git a/server/src/server.ts b/server/src/server.ts index a985c044..6c5ba3a4 100755 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -14,7 +14,7 @@ import Strings = require( './languageService/utils/strings'); import URI from './languageService/utils/uri'; import * as URL from 'url'; import fs = require('fs'); -import {snippitAutocompletor} from './SnippitSupport/snippit'; +import {snippetAutocompletor} from './SnippetSupport/snippet'; import {traverseForSymbols} from './languageService/utils/astServices'; var glob = require('glob'); From df782b767ac8a11209cf47802c3f82fb84ca7f86 Mon Sep 17 00:00:00 2001 From: jpinkney Date: Wed, 28 Jun 2017 10:21:15 -0400 Subject: [PATCH 4/4] Added quickfix to general LSP --- server/src/server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/server.ts b/server/src/server.ts index 6c5ba3a4..170f3c98 100755 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -112,7 +112,7 @@ interface filesToIgnore { filesNotValidating: Array; } -let filesToIgnore: Array; +let filesToIgnore: Array = []; connection.onDidChangeConfiguration((change) => { let settings = change.settings; filesToIgnore = settings.k8s.filesNotValidating || [];