Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linting to CI #40

Merged
merged 2 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off"
"semi": "off",
"@typescript-eslint/quotes": [
"warn",
"double",
{
"avoidEscape": true,
"allowTemplateLiterals": true
}
]
},
"ignorePatterns": [
"out",
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
with:
node-version: 14.x
- run: npm install
- name: lint
run: npm run lint
- run: xvfb-run -a npm test
if: runner.os == 'Linux'
- run: npm test
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@
"watch-tests": "tsc -p . -w --outDir out",
"pretest": "npm run compile-tests && npm run compile && npm run lint",
"lint": "eslint src --ext ts",
"lint-fix": "eslint --fix src --ext ts",
"test": "npm run test:unit",
"test:unit": "jest",
"download-all": "./node_modules/.bin/gulp download-all",
Expand Down
16 changes: 8 additions & 8 deletions src/commands/gototest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as vscode from 'vscode';
import * as path from 'path';
import { LanguageClient } from 'vscode-languageclient/node';
import { createFile } from '../new-file-controller';
import * as vscode from "vscode";
import * as path from "path";
import { LanguageClient } from "vscode-languageclient/node";
import { createFile } from "../new-file-controller";

export async function goToTest(client: LanguageClient) {
const document = vscode.window.activeTextEditor?.document;
Expand All @@ -14,7 +14,7 @@ export async function goToTest(client: LanguageClient) {
}

const vscodePosition = client.protocol2CodeConverter.asPosition(document.positionAt(0));
const references = await client.getFeature('textDocument/references').getProvider(document)?.provideReferences(document, vscodePosition, { includeDeclaration: false }, new vscode.CancellationTokenSource().token);
const references = await client.getFeature("textDocument/references").getProvider(document)?.provideReferences(document, vscodePosition, { includeDeclaration: false }, new vscode.CancellationTokenSource().token);

if (!references) {
return;
Expand All @@ -28,7 +28,7 @@ export async function goToTest(client: LanguageClient) {
if (createTestPrompt !== "Yes") {
return;
}
await createFile(undefined, 'TESTCASE', client);
await createFile(undefined, "TESTCASE", client);
return;
}

Expand All @@ -42,12 +42,12 @@ export async function goToTest(client: LanguageClient) {
else {
// There are more than one testcases, so show actual calling locations
// to have a better context when chosing where to navigate to.
await vscode.commands.executeCommand('editor.action.showReferences', document.uri, vscodePosition, callingTests);
await vscode.commands.executeCommand("editor.action.showReferences", document.uri, vscodePosition, callingTests);
}
};

async function navigateToSut(document: vscode.TextDocument, client: LanguageClient) {
const response: { uris: string[] } = await client.sendRequest('calledModules', { identifier: client.code2ProtocolConverter.asTextDocumentIdentifier(document) });
const response: { uris: string[] } = await client.sendRequest("calledModules", { identifier: client.code2ProtocolConverter.asTextDocumentIdentifier(document) });
const paths = response.uris.map(u => client.protocol2CodeConverter.asUri(u).fsPath);
const possibleSuts = paths.filter(p => couldBeSut(p));

Expand Down
48 changes: 24 additions & 24 deletions src/completion/inlinecompletion.test.ts
Original file line number Diff line number Diff line change
@@ -1,74 +1,74 @@
import { describe, expect, test } from '@jest/globals';
import { describe, expect, test } from "@jest/globals";
import { provideInlineCompletion } from "./inlinecompletion";

describe('provideInlineCompletions should', () => {
it('complete a statement', () => {
describe("provideInlineCompletions should", () => {
it("complete a statement", () => {
const completions = provideInlineCompletion("COMP", "COMP");
expect(completions)
.toEqual([
'RESS ${1:#VAR} INTO ${2:#TARGET}',
'RESS NUMERIC ${1:#VAR} INTO ${2:#TARGET}'
"RESS ${1:#VAR} INTO ${2:#TARGET}",
"RESS NUMERIC ${1:#VAR} INTO ${2:#TARGET}"
]);
});

it('complete a statement when more than the trigger matches', () => {
it("complete a statement when more than the trigger matches", () => {
const completions = provideInlineCompletion("COMPR", "COMPR");
expect(completions)
.toEqual([
'ESS ${1:#VAR} INTO ${2:#TARGET}',
'ESS NUMERIC ${1:#VAR} INTO ${2:#TARGET}'
"ESS ${1:#VAR} INTO ${2:#TARGET}",
"ESS NUMERIC ${1:#VAR} INTO ${2:#TARGET}"
]);
});

it('complete a statement case insensitive', () => {
it("complete a statement case insensitive", () => {
const completions = provideInlineCompletion("comp", "comp");
expect(completions)
.toEqual([
'RESS ${1:#VAR} INTO ${2:#TARGET}',
'RESS NUMERIC ${1:#VAR} INTO ${2:#TARGET}'
"RESS ${1:#VAR} INTO ${2:#TARGET}",
"RESS NUMERIC ${1:#VAR} INTO ${2:#TARGET}"
]);
});

it('completes missing parts of a statement', () => {
it("completes missing parts of a statement", () => {
const completions = provideInlineCompletion("COMPRESS NUM", "NUM");
expect(completions)
.toEqual([
'ERIC ${1:#VAR} INTO ${2:#TARGET}'
"ERIC ${1:#VAR} INTO ${2:#TARGET}"
]);
});

it('complete an inline expression', () => {
it("complete an inline expression", () => {
const completions = provideInlineCompletion("SUBS", "SUBS");
expect(completions)
.toEqual([
'TRING(${1:#STRING}, ${2:1})',
'TRING(${1:#STRING}, ${2:1}, ${3:2})'
"TRING(${1:#STRING}, ${2:1})",
"TRING(${1:#STRING}, ${2:1}, ${3:2})"
]);
});

it('complete an inline expression case insensitive', () => {
it("complete an inline expression case insensitive", () => {
const completions = provideInlineCompletion("subs", "subs");
expect(completions)
.toEqual([
'TRING(${1:#STRING}, ${2:1})',
'TRING(${1:#STRING}, ${2:1}, ${3:2})'
"TRING(${1:#STRING}, ${2:1})",
"TRING(${1:#STRING}, ${2:1}, ${3:2})"
]);
});

it('complete different statements for same trigger', () => {
it("complete different statements for same trigger", () => {
const completions = provideInlineCompletion("writ", "writ");
expect(completions)
.toEqual([
'E ${1:#VAR}',
'E WORK FILE ${1:1}',
"E ${1:#VAR}",
"E WORK FILE ${1:1}",
]);
});

it('complete only matching statements', () => {
it("complete only matching statements", () => {
const completions = provideInlineCompletion("write wo", "wo");
expect(completions)
.toEqual([
'RK FILE ${1:1}'
"RK FILE ${1:1}"
]);
});
});
114 changes: 57 additions & 57 deletions src/completion/inlinecompletion.ts
Original file line number Diff line number Diff line change
@@ -1,114 +1,114 @@
type NaturalInlineCompletionSnippet = {
kind: 'statement' | 'expression';
kind: "statement" | "expression";
trigger: string,
snippet: string
};

const snippets: NaturalInlineCompletionSnippet[] = [
{
kind: 'statement',
trigger: 'comp',
snippet: 'COMPRESS ${1:#VAR} INTO ${2:#TARGET}'
kind: "statement",
trigger: "comp",
snippet: "COMPRESS ${1:#VAR} INTO ${2:#TARGET}"
},
{
kind: 'statement',
trigger: 'comp',
snippet: 'COMPRESS NUMERIC ${1:#VAR} INTO ${2:#TARGET}'
kind: "statement",
trigger: "comp",
snippet: "COMPRESS NUMERIC ${1:#VAR} INTO ${2:#TARGET}"
},
{
kind: 'statement',
trigger: 'sep',
kind: "statement",
trigger: "sep",
snippet: "SEPARATE ${1:#ALPHANUMERIC} INTO ${2:#GROUP} WITH DELIMITERS ${3:';'}"
},
{
kind: 'statement',
trigger: 'if',
snippet: 'IF ${1:TRUE}\n ${0:IGNORE}\nEND-IF'
kind: "statement",
trigger: "if",
snippet: "IF ${1:TRUE}\n ${0:IGNORE}\nEND-IF"
},
{
kind: 'statement',
trigger: 'if',
snippet: 'IF ${1:TRUE}\n ${2:IGNORE}\nELSE\nVj ${3:IGNORE}\nEND-IF'
kind: "statement",
trigger: "if",
snippet: "IF ${1:TRUE}\n ${2:IGNORE}\nELSE\nVj ${3:IGNORE}\nEND-IF"
},
{
kind: 'statement',
trigger: 'exp',
kind: "statement",
trigger: "exp",
snippet: "EXPAND ARRAY ${1:#ARRAY} TO (${2:1:*})"
},
{
kind: 'statement',
trigger: 'red',
kind: "statement",
trigger: "red",
snippet: "REDUCE ARRAY ${1:#ARRAY} TO ${2:0}"
},
{
kind: 'statement',
trigger: 'res',
kind: "statement",
trigger: "res",
snippet: "RESIZE ARRAY ${1:#ARRAY} TO (${2:1:*})"
},
{
kind: 'statement',
trigger: 'exa',
kind: "statement",
trigger: "exa",
snippet: "EXAMINE ${1:#TEXT} FOR ${2:#SEARCHED} GIVING NUMBER ${3:#NUMBER}"
},
{
kind: 'statement',
trigger: 'exa',
kind: "statement",
trigger: "exa",
snippet: "EXAMINE ${1:#TEXT} FOR ${2:#SEARCHED} REPLACE FIRST WITH ${3:#REPLACEMENT}"
},
{
kind: 'statement',
trigger: 'exa',
kind: "statement",
trigger: "exa",
snippet: "EXAMINE ${1:#TEXT} FOR ${2:#SEARCHED} REPLACE WITH ${3:#REPLACEMENT}"
},
{
kind: 'statement',
trigger: 'exa',
kind: "statement",
trigger: "exa",
snippet: "EXAMINE ${1:#TEXT} FOR ${2:#SEARCHED} DELETE FIRST"
},
{
kind: 'statement',
trigger: 'exa',
kind: "statement",
trigger: "exa",
snippet: "EXAMINE ${1:#TEXT} FOR ${2:#SEARCHED} DELETE"
},
{
kind: 'statement',
trigger: 'for',
snippet: 'FOR ${1:#I} := 1 TO ${2:#UPPER}\n ${0:IGNORE}\nEND-FOR'
kind: "statement",
trigger: "for",
snippet: "FOR ${1:#I} := 1 TO ${2:#UPPER}\n ${0:IGNORE}\nEND-FOR"
},
{
kind: 'statement',
trigger: 'mov',
snippet: 'MOVE BY NAME ${1:#FIRST} TO ${2:#SECOND}'
kind: "statement",
trigger: "mov",
snippet: "MOVE BY NAME ${1:#FIRST} TO ${2:#SECOND}"
},
{
kind: 'statement',
trigger: 'def',
snippet: 'DEFINE WORK FILE ${1:1} ${2:#PATH}'
kind: "statement",
trigger: "def",
snippet: "DEFINE WORK FILE ${1:1} ${2:#PATH}"
},
{
kind: 'statement',
trigger: 'clos',
snippet: 'CLOSE WORK FILE ${1:1}'
kind: "statement",
trigger: "clos",
snippet: "CLOSE WORK FILE ${1:1}"
},
{
kind: 'statement',
trigger: 'writ',
snippet: 'WRITE ${1:#VAR}'
kind: "statement",
trigger: "writ",
snippet: "WRITE ${1:#VAR}"
},
{
kind: 'statement',
trigger: 'writ',
snippet: 'WRITE WORK FILE ${1:1}'
kind: "statement",
trigger: "writ",
snippet: "WRITE WORK FILE ${1:1}"
},
{
kind: 'expression',
trigger: 'subs',
snippet: 'SUBSTRING(${1:#STRING}, ${2:1})'
kind: "expression",
trigger: "subs",
snippet: "SUBSTRING(${1:#STRING}, ${2:1})"
},
{
kind: 'expression',
trigger: 'subs',
snippet: 'SUBSTRING(${1:#STRING}, ${2:1}, ${3:2})'
kind: "expression",
trigger: "subs",
snippet: "SUBSTRING(${1:#STRING}, ${2:1}, ${3:2})"
}
];

Expand All @@ -128,9 +128,9 @@ export function provideInlineCompletion(currentLine: string, currentWord: string
}
else {
if (currentWord.toLowerCase().startsWith(snippet.trigger)) {
const firstWordOfStatement = snippet.snippet.split(' ')[0];
const firstWordOfStatement = snippet.snippet.split(" ")[0];
const missingPartsOfFirstKeyword = firstWordOfStatement.substring(currentWord.length);
const restOfSnippet = snippet.snippet.split(' ').slice(1).join(' ');
const restOfSnippet = snippet.snippet.split(" ").slice(1).join(" ");
result.push(`${missingPartsOfFirstKeyword} ${restOfSnippet}`);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/completion/inlinecompletionprovider.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as vscode from 'vscode';
import { provideInlineCompletion } from './inlinecompletion';
import * as vscode from "vscode";
import { provideInlineCompletion } from "./inlinecompletion";

export class NaturalStatementInlineCompletion implements vscode.InlineCompletionItemProvider {
provideInlineCompletionItems(document: vscode.TextDocument, position: vscode.Position, context: vscode.InlineCompletionContext, token: vscode.CancellationToken): vscode.ProviderResult<vscode.InlineCompletionItem[] | vscode.InlineCompletionList> {
const lineContent = document.getText(new vscode.Range(new vscode.Position(position.line, 0), position));
const lineContentToCursor = lineContent.substring(0, position.character);
const lastWord = lineContentToCursor.split(' ').pop();
const lastWord = lineContentToCursor.split(" ").pop();

const result = new vscode.InlineCompletionList([]);

Expand Down
Loading
Loading