How to use the quicktype-core.languageNamed function in quicktype-core

To help you get started, we’ve selected a few quicktype-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github quicktype / quicktype-vscode / src / extension.ts View on Github external
openForEditor(editor, "json")
        ),
        vscode.commands.registerTextEditorCommand(Command.OpenQuicktypeForJSONSchema, editor =>
            openForEditor(editor, "schema")
        ),
        vscode.commands.registerTextEditorCommand(Command.OpenQuicktypeForTypeScript, editor =>
            openForEditor(editor, "typescript")
        ),
        vscode.commands.registerCommand(Command.ChangeTargetLanguage, changeTargetLanguage)
    );

    await persist.init({ dir: path.join(homedir(), ".quicktype-vscode") });

    const maybeName = await persist.getItem(lastTargetLanguageUsedKey);
    if (typeof maybeName === "string") {
        explicitlySetTargetLanguage = languageNamed(maybeName);
    }
}
github quicktype / quicktype-vscode / src / extension.ts View on Github external
async function pickTargetLanguage(): Promise {
    const languageChoices = defaultTargetLanguages.map(l => l.displayName).sort();
    let chosenName = await vscode.window.showQuickPick(languageChoices);
    const cancelled = chosenName === undefined;
    if (chosenName === undefined) {
        chosenName = "typescript";
    }
    return { cancelled, lang: languageNamed(chosenName)! };
}
github quicktype / quicktype-vscode / src / extension.ts View on Github external
async function getTargetLanguage(editor: vscode.TextEditor): Promise {
    const documentLanguage = editor.document.languageId;
    const currentLanguage = languageNamed(documentLanguage);
    if (currentLanguage !== undefined) {
        return {
            cancelled: false,
            lang: currentLanguage
        };
    }
    return await pickTargetLanguage();
}
github quicktype / quicktype-vscode / src / extension.ts View on Github external
const counts = new Map();
    for (const doc of documents) {
        const name = doc.languageId;
        let count = counts.get(name);
        if (count === undefined) {
            count = 0;
        }
        count += 1;
        counts.set(name, count);
    }
    const sorted = Array.from(counts).sort(([_na, ca], [_nb, cb]) => cb - ca);
    for (const [name] of sorted) {
        const lang = languageNamed(name);
        if (lang !== undefined) return lang;
    }
    return languageNamed("typescript")!;
}
github quicktype / quicktype-vscode / src / extension.ts View on Github external
function deduceTargetLanguage(): TargetLanguage {
    const documents = vscode.workspace.textDocuments;
    const counts = new Map();
    for (const doc of documents) {
        const name = doc.languageId;
        let count = counts.get(name);
        if (count === undefined) {
            count = 0;
        }
        count += 1;
        counts.set(name, count);
    }
    const sorted = Array.from(counts).sort(([_na, ca], [_nb, cb]) => cb - ca);
    for (const [name] of sorted) {
        const lang = languageNamed(name);
        if (lang !== undefined) return lang;
    }
    return languageNamed("typescript")!;
}