fix(color-scheme): import PyCharm's function call, class and f-string colours (#4965)

Importing a PyCharm color scheme skipped eight PyCharm Python keys (PY.FUNCTION_CALL, PY.CLASS_DEFINITION, PY.PARAMETER, PY.LOCAL_VARIABLE, PY.TYPE_PARAMETER, PY.INVALID_STRING_ESCAPE, PY.FSTRING_FRAGMENT_BRACES, PY.FSTRING_FORMAT_SPEC_NUMBER), so Python calls took the shared call colour. They now map to the existing Python attributes and export under PyCharm's keys; files exported earlier under OPENIDEA_ names still import.

Co-authored-by: wildcatDownstairs <26499420+wildcatDownstairs@users.noreply.github.com>
This commit is contained in:
LU XIANGRUI
2026-11-21 14:48:07 +08:00
committed by GitHub
co-authored by wildcatDownstairs
parent 6b2b4a96e7
commit fa7fcd0d90
2 changed files with 56 additions and 0 deletions
+36
View File
@@ -398,6 +398,42 @@ describe(".icls schemes", () => {
for (const [name, value] of names) expect(attrs[name]?.foreground).toBe(`#${value}`);
});
it("imports PyCharm's function call, class, parameter and f-string keys and exports them by those keys", () => {
const keys = [
["PY.FUNCTION_CALL", "pyFunctionCall", "d56075"],
["PY.CLASS_DEFINITION", "pyClassDefinition", "7bcbff"],
["PY.PARAMETER", "pyParameter", "101010"],
["PY.LOCAL_VARIABLE", "pyLocalVariable", "202020"],
["PY.TYPE_PARAMETER", "pyTypeParameter", "303030"],
["PY.INVALID_STRING_ESCAPE", "pyInvalidEscape", "404040"],
["PY.FSTRING_FRAGMENT_BRACES", "pyFString", "e89c45"],
["PY.FSTRING_FORMAT_SPEC_NUMBER", "pyFormat", "505050"],
] as const;
const xml = `<scheme name="PyCharm" parent_scheme="Darcula"><attributes>${keys
.map(
([key, , value]) =>
`<option name="${key}"><value><option name="FOREGROUND" value="${value}"/></value></option>`,
)
.join("")}<option name="JS.GLOBAL_FUNCTION"><value><option name="FOREGROUND" value="6dacff"/></value></option>
</attributes></scheme>`;
const { scheme, skipped } = parseIcls(xml);
expect(skipped).toBe(0);
for (const [, id, value] of keys) expect(scheme.attributes[id]?.foreground).toBe(`#${value}`);
// A WebStorm function colour still sets the shared call colour; Python calls keep PyCharm's.
expect(scheme.attributes.functionCall?.foreground).toBe("#6dacff");
const { id, customs } = importScheme({}, scheme);
const exported = exportIcls(id, customs);
for (const [key] of keys) expect(exported).toContain(`name="${key}"`);
expect(exported).not.toContain('name="PY.STRING.F"');
});
it("still reads Python attributes that earlier versions exported under OPENIDEA_ names", () => {
const xml =
'<scheme name="Old"><attributes><option name="OPENIDEA_pyFunctionCall"><value>' +
'<option name="FOREGROUND" value="d56075"/></value></option></attributes></scheme>';
expect(parseIcls(xml).scheme.attributes.pyFunctionCall?.foreground).toBe("#d56075");
});
it("imports the Python f-string colour", () => {
const xml =
'<scheme name="F"><attributes><option name="PY.STRING.F"><value>' +
+20
View File
@@ -165,7 +165,16 @@ Object.assign(ATTRIBUTE_NAMES, {
"PY.STRING.U": "pyString",
"PY.FUNC_DEFINITION": "pyFunctionDeclaration",
"PY.NESTED_FUNC_DEFINITION": "pyNestedFunction",
"PY.FUNCTION_CALL": "pyFunctionCall",
"PY.METHOD_CALL": "pyMethodCall",
"PY.CLASS_DEFINITION": "pyClassDefinition",
"PY.PARAMETER": "pyParameter",
"PY.LOCAL_VARIABLE": "pyLocalVariable",
"PY.TYPE_PARAMETER": "pyTypeParameter",
"PY.INVALID_STRING_ESCAPE": "pyInvalidEscape",
// PyCharm's own f-string keys come first, so exports use them; PY.STRING.F is still read.
"PY.FSTRING_FRAGMENT_BRACES": "pyFString",
"PY.FSTRING_FORMAT_SPEC_NUMBER": "pyFormat",
"PY.DOC_COMMENT": "pyDocstring",
"PY.BUILTIN_NAME": "pyBuiltin",
"PY.DECORATOR": "pyDecorator",
@@ -260,6 +269,17 @@ Object.assign(ATTRIBUTE_NAMES, {
// Preserve editor attributes without a standard exchange name on our own round trip.
for (const attr of ATTRIBUTES)
if (!Object.values(ATTRIBUTE_NAMES).includes(attr.id)) ATTRIBUTE_NAMES[`OPENIDEA_${attr.id}`] = attr.id;
// Earlier versions exported these under OPENIDEA_ names, before their PyCharm keys were mapped.
for (const id of [
"pyFunctionCall",
"pyClassDefinition",
"pyParameter",
"pyLocalVariable",
"pyTypeParameter",
"pyInvalidEscape",
"pyFormat",
])
ATTRIBUTE_NAMES[`OPENIDEA_${id}`] ??= id;
// One key colours an attribute, as IntelliJ shows it in the file the user sees: an explicit value replaces
// its fallback's. TypeScript keys win over JavaScript (TS.* falls back to JS.*), then Python, then the