Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

add paths option to vti diagnostics #2825

Merged
merged 1 commit into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Add `--log-level` option for `vti diagnostics` to configure log level to print. #2752.
- 🙌 Semantic tokens for typescript and highlight `.value` if using composition API. Thanks to contribution from [@jasonlyu123](https://github.com/jasonlyu123). #2802 #1904 # 2434
- 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()) {
yoyo930021 marked this conversation as resolved.
Show resolved Hide resolved
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