Skip to content

Commit 19e5b5a

Browse files
fbricondatho7561
authored andcommitted
fix: parsing lombok version error
Signed-off-by: Fred Bricon <fbricon@gmail.com>
1 parent c3fd1e0 commit 19e5b5a

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

src/lombokSupport.ts

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,30 @@ function getExtensionLombokPath(context: ExtensionContext): string {
6767
return path.join(context.asAbsolutePath("lombok"), files[0]);
6868
}
6969

70-
function lombokPath2Version(lombokPath: string): string {
71-
const lombokVersion = lombokJarRegex.exec(lombokPath)[0].split('.jar')[0];
70+
function lombokPath2Version(lombokPath: string): string | undefined {
71+
const match = lombokJarRegex.exec(lombokPath);
72+
if (!match) {
73+
return undefined;
74+
}
75+
const lombokVersion = match[0].split('.jar')[0];
7276
return lombokVersion;
7377
}
7478

75-
function lombokPath2VersionNumber(lombokPath: string): string {
76-
const lombokVersionNumber = lombokPath2Version(lombokPath).split('-')[1];
79+
function lombokPath2VersionNumber(lombokPath: string): string | undefined {
80+
const lombokVersion = lombokPath2Version(lombokPath);
81+
if (!lombokVersion) {
82+
return undefined;
83+
}
84+
const lombokVersionNumber = lombokVersion.split('-')[1];
7785
return lombokVersionNumber;
7886
}
7987

80-
export function getLombokVersion(): string {
81-
return lombokPath2Version(activeLombokPath);
88+
export function getLombokVersion(): string | undefined {
89+
return lombokPath2VersionNumber(activeLombokPath);
8290
}
8391

84-
function isCompatibleLombokVersion(currentVersion: string): boolean {
85-
return semver.gte(currentVersion, compatibleVersion);
92+
function isCompatibleLombokVersion(currentVersion: string | undefined): boolean {
93+
return currentVersion && semver.gte(currentVersion, compatibleVersion);
8694
}
8795

8896
export function addLombokParam(context: ExtensionContext, params: string[]) {
@@ -102,12 +110,14 @@ export function addLombokParam(context: ExtensionContext, params: string[]) {
102110
isExtensionLombok = true;
103111
let lombokJarPath: string = context.workspaceState.get(JAVA_LOMBOK_PATH);
104112
if (lombokJarPath && fse.existsSync(lombokJarPath)) {
105-
if (isCompatibleLombokVersion(lombokPath2VersionNumber(lombokJarPath))) {
113+
const lombokVersion = lombokPath2VersionNumber(lombokJarPath);
114+
if (lombokVersion && isCompatibleLombokVersion(lombokVersion)) {
106115
isExtensionLombok = false;
107116
}
108117
else {
109118
cleanupLombokCache(context);
110-
logger.warn(`The project's Lombok version ${lombokPath2VersionNumber(lombokJarPath)} is not supported, Falling back to the built-in Lombok version ${lombokPath2VersionNumber(getExtensionLombokPath(context))}`);
119+
const extensionLombokVersion = lombokPath2VersionNumber(getExtensionLombokPath(context));
120+
logger.warn(`The project's Lombok version ${lombokVersion || 'unknown'} is not supported, Falling back to the built-in Lombok version ${extensionLombokVersion || 'unknown'}`);
111121
}
112122
}
113123
if (isExtensionLombok) {
@@ -197,11 +207,11 @@ export function registerLombokConfigureCommand(context: ExtensionContext) {
197207
const lombokPathItems = [
198208
{
199209
label: isExtensionLombok? extensionItemLabelCheck : extensionItemLabel,
200-
description: lombokPath2Version(extensionLombokPath)
210+
description: `Lombok ${lombokPath2VersionNumber(extensionLombokPath) || 'unknown'}`
201211
},
202212
{
203213
label: isExtensionLombok? projectItemLabel : projectItemLabelCheck,
204-
description: lombokPath2Version(projectLombokPath),
214+
description: `Lombok ${lombokPath2VersionNumber(projectLombokPath) || 'unknown'}`,
205215
detail: projectLombokPath
206216
}
207217
];
@@ -222,7 +232,7 @@ export function registerLombokConfigureCommand(context: ExtensionContext) {
222232
if (isExtensionLombok) {
223233
const projectLombokVersion = lombokPath2VersionNumber(projectLombokPath);
224234
if (!isCompatibleLombokVersion(projectLombokVersion)) {
225-
const msg = `The project's Lombok version ${projectLombokVersion} is not supported. Falling back to the built-in Lombok version in the extension.`;
235+
const msg = `The project's Lombok version ${projectLombokVersion || 'unknown'} is not supported. Falling back to the built-in Lombok version in the extension.`;
226236
window.showWarningMessage(msg);
227237
return;
228238
}
@@ -250,17 +260,17 @@ export function registerLombokConfigureCommand(context: ExtensionContext) {
250260
}
251261

252262
export namespace LombokVersionItemFactory {
253-
export function create(text: string): vscode.LanguageStatusItem {
263+
export function create(version: string): vscode.LanguageStatusItem {
254264
const item = vscode.languages.createLanguageStatusItem("javaLombokVersionItem", languageServerDocumentSelector);
255265
item.severity = vscode.LanguageStatusSeverity?.Information;
256266
item.name = "Lombok Version";
257-
item.text = text;
267+
update(item, version);
258268
item.command = getLombokChangeCommand();
259269
return item;
260270
}
261271

262-
export function update(item: any, text: string): void {
263-
item.text = text;
272+
export function update(item: any, version: string | undefined): void {
273+
item.text = `Lombok ${version || 'unknown'}`;
264274
}
265275

266276
function getLombokChangeCommand(): vscode.Command {

0 commit comments

Comments
 (0)