From 3ff92cd3f1b05de9e4381084a076cc3702a437c8 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Wed, 24 Apr 2024 16:53:21 +0100 Subject: [PATCH] More types Related: #1225 --- .../src/providers/completionProvider.ts | 3 ++- .../src/services/ansibleInventory.ts | 2 +- packages/ansible-language-server/src/utils/yaml.ts | 7 ++++--- packages/ansible-language-server/test/rootMochaHooks.ts | 6 ++---- packages/ansible-language-server/tsconfig.json | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/ansible-language-server/src/providers/completionProvider.ts b/packages/ansible-language-server/src/providers/completionProvider.ts index 58b61b222..31ab2be94 100644 --- a/packages/ansible-language-server/src/providers/completionProvider.ts +++ b/packages/ansible-language-server/src/providers/completionProvider.ts @@ -37,6 +37,7 @@ import { isPlaybook, } from "../utils/yaml"; import { getVarsCompletion } from "./completionProviderUtils"; +import { HostType } from "../services/ansibleInventory"; const priorityMap = { nameKeyword: 1, @@ -480,7 +481,7 @@ function getKeywordCompletion( }); } -function getHostCompletion(hostObjectList): CompletionItem[] { +function getHostCompletion(hostObjectList: HostType[]): CompletionItem[] { return hostObjectList.map(({ host, priority }) => { const completionItem: CompletionItem = { label: host, diff --git a/packages/ansible-language-server/src/services/ansibleInventory.ts b/packages/ansible-language-server/src/services/ansibleInventory.ts index ff85dc8fa..ed02974b2 100644 --- a/packages/ansible-language-server/src/services/ansibleInventory.ts +++ b/packages/ansible-language-server/src/services/ansibleInventory.ts @@ -3,7 +3,7 @@ import { WorkspaceFolderContext } from "./workspaceManager"; import { CommandRunner } from "../utils/commandRunner"; import { URI } from "vscode-uri"; -type HostType = { host: string; priority: number }; +export type HostType = { host: string; priority: number }; type inventoryHostEntry = { children: string[]; diff --git a/packages/ansible-language-server/src/utils/yaml.ts b/packages/ansible-language-server/src/utils/yaml.ts index 0c7ef2ec6..affe2c701 100644 --- a/packages/ansible-language-server/src/utils/yaml.ts +++ b/packages/ansible-language-server/src/utils/yaml.ts @@ -11,6 +11,7 @@ import { Pair, parseDocument, ParseOptions, + Schema, SchemaOptions, YAMLMap, YAMLSeq, @@ -45,7 +46,7 @@ export class AncestryBuilder { * up. */ parent( - type?: new (...args: unknown[]) => X, + type?: new (...args: Schema[]) => X, ): AncestryBuilder { this._index--; if (isPair(this.get())) { @@ -313,7 +314,7 @@ function getDeclaredCollectionsForMap(playNode: YAMLMap | null): string[] { if (isSeq(collectionsNode)) { for (const collectionNode of collectionsNode.items) { if (isScalar(collectionNode)) { - declaredCollections.push(collectionNode.value.toString()); + declaredCollections.push(String(collectionNode.value)); } } } @@ -565,7 +566,7 @@ export function isPlaybook(textDocument: TextDocument): boolean { return false; } - const playbookKeysSet = new Set(); + const playbookKeysSet: Set = new Set(); const playbookJSON = path[0].toJSON(); Object.keys(playbookJSON).forEach(function (key) { diff --git a/packages/ansible-language-server/test/rootMochaHooks.ts b/packages/ansible-language-server/test/rootMochaHooks.ts index 170560e5f..7f3d8859f 100644 --- a/packages/ansible-language-server/test/rootMochaHooks.ts +++ b/packages/ansible-language-server/test/rootMochaHooks.ts @@ -11,10 +11,8 @@ export const mochaHooks = (): Mocha.RootHookObject => { consoleOutput.capture(); }, - afterEach() { - if (this.currentTest.state !== "passed") { - consoleOutput.release(); - } + afterEach(this: Mocha.Context) { + console.log(this.currentTest?.title); }, }; }; diff --git a/packages/ansible-language-server/tsconfig.json b/packages/ansible-language-server/tsconfig.json index dd91cdb9c..610a771b5 100644 --- a/packages/ansible-language-server/tsconfig.json +++ b/packages/ansible-language-server/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - // "strict": true, + "strict": true, "declaration": true, "esModuleInterop": true, "forceConsistentCasingInFileNames": true,