Skip to content

Commit

Permalink
Merge pull request redhat-developer#28 from JPinkney/master
Browse files Browse the repository at this point in the history
Added new features and bug fixes
  • Loading branch information
JPinkney authored Jun 28, 2017
2 parents fc2255d + df782b7 commit 30d89ef
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 27 deletions.
3 changes: 2 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 6 additions & 5 deletions client/test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
});
});
2 changes: 1 addition & 1 deletion server/.vscode/snippits.ts → server/.vscode/snippets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export let snippits = {
export let snippets = {
"deployment": {
"prefix": "deployment",
"body": [
Expand Down
1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { snippits } from "../../.vscode/snippits";
import { snippets } from "../../.vscode/snippets";
import {
IPCMessageReader, IPCMessageWriter,
createConnection, IConnection, TextDocumentSyncKind,
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions server/src/languageService/services/yamlCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});

Expand Down
32 changes: 31 additions & 1 deletion server/src/languageService/utils/astServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function traverse ( node: YAMLNode, visitor:ASTVisitor){
break
}
}

export class ASTVisitor{
public visit(node: YAMLNode) : boolean {
return true;
Expand Down Expand Up @@ -85,4 +86,33 @@ export function generateChildren(node){
});
return [].concat([], yamlSeqNodeList);
}
}
}

export function traverseForSymbols(node: YAMLNode){
if(!node) return;
switch(node.kind){
case Kind.SCALAR:
let scalar = <YAMLScalar> node;
return [{type: 0, value: scalar}];
case Kind.SEQ:
let seq = <YAMLSequence> node;
let seqList = [];
seq.items.forEach(item=>{
seqList.push(traverseForSymbols(item));
});
return seqList.concat({kind: 9, value: seq.key});
case Kind.MAPPING:
let mapping = <YAMLMapping> node;
return traverseForSymbols(mapping.value).concat({kind: 9, value: mapping.key});
case Kind.MAP:
let map = <YamlMap> node;
let mapList = [];
map.mappings.forEach(mapping=>{
mapList.push(traverseForSymbols(mapping));
});
return mapList;
case Kind.ANCHOR_REF:
let anchor = <YAMLAnchorReference> node;
return traverseForSymbols(anchor.value).concat({kind: 9, value: anchor.key});
}
}
34 changes: 30 additions & 4 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {snippetAutocompletor} from './SnippetSupport/snippet';
import {traverseForSymbols} from './languageService/utils/astServices';
var glob = require('glob');

namespace VSCodeContentRequest {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -110,7 +112,7 @@ interface filesToIgnore {
filesNotValidating: Array<string>;
}

let filesToIgnore: Array<string>;
let filesToIgnore: Array<string> = [];
connection.onDidChangeConfiguration((change) => {
let settings = <Settings>change.settings;
filesToIgnore = settings.k8s.filesNotValidating || [];
Expand Down Expand Up @@ -246,6 +248,30 @@ connection.onCompletionResolve((item: CompletionItem): CompletionItem => {
return item;
});

connection.onDocumentSymbol(params => {
let doc = documents.get(params.textDocument.uri);
let yamlDoc:YAMLDocument = <YAMLDocument> yamlLoader(doc.getText(),{});
let symbols = traverseForSymbols(<YAMLNode>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[] = [];
Expand Down
2 changes: 1 addition & 1 deletion server/test/autoCompletion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion server/test/schemaToMappingTransformer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion server/test/schemaValidation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 30d89ef

Please sign in to comment.