Skip to content

Commit

Permalink
Fix linting and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbockhorst committed May 28, 2020
1 parent 209d04e commit 57bca03
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
trailingComma: "all"
trailingComma: "all"
endOfLine: "auto"
8 changes: 4 additions & 4 deletions src/providers/completionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ export class CompletionProvider {
private getSameFileTopLevelCompletions(
tree: Tree,
range: Range,
moduleDefinition: boolean = false,
moduleDefinition = false,
): CompletionItem[] {
const completions: CompletionItem[] = [];
const topLevelFunctions = TreeUtils.findAllTopLeverFunctionDeclarations(
Expand Down Expand Up @@ -872,7 +872,7 @@ export class CompletionProvider {
documentation,
possibleImport.value,
range,
"e" + i,
`e${i}`,
detail,
importTextEdit,
),
Expand All @@ -883,7 +883,7 @@ export class CompletionProvider {
documentation,
possibleImport.value,
range,
"e" + i,
`e${i}`,
detail,
importTextEdit,
),
Expand All @@ -894,7 +894,7 @@ export class CompletionProvider {
documentation,
possibleImport.value,
range,
"e" + i,
`e${i}`,
detail,
importTextEdit,
),
Expand Down
12 changes: 9 additions & 3 deletions src/test/completionProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,22 @@ describe("CompletionProvider", () => {
treeParser.getWorkspace(newSources),
) ?? [];

const completionsList = Array.isArray(completions)
? completions
: completions.items;

if (testExactCompletions) {
expect(completions.length).toBe(expectedCompletions.length);
expect(completionsList.length).toBe(expectedCompletions.length);
} else {
expect(completions.length).toBeGreaterThanOrEqual(
expect(completionsList.length).toBeGreaterThanOrEqual(
expectedCompletions.length,
);
}

expectedCompletions.forEach((completion) => {
expect(completions.find((c) => c.label === completion)).toBeTruthy();
expect(
completionsList.find((c) => c.label === completion),
).toBeTruthy();
});
}

Expand Down
13 changes: 7 additions & 6 deletions src/util/importUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import RANKING_LIST from "../providers/ranking";
import { TreeUtils, NodeType } from "./treeUtils";
import { SyntaxNode } from "web-tree-sitter";

interface PossibleImport {
interface IPossibleImport {
module: string;
value: string;
type: NodeType;
Expand All @@ -17,7 +17,7 @@ export class ImportUtils {
forest: IForest,
uri: string,
filterText: string,
): PossibleImport[] {
): IPossibleImport[] {
const currentTree = forest.getTree(uri);

if (currentTree) {
Expand Down Expand Up @@ -52,8 +52,9 @@ export class ImportUtils {
} else if (!aStartsWith && bStartsWith) {
return 1;
} else {
const aMatches = aValue.match(filterText);
const bMatches = bValue.match(filterText);
const regex = new RegExp(filterText);
const aMatches = regex.exec(aValue);
const bMatches = regex.exec(bValue);

if (aMatches && !bMatches) {
return -1;
Expand All @@ -72,10 +73,10 @@ export class ImportUtils {
public static getPossibleImports(
forest: IForest,
uri: string,
): PossibleImport[] {
): IPossibleImport[] {
const currentModule = forest.getByUri(uri)?.moduleName;

const exposedValues: PossibleImport[] = [];
const exposedValues: IPossibleImport[] = [];

// Find all exposed values that could be imported
if (forest) {
Expand Down

0 comments on commit 57bca03

Please sign in to comment.