Skip to content

Commit

Permalink
Bring back "scanFileForErrors" command
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderRonde committed Apr 24, 2024
1 parent 79c589a commit 6d28ebf
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
34 changes: 34 additions & 0 deletions client/src/lib/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { commands, Commands } from '../../../shared/commands/defs';
// eslint-disable-next-line node/no-extraneous-import
import { autoRegisterCommand } from 'vscode-generate-package-json';
import type { LanguageClient } from 'vscode-languageclient/node';
import { getEditorConfiguration } from './editorConfig';
import { showError } from './errorUtil';
import * as vscode from 'vscode';

Expand All @@ -17,6 +18,39 @@ export function registerListeners(
errorManager: ErrorManager,
phpstanProManager: PHPStanProManager
): void {
context.subscriptions.push(
autoRegisterCommand(
Commands.SCAN_FILE_FOR_ERRORS,
async () => {
const editorConfig = await getEditorConfiguration();

Check warning on line 25 in client/src/lib/commands.ts

View workflow job for this annotation

GitHub Actions / lint-and-tsc

Unexpected `await` of a non-Promise (non-"Thenable") value
if (!editorConfig.singleFileMode) {
showError(
'Please enable single-file mode in the settings to scan a single file. Instead use "Scan project for errors" to scan the whole project.'
);
return;
}

const doc = vscode.window.activeTextEditor?.document;
if (doc) {
if (doc.languageId !== 'php') {
showError('Only PHP files can be scanned for errors');
return;
}

await client.sendNotification(watcherNotification, {
operation: 'check',
file: {
content: doc.getText(),
uri: doc.uri.toString(),
languageId: doc.languageId,
},
});
}
},
commands
)
);

context.subscriptions.push(
autoRegisterCommand(
Commands.SCAN_PROJECT,
Expand Down
20 changes: 18 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@
}
},
"commands": [
{
"command": "phpstan.scanFileForErrors",
"title": "Scan current file for errors"
},
{
"command": "phpstan.scanProjectForErrors",
"title": "Scan project for errors"
Expand All @@ -184,6 +188,10 @@
"command": "phpstan.openPhpstanPro",
"title": "Open PHPStan Pro in browser"
},
{
"command": "cmd.phpstan.scanFileForErrors",
"title": "PHPStan: Scan current file for errors"
},
{
"command": "cmd.phpstan.scanProjectForErrors",
"title": "PHPStan: Scan project for errors"
Expand All @@ -207,6 +215,10 @@
],
"menus": {
"commandPalette": [
{
"command": "phpstan.scanFileForErrors",
"when": "false"
},
{
"command": "phpstan.scanProjectForErrors",
"when": "false"
Expand All @@ -227,6 +239,10 @@
"command": "phpstan.openPhpstanPro",
"when": "false"
},
{
"command": "cmd.phpstan.scanFileForErrors",
"when": "true"
},
{
"command": "cmd.phpstan.scanProjectForErrors",
"when": "true"
Expand Down Expand Up @@ -291,7 +307,7 @@
"@typescript-eslint/eslint-plugin": "^5.12.0",
"@typescript-eslint/parser": "latest",
"esbuild": "^0.20.2",
"eslint": "latest",
"eslint": "8",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "latest",
"eslint-plugin-unused-imports": "^2.0.0",
Expand All @@ -312,4 +328,4 @@
"dependencies": {
"tmp-promise": "^3.0.3"
}
}
}
5 changes: 5 additions & 0 deletions shared/commands/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
} from 'vscode-generate-package-json';

export enum Commands {
SCAN_FILE_FOR_ERRORS = 'phpstan.scanFileForErrors',
SCAN_PROJECT = 'phpstan.scanProjectForErrors',
RELOAD = 'phpstan.reload',
NEXT_ERROR = 'phpstan.nextError',
Expand All @@ -13,6 +14,10 @@ export enum Commands {
}

export const commands: Record<Commands, CommandDefinition> = {
[Commands.SCAN_FILE_FOR_ERRORS]: {
title: 'Scan current file for errors',
inCommandPalette: true,
},
[Commands.SCAN_PROJECT]: {
title: 'Scan project for errors',
inCommandPalette: true,
Expand Down

0 comments on commit 6d28ebf

Please sign in to comment.