fabric8-analytics-lsp-server
Advanced tools
Comparing version 0.4.9 to 0.4.10
@@ -18,3 +18,6 @@ /* -------------------------------------------------------------------------------------------- | ||
//import semverRegex = require('semver-regex'); | ||
const regExp = /(?<=^v?|\sv?)(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|[\da-z-]*[a-z-][\da-z-]*)(?:\.(?:0|[1-9]\d*|[\da-z-]*[a-z-][\da-z-]*))*)?(?:\+[\da-z-]+(?:\.[\da-z-]+)*)?(?=$|\s)/ig; | ||
function semVerRegExp(line) { | ||
const regExp = /(?<=^v?|\sv?)(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|[\da-z-]*[a-z-][\da-z-]*)(?:\.(?:0|[1-9]\d*|[\da-z-]*[a-z-][\da-z-]*))*)?(?:\+[\da-z-]+(?:\.[\da-z-]+)*)?(?=$|\s)/ig; | ||
return regExp.exec(line); | ||
} | ||
/* Dependency class that can be created from `IKeyValueEntry` */ | ||
@@ -77,14 +80,48 @@ class Dependency { | ||
} | ||
static getReplaceMap(line, index) { | ||
// split the replace statements by '=>' | ||
const parts = line.replace('replace', '').replace('(', '').replace(')', '').trim().split('=>'); | ||
const replaceWithVersion = semVerRegExp(parts[1]); | ||
// Skip lines without final version string | ||
if (replaceWithVersion && replaceWithVersion.length > 0) { | ||
const replaceTo = (parts[0] || '').trim().split(' '); | ||
const replaceToVersion = semVerRegExp(replaceTo[1]); | ||
const replaceWith = (parts[1] || '').trim().split(' '); | ||
const replaceWithIndex = line.lastIndexOf(parts[1]); | ||
const replaceEntry = new types_1.KeyValueEntry(replaceWith[0].trim(), { line: 0, column: 0 }); | ||
replaceEntry.value = new types_1.Variant(types_1.ValueType.String, 'v' + replaceWithVersion[0]); | ||
replaceEntry.value_position = { line: index + 1, column: (replaceWithIndex + replaceWithVersion.index) }; | ||
const replaceDependency = new Dependency(replaceEntry); | ||
const isReplaceToVersion = replaceToVersion && replaceToVersion.length > 0; | ||
return { key: replaceTo[0].trim() + (isReplaceToVersion ? ('@v' + replaceToVersion[0]) : ''), value: replaceDependency }; | ||
} | ||
return null; | ||
} | ||
static applyReplaceMap(dep, replaceMap) { | ||
let replaceDependency = replaceMap.get(dep.name.value + "@" + dep.version.value); | ||
if (replaceDependency === undefined) { | ||
replaceDependency = replaceMap.get(dep.name.value); | ||
if (replaceDependency === undefined) { | ||
return dep; | ||
} | ||
} | ||
return replaceDependency; | ||
} | ||
static parseDependencies(contents, goImports) { | ||
let replaceMap = new Map(); | ||
let goModDeps = contents.split("\n").reduce((dependencies, line, index) => { | ||
// Ignore "replace" lines | ||
if (!line.includes("=>")) { | ||
// skip any text after '//' | ||
if (line.includes("//")) { | ||
line = line.split("//")[0]; | ||
// skip any text after '//' | ||
if (line.includes("//")) { | ||
line = line.split("//")[0]; | ||
} | ||
if (line.includes("=>")) { | ||
let replaceEntry = NaiveGomodParser.getReplaceMap(line, index); | ||
if (replaceEntry) { | ||
replaceMap.set(replaceEntry.key, replaceEntry.value); | ||
} | ||
} | ||
else { | ||
// Not using semver directly, look at comment on import statement. | ||
//const version = semverRegex().exec(line) | ||
regExp.lastIndex = 0; | ||
const version = regExp.exec(line); | ||
const version = semVerRegExp(line); | ||
// Skip lines without version string | ||
@@ -127,8 +164,13 @@ if (version && version.length > 0) { | ||
// Software stack uses a package from the module | ||
const entry = new types_1.KeyValueEntry(importStatement + '@' + moduleMatchDep.name.value, moduleMatchDep.name.position); | ||
entry.value = new types_1.Variant(types_1.ValueType.String, moduleMatchDep.version.value); | ||
entry.value_position = moduleMatchDep.version.position; | ||
let replaceDependency = NaiveGomodParser.applyReplaceMap(moduleMatchDep, replaceMap); | ||
if (replaceDependency !== moduleMatchDep) { | ||
importStatement = importStatement.replace(moduleMatchDep.name.value, replaceDependency.name.value); | ||
} | ||
const entry = new types_1.KeyValueEntry(importStatement + '@' + replaceDependency.name.value, replaceDependency.name.position); | ||
entry.value = new types_1.Variant(types_1.ValueType.String, replaceDependency.version.value); | ||
entry.value_position = replaceDependency.version.position; | ||
goPackageDeps.push(new Dependency(entry)); | ||
} | ||
}); | ||
goModDeps = goModDeps.map(goModDep => NaiveGomodParser.applyReplaceMap(goModDep, replaceMap)); | ||
// Return modules present in go.mod and packages used in imports. | ||
@@ -135,0 +177,0 @@ return [...goModDeps, ...goPackageDeps]; |
{ | ||
"name": "fabric8-analytics-lsp-server", | ||
"description": "LSP Server for Dependency Analytics", | ||
"version": "0.4.9", | ||
"version": "0.4.10", | ||
"author": "Pavel Odvody", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
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
96527
1011