Code coverage report for src/extension.ts

# All files / src extension.ts

78.95% Statements 15/19
0% Branches 0/4
33.33% Functions 2/6
78.95% Lines 15/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    941x
    1x
    1x
    1x

    1x

    1x

    1x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    1x
     import * as vscode from 'vscode';
    import CommandController from './controllers/CommandController';
    import BreakingChangesNotifier from './BreakingChangesNotifier';
    import { getRootPath, withErrorHandler } from './utils';

    const EXTENSION_NAME = 'phpserver';

    type ExtensionContext = Pick<
      vscode.ExtensionContext,
      'subscriptions' | 'extensionPath' | 'globalState'
    >;

    const ErrorHandler = withErrorHandler((error) => {
      vscode.window.showErrorMessage(error.message);
    });

    export async function activate({
      subscriptions,
      extensionPath,
      globalState,
    }: ExtensionContext) {
      new BreakingChangesNotifier(globalState).notifyIfRequired();

      const controller = new CommandController(
        getCommandControllerContext(extensionPath)
      );

      subscriptions.push(
        vscode.commands.registerCommand(
          'extension.phpServer.serveProject',
          ErrorHandler(controller.serveProject)
        )
      );
      subscriptions.push(
        vscode.commands.registerCommand(
          'extension.phpServer.reloadServer',
          ErrorHandler(controller.reloadServer)
        )
      );
      subscriptions.push(
        vscode.commands.registerCommand(
          'extension.phpServer.openFileInBrowser',
          ErrorHandler(controller.openFileInBrowser)
        )
      );
      subscriptions.push(
        vscode.commands.registerCommand(
          'extension.phpServer.stopServer',
          ErrorHandler(controller.stopServer)
        )
      );
    }

    function getCommandControllerContext(extensionPath: string) {
      return {
        extension: {
          path: extensionPath,
          getConfiguration: getExtensionConfiguration,
        },
        notify: vscode.window.showInformationMessage,
        getRootPath,
        getAbsolutePathToActiveFile: () =>
          vscode.window.activeTextEditor?.document.fileName,
      };
    }

    export interface ExtensionConfiguration {
      ip?: string;
      port?: number;
      relativePath?: string;
      browser?: string;
      router?: string;
      phpPath?: string;
      phpConfigPath?: string;
      autoOpenOnReload?: boolean;
    }

    function getExtensionConfiguration(): ExtensionConfiguration {
      const config = vscode.workspace.getConfiguration(EXTENSION_NAME);

      return {
        ip: config.get<string>('ip'),
        port: config.get<number>('port'),
        relativePath: config.get<string>('relativePath'),
        browser: config.get<string>('browser'),
        router: config.get<string>('router'),
        phpPath: config.get<string>('phpPath'),
        phpConfigPath: config.get<string>('phpConfigPath'),
        autoOpenOnReload: config.get<boolean>('autoOpenOnReload'),
      };
    }

    export function deactivate() {}