Skip to content

Commit

Permalink
Improve Developer & User experience (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vigilans authored and jdneo committed Sep 19, 2019
1 parent f194657 commit 7923914
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 10 deletions.
9 changes: 8 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "npm: watch"
},
{
"type": "java",
"name": "Attach to Checkstyle Plugin",
"request": "attach",
"hostName": "localhost",
"port": 1044
}
]
}
}
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
"typescript.tsc.autoDetect": "off",
// Use workspace's typescript version to provide correct language service
"typescript.tsdk": "node_modules/typescript/lib",
"java.checkstyle.configuration": "${workspaceFolder}/jdtls.ext/checkstyle.xml"
"java.checkstyle.configuration": "${workspaceFolder}/jdtls.ext/config/checkstyle.xml",
"java.checkstyle.properties": {
"checkstyle.header.file": "${workspaceFolder}/jdtls.ext/config/java.header"
},
}
3 changes: 2 additions & 1 deletion jdtls.ext/com.shengchen.checkstyle.runner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
</dependency>
</dependencies>
<configuration>
<configLocation>${project.parent.basedir}/checkstyle.xml</configLocation>
<configLocation>${project.parent.basedir}/config/checkstyle.xml</configLocation>
<propertyExpansion>checkstyle.header.file=${project.parent.basedir}/config/java.header</propertyExpansion>
<failOnViolation>true</failOnViolation>
</configuration>
</plugin>
Expand Down
6 changes: 6 additions & 0 deletions jdtls.ext/checkstyle.xml → jdtls.ext/config/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ what the following rules do, please see the checkstyle configuration
page at http://checkstyle.sourceforge.net/config.html -->

<module name="Checker">
<!-- Headers -->
<module name="Header">
<property name="headerFile" value="${checkstyle.header.file}"/>
<property name="fileExtensions" value="java"/>
<property name="id" value="header"/>
</module>

<module name="FileTabCharacter">
<!-- Checks that there are no tab characters in the file.
Expand Down
16 changes: 16 additions & 0 deletions jdtls.ext/config/java.header
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (C) jdneo

* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.

* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
19 changes: 12 additions & 7 deletions src/commands/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ async function queryForVersion(): Promise<string | undefined> {
if (!result) {
return undefined;
} else if (result.value === ':list') {
return await window.showQuickPick(await getAllSupportedVersions(), { ignoreFocusOut: true });
try {
return await window.showQuickPick(await getAllSupportedVersions(), { ignoreFocusOut: true });
} catch (error) {
window.showQuickPick(['Network error']);
return undefined;
}
} else {
return result.label;
return result.value;
}
}

Expand All @@ -39,18 +44,18 @@ async function getRecommendedVersions(): Promise<IQuickPickItemEx[]> {
function setDescription(version: string, description: string): void {
versions.set(version, [...(versions.get(version) || []), description]);
}
setDescription(await getLatestVersion(), 'latest version');
try { // Do not set latest version if there's network issue
setDescription(await getLatestVersion(), 'latest version');
} catch (error) { /* Skip */ }
for (const version of await checkstyleConfigurationManager.getDownloadedVersions()) {
setDescription(version, 'downloaded');
}
setDescription(checkstyleConfigurationManager.getBuiltinVersion(), 'built-in');
const currentVersion: string | undefined = await checkstyleConfigurationManager.getCurrentVersion();
if (currentVersion) {
setDescription(currentVersion, 'current');
}
return sortVersions([...versions.keys()]).map((version: string) => ({
label: version,
label: (version === currentVersion ? '$(check) ' : '') + version,
description: versions.get(version)!.join(', '),
value: version,
}));
}

Expand Down
23 changes: 23 additions & 0 deletions src/utils/errorUtils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
// Copyright (c) jdneo. All rights reserved.
// Licensed under the GNU LGPLv3 license.

import * as vscode from 'vscode';
import { checkstyleChannel } from '../checkstyleChannel';
import { checkstyleConfigurationManager } from '../checkstyleConfigurationManager';
import { checkstyleStatusBar } from '../checkstyleStatusBar';

export async function handleErrors(error: Error): Promise<void> {
if (error['data']) {
const message: string = error['data'].message;
if (message.startsWith('cannot initialize module')) {
handleModuleIntialization(message);
}
checkstyleChannel.appendLine(JSON.stringify(error['data']));
} else {
checkstyleChannel.appendLine(error.stack || error.toString());
}

checkstyleStatusBar.showError();
}

async function handleModuleIntialization(message: string): Promise<void> {
const module: string = message.match(/cannot initialize module (.+) -/)![1];
const choice: string | undefined = await vscode.window.showErrorMessage(
`Module ${module} initialization failed. It may be caused by wrong configuraiton or incompatible version.`,
'Select another version', 'Open Configuration',
);
if (choice === 'Select another version') {
vscode.commands.executeCommand('java.checkstyle.setVersion');
} else if (choice === 'Open Configuration') {
if (checkstyleConfigurationManager.configUri) {
vscode.workspace.openTextDocument(checkstyleConfigurationManager.configUri).then((document: vscode.TextDocument) => {
return vscode.window.showTextDocument(document);
});
}
}
}

0 comments on commit 7923914

Please sign in to comment.