Skip to content

Commit

Permalink
Work on implementing pro support
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderRonde committed Nov 15, 2023
1 parent 0c194c8 commit 53bba94
Show file tree
Hide file tree
Showing 15 changed files with 508 additions and 244 deletions.
1 change: 1 addition & 0 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ async function startLanguageServer(
run: {
module: serverModule,
transport: TransportKind.ipc,

},
debug: {
module: serverModule,
Expand Down
8 changes: 4 additions & 4 deletions client/src/lib/proc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class ProcessSpawner implements Disposable {
client: LanguageClient,
private readonly _context: ExtensionContext
) {
this._kill();
this._kill(true);
this._disposables.push(
client.onNotification(processNotification, ({ pid, timeout }) => {
console.log('pushing pid', pid, timeout);
Expand Down Expand Up @@ -48,7 +48,7 @@ export class ProcessSpawner implements Disposable {
} catch (e) {}
}

private _kill(): void {
private _kill(killTimeoutless: boolean = false): void {
const processes = this._context.workspaceState.get(
ProcessSpawner.STORAGE_KEY,
{}
Expand All @@ -59,7 +59,7 @@ export class ProcessSpawner implements Disposable {

const killed: number[] = [];
Object.entries(processes).forEach(([pid, timeout]) => {
if (Date.now() > timeout) {
if (Date.now() > timeout && (timeout !== 0 || killTimeoutless)) {
const pidNum = parseInt(pid, 10);
killed.push(pidNum);
console.log('killing', pid, 'because', timeout, 'is over');
Expand All @@ -83,7 +83,7 @@ export class ProcessSpawner implements Disposable {
private async _pushPid(pid: number, timeout: number): Promise<void> {
await this._context.workspaceState.update(ProcessSpawner.STORAGE_KEY, {
...this._context.workspaceState.get(ProcessSpawner.STORAGE_KEY, {}),
[pid]: Date.now() + timeout,
[pid]: timeout === 0 ? 0 : Date.now() + timeout,
});
}

Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"contributes": {
"configuration": {
"type": "object",
"title": "Extension Configuration",
"title": "PHPStan",
"properties": {
"phpstan.binPath": {
"type": "string",
Expand Down Expand Up @@ -141,6 +141,11 @@
"type": "boolean",
"description": "Stop showing an error when using a multi-workspace project",
"default": false
},
"phpstan.pro": {
"type": "boolean",
"description": "Use PHPStan Pro under the hood (if you have a license)",
"default": false
}
}
},
Expand Down
55 changes: 0 additions & 55 deletions server/src/lib/diagnosticsProvider.ts

This file was deleted.

30 changes: 21 additions & 9 deletions server/src/lib/documentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ export class DocumentManager implements Disposable {
private readonly _connection: _Connection;
private readonly _documents: Map<string, WatcherNotificationFileData> =
new Map();
private readonly _watcher: Watcher;
private readonly _watcher?: Watcher;

public constructor({
connection,
watcher,
}: {
connection: _Connection;
watcher: Watcher;
watcher?: Watcher;
}) {
this._connection = connection;
this._watcher = watcher;

if (!this._watcher) {
return;
}
this._disposables.push(
// eslint-disable-next-line @typescript-eslint/no-misused-promises
this._connection.onNotification(watcherNotification, (data) => {
Expand All @@ -38,9 +41,9 @@ export class DocumentManager implements Disposable {
case 'check':
return this._onDocumentCheck(data.file);
case 'clear':
return this._watcher.clearData();
return this._watcher!.clearData();
case 'checkProject':
return this._watcher.onScanProject();
return this._watcher!.onScanProject();
default:
assertUnreachable(data);
}
Expand All @@ -52,28 +55,28 @@ export class DocumentManager implements Disposable {
e: WatcherNotificationFileData
): Promise<void> {
this._documents.set(e.uri, e);
await this._watcher.onDocumentChange(e);
await this._watcher!.onDocumentChange(e);
}

private async _onDocumentSave(
e: WatcherNotificationFileData
): Promise<void> {
this._documents.set(e.uri, e);
await this._watcher.onDocumentSave(e);
await this._watcher!.onDocumentSave(e);
}

private async _onDocumentCheck(
e: WatcherNotificationFileData
): Promise<void> {
this._documents.set(e.uri, e);
await this._watcher.onDocumentCheck(e);
await this._watcher!.onDocumentCheck(e);
}

private async _onDocumentActive(
e: WatcherNotificationFileData
): Promise<void> {
this._documents.set(e.uri, e);
await this._watcher.onDocumentActive(e);
await this._watcher!.onDocumentActive(e);
}

private async _onDocumentOpen(
Expand All @@ -82,7 +85,7 @@ export class DocumentManager implements Disposable {
): Promise<void> {
this._documents.set(e.uri, e);
if (check) {
await this._watcher.onDocumentOpen(e);
await this._watcher!.onDocumentOpen(e);
}
}

Expand All @@ -94,6 +97,15 @@ export class DocumentManager implements Disposable {
return this._documents.get(uri) ?? null;
}

public getAll(): Record<string, string> {
const result: Record<string, string> = {};
for (const [uri, data] of this._documents.entries()) {
result[uri] = data.content;
}

return result;
}

public dispose(): void {
this._disposables.forEach((d) => void d.dispose());
this._disposables = [];
Expand Down
57 changes: 56 additions & 1 deletion server/src/lib/phpstan/configManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { replaceVariables } from '../variables';
import { showErrorOnce } from '../errorUtil';
import { getConfiguration } from '../config';
import type { ClassConfig } from './manager';
import type { Disposable } from 'vscode';
import * as fs from 'fs/promises';
import { constants } from 'fs';
import * as path from 'path';
Expand All @@ -12,13 +13,15 @@ export interface CheckConfig {
configFile: string | null;
remoteConfigFile: string | null;
binCmd: string | null;
binStr: string;
binPath: string | null;
initialArgs: string[];
args: string[];
memoryLimit: string;
}

export class ConfigurationManager {
export class ConfigurationManager implements Disposable {
private _disposables: Disposable[] = [];
private __config: CheckConfig | null = null;

public constructor(private readonly _config: ClassConfig) {}
Expand All @@ -31,6 +34,16 @@ export class ConfigurationManager {
return pathMapper(filePath);
}

public static escapeFilePath(filePath: string): string {
if (os.platform() !== 'win32') {
return filePath;
}
if (filePath.indexOf(' ') !== -1) {
filePath = '"' + filePath + '"';
}
return filePath;
}

public static async getPathMapper(
config: ClassConfig
): Promise<(filePath: string, inverse?: boolean) => string> {
Expand Down Expand Up @@ -239,9 +252,51 @@ export class ConfigurationManager {
replaceVariables(arg, this._config)
),
memoryLimit: extensionConfig.memoryLimit,
binStr: binConfig.binCmd
? binConfig.binCmd
: ConfigurationManager.escapeFilePath(binConfig.binPath!),
...binConfig,
};
this.__config = config;
return config;
}

public async getArgs(
config: CheckConfig,
progress: boolean = true
): Promise<string[]> {
const args = [...config.initialArgs, 'analyse'];
if (config.remoteConfigFile) {
args.push(
...[
'-c',
ConfigurationManager.escapeFilePath(
config.remoteConfigFile
),
]
);
} else if (config.configFile) {
args.push('-c', config.configFile);
}

args.push(
'--error-format=raw',
'--no-interaction',
`--memory-limit=${config.memoryLimit}`
);
if (!progress) {
args.push('--no-progress');
}
args.push(...config.args);
return await this._config.hooks.provider.transformArgs(
config,
[config.binStr, ...args],
this._disposables
);
}

public dispose(): void {
this._disposables.forEach((d) => void d.dispose());
this._disposables = [];
}
}
Loading

0 comments on commit 53bba94

Please sign in to comment.