Skip to content

Commit

Permalink
Configuration detection fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Vigilans committed Sep 24, 2019
1 parent 7973f83 commit a420570
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/commands/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import * as fse from 'fs-extra';
import { Uri, window, workspace } from 'vscode';
import { checkstyleDiagnosticManager } from '../checkstyleDiagnosticManager';
import { findNonIgnoredFiles } from '../utils/workspaceUtils';

export async function checkCode(uri?: Uri): Promise<void> {
if (!uri) { // If not specified, check active editor
Expand All @@ -14,7 +15,7 @@ export async function checkCode(uri?: Uri): Promise<void> {
}
let filesToCheck: Uri[];
if ((await fse.stat(uri.fsPath)).isDirectory()) {
filesToCheck = await workspace.findFiles(`${workspace.asRelativePath(uri)}/**/*.java`);
filesToCheck = await findNonIgnoredFiles(`${workspace.asRelativePath(uri)}/**/*.java`);
} else {
filesToCheck = [uri];
}
Expand Down
14 changes: 10 additions & 4 deletions src/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

import * as fse from 'fs-extra';
import * as path from 'path';
import { Uri, window, workspace, WorkspaceFolder } from 'vscode';
import { Uri, window, WorkspaceFolder } from 'vscode';
import * as xmljs from 'xml-js';
import { checkstyleChannel } from '../checkstyleChannel';
import { BuiltinConfiguration, checkstyleDoctypeIds } from '../constants/checkstyleConfigs';
import { IQuickPickItemEx } from '../models';
import { getDefaultWorkspaceFolder, setCheckstyleConfigurationPath, tryUseWorkspaceFolder } from '../utils/settingUtils';
import { setCheckstyleConfigurationPath } from '../utils/settingUtils';
import { findNonIgnoredFiles, getDefaultWorkspaceFolder, tryUseWorkspaceFolder } from '../utils/workspaceUtils';

export async function setConfiguration(uri?: Uri): Promise<void> {
if (uri) {
Expand Down Expand Up @@ -88,7 +90,7 @@ async function inputConfiguration(): Promise<string | undefined> {

async function detectConfigurations(): Promise<IQuickPickItemEx[]> {
const detected: IQuickPickItemEx[] = [];
for (const xml of await workspace.findFiles('**/*.xml')) {
for (const xml of await findNonIgnoredFiles('**/*.xml')) {
const relativeXml: string = tryUseWorkspaceFolder(xml.fsPath);
function doctypeFn(doctype: string): void {
const [name, type] = doctype.split(/\s+/, 2);
Expand All @@ -103,7 +105,11 @@ async function detectConfigurations(): Promise<IQuickPickItemEx[]> {
}
}
}
xmljs.xml2js(await fse.readFile(xml.fsPath, 'utf8'), { doctypeFn });
try {
xmljs.xml2js(await fse.readFile(xml.fsPath, 'utf8'), { doctypeFn });
} catch (error) { // Skip this xml, continue detecting process
checkstyleChannel.appendLine(`Parse failed: ${xml}`);
}
}
return detected;
}
4 changes: 4 additions & 0 deletions src/constants/checkstyleConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export enum BuiltinConfiguration {
}

export const checkstyleDoctypeIds: string[] = [
'-//Checkstyle//DTD Configuration 1.0//EN',
'-//Checkstyle//DTD Configuration 1.1//EN',
'-//Checkstyle//DTD Configuration 1.2//EN',
'-//Checkstyle//DTD Configuration 1.3//EN',
'-//Checkstyle//DTD Checkstyle Configuration 1.0//EN',
'-//Checkstyle//DTD Checkstyle Configuration 1.1//EN',
'-//Checkstyle//DTD Checkstyle Configuration 1.2//EN',
Expand Down

0 comments on commit a420570

Please sign in to comment.