diff --git a/packages/ansible-language-server/Taskfile.yml b/packages/ansible-language-server/Taskfile.yml index 6f16f843c..db5d9c5a6 100644 --- a/packages/ansible-language-server/Taskfile.yml +++ b/packages/ansible-language-server/Taskfile.yml @@ -43,7 +43,7 @@ tasks: desc: Update dependencies cmds: - npm install -g npm@latest - - # installs tools from .tool-versions + # - installs tools from .tool-versions - asdf install - "{{.VIRTUAL_ENV}}/bin/python3 -m pre_commit autoupdate" - npm outdated @@ -88,6 +88,7 @@ tasks: dir: "{{ .TASKFILE_DIR }}" desc: Run only ee tests cmds: + - task: build - > source {{.VIRTUAL_ENV}}/bin/activate && bash -c 'npm run test-with-ee' @@ -96,6 +97,7 @@ tasks: desc: Run only non-ee tests dir: "{{ .TASKFILE_DIR }}" cmds: + - task: build - > source {{.VIRTUAL_ENV}}/bin/activate && bash -c 'npm run test-without-ee' diff --git a/packages/ansible-language-server/src/providers/completionProvider.ts b/packages/ansible-language-server/src/providers/completionProvider.ts index 3009b0596..75a0fbc70 100644 --- a/packages/ansible-language-server/src/providers/completionProvider.ts +++ b/packages/ansible-language-server/src/providers/completionProvider.ts @@ -156,7 +156,7 @@ export async function doCompletion( const inlineCollections = getDeclaredCollections(path); const cursorAtEndOfLine = atEndOfLine(document, position); - let textEdit: TextEdit | undefined; + let textEdit: TextEdit; const nodeRange = getNodeRange(node, document); if (nodeRange) { textEdit = { @@ -347,47 +347,49 @@ export async function doCompletion( const nodeRange = getNodeRange(node, document); const option = keyOptions.get(keyNode.value as string); - const choices = []; - let defaultChoice = option.default; - if (option.type === "bool" && typeof option.default === "string") { - // the YAML parser does not recognize values such as 'Yes'/'no' as booleans - defaultChoice = - option.default.toLowerCase() === "yes" ? true : false; - } - if (option.choices) { - choices.push(...option.choices); - } else if (option.type === "bool") { - choices.push(true); - choices.push(false); - } else if (defaultChoice !== undefined) { - choices.push(defaultChoice); - } - return choices.map((choice, index) => { - let priority; - if (choice === defaultChoice) { - priority = priorityMap.defaultChoice; - } else { - priority = priorityMap.choice; + if (option) { + const choices = []; + let defaultChoice = option.default; + if (option.type === "bool" && typeof option.default === "string") { + // the YAML parser does not recognize values such as 'Yes'/'no' as booleans + defaultChoice = + option.default.toLowerCase() === "yes" ? true : false; } - const insertValue = new String(choice).toString(); - const completionItem: CompletionItem = { - label: insertValue, - detail: choice === defaultChoice ? "default" : undefined, - // using index preserves order from the specification - // except when overridden by the priority - sortText: priority.toString() + index.toString().padStart(3), - kind: CompletionItemKind.Value, - }; - if (nodeRange) { - completionItem.textEdit = { - range: nodeRange, - newText: insertValue, - }; - } else { - completionItem.insertText = insertValue; + if (option.choices) { + choices.push(...option.choices); + } else if (option.type === "bool") { + choices.push(true); + choices.push(false); + } else if (defaultChoice !== undefined) { + choices.push(defaultChoice); } - return completionItem; - }); + return choices.map((choice, index) => { + let priority; + if (choice === defaultChoice) { + priority = priorityMap.defaultChoice; + } else { + priority = priorityMap.choice; + } + const insertValue = new String(choice).toString(); + const completionItem: CompletionItem = { + label: insertValue, + detail: choice === defaultChoice ? "default" : undefined, + // using index preserves order from the specification + // except when overridden by the priority + sortText: priority.toString() + index.toString().padStart(3), + kind: CompletionItemKind.Value, + }; + if (nodeRange) { + completionItem.textEdit = { + range: nodeRange, + newText: insertValue, + }; + } else { + completionItem.insertText = insertValue; + } + return completionItem; + }); + } } } @@ -616,7 +618,13 @@ function atEndOfLine(document: TextDocument, position: Position): boolean { * @param nodeRange - range of the keyword in the document * @returns boolean true if the key is the first element of the list, else false */ -function firstElementOfList(document: TextDocument, nodeRange: Range): boolean { +function firstElementOfList( + document: TextDocument, + nodeRange: Range | undefined, +): boolean { + if (!nodeRange) { + return false; + } const checkNodeRange = { start: { line: nodeRange.start.line, character: 0 }, end: nodeRange.start, diff --git a/packages/ansible-language-server/src/providers/validationProvider.ts b/packages/ansible-language-server/src/providers/validationProvider.ts index 09113cb3e..e33ab0b9c 100644 --- a/packages/ansible-language-server/src/providers/validationProvider.ts +++ b/packages/ansible-language-server/src/providers/validationProvider.ts @@ -25,7 +25,10 @@ export async function doValidate( context?: WorkspaceFolderContext, connection?: Connection, ): Promise> { - let diagnosticsByFile; + let diagnosticsByFile: Map = new Map< + string, + Diagnostic[] + >(); if (quick || !context) { // get validation from cache diagnosticsByFile = @@ -106,13 +109,8 @@ export function getYamlValidation(textDocument: TextDocument): Diagnostic[] { yDoc.errors.forEach((error) => { const [errStart, errEnd] = error.pos; if (errStart) { - const start = textDocument.positionAt( - errStart !== undefined ? errStart : null, - ); - - const end = textDocument.positionAt( - errEnd !== undefined ? errEnd : null, - ); + const start = textDocument.positionAt(errStart); + const end = textDocument.positionAt(errEnd); const range = Range.create(start, end); @@ -128,7 +126,15 @@ export function getYamlValidation(textDocument: TextDocument): Diagnostic[] { severity = DiagnosticSeverity.Information; break; } - rangeTree.insert([error.linePos[0].line, error.linePos[1].line], { + let a: number = 0; + let b: number = 0; + if (error.linePos) { + a = error.linePos[0].line; + if (error.linePos[1]) { + b = error.linePos[1].line; + } + } + rangeTree.insert([a, b], { message: error.message, range: range || Range.create(0, 0, 0, 0), severity: severity, diff --git a/packages/ansible-language-server/src/services/ansibleInventory.ts b/packages/ansible-language-server/src/services/ansibleInventory.ts index d7d81c65a..ff85dc8fa 100644 --- a/packages/ansible-language-server/src/services/ansibleInventory.ts +++ b/packages/ansible-language-server/src/services/ansibleInventory.ts @@ -3,8 +3,23 @@ import { WorkspaceFolderContext } from "./workspaceManager"; import { CommandRunner } from "../utils/commandRunner"; import { URI } from "vscode-uri"; +type HostType = { host: string; priority: number }; + +type inventoryHostEntry = { + children: string[]; + hosts: string[]; +}; + +type inventoryType = Omit< + { + [name: string]: inventoryHostEntry; + }, + "_meta" +>; + /* Example of minimal inventory object, anything else may be missing. + { "_meta": { "hostvars": {} @@ -60,7 +75,7 @@ Example of more complex inventory. export class AnsibleInventory { private connection: Connection; private context: WorkspaceFolderContext; - private _hostList: unknown[]; + private _hostList: HostType[] = []; constructor(connection: Connection, context: WorkspaceFolderContext) { this.connection = connection; @@ -92,9 +107,11 @@ export class AnsibleInventory { defaultHostListPath, ); - let inventoryHostsObject = []; + let inventoryHostsObject = {} as inventoryType; try { - inventoryHostsObject = JSON.parse(ansibleInventoryResult.stdout); + inventoryHostsObject = JSON.parse( + ansibleInventoryResult.stdout, + ) as inventoryType; } catch (error) { this.connection.console.error( `Exception in AnsibleInventory service: ${JSON.stringify(error)}`, @@ -115,7 +132,7 @@ export class AnsibleInventory { * @param hostObj - nested object of hosts * @returns an array of object with host and priority as keys */ -function parseInventoryHosts(hostObj: object): unknown[] { +function parseInventoryHosts(hostObj: inventoryType): HostType[] { if ( !( "all" in hostObj && @@ -145,9 +162,12 @@ function parseInventoryHosts(hostObj: object): unknown[] { return { host: item, priority: 2 }; }); - const allGroups = [...topLevelGroupsObjList, ...otherGroupsObjList]; + const allGroups: HostType[] = [ + ...topLevelGroupsObjList, + ...otherGroupsObjList, + ]; - let ungroupedHostsObjList = []; + let ungroupedHostsObjList: HostType[] = []; if ( "ungrouped" in hostObj && @@ -157,13 +177,13 @@ function parseInventoryHosts(hostObj: object): unknown[] { hostObj.ungrouped ) { ungroupedHostsObjList = hostObj.ungrouped.hosts.map((item) => { - return { host: item, priority: 3 }; + return { host: item, priority: 3 } as HostType; }); } // Add 'localhost' and 'all' to the inventory list - const localhostObj = { host: "localhost", priority: 5 }; - const allHostObj = { host: "all", priority: 6 }; + const localhostObj: HostType = { host: "localhost", priority: 5 }; + const allHostObj: HostType = { host: "all", priority: 6 }; let allHosts = [localhostObj, allHostObj, ...ungroupedHostsObjList]; @@ -179,7 +199,11 @@ function parseInventoryHosts(hostObj: object): unknown[] { return [...allGroups, ...allHosts]; } -function getChildGroups(groupList, hostObj, res = []) { +function getChildGroups( + groupList: string[], + hostObj: inventoryType, + res: string[] = [], +): string[] { for (const host of groupList) { if (hostObj[`${host}`].children) { getChildGroups(hostObj[`${host}`].children, hostObj, res); diff --git a/packages/ansible-language-server/test/providers/hoverProvider.test.ts b/packages/ansible-language-server/test/providers/hoverProvider.test.ts index 2ac997d74..834272f90 100644 --- a/packages/ansible-language-server/test/providers/hoverProvider.test.ts +++ b/packages/ansible-language-server/test/providers/hoverProvider.test.ts @@ -1,5 +1,5 @@ import { TextDocument } from "vscode-languageserver-textdocument"; -import { Position } from "vscode-languageserver"; +import { Hover, MarkupContent, Position } from "vscode-languageserver"; import { expect } from "chai"; import { createTestWorkspaceManager, @@ -12,6 +12,18 @@ import { import { doHover } from "../../src/providers/hoverProvider"; import { WorkspaceFolderContext } from "../../src/services/workspaceManager"; +function get_hover_value(hover: Hover | undefined | null): string { + if (hover) { + if (Array.isArray(hover)) { + return ""; + } else { + if (Object.hasOwn(hover.contents as object, "value")) { + return (hover.contents as MarkupContent)["value"]; + } + } + } + return ""; +} function testPlayKeywords( context: WorkspaceFolderContext, textDoc: TextDocument, @@ -41,7 +53,11 @@ function testPlayKeywords( position, await context.docsLibrary, ); - expect(actualHover.contents["value"]).includes(doc); + if (actualHover) { + expect(get_hover_value(actualHover)).includes(doc); + } else { + expect(false); + } }); }); } @@ -65,7 +81,11 @@ function testTaskKeywords( position, await context.docsLibrary, ); - expect(actualHover.contents["value"]).includes(doc); + if (actualHover) { + expect(get_hover_value(actualHover)).includes(doc); + } else { + expect(false); + } }); }); } @@ -89,7 +109,11 @@ function testBlockKeywords( position, await context.docsLibrary, ); - expect(actualHover.contents["value"]).includes(doc); + if (actualHover) { + expect(get_hover_value(actualHover)).includes(doc); + } else { + expect(false); + } }); }); } @@ -113,7 +137,11 @@ function testRoleKeywords( position, await context.docsLibrary, ); - expect(actualHover.contents["value"]).includes(doc); + if (actualHover) { + expect(get_hover_value(actualHover)).includes(doc); + } else { + expect(false); + } }); }); } @@ -142,7 +170,7 @@ function testModuleNames( position, await context.docsLibrary, ); - expect(actualHover.contents["value"]).includes(doc); + expect(get_hover_value(actualHover)).includes(doc); }); }); } @@ -205,7 +233,7 @@ function testPlaybookAdjacentCollection( position, await context.docsLibrary, ); - expect(actualHover.contents["value"]).includes(doc); + expect(get_hover_value(actualHover)).includes(doc); }); }); } @@ -239,7 +267,7 @@ function testNonPlaybookAdjacentCollection( expect(actualHover).to.be.null; } else { expect( - actualHover.contents["value"], + get_hover_value(actualHover), `actual hover -> ${actualHover}`, ).includes(doc); } diff --git a/packages/ansible-language-server/test/providers/validationProvider.test.ts b/packages/ansible-language-server/test/providers/validationProvider.test.ts index 7f6597ccb..5c66544ff 100644 --- a/packages/ansible-language-server/test/providers/validationProvider.test.ts +++ b/packages/ansible-language-server/test/providers/validationProvider.test.ts @@ -1,6 +1,6 @@ import { TextDocument } from "vscode-languageserver-textdocument"; import { expect } from "chai"; -import { Position, integer } from "vscode-languageserver"; +import { Diagnostic, Position, integer } from "vscode-languageserver"; import { doValidate, getYamlValidation, @@ -29,7 +29,7 @@ function testValidationFromCache( } function assertValidateTests( - tests, + tests: testType[], context: WorkspaceFolderContext, validationManager: ValidationManager, textDoc: TextDocument, @@ -37,7 +37,7 @@ function assertValidateTests( ) { tests.forEach((test) => { it(`should provide diagnostics for ${test.name}`, async function () { - const actualDiagnostics = await doValidate( + const actualDiagnostics: Map = await doValidate( textDoc, validationManager, false, @@ -52,31 +52,38 @@ function assertValidateTests( if (test.diagnosticReport.length === 0) { expect(actualDiagnostics.has(`file://${textDoc.uri}`)).to.be.false; } else { - expect(actualDiagnostics.get(`file://${textDoc.uri}`).length).to.equal( - test.diagnosticReport.length, - ); - - actualDiagnostics.get(`file://${textDoc.uri}`).forEach((diag, i) => { - const actDiag = diag; - const expDiag = test.diagnosticReport[i]; - - expect(actDiag.message).include(expDiag.message); - expect(actDiag.range).to.deep.equal(expDiag.range); - expect(actDiag.severity).to.equal(expDiag.severity); - expect(actDiag.source).to.equal(expDiag.source); - }); + const diags = actualDiagnostics.get(`file://${textDoc.uri}`); + if (diags) { + expect(diags.length).to.equal(test.diagnosticReport.length); + diags.forEach((diag, i) => { + const actDiag = diag; + const expDiag = test.diagnosticReport[i]; + + expect(actDiag.message).include(expDiag.message); + expect(actDiag.range).to.deep.equal(expDiag.range); + expect(actDiag.severity).to.equal(expDiag.severity); + expect(actDiag.source).to.equal(expDiag.source); + }); + } else { + expect(false); + } } }); }); } +type testType = { + name: string; + diagnosticReport: Diagnostic[]; +}; + function testAnsibleLintErrors( context: WorkspaceFolderContext, validationManager: ValidationManager, textDoc: TextDocument, validationEnabled: boolean, ) { - const tests = [ + const tests: testType[] = [ { name: "specific ansible lint errors and warnings (Warnings come from warn_list in ansible-lint config)", diagnosticReport: [ @@ -224,7 +231,7 @@ function testAnsibleSyntaxCheckNoHost( textDoc: TextDocument, validationEnabled: boolean, ) { - const tests = [ + const tests: testType[] = [ { name: "no host", diagnosticReport: [ @@ -337,37 +344,10 @@ describe("doValidate()", () => { let context = workspaceManager.getContext(fixtureFileUri); let textDoc = getDoc(fixtureFilePath); - let docSettings = context.documentSettings.get(textDoc.uri); - - describe("Get validation only from cache", () => { - describe("With EE enabled @ee", () => { - before(async () => { - setFixtureAnsibleCollectionPathEnv( - "/home/runner/.ansible/collections:/usr/share/ansible", - ); - await enableExecutionEnvironmentSettings(docSettings); - }); - - testValidationFromCache(validationManager, textDoc); - - after(async () => { - setFixtureAnsibleCollectionPathEnv(); - await disableExecutionEnvironmentSettings(docSettings); - }); - }); - - describe("With EE disabled", () => { - before(async () => { - setFixtureAnsibleCollectionPathEnv(); - await disableExecutionEnvironmentSettings(docSettings); - }); + if (context) { + let docSettings = context.documentSettings.get(textDoc.uri); - testValidationFromCache(validationManager, textDoc); - }); - }); - - describe("Ansible diagnostics", () => { - describe("Diagnostics using ansible-lint", () => { + describe("Get validation only from cache", () => { describe("With EE enabled @ee", () => { before(async () => { setFixtureAnsibleCollectionPathEnv( @@ -376,7 +356,7 @@ describe("doValidate()", () => { await enableExecutionEnvironmentSettings(docSettings); }); - testAnsibleLintErrors(context, validationManager, textDoc, true); + testValidationFromCache(validationManager, textDoc); after(async () => { setFixtureAnsibleCollectionPathEnv(); @@ -390,30 +370,23 @@ describe("doValidate()", () => { await disableExecutionEnvironmentSettings(docSettings); }); - testAnsibleLintErrors(context, validationManager, textDoc, true); + testValidationFromCache(validationManager, textDoc); }); }); - describe("Diagnostics using ansible-playbook --syntax-check", () => { - describe("no specific ansible lint errors", () => { + describe("Ansible diagnostics", () => { + describe("Diagnostics using ansible-lint", () => { describe("With EE enabled @ee", () => { before(async () => { - (await docSettings).validation.lint.enabled = false; setFixtureAnsibleCollectionPathEnv( "/home/runner/.ansible/collections:/usr/share/ansible", ); await enableExecutionEnvironmentSettings(docSettings); }); - testAnsibleSyntaxCheckNoErrors( - context, - validationManager, - textDoc, - true, - ); + testAnsibleLintErrors(context, validationManager, textDoc, true); after(async () => { - (await docSettings).validation.lint.enabled = true; setFixtureAnsibleCollectionPathEnv(); await disableExecutionEnvironmentSettings(docSettings); }); @@ -421,49 +394,53 @@ describe("doValidate()", () => { describe("With EE disabled", () => { before(async () => { - (await docSettings).validation.lint.enabled = false; setFixtureAnsibleCollectionPathEnv(); await disableExecutionEnvironmentSettings(docSettings); }); - testAnsibleSyntaxCheckNoErrors( - context, - validationManager, - textDoc, - true, - ); - }); - after(async () => { - (await docSettings).validation.lint.enabled = true; - setFixtureAnsibleCollectionPathEnv(); - await disableExecutionEnvironmentSettings(docSettings); + testAnsibleLintErrors(context, validationManager, textDoc, true); }); }); - describe("empty playbook", () => { - fixtureFilePath = "diagnostics/empty.yml"; - fixtureFileUri = resolveDocUri(fixtureFilePath); - context = workspaceManager.getContext(fixtureFileUri); + describe("Diagnostics using ansible-playbook --syntax-check", () => { + describe("no specific ansible lint errors", () => { + describe("With EE enabled @ee", () => { + before(async () => { + (await docSettings).validation.lint.enabled = false; + setFixtureAnsibleCollectionPathEnv( + "/home/runner/.ansible/collections:/usr/share/ansible", + ); + await enableExecutionEnvironmentSettings(docSettings); + }); + + testAnsibleSyntaxCheckNoErrors( + context, + validationManager, + textDoc, + true, + ); - textDoc = getDoc(fixtureFilePath); - docSettings = context.documentSettings.get(textDoc.uri); + after(async () => { + (await docSettings).validation.lint.enabled = true; + setFixtureAnsibleCollectionPathEnv(); + await disableExecutionEnvironmentSettings(docSettings); + }); + }); - describe("With EE enabled @ee", () => { - before(async () => { - (await docSettings).validation.lint.enabled = false; - setFixtureAnsibleCollectionPathEnv( - "/home/runner/.ansible/collections:/usr/share/ansible", + describe("With EE disabled", () => { + before(async () => { + (await docSettings).validation.lint.enabled = false; + setFixtureAnsibleCollectionPathEnv(); + await disableExecutionEnvironmentSettings(docSettings); + }); + + testAnsibleSyntaxCheckNoErrors( + context, + validationManager, + textDoc, + true, ); - await enableExecutionEnvironmentSettings(docSettings); }); - - testAnsibleSyntaxCheckEmptyPlaybook( - context, - validationManager, - textDoc, - true, - ); - after(async () => { (await docSettings).validation.lint.enabled = true; setFixtureAnsibleCollectionPathEnv(); @@ -471,51 +448,51 @@ describe("doValidate()", () => { }); }); - describe("With EE disabled", () => { - before(async () => { - (await docSettings).validation.lint.enabled = false; - setFixtureAnsibleCollectionPathEnv(); - await disableExecutionEnvironmentSettings(docSettings); - }); - - testAnsibleSyntaxCheckEmptyPlaybook( - context, - validationManager, - textDoc, - true, - ); - }); - after(async () => { - (await docSettings).validation.lint.enabled = true; - setFixtureAnsibleCollectionPathEnv(); - await disableExecutionEnvironmentSettings(docSettings); - }); - }); - - describe("no host", () => { - fixtureFilePath = "diagnostics/noHost.yml"; - fixtureFileUri = resolveDocUri(fixtureFilePath); - context = workspaceManager.getContext(fixtureFileUri); + describe("empty playbook", () => { + fixtureFilePath = "diagnostics/empty.yml"; + fixtureFileUri = resolveDocUri(fixtureFilePath); + context = workspaceManager.getContext(fixtureFileUri); + + textDoc = getDoc(fixtureFilePath); + docSettings = context.documentSettings.get(textDoc.uri); + + describe("With EE enabled @ee", () => { + before(async () => { + (await docSettings).validation.lint.enabled = false; + setFixtureAnsibleCollectionPathEnv( + "/home/runner/.ansible/collections:/usr/share/ansible", + ); + await enableExecutionEnvironmentSettings(docSettings); + }); + + testAnsibleSyntaxCheckEmptyPlaybook( + context, + validationManager, + textDoc, + true, + ); - textDoc = getDoc(fixtureFilePath); - docSettings = context.documentSettings.get(textDoc.uri); + after(async () => { + (await docSettings).validation.lint.enabled = true; + setFixtureAnsibleCollectionPathEnv(); + await disableExecutionEnvironmentSettings(docSettings); + }); + }); - describe("With EE enabled @ee", () => { - before(async () => { - (await docSettings).validation.lint.enabled = false; - setFixtureAnsibleCollectionPathEnv( - "/home/runner/.ansible/collections:/usr/share/ansible", + describe("With EE disabled", () => { + before(async () => { + (await docSettings).validation.lint.enabled = false; + setFixtureAnsibleCollectionPathEnv(); + await disableExecutionEnvironmentSettings(docSettings); + }); + + testAnsibleSyntaxCheckEmptyPlaybook( + context, + validationManager, + textDoc, + true, ); - await enableExecutionEnvironmentSettings(docSettings); }); - - testAnsibleSyntaxCheckNoHost( - context, - validationManager, - textDoc, - true, - ); - after(async () => { (await docSettings).validation.lint.enabled = true; setFixtureAnsibleCollectionPathEnv(); @@ -523,56 +500,115 @@ describe("doValidate()", () => { }); }); - describe("With EE disabled", () => { - before(async () => { - (await docSettings).validation.lint.enabled = false; + describe("no host", () => { + fixtureFilePath = "diagnostics/noHost.yml"; + fixtureFileUri = resolveDocUri(fixtureFilePath); + context = workspaceManager.getContext(fixtureFileUri); + + textDoc = getDoc(fixtureFilePath); + if (context) { + docSettings = context.documentSettings.get(textDoc.uri); + } + + describe("With EE enabled @ee", () => { + before(async () => { + (await docSettings).validation.lint.enabled = false; + setFixtureAnsibleCollectionPathEnv( + "/home/runner/.ansible/collections:/usr/share/ansible", + ); + await enableExecutionEnvironmentSettings(docSettings); + }); + + testAnsibleSyntaxCheckNoHost( + context, + validationManager, + textDoc, + true, + ); + + after(async () => { + (await docSettings).validation.lint.enabled = true; + setFixtureAnsibleCollectionPathEnv(); + await disableExecutionEnvironmentSettings(docSettings); + }); + }); + + describe("With EE disabled", () => { + before(async () => { + (await docSettings).validation.lint.enabled = false; + setFixtureAnsibleCollectionPathEnv(); + await disableExecutionEnvironmentSettings(docSettings); + }); + + testAnsibleSyntaxCheckNoHost( + context, + validationManager, + textDoc, + true, + ); + }); + after(async () => { + (await docSettings).validation.lint.enabled = true; setFixtureAnsibleCollectionPathEnv(); await disableExecutionEnvironmentSettings(docSettings); }); - - testAnsibleSyntaxCheckNoHost( - context, - validationManager, - textDoc, - true, - ); - }); - after(async () => { - (await docSettings).validation.lint.enabled = true; - setFixtureAnsibleCollectionPathEnv(); - await disableExecutionEnvironmentSettings(docSettings); }); }); - }); - describe("Diagnostics when validation is disabled", () => { - describe("no specific ansible lint errors", () => { - fixtureFilePath = "diagnostics/lint_errors.yml"; - fixtureFileUri = resolveDocUri(fixtureFilePath); - context = workspaceManager.getContext(fixtureFileUri); + describe("Diagnostics when validation is disabled", () => { + describe("no specific ansible lint errors", () => { + fixtureFilePath = "diagnostics/lint_errors.yml"; + fixtureFileUri = resolveDocUri(fixtureFilePath); + context = workspaceManager.getContext(fixtureFileUri); + + textDoc = getDoc(fixtureFilePath); + docSettings = context.documentSettings.get(textDoc.uri); + + describe("With EE enabled @ee", () => { + before(async () => { + // (await docSettings).validation.lint.enabled = false; + // (await docSettings).validation.lint.path = + // "invalid-ansible-lint-path"; + (await docSettings).validation.enabled = false; + setFixtureAnsibleCollectionPathEnv( + "/home/runner/.ansible/collections:/usr/share/ansible", + ); + await enableExecutionEnvironmentSettings(docSettings); + }); + + testAnsibleSyntaxCheckNoErrors( + context, + validationManager, + textDoc, + false, + ); - textDoc = getDoc(fixtureFilePath); - docSettings = context.documentSettings.get(textDoc.uri); + after(async () => { + // (await docSettings).validation.lint.enabled = true; + // (await docSettings).validation.lint.path = "ansible-lint"; + (await docSettings).validation.enabled = true; + setFixtureAnsibleCollectionPathEnv(); + await disableExecutionEnvironmentSettings(docSettings); + }); + }); - describe("With EE enabled @ee", () => { - before(async () => { - // (await docSettings).validation.lint.enabled = false; - // (await docSettings).validation.lint.path = - // "invalid-ansible-lint-path"; - (await docSettings).validation.enabled = false; - setFixtureAnsibleCollectionPathEnv( - "/home/runner/.ansible/collections:/usr/share/ansible", + describe("With EE disabled", () => { + before(async () => { + // (await docSettings).validation.lint.enabled = false; + // (await docSettings).validation.lint.path = + // "invalid-ansible-lint-path"; + (await docSettings).validation.enabled = false; + setFixtureAnsibleCollectionPathEnv(); + await disableExecutionEnvironmentSettings(docSettings); + }); + + testAnsibleSyntaxCheckNoErrors( + context, + validationManager, + textDoc, + false, ); - await enableExecutionEnvironmentSettings(docSettings); }); - - testAnsibleSyntaxCheckNoErrors( - context, - validationManager, - textDoc, - false, - ); - after(async () => { // (await docSettings).validation.lint.enabled = true; // (await docSettings).validation.lint.path = "ansible-lint"; @@ -582,59 +618,59 @@ describe("doValidate()", () => { }); }); - describe("With EE disabled", () => { - before(async () => { - // (await docSettings).validation.lint.enabled = false; - // (await docSettings).validation.lint.path = - // "invalid-ansible-lint-path"; - (await docSettings).validation.enabled = false; - setFixtureAnsibleCollectionPathEnv(); - await disableExecutionEnvironmentSettings(docSettings); - }); - - testAnsibleSyntaxCheckNoErrors( - context, - validationManager, - textDoc, - false, - ); - }); - after(async () => { - // (await docSettings).validation.lint.enabled = true; - // (await docSettings).validation.lint.path = "ansible-lint"; - (await docSettings).validation.enabled = true; - setFixtureAnsibleCollectionPathEnv(); - await disableExecutionEnvironmentSettings(docSettings); - }); - }); - - describe("no host", () => { - fixtureFilePath = "diagnostics/noHost.yml"; - fixtureFileUri = resolveDocUri(fixtureFilePath); - context = workspaceManager.getContext(fixtureFileUri); + describe("no host", () => { + fixtureFilePath = "diagnostics/noHost.yml"; + fixtureFileUri = resolveDocUri(fixtureFilePath); + context = workspaceManager.getContext(fixtureFileUri); + + textDoc = getDoc(fixtureFilePath); + docSettings = context.documentSettings.get(textDoc.uri); + + describe("With EE enabled @ee", () => { + before(async () => { + // (await docSettings).validation.lint.enabled = false; + // (await docSettings).validation.lint.path = + // "invalid-ansible-lint-path"; + (await docSettings).validation.enabled = false; + setFixtureAnsibleCollectionPathEnv( + "/home/runner/.ansible/collections:/usr/share/ansible", + ); + await enableExecutionEnvironmentSettings(docSettings); + }); + + testAnsibleSyntaxCheckNoHost( + context, + validationManager, + textDoc, + false, + ); - textDoc = getDoc(fixtureFilePath); - docSettings = context.documentSettings.get(textDoc.uri); + after(async () => { + // (await docSettings).validation.lint.enabled = true; + // (await docSettings).validation.lint.path = "ansible-lint"; + (await docSettings).validation.enabled = true; + setFixtureAnsibleCollectionPathEnv(); + await disableExecutionEnvironmentSettings(docSettings); + }); + }); - describe("With EE enabled @ee", () => { - before(async () => { - // (await docSettings).validation.lint.enabled = false; - // (await docSettings).validation.lint.path = - // "invalid-ansible-lint-path"; - (await docSettings).validation.enabled = false; - setFixtureAnsibleCollectionPathEnv( - "/home/runner/.ansible/collections:/usr/share/ansible", + describe("With EE disabled", () => { + before(async () => { + // (await docSettings).validation.lint.enabled = false; + // (await docSettings).validation.lint.path = + // "invalid-ansible-lint-path"; + (await docSettings).validation.enabled = false; + setFixtureAnsibleCollectionPathEnv(); + await disableExecutionEnvironmentSettings(docSettings); + }); + + testAnsibleSyntaxCheckNoHost( + context, + validationManager, + textDoc, + false, ); - await enableExecutionEnvironmentSettings(docSettings); }); - - testAnsibleSyntaxCheckNoHost( - context, - validationManager, - textDoc, - false, - ); - after(async () => { // (await docSettings).validation.lint.enabled = true; // (await docSettings).validation.lint.path = "ansible-lint"; @@ -643,66 +679,41 @@ describe("doValidate()", () => { await disableExecutionEnvironmentSettings(docSettings); }); }); + }); + }); - describe("With EE disabled", () => { - before(async () => { - // (await docSettings).validation.lint.enabled = false; - // (await docSettings).validation.lint.path = - // "invalid-ansible-lint-path"; - (await docSettings).validation.enabled = false; - setFixtureAnsibleCollectionPathEnv(); - await disableExecutionEnvironmentSettings(docSettings); - }); + describe("YAML diagnostics", () => { + fixtureFilePath = "diagnostics/invalid_yaml.yml"; + fixtureFileUri = resolveDocUri(fixtureFilePath); + context = workspaceManager.getContext(fixtureFileUri); + + textDoc = getDoc(fixtureFilePath); + docSettings = context.documentSettings.get(textDoc.uri); - testAnsibleSyntaxCheckNoHost( - context, - validationManager, - textDoc, - false, + describe("With EE enabled @ee", () => { + before(async () => { + setFixtureAnsibleCollectionPathEnv( + "/home/runner/.ansible/collections:/usr/share/ansible", ); + await enableExecutionEnvironmentSettings(docSettings); }); + + testInvalidYamlFile(textDoc); + after(async () => { - // (await docSettings).validation.lint.enabled = true; - // (await docSettings).validation.lint.path = "ansible-lint"; - (await docSettings).validation.enabled = true; setFixtureAnsibleCollectionPathEnv(); await disableExecutionEnvironmentSettings(docSettings); }); }); - }); - }); - - describe("YAML diagnostics", () => { - fixtureFilePath = "diagnostics/invalid_yaml.yml"; - fixtureFileUri = resolveDocUri(fixtureFilePath); - context = workspaceManager.getContext(fixtureFileUri); - - textDoc = getDoc(fixtureFilePath); - docSettings = context.documentSettings.get(textDoc.uri); - describe("With EE enabled @ee", () => { - before(async () => { - setFixtureAnsibleCollectionPathEnv( - "/home/runner/.ansible/collections:/usr/share/ansible", - ); - await enableExecutionEnvironmentSettings(docSettings); - }); - - testInvalidYamlFile(textDoc); - - after(async () => { - setFixtureAnsibleCollectionPathEnv(); - await disableExecutionEnvironmentSettings(docSettings); - }); - }); + describe("With EE disabled", () => { + before(async () => { + setFixtureAnsibleCollectionPathEnv(); + await disableExecutionEnvironmentSettings(docSettings); + }); - describe("With EE disabled", () => { - before(async () => { - setFixtureAnsibleCollectionPathEnv(); - await disableExecutionEnvironmentSettings(docSettings); + testInvalidYamlFile(textDoc); }); - - testInvalidYamlFile(textDoc); }); - }); + } });