Skip to content

Commit

Permalink
v1.1.1-rc.0 (#15)
Browse files Browse the repository at this point in the history
Preview features toggle.
Hover and go-to definitions.
Actions for missing separator and documentation on methods.
  • Loading branch information
atiplea authored May 22, 2018
1 parent a1dafd5 commit 1a9349e
Show file tree
Hide file tree
Showing 28 changed files with 3,122 additions and 386 deletions.
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"isBackground": true,
"problemMatcher": "$tsc-watch",
"presentation": {
"reveal": "silent",
"reveal": "never",
"focus": false,
"panel": "shared"
}
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Change Log
All notable changes to the "vscode-psl" extension will be documented in this file.

## v1.1.1 (preview)

Introduced toggle to enable preview features (`"psl.previewFeatures" : true`). Restart after configuring to enable.

#### release candidate 0
- Hover and go-to definitions.
- Actions for missing separator and documentation on methods.

## v1.1.0
Implementation of the psl-lint code quality checker. Enable it by adding the setting `"psl.lint" : true` to your settings.json.

## v1.0.1
Fix a small bug where the Configure Environments button does not update properly.

Expand Down
13 changes: 13 additions & 0 deletions __tests__/files/ZChild.PROC
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#CLASSDEF extends = ZParent

#PROPERTYDEF dummy class = String position = 2
#PROPERTYDEF propInParentAndChild class = String position = 3
#PROPERTYDEF propInChild class = String position = 4

public void String methodInParentAndChild()
type Number x
quit

private void String methodInChild()
type String y
quit
12 changes: 12 additions & 0 deletions __tests__/files/ZParent.PROC
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#CLASSDEF public

#PROPERTYDEF dummy class = String position = 2
#PROPERTYDEF propInParent class = String position = 3
#PROPERTYDEF propInParentAndChild class = String position = 4

private void String methodInParent()
quit

public void String methodInParentAndChild()
type String reallySpecificName
quit
10 changes: 8 additions & 2 deletions __tests__/parameters-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as api from '../src/pslLint/api';
import { parseText } from '../src/parser/parser';
import * as fs from 'fs-extra';
import * as path from 'path';
import * as activate from '../src/pslLint/activate';

const testFilePath = path.resolve('__tests__', 'files', 'ZTestParams.PROC');
let parametersReport: api.Diagnostic[];
Expand All @@ -22,8 +23,13 @@ function reportsOnLine(lineNumber: number, reports?: api.Diagnostic[]) {
describe('Parameter tests', () => {
beforeAll(async () => {
let text = await fs.readFile(testFilePath).then(b => b.toString());
let returnDoc = new api.Document(parseText(text));
parametersReport = new ParametersOnNewLine().report(returnDoc);

let pslDocument = new api.PslDocument(parseText(text), text, testFilePath);
let ruleSubscriptions = new activate.RuleSubscription(pslDocument);
ruleSubscriptions.addMethodRules(new ParametersOnNewLine());
activate.reportRules(ruleSubscriptions);
parametersReport = ruleSubscriptions.diagnostics;

})

test('No report for no params', () => {
Expand Down
12 changes: 6 additions & 6 deletions __tests__/parser-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ import * as tokenizer from '../src/parser/tokenizer';
import * as parser from '../src/parser/parser';


function getMethod(methodString: string): parser.IMethod | undefined {
let d = parser.parseText(methodString)
function getMethod(methodString: string): parser.Method | undefined {
let d = parser.parseText(methodString)
return d.methods[0];
}
function getParsedDoc(documentString: string): parser.IDocument {
function getParsedDoc(documentString: string): parser.ParsedDocument {
return parser.parseText(documentString);
}

function toValues(tokens: tokenizer.Token[]): string[] {
return tokens.map(t => t.value);
}

function argsToValues(args: parser.IParameter[]): string[][] {
function argsToValues(args: parser.Parameter[]): string[][] {
return args.map(a => a.types).map(ts => toValues(ts));
}

function argsToNames(args: parser.IParameter[]): string[] {
function argsToNames(args: parser.Parameter[]): string[] {
return toValues(args.map(a => a.id));
}

Expand Down Expand Up @@ -701,7 +701,7 @@ describe('type declarations', () => {
expect(doc.declarations[0].id.value).toEqual('type')
})

test ('method declarations', () => {
test('method declarations', () => {
let documentString = `
public static void main()
type String x
Expand Down
262 changes: 262 additions & 0 deletions __tests__/utilities-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
import * as path from 'path';
import * as tokenizer from '../src/parser/tokenizer';
import * as utilities from '../src/parser/utillities';
import { ParsedDocument, parseFile, MemberClass } from '../src/parser/parser';

function getTokens(str: string): tokenizer.Token[] {
let ret: tokenizer.Token[] = [];
for (const token of tokenizer.getTokens(str)) {
ret.push(token);
}
return ret;
}

describe('completion', () => {
test('empty', () => {
let tokensOnLine: tokenizer.Token[] = [];
let index = 0;
let result = utilities.getChildNode(tokensOnLine, index);
expect(result.token).toBeUndefined();
})
test('undefined', () => {
let tokensOnLine: tokenizer.Token[] = getTokens('a()');
let index = 1;
let result = utilities.getChildNode(tokensOnLine, index);
expect(result).toBeUndefined();
})
test('undefined 2', () => {
let tokensOnLine: tokenizer.Token[] = getTokens('a()');
let index = 2;
let result = utilities.getChildNode(tokensOnLine, index);
expect(result).toBeUndefined();
})
test('undefined 3', () => {
let tokensOnLine: tokenizer.Token[] = getTokens('a ');
let index = 1;
let result = utilities.getChildNode(tokensOnLine, index);
expect(result).toBeUndefined();
})
test('basic dot', () => {
let tokensOnLine: tokenizer.Token[] = getTokens('a.b');
let index = 2;
let result = utilities.getChildNode(tokensOnLine, index);
expect(result.token.value).toBe('b');
expect(result.parent.token.value).toBe('a');
})
test('two dots', () => {
let tokensOnLine: tokenizer.Token[] = getTokens('a.b.c');
let index = 4;
let result = utilities.getChildNode(tokensOnLine, index);
expect(result.token.value).toBe('c');
expect(result.parent.token.value).toBe('b');
expect(result.parent.parent.token.value).toBe('a');
})
test('single reference', () => {
let tokensOnLine: tokenizer.Token[] = getTokens('do a()');
let index = 2;
let result = utilities.getChildNode(tokensOnLine, index);
expect(result.token.value).toBe('a');
})
test('dot with parens', () => {
let tokensOnLine: tokenizer.Token[] = getTokens('a().b');
let index = 4;
let result = utilities.getChildNode(tokensOnLine, index);
expect(result.token.value).toBe('b');
expect(result.parent.token.value).toBe('a');
})
test('dot with parens content', () => {
let tokensOnLine: tokenizer.Token[] = getTokens('a(blah).b');
let index = 5;
let result = utilities.getChildNode(tokensOnLine, index);
expect(result.token.value).toBe('b');
expect(result.parent.token.value).toBe('a');
})
test('dot with parens content with parens', () => {
let tokensOnLine: tokenizer.Token[] = getTokens('a(blah(bleh())).b');
let index = 10;
let result = utilities.getChildNode(tokensOnLine, index);
expect(result.token.value).toBe('b');
expect(result.parent.token.value).toBe('a');
})
test('dot with parens content on dot', () => {
let tokensOnLine: tokenizer.Token[] = getTokens('a(blah).b');
let index = 4;
let result = utilities.getChildNode(tokensOnLine, index);
expect(result.token.value).toBe('.');
expect(result.parent.token.value).toBe('a');
})
test('clusterfuck', () => {
let tokensOnLine: tokenizer.Token[] = getTokens('a.b().c(x(y)).d');
let index = 14;
let result = utilities.getChildNode(tokensOnLine, index);
expect(result.token.value).toBe('d');
expect(result.parent.token.value).toBe('c');
expect(result.parent.parent.token.value).toBe('b');
expect(result.parent.parent.parent.token.value).toBe('a');
})
test('clusterfuck2', () => {
let tokensOnLine: tokenizer.Token[] = getTokens('a.b().c(x(y)).d');
let index = 14;
let result = utilities.getCallTokens(tokensOnLine, index);
expect(result[0].value).toBe('a');
expect(result[1].value).toBe('b');
expect(result[2].value).toBe('c');
expect(result[3].value).toBe('d');
})
})

describe('ParsedDocFinder', () => {
let filesDir: string;

let parentFilePath: string;
let childFilePath: string;

let parsedParent: ParsedDocument;
let parsedChild: ParsedDocument;

beforeAll(async () => {
filesDir = path.resolve('__tests__', 'files');

parentFilePath = path.join(filesDir, 'ZParent.PROC');
childFilePath = path.join(filesDir, 'ZChild.PROC');

parsedParent = await parseFile(parentFilePath);
parsedChild = await parseFile(childFilePath);
});

test('Find dummy in child', async () => {
let paths: utilities.FinderPaths = {
corePsl: '',
projectPsl: [filesDir],
routine: childFilePath,
table: ''
}
let finder: utilities.ParsedDocFinder = new utilities.ParsedDocFinder(parsedChild, paths);
let result = await finder.searchParser(new tokenizer.Token(tokenizer.Type.Alphanumeric, 'dummy', { character: 0, line: 0 }));
expect(result.member.memberClass).toBe(MemberClass.property);
expect(result.member.id.value).toBe('dummy');
expect(result.fsPath).toBe(childFilePath);
});

test('Find property in child', async () => {
let paths: utilities.FinderPaths = {
corePsl: '',
projectPsl: [filesDir],
routine: childFilePath,
table: ''
}
let finder: utilities.ParsedDocFinder = new utilities.ParsedDocFinder(parsedChild, paths);
let result = await finder.searchParser(new tokenizer.Token(tokenizer.Type.Alphanumeric, 'propInChild', { character: 0, line: 0 }));
expect(result.member.memberClass).toBe(MemberClass.property);
expect(result.member.id.value).toBe('propInChild');
expect(result.fsPath).toBe(childFilePath);
});

test('Find method in child', async () => {
let paths: utilities.FinderPaths = {
corePsl: '',
projectPsl: [filesDir],
routine: childFilePath,
table: ''
}
let finder: utilities.ParsedDocFinder = new utilities.ParsedDocFinder(parsedChild, paths);
let result = await finder.searchParser(new tokenizer.Token(tokenizer.Type.Alphanumeric, 'methodInChild', { character: 0, line: 0 }));
expect(result.member.memberClass).toBe(MemberClass.method);
expect(result.member.id.value).toBe('methodInChild');
expect(result.fsPath).toBe(childFilePath);
})

test('Find method overriden method in child', async () => {
let paths: utilities.FinderPaths = {
corePsl: '',
projectPsl: [filesDir],
routine: childFilePath,
table: ''
}
let finder: utilities.ParsedDocFinder = new utilities.ParsedDocFinder(parsedChild, paths);
let result = await finder.searchParser(new tokenizer.Token(tokenizer.Type.Alphanumeric, 'methodInParentAndChild', { character: 0, line: 0 }));
expect(result.member.memberClass).toBe(MemberClass.method);
expect(result.member.id.value).toBe('methodInParentAndChild');
expect(result.fsPath).toBe(childFilePath);
});

test('Find method inherited method in parent', async () => {
let paths: utilities.FinderPaths = {
corePsl: '',
projectPsl: [filesDir],
routine: childFilePath,
table: ''
}
let finder: utilities.ParsedDocFinder = new utilities.ParsedDocFinder(parsedChild, paths);
let result = await finder.searchParser(new tokenizer.Token(tokenizer.Type.Alphanumeric, 'methodInParent', { character: 0, line: 0 }));
expect(result.member.memberClass).toBe(MemberClass.method);
expect(result.member.id.value).toBe('methodInParent');
expect(result.fsPath).toBe(parentFilePath);
});

test('Find method in parent', async () => {
let paths: utilities.FinderPaths = {
corePsl: '',
projectPsl: [filesDir],
routine: parentFilePath,
table: ''
}
let finder: utilities.ParsedDocFinder = new utilities.ParsedDocFinder(parsedParent, paths);
let result = await finder.searchParser(new tokenizer.Token(tokenizer.Type.Alphanumeric, 'methodInParent', { character: 0, line: 0 }));
expect(result.member.memberClass).toBe(MemberClass.method);
expect(result.member.id.value).toBe('methodInParent');
expect(result.fsPath).toBe(parentFilePath);
});

test('Find y in methodInChild', async () => {
let paths: utilities.FinderPaths = {
corePsl: '',
projectPsl: [filesDir],
routine: childFilePath,
table: ''
}
let finder: utilities.ParsedDocFinder = new utilities.ParsedDocFinder(parsedChild, paths);
let result = await finder.searchParser(new tokenizer.Token(tokenizer.Type.Alphanumeric, 'y', { character: 0, line: 12 }));
expect(result.member.memberClass).toBe(MemberClass.declaration);
expect(result.member.id.value).toBe('y');
expect(result.fsPath).toBe(childFilePath);
});

test('Do not find x', async () => {
let paths: utilities.FinderPaths = {
corePsl: '',
projectPsl: [filesDir],
routine: childFilePath,
table: ''
}
let finder: utilities.ParsedDocFinder = new utilities.ParsedDocFinder(parsedChild, paths);
let result = await finder.searchParser(new tokenizer.Token(tokenizer.Type.Alphanumeric, 'x', { character: 0, line: 12 }));
expect(result).toBeUndefined();
});

test('Do not find reallySpecificName', async () => {
let paths: utilities.FinderPaths = {
corePsl: '',
projectPsl: [filesDir],
routine: childFilePath,
table: ''
}
let finder: utilities.ParsedDocFinder = new utilities.ParsedDocFinder(parsedChild, paths);
let result = await finder.searchParser(new tokenizer.Token(tokenizer.Type.Alphanumeric, 'reallySpecificName', { character: 0, line: 10 }));
expect(result).toBeUndefined();
});

test('Do find reallySpecificName', async () => {
let paths: utilities.FinderPaths = {
corePsl: '',
projectPsl: [filesDir],
routine: parentFilePath,
table: ''
}
let finder: utilities.ParsedDocFinder = new utilities.ParsedDocFinder(parsedParent, paths);
let result = await finder.searchParser(new tokenizer.Token(tokenizer.Type.Alphanumeric, 'reallySpecificName', { character: 0, line: 10 }));
expect(result.member.memberClass).toBe(MemberClass.declaration);
expect(result.member.id.value).toBe('reallySpecificName');
expect(result.fsPath).toBe(parentFilePath);
});
})
2 changes: 1 addition & 1 deletion package-lock.json

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

Loading

0 comments on commit 1a9349e

Please sign in to comment.