Skip to content

Commit

Permalink
Showing 8 changed files with 224 additions and 41 deletions.
68 changes: 54 additions & 14 deletions src/hooks/updateVSCtypes.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,78 @@
import * as path from "path";
import { writeFileSync } from "fs";
import { JSONSchema, compile } from "json-schema-to-typescript";
import { compile, JSONSchema } from "json-schema-to-typescript";
import fetch from "node-fetch";

const vscodeSchemasRoot =
"https://raw.githubusercontent.com/wraith13/vscode-schemas/master/en/latest/schemas/";
const tag = process.argv[2] ?? "latest";
const vscodeSchemasRoot = `https://raw.githubusercontent.com/wraith13/vscode-schemas/master/en/${tag}/schemas/`;

const bannerComment = `/* eslint-disable */
/**
* This file was automatically generated.
* DO NOT MODIFY IT BY HAND.
* Instead, run \`yarn run updateVSCtypes\` to regenerate this file.
*/`;

const mappings = [
{
schema: "token-styling.json",
schema: vscodeSchemasRoot + "token-styling.json",
name: "SemanticTokens",
fname: "token-styling.d.ts",
kind: "jsonschema",
},
{
schema: "textmate-colors.json",
schema: vscodeSchemasRoot + "textmate-colors.json",
name: "TextmateColors",
fname: "textmate-colors.d.ts",
kind: "jsonschema",
},
{
schema: "workbench-colors.json",
schema: vscodeSchemasRoot + "workbench-colors.json",
name: "WorkbenchColors",
fname: "workbench-colors.d.ts",
kind: "jsonschema",
},
{
schema:
"https://raw.githubusercontent.com/usernamehw/vscode-error-lens/v3.13.0/package.json",
name: "ErrorLensColors",
fname: "errorlens.d.ts",
kind: "extension-packagejson",
},
];

for (const { schema, name, fname } of mappings) {
fetch(vscodeSchemasRoot + schema)
for (const { schema, name, fname, kind } of mappings) {
fetch(schema)
.then((data) => data.json())
.then((data) => {
compile(data as JSONSchema, name, {
additionalProperties: false,
}).then((typeDefs) => {
const fp = path.join(__dirname, `../types/${fname}`);
writeFileSync(fp, typeDefs, "utf-8");
});
switch (kind) {
case "jsonschema":
return compile(data as JSONSchema, name, {
additionalProperties: false,
bannerComment,
});
case "extension-packagejson":
return fromVSIXColors(name, data);
default:
throw new Error(`Unknown kind: ${kind}`);
}
})
.then((typeDefs) => {
const fp = path.join(__dirname, `../types/${fname}`);
writeFileSync(fp, typeDefs, "utf-8");
});
}

const fromVSIXColors = (interfaceName: string, data: any) => {
let content = `${bannerComment}
export interface ${interfaceName} {`;
data.contributes.colors.map((color: any) => {
content += `
/**
* ${color.description}
*/
"${color.id}": string;
`;
});
return content + "};\n";
};
36 changes: 19 additions & 17 deletions src/theme/extensions/error-lens.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
import type { ThemeContext } from "../../types";
import type { ErrorLensColors, ThemeContext } from "../../types";
import { opacity } from "../utils";

export default function colors(context: ThemeContext) {
export default function colors(
context: ThemeContext,
): Partial<ErrorLensColors> {
const { palette } = context;

return {
"errorLens.errorBackground": opacity(palette.red, 0.15),
"errorLens.errorMessageBackground": opacity(palette.red, 0.15),
"errorLens.errorBackgroundLight": opacity(palette.red, 0.15),
"errorLens.errorForeground": palette.red,
"errorLens.errorForegroundLight": palette.red,
"errorLens.warningBackground": opacity(palette.peach, 0.15),
"errorLens.warningMessageBackground": opacity(palette.peach, 0.15),
"errorLens.warningBackgroundLight": opacity(palette.peach, 0.15),
"errorLens.warningForeground": palette.peach,
"errorLens.warningForegroundLight": palette.peach,
"errorLens.infoBackground": opacity(palette.blue, 0.15),
"errorLens.infoMessageBackground": opacity(palette.blue, 0.15),
"errorLens.infoBackgroundLight": opacity(palette.blue, 0.15),
"errorLens.infoForeground": palette.blue,
"errorLens.infoForegroundLight": palette.blue,
"errorLens.errorMessageBackground": opacity(palette.red, 0.15),
"errorLens.hintBackground": opacity(palette.green, 0.15),
"errorLens.hintMessageBackground": opacity(palette.green, 0.15),
"errorLens.hintBackgroundLight": opacity(palette.green, 0.15),
"errorLens.hintForeground": palette.green,
"errorLens.hintForegroundLight": palette.green,
"errorLens.hintMessageBackground": opacity(palette.green, 0.15),
"errorLens.infoBackground": opacity(palette.blue, 0.15),
"errorLens.infoBackgroundLight": opacity(palette.blue, 0.15),
"errorLens.infoForeground": palette.blue,
"errorLens.infoForegroundLight": palette.blue,
"errorLens.infoMessageBackground": opacity(palette.blue, 0.15),
"errorLens.statusBarErrorForeground": palette.red,
"errorLens.statusBarHintForeground": palette.green,
"errorLens.statusBarIconErrorForeground": palette.red,
"errorLens.statusBarIconWarningForeground": palette.peach,
"errorLens.statusBarErrorForeground": palette.red,
"errorLens.statusBarWarningForeground": palette.peach,
"errorLens.statusBarInfoForeground": palette.blue,
"errorLens.statusBarHintForeground": palette.green,
"errorLens.statusBarWarningForeground": palette.peach,
"errorLens.warningBackground": opacity(palette.peach, 0.15),
"errorLens.warningBackgroundLight": opacity(palette.peach, 0.15),
"errorLens.warningForeground": palette.peach,
"errorLens.warningForegroundLight": palette.peach,
"errorLens.warningMessageBackground": opacity(palette.peach, 0.15),
};
}
2 changes: 1 addition & 1 deletion src/theme/extensions/index.ts
Original file line number Diff line number Diff line change
@@ -3,6 +3,6 @@ import errorLens from "./error-lens";

export default function (context: ThemeContext) {
return {
...errorLens(context),
...[errorLens].map((el) => el(context)),
};
}
137 changes: 137 additions & 0 deletions src/types/errorlens.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/* eslint-disable */
/**
* This file was automatically generated.
* DO NOT MODIFY IT BY HAND.
* Instead, run `yarn run updateVSCtypes` to regenerate this file.
*/
export interface ErrorLensColors {
/**
* Background color of the entire line containing error.
*/
"errorLens.errorBackground": string;

/**
* Background color of the error message.
*/
"errorLens.errorMessageBackground": string;

/**
* Background color of the entire line containing error (Only in light themes).
*/
"errorLens.errorBackgroundLight": string;

/**
* Text color used to highlight lines containing errors.
*/
"errorLens.errorForeground": string;

/**
* Text color used to highlight lines containing errors (Only in light themes).
*/
"errorLens.errorForegroundLight": string;

/**
* Background color used to highlight lines containing warnings.
*/
"errorLens.warningBackground": string;

/**
* Background color of the warning message.
*/
"errorLens.warningMessageBackground": string;

/**
* Background color used to highlight lines containing warnings (Only in light themes).
*/
"errorLens.warningBackgroundLight": string;

/**
* Text color used to highlight lines containing warnings.
*/
"errorLens.warningForeground": string;

/**
* Text color used to highlight lines containing warnings (Only in light themes).
*/
"errorLens.warningForegroundLight": string;

/**
* Background color used to highlight lines containing info.
*/
"errorLens.infoBackground": string;

/**
* Background color of the info message.
*/
"errorLens.infoMessageBackground": string;

/**
* Background color used to highlight lines containing info (Only in light themes).
*/
"errorLens.infoBackgroundLight": string;

/**
* Text color used to highlight lines containing info.
*/
"errorLens.infoForeground": string;

/**
* Text color used to highlight lines containing info (Only in light themes).
*/
"errorLens.infoForegroundLight": string;

/**
* Background color used to highlight lines containing hints.
*/
"errorLens.hintBackground": string;

/**
* Background color of the hint message.
*/
"errorLens.hintMessageBackground": string;

/**
* Background color used to highlight lines containing hints (Only in light themes).
*/
"errorLens.hintBackgroundLight": string;

/**
* Text color used to highlight lines containing hints.
*/
"errorLens.hintForeground": string;

/**
* Text color used to highlight lines containing hints (Only in light themes).
*/
"errorLens.hintForegroundLight": string;

/**
* Status bar icon item error color. Foreground is used when the `errorLens.statusBarIconsUseBackground` setting is disabled.
*/
"errorLens.statusBarIconErrorForeground": string;

/**
* Status bar icon item error color. Foreground is used when the `errorLens.statusBarIconsUseBackground` setting is disabled.
*/
"errorLens.statusBarIconWarningForeground": string;

/**
* Status bar item error color.
*/
"errorLens.statusBarErrorForeground": string;

/**
* Status bar item warning color.
*/
"errorLens.statusBarWarningForeground": string;

/**
* Status bar item info color.
*/
"errorLens.statusBarInfoForeground": string;

/**
* Status bar item hint color.
*/
"errorLens.statusBarHintForeground": string;
}
4 changes: 4 additions & 0 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -2,10 +2,14 @@ import { labels, variants } from "@catppuccin/palette";

import type { Uri } from "vscode";

// vscode schemas
export type * from "./textmate-colors";
export type * from "./workbench-colors";
export type * from "./token-styling";

// extensions
export type * from "./errorlens";

export type CatppuccinFlavour = keyof typeof variants;
export type CatppuccinAccent =
| "rosewater"
6 changes: 3 additions & 3 deletions src/types/textmate-colors.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable */
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file.
* This file was automatically generated.
* DO NOT MODIFY IT BY HAND.
* Instead, run `yarn run updateVSCtypes` to regenerate this file.
*/

export type TextmateColors = {
6 changes: 3 additions & 3 deletions src/types/token-styling.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable */
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file.
* This file was automatically generated.
* DO NOT MODIFY IT BY HAND.
* Instead, run `yarn run updateVSCtypes` to regenerate this file.
*/

export interface SemanticTokens {
6 changes: 3 additions & 3 deletions src/types/workbench-colors.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable */
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file.
* This file was automatically generated.
* DO NOT MODIFY IT BY HAND.
* Instead, run `yarn run updateVSCtypes` to regenerate this file.
*/

export interface WorkbenchColors {

0 comments on commit 1adf178

Please sign in to comment.