@ansible/ansible-language-server
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -23,2 +23,10 @@ <!-- markdownlint-disable no-duplicate-heading no-multiple-blanks --> | ||
## v1.0.2 | ||
### Bugfixes | ||
- Avoid parsing ansible-lint config file (#478) @priyamsahoo | ||
- Enhance ansible meta-data (#475) @priyamsahoo | ||
- Add support for ansible-lint config file (#474) @priyamsahoo | ||
## v1.0.1 | ||
@@ -25,0 +33,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { Connection, Diagnostic, DidChangeWatchedFilesParams } from "vscode-languageserver"; | ||
import { Connection, Diagnostic } from "vscode-languageserver"; | ||
import { TextDocument } from "vscode-languageserver-textdocument"; | ||
@@ -14,3 +14,3 @@ import { WorkspaceFolderContext } from "./workspaceManager"; | ||
private useProgressTracker; | ||
private configCache; | ||
private _ansibleLintConfigFilePath; | ||
constructor(connection: Connection, context: WorkspaceFolderContext); | ||
@@ -28,6 +28,4 @@ /** | ||
private processReport; | ||
handleWatchedDocumentChange(params: DidChangeWatchedFilesParams): void; | ||
private getAnsibleLintConfig; | ||
private readAnsibleLintConfig; | ||
private findAnsibleLintConfigFile; | ||
get ansibleLintConfigFilePath(): string; | ||
} |
@@ -13,7 +13,5 @@ "use strict"; | ||
exports.AnsibleLint = void 0; | ||
const fs_1 = require("fs"); | ||
const path = require("path"); | ||
const vscode_uri_1 = require("vscode-uri"); | ||
const vscode_languageserver_1 = require("vscode-languageserver"); | ||
const yaml_1 = require("yaml"); | ||
const misc_1 = require("../utils/misc"); | ||
@@ -31,3 +29,2 @@ const commandRunner_1 = require("../utils/commandRunner"); | ||
this.useProgressTracker = false; | ||
this.configCache = new Map(); | ||
this.connection = connection; | ||
@@ -67,2 +64,3 @@ this.context = context; | ||
} | ||
this._ansibleLintConfigFilePath = ansibleLintConfigPath; | ||
linterArguments = `${linterArguments} --offline --nocolor -f codeclimate`; | ||
@@ -77,9 +75,8 @@ const docPath = vscode_uri_1.URI.parse(textDocument.uri).path; | ||
}; | ||
const ansibleLintConfigPromise = this.getAnsibleLintConfig(workingDirectory, ansibleLintConfigPath); | ||
progressTracker.begin("ansible-lint", undefined, "Processing files..."); | ||
const commandRunner = new commandRunner_1.CommandRunner(this.connection, this.context, settings); | ||
try { | ||
// get Ansible configuration | ||
// get ansible-lint result on the doc | ||
const result = yield commandRunner.runCommand("ansible-lint", `${linterArguments} "${docPath}"`, workingDirectory, mountPaths); | ||
diagnostics = this.processReport(result.stdout, yield ansibleLintConfigPromise, workingDirectory); | ||
diagnostics = this.processReport(result.stdout, workingDirectory); | ||
if (result.stderr) { | ||
@@ -93,3 +90,3 @@ this.connection.console.info(`[ansible-lint] ${result.stderr}`); | ||
if (execError.stdout) { | ||
diagnostics = this.processReport(execError.stdout, yield ansibleLintConfigPromise, workingDirectory); | ||
diagnostics = this.processReport(execError.stdout, workingDirectory); | ||
} | ||
@@ -117,4 +114,3 @@ else { | ||
} | ||
processReport(result, ansibleLintConfig, workingDirectory) { | ||
var _a, _b; | ||
processReport(result, workingDirectory) { | ||
const diagnostics = new Map(); | ||
@@ -150,14 +146,9 @@ if (!result) { | ||
let severity = vscode_languageserver_1.DiagnosticSeverity.Error; | ||
if (ansibleLintConfig) { | ||
const lintRuleName = (_b = (_a = item.check_name.match(/\[(?<name>[a-z\-]+)\].*/)) === null || _a === void 0 ? void 0 : _a.groups) === null || _b === void 0 ? void 0 : _b.name; | ||
if (lintRuleName && | ||
ansibleLintConfig.warnList.has(lintRuleName)) { | ||
if (item.level) { | ||
if (item.level === "error") { | ||
severity = vscode_languageserver_1.DiagnosticSeverity.Error; | ||
} | ||
else if (item.level === "warning") { | ||
severity = vscode_languageserver_1.DiagnosticSeverity.Warning; | ||
} | ||
const categories = item.categories; | ||
if (categories instanceof Array) { | ||
if (categories.some((c) => ansibleLintConfig.warnList.has(c))) { | ||
severity = vscode_languageserver_1.DiagnosticSeverity.Warning; | ||
} | ||
} | ||
} | ||
@@ -204,48 +195,2 @@ const path = `${workingDirectory}/${item.location.path}`; | ||
} | ||
handleWatchedDocumentChange(params) { | ||
for (const fileEvent of params.changes) { | ||
// remove from cache on any change | ||
this.configCache.delete(fileEvent.uri); | ||
} | ||
} | ||
getAnsibleLintConfig(workingDirectory, configPath) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (configPath) { | ||
const absConfigPath = path.resolve(workingDirectory, configPath); | ||
let config = this.configCache.get(absConfigPath); | ||
if (!config) { | ||
config = yield this.readAnsibleLintConfig(absConfigPath); | ||
this.configCache.set(absConfigPath, config); | ||
} | ||
return config; | ||
} | ||
}); | ||
} | ||
readAnsibleLintConfig(configPath) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const config = { | ||
warnList: new Set(), | ||
}; | ||
try { | ||
const configContents = yield fs_1.promises.readFile(configPath, { | ||
encoding: "utf8", | ||
}); | ||
(0, yaml_1.parseAllDocuments)(configContents).forEach((configDoc) => { | ||
const configObject = configDoc.toJSON(); | ||
if ((0, misc_1.hasOwnProperty)(configObject, "warn_list") && | ||
configObject.warn_list instanceof Array) { | ||
for (const warn_item of configObject.warn_list) { | ||
if (typeof warn_item === "string") { | ||
config.warnList.add(warn_item); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
catch (error) { | ||
this.connection.window.showErrorMessage(error); | ||
} | ||
return config; | ||
}); | ||
} | ||
findAnsibleLintConfigFile(uri) { | ||
@@ -258,7 +203,9 @@ return __awaiter(this, void 0, void 0, function* () { | ||
for (let index = pathArray.length - 1; index >= 0; index--) { | ||
const candidatePath = pathArray | ||
let candidatePath = pathArray | ||
.slice(0, index) | ||
.concat(".ansible-lint") | ||
.join("/"); | ||
if (!candidatePath.startsWith(this.context.workspaceFolder.uri)) { | ||
const workspacePath = vscode_uri_1.URI.parse(this.context.workspaceFolder.uri).path; | ||
candidatePath = vscode_uri_1.URI.parse(candidatePath).path; | ||
if (!candidatePath.startsWith(workspacePath)) { | ||
// we've gone out of the workspace folder | ||
@@ -268,3 +215,3 @@ break; | ||
if (yield (0, misc_1.fileExists)(candidatePath)) { | ||
configPath = candidatePath; | ||
configPath = vscode_uri_1.URI.parse(candidatePath).path; | ||
break; | ||
@@ -276,4 +223,7 @@ } | ||
} | ||
get ansibleLintConfigFilePath() { | ||
return this._ansibleLintConfigFilePath; | ||
} | ||
} | ||
exports.AnsibleLint = AnsibleLint; | ||
//# sourceMappingURL=ansibleLint.js.map |
@@ -52,3 +52,3 @@ "use strict"; | ||
image: { | ||
default: "quay.io/ansible/creator-ee:v0.9.2", | ||
default: "quay.io/ansible/creator-ee:latest", | ||
description: "Name of the execution environment to be used", | ||
@@ -55,0 +55,0 @@ }, |
@@ -125,3 +125,2 @@ "use strict"; | ||
this.documentMetadata.handleWatchedDocumentChange(params); | ||
this.ansibleLint.handleWatchedDocumentChange(params); | ||
for (const fileEvent of params.changes) { | ||
@@ -128,0 +127,0 @@ if (fileEvent.uri.startsWith(this.workspaceFolder.uri)) { |
@@ -73,8 +73,8 @@ "use strict"; | ||
} | ||
ansibleInfo["ansible version"] = `Ansible ${ansibleVersion[1].slice(0, -1)}`; | ||
ansibleInfo["ansible location"] = (yield context.ansibleConfig).ansible_location; | ||
ansibleInfo["config file path"] = [ansibleVersionObj["config file"]]; | ||
ansibleInfo["ansible collections location"] = (yield context.ansibleConfig).collections_paths; | ||
ansibleInfo["ansible module location"] = (yield context.ansibleConfig).module_locations; | ||
ansibleInfo["ansible default host list path"] = (yield context.ansibleConfig).default_host_list; | ||
ansibleInfo["version"] = `Ansible ${ansibleVersion[1].slice(0, -1)}`; | ||
ansibleInfo["location"] = (yield context.ansibleConfig).ansible_location; | ||
ansibleInfo["config file path"] = ansibleVersionObj["config file"]; | ||
ansibleInfo["collections location"] = (yield context.ansibleConfig).collections_paths; | ||
ansibleInfo["modules location"] = (yield context.ansibleConfig).module_locations; | ||
ansibleInfo["default host list path"] = (yield context.ansibleConfig).default_host_list; | ||
return ansibleInfo; | ||
@@ -90,5 +90,5 @@ }); | ||
} | ||
pythonInfo["python version"] = pythonVersionResult.stdout.trim(); | ||
pythonInfo["version"] = pythonVersionResult.stdout.trim(); | ||
const pythonPathResult = yield getResultsThroughCommandRunner("python3", '-c "import sys; print(sys.executable)"'); | ||
pythonInfo["python location"] = pythonPathResult.stdout.trim(); | ||
pythonInfo["location"] = pythonPathResult.stdout.trim(); | ||
return pythonInfo; | ||
@@ -105,6 +105,6 @@ }); | ||
const ansibleLintPathResult = yield getResultsThroughCommandRunner("command -v", "ansible-lint"); | ||
ansibleLintInfo["ansible-lint version"] = | ||
ansibleLintVersionResult.stdout.trim(); | ||
ansibleLintInfo["ansible-lint location"] = | ||
ansibleLintPathResult.stdout.trim(); | ||
ansibleLintInfo["version"] = ansibleLintVersionResult.stdout.trim(); | ||
ansibleLintInfo["location"] = ansibleLintPathResult.stdout.trim(); | ||
ansibleLintInfo["config file path"] = | ||
context.ansibleLint.ansibleLintConfigFilePath; | ||
return ansibleLintInfo; | ||
@@ -121,3 +121,2 @@ }); | ||
eeInfo["container image ID"] = basicDetails.containerImageId; | ||
eeInfo["container volume mounts"] = basicDetails.containerVolumeMounts; | ||
let eeServiceWorking = false; | ||
@@ -124,0 +123,0 @@ let inspectResult; |
@@ -7,3 +7,3 @@ { | ||
"license": "MIT", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"contributors": [ | ||
@@ -10,0 +10,0 @@ { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10
442076
102
5575