Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Fallback to syntax-check if ansible-lint is not installed or disabled #5

Merged
merged 44 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
0ef7af6
Add support for ansible syntax-check
priyamsahoo Aug 23, 2021
08c077a
Add utility function for library checking
priyamsahoo Aug 23, 2021
5a72cc6
Add logic to fallback to ansible syntax-check if ansible-lint is not …
priyamsahoo Aug 23, 2021
f7eb904
Resolve bug for overrunning the syntax-check service
priyamsahoo Aug 25, 2021
239c3c6
Remove copy-paste leftovers
priyamsahoo Aug 25, 2021
e95be14
Use ansible path to run syntax-check rather than having to create a n…
priyamsahoo Aug 25, 2021
420a0ec
Rename ansibleSyntaxCheck service to ansibleSyntaxChecker
priyamsahoo Aug 26, 2021
63a6419
Remove unused imports
priyamsahoo Aug 31, 2021
dc25ff7
add new package-lock.json
priyamsahoo Aug 31, 2021
4590c0b
Add support for ansible syntax-check
priyamsahoo Aug 23, 2021
d0fcdac
Remove copy-paste leftovers
priyamsahoo Aug 25, 2021
3ca5cae
Use ansible path to run syntax-check rather than having to create a n…
priyamsahoo Aug 25, 2021
dced3bc
Rename ansibleSyntaxCheck service to ansibleSyntaxChecker
priyamsahoo Aug 26, 2021
d9bf372
Remove unused imports
priyamsahoo Aug 31, 2021
c159795
Add fallback logic to the right place
priyamsahoo Aug 31, 2021
f9cebb6
Add support for fallback to ansible syntax-check when the ansible-lin…
priyamsahoo Aug 31, 2021
a89e808
New implementation of libraryChecker as getExecutablePath
priyamsahoo Aug 31, 2021
4a23964
Remaned AnsibleSyntaxChecker class to AnsiblePlaybook class
priyamsahoo Aug 31, 2021
bb18f33
Embed `private` attributes into the constructor declaration
priyamsahoo Sep 9, 2021
21dd1e4
Convert else block with guard expression @ doValidate for ansibleLint
priyamsahoo Sep 9, 2021
4367320
Make invoking progressTracker unconditional
priyamsahoo Sep 9, 2021
f0de9f5
Move await to the getExecutablePath method invocation
priyamsahoo Sep 9, 2021
1d033e6
Remove redundant child_process imports
priyamsahoo Sep 9, 2021
ad21769
Reformat AnsiblePlaybook constructor
priyamsahoo Sep 9, 2021
d5e46f1
Refactor processReport method @ AnsiblePlaybook
priyamsahoo Sep 9, 2021
8a9f59d
Remove unnecessary statements from try-catch block
priyamsahoo Sep 13, 2021
0d38292
Use config variable in getExecutablePath in place of hardcoded string
priyamsahoo Sep 15, 2021
064d23a
Add new package-lock.json
priyamsahoo Sep 15, 2021
4613993
Merge branch 'main' into syntax-check
priyamsahoo Sep 30, 2021
c6ab5c6
sync package-lock.json
priyamsahoo Sep 30, 2021
09ac750
revert the gramatical change to have it fixed in a separate PR.
priyamsahoo Sep 30, 2021
78212ce
separate the imports from exec initialization
priyamsahoo Sep 30, 2021
6e82a13
add jsdoc for the AnsiblePlaybook constructor
priyamsahoo Sep 30, 2021
035bb33
use URI from vscode-uri instead of URL
priyamsahoo Sep 30, 2021
ff84617
change variable name from ansibleSyntaxCheck to ansiblePlaybook
priyamsahoo Sep 30, 2021
f7ffbd8
Merge branch 'main' into syntax-check
priyamsahoo Oct 5, 2021
a272ae6
chore: auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 5, 2021
e01b8db
Change variable name to something more sensible
priyamsahoo Oct 5, 2021
589f0c9
Merge branch 'main' into syntax-check
priyamsahoo Oct 5, 2021
4f32dd8
Merge branch 'syntax-check' of github.com:priyamsahoo/ansible-languag…
priyamsahoo Oct 5, 2021
e5dc2f3
remove duplicate import statements
priyamsahoo Oct 6, 2021
6afb113
add connection parameter to doValidate function in validation provider
priyamsahoo Oct 7, 2021
c41d8d8
move syntax-check notification to from ansible lint service to valida…
priyamsahoo Oct 7, 2021
58b1971
Merge branch 'main' into syntax-check
ssbarnea Oct 8, 2021
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
19 changes: 16 additions & 3 deletions src/ansibleLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,13 @@ export class AnsibleLanguageService {
const context = this.workspaceManager.getContext(e.document.uri);
if (context) {
// perform full validation
await doValidate(e.document, this.validationManager, false, context);
await doValidate(
e.document,
this.validationManager,
false,
context,
this.connection
);
}
} catch (error) {
this.handleError(error, 'onDidOpen');
Expand Down Expand Up @@ -177,7 +183,13 @@ export class AnsibleLanguageService {
const context = this.workspaceManager.getContext(e.document.uri);
if (context) {
// perform full validation
await doValidate(e.document, this.validationManager, false, context);
await doValidate(
e.document,
this.validationManager,
false,
context,
this.connection
);
}
} catch (error) {
this.handleError(error, 'onDidSave');
Expand All @@ -201,7 +213,8 @@ export class AnsibleLanguageService {
e.document,
this.validationManager,
true,
this.workspaceManager.getContext(e.document.uri)
this.workspaceManager.getContext(e.document.uri),
this.connection
);
} catch (error) {
this.handleError(error, 'onDidChangeContent');
Expand Down
15 changes: 13 additions & 2 deletions src/providers/validationProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import IntervalTree from '@flatten-js/interval-tree';
import * as _ from 'lodash';
import {
Connection,
Diagnostic,
DiagnosticRelatedInformation,
DiagnosticSeverity,
Expand All @@ -24,7 +25,8 @@ export async function doValidate(
textDocument: TextDocument,
validationManager: ValidationManager,
quick = true,
context?: WorkspaceFolderContext
context?: WorkspaceFolderContext,
connection?: Connection
): Promise<Map<string, Diagnostic[]>> {
let diagnosticsByFile;
if (quick || !context) {
Expand All @@ -45,7 +47,16 @@ export async function doValidate(
diagnosticsByFile = await context.ansibleLint.doValidate(textDocument);
}

if (!diagnosticsByFile || !lintAvailability) {
if (!diagnosticsByFile || !lintAvailability || diagnosticsByFile === -1) {
// Notifying the user about the failed ansible-lint command and falling back to ansible syntax-check in this scenario
if (diagnosticsByFile === -1) {
console.debug(
'Ansible-lint command execution failed. Falling back to ansible syntax-check'
);
connection.window.showInformationMessage(
'Falling back to ansible syntax-check.'
);
}
console.debug('Validating using ansible syntax-check');
diagnosticsByFile = await context.ansiblePlaybook.doValidate(
textDocument
Expand Down
11 changes: 2 additions & 9 deletions src/services/ansibleLint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class AnsibleLint {
*/
public async doValidate(
textDocument: TextDocument
): Promise<Map<string, Diagnostic[]>> {
): Promise<Map<string, Diagnostic[]> | -1> {
let diagnostics: Map<string, Diagnostic[]> = new Map();

const workingDirectory = URI.parse(this.context.workspaceFolder.uri).path;
Expand Down Expand Up @@ -136,15 +136,8 @@ export class AnsibleLint {
workingDirectory
);
} else {
// Notifying the user about the failed command and falling back to ansible syntax-check in this scenario
this.connection.window.showWarningMessage(
'Falling back to ansible syntax-check.'
);
this.connection.window.showErrorMessage(execError.message);
console.debug(
'Ansible-lint command execution failed. Falling back to ansible syntax-check'
);
return;
return -1;
ganeshrn marked this conversation as resolved.
Show resolved Hide resolved
}

if (execError.stderr) {
Expand Down
2 changes: 0 additions & 2 deletions src/utils/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { promisify } from 'util';
import { TextDocument } from 'vscode-languageserver-textdocument';
import { Range } from 'vscode-languageserver-types';
import * as path from 'path';
import * as child_process from 'child_process';
import { promisify } from 'util';

export async function fileExists(fileUri: string): Promise<boolean> {
return !!(await fs.stat(new URL(fileUri)).catch(() => false));
Expand Down