All files / src/frontend ModesProvider.ts

0% Statements 0/23
0% Branches 0/3
0% Functions 0/5
0% Lines 0/23

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                                                                                                                                         
/*
 * This file is released under the MIT license.
 * Copyright (c) 2018, 2020, Mike Lischke
 *
 * See LICENSE file for more info.
 */
 
/* eslint-disable max-classes-per-file */
 
import * as path from "path";
 
import { TreeItem, TreeItemCollapsibleState, Command, ProviderResult } from "vscode";
import { AntlrTreeDataProvider } from "./AntlrTreeDataProvider";
 
export class ModeEntry extends TreeItem {
 
    public iconPath = {
        light: path.join(__dirname, "..", "..", "..", "misc", "mode-light.svg"),
        dark: path.join(__dirname, "..", "..", "..", "misc", "mode-dark.svg"),
    };
 
    public contextValue = "lexerSymbols";
 
    public constructor(
        public readonly label: string,
        public readonly collapsibleState: TreeItemCollapsibleState,
        command?: Command,
    ) {
        super(label, collapsibleState);
        this.command = command;
    }
}
 
export class ModesProvider extends AntlrTreeDataProvider<ModeEntry> {
 
    public getTreeItem(element: ModeEntry): TreeItem {
        return element;
    }
 
    public getChildren(element?: ModeEntry): ProviderResult<ModeEntry[]> {
        Iif (!element) {
            let modes;
            Iif (this.currentFile) {
                modes = this.backend.getModes(this.currentFile);
            }
 
            Iif (modes) {
                const list: ModeEntry[] = [];
                for (const mode of modes) {
                    list.push(new ModeEntry(mode, TreeItemCollapsibleState.None, {
                        title: "<unused>",
                        command: "",
                        arguments: [],
                    }));
                }
 
                return new Promise((resolve) => {
                    resolve(list);
                });
            }
        }
 
        return new Promise((resolve) => {
            resolve([]);
        });
    }
 
}