Skip to content

Commit

Permalink
Add type to smartFilter
Browse files Browse the repository at this point in the history
Related: #1225
  • Loading branch information
ssbarnea committed Apr 22, 2024
1 parent f6ad87b commit 2a7bd5f
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions packages/ansible-language-server/test/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import { TextDocument } from "vscode-languageserver-textdocument";
import * as path from "path";
import { readFileSync } from "fs";
import { WorkspaceManager } from "../src/services/workspaceManager";
import { createConnection, TextDocuments } from "vscode-languageserver/node";
import {
CompletionItem,
createConnection,
TextDocuments,
} from "vscode-languageserver/node";
import { ValidationManager } from "../src/services/validationManager";
import { ExtensionSettings } from "../src/interfaces/extensionSettings";

import Fuse from "fuse.js";
import Fuse, { FuseResult } from "fuse.js";

export const FIXTURES_BASE_PATH = path.join("test", "fixtures");
export const ANSIBLE_COLLECTIONS_FIXTURES_BASE_PATH = path.resolve(
Expand Down Expand Up @@ -93,7 +97,10 @@ export function isWindows(): boolean {
* @param triggerCharacter - string against which fuzzy search is to be done
* @returns list after sorting and filtering
*/
export function smartFilter(completionList, triggerCharacter) {
export function smartFilter(
completionList: CompletionItem[],
triggerCharacter: string,
): CompletionItem[] {
if (!completionList) {
return [];
}
Expand All @@ -107,7 +114,7 @@ export function smartFilter(completionList, triggerCharacter) {
threshold: 0.4,
});

let filteredCompletionList = triggerCharacter
const filteredCompletionList = triggerCharacter
? searcher.search(triggerCharacter).slice(0, 5)
: completionList.slice(0, 5);

Expand All @@ -119,12 +126,14 @@ export function smartFilter(completionList, triggerCharacter) {
threshold: 0.2,
});

filteredCompletionList = triggerCharacter
? newSearcher.search(triggerCharacter).slice(0, 5)
: completionList.slice(0, 5);
if (triggerCharacter) {
const x = newSearcher.search(triggerCharacter).slice(0, 5);
return x;
}
return completionList.slice(0, 5);
}

return filteredCompletionList;
return completionList.slice(0, 5);
}

/**
Expand Down

0 comments on commit 2a7bd5f

Please sign in to comment.