Skip to content

Commit

Permalink
Merge branch 'gregoirechauvet/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyo930021 committed Jun 1, 2021
2 parents fcea32b + 5081987 commit 69cba40
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- 🙌 Syntax Highlighting for SugarSS. Thanks to contribution from [@softwaredeveloptam](https://github.com/softwaredeveloptam). #2828.
- 🙌 Fix component data not shown in hover when template interpolation is on. Thanks to contribution from [@rchl](https://github.com/rchl). #2879 #2878.
- 🙌 Look for a `.stylintrc` file when formatting stylus code. Thanks to contribution from [@ntraut](https://github.com/ntraut). #2689.
- Add paths option for `vti diagnostics` to diagnose only sub files or directories. #2455.

### 0.33.1 | 2021-03-07 | [VSIX](https://marketplace.visualstudio.com/_apis/public/gallery/publishers/octref/vsextensions/vetur/0.33.1/vspackage)

Expand Down
6 changes: 3 additions & 3 deletions vti/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ function validateLogLevel(logLevelInput: unknown): logLevelInput is LogLevel {
program.name('vti').description('Vetur Terminal Interface').version(getVersion());

program
.command('diagnostics [workspace]')
.command('diagnostics [workspace] [paths...]')
.description('Print all diagnostics')
.addOption(
new Option('-l, --log-level <logLevel>', 'Log level to print')
.default('WARN')
// logLevels is readonly array but .choices need read-write array (because of weak typing)
.choices((logLevels as unknown) as string[])
)
.action(async (workspace, options) => {
.action(async (workspace, paths, options) => {
const logLevelOption: unknown = options.logLevel;
if (!validateLogLevel(logLevelOption)) {
throw new Error(`Invalid log level: ${logLevelOption}`);
}
await diagnostics(workspace, logLevelOption);
await diagnostics(workspace, paths, logLevelOption);
});

program.parse(process.argv);
Expand Down
26 changes: 22 additions & 4 deletions vti/src/commands/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const logLevel2Severity = {
HINT: DiagnosticSeverity.Hint
};

export async function diagnostics(workspace: string | null, logLevel: LogLevel) {
export async function diagnostics(workspace: string | null, paths: string[], logLevel: LogLevel) {
console.log('====================================');
console.log('Getting Vetur diagnostics');
let workspaceUri;
Expand All @@ -47,7 +47,7 @@ export async function diagnostics(workspace: string | null, logLevel: LogLevel)
workspaceUri = URI.file(process.cwd());
}

const errCount = await getDiagnostics(workspaceUri, logLevel2Severity[logLevel]);
const errCount = await getDiagnostics(workspaceUri, paths, logLevel2Severity[logLevel]);
console.log('====================================');

if (errCount === 0) {
Expand Down Expand Up @@ -121,10 +121,28 @@ function range2Location(range: Range): SourceLocation {
};
}

async function getDiagnostics(workspaceUri: URI, severity: DiagnosticSeverity) {
async function getDiagnostics(workspaceUri: URI, paths: string[], severity: DiagnosticSeverity) {
const clientConnection = await prepareClientConnection(workspaceUri);

const files = glob.sync('**/*.vue', { cwd: workspaceUri.fsPath, ignore: ['node_modules/**'] });
let files: string[];
if (paths.length === 0) {
files = glob.sync('**/*.vue', { cwd: workspaceUri.fsPath, ignore: ['node_modules/**'] });
} else {
// Could use `flatMap` once available:
const listOfPaths = paths.map(inputPath => {
const absPath = path.resolve(workspaceUri.fsPath, inputPath);

if (fs.lstatSync(absPath).isFile()) {
return [inputPath];
}

const directory = URI.file(absPath);
const directoryFiles = glob.sync('**/*.vue', { cwd: directory.fsPath, ignore: ['node_modules/**'] });
return directoryFiles.map(f => path.join(inputPath, f));
});

files = listOfPaths.reduce((acc: string[], paths) => [...acc, ...paths], []);
}

if (files.length === 0) {
console.log('No input files');
Expand Down

0 comments on commit 69cba40

Please # to comment.