дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-09 19:25:54 +02:00
fix(go): enable semantic colors and Go scheme settings (#2017)
Go files showed no semantic colours because gopls semantic tokens were not requested, and Color Scheme had no Go page. gopls is now initialised with semantic tokens, constants, package variables and package references get Go-specific roles, and Color Scheme has a Go page with a preview. Siblings covered: Go-specific attributes inherit from Language Defaults, Reset restores them, Chinese labels show in the Color Scheme tree, and a user's own gopls settings are kept. Co-authored-by: shohruh-genius <[email protected]>
Цей коміт міститься в:
1 джерело
e8cf744463
коміт
fff2c35181
15 files changed
+330
-5
No files matched your search
@@ -1,8 +1,9 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { act, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { act, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { executeAction } from "@/platform/actions";
|
||||
import { CLEAR_COLOR } from "@/platform/colorScheme";
|
||||
import { setLocale } from "@/platform/i18n";
|
||||
import { useProject } from "@/platform/project";
|
||||
import { DEFAULT_SETTINGS } from "../model/schema";
|
||||
import { openSettings, stage, stagedValue, useSettingsDialog } from "../model/staging";
|
||||
@@ -120,6 +121,49 @@ describe("scheme actions", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("Go scheme attributes", () => {
|
||||
it("translates the attribute tree and preview selection in Chinese", async () => {
|
||||
await act(async () => {
|
||||
await setLocale("zh");
|
||||
});
|
||||
try {
|
||||
schemePage("editor.colorScheme.go");
|
||||
expect(screen.getByRole("treeitem", { name: "标识符" })).toBeInTheDocument();
|
||||
const preview = screen.getByLabelText("配色方案预览");
|
||||
act(() => fireEvent.click(within(preview).getByText("fmt")));
|
||||
expect(screen.getByRole("treeitem", { name: "包引用" })).toHaveAttribute("aria-selected", "true");
|
||||
} finally {
|
||||
await act(async () => {
|
||||
await setLocale("en");
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it("selects package references from the preview, inherits defaults and restores overrides", () => {
|
||||
act(() => {
|
||||
stage("editor.colorScheme", "global", "editor.colorScheme", "dark");
|
||||
stage("editor.colorScheme", "global", "editor.colorOverrides", {
|
||||
dark: { packageReference: { foreground: "#139839" } },
|
||||
});
|
||||
});
|
||||
schemePage("editor.colorScheme.go");
|
||||
const preview = screen.getByLabelText("Color scheme preview");
|
||||
act(() => fireEvent.click(within(preview).getByText("fmt")));
|
||||
expect(screen.getByRole("treeitem", { name: "Package reference" })).toHaveAttribute("aria-selected", "true");
|
||||
expect(preview.style.getPropertyValue("--syn-namespace")).toBe("#139839");
|
||||
|
||||
act(() => fireEvent.click(screen.getByRole("checkbox", { name: "Bold" })));
|
||||
expect(value("colorOverrides")).toEqual({
|
||||
dark: { packageReference: { foreground: "#139839" }, "go.packageReference": { bold: true } },
|
||||
});
|
||||
expect(preview.style.getPropertyValue("--syn-namespace-bold")).toBe("var(--fw-code-bold, 700)");
|
||||
|
||||
act(() => fireEvent.click(screen.getByRole("button", { name: "Restore Defaults" })));
|
||||
expect(value("colorOverrides")).toEqual({});
|
||||
expect(screen.getByRole("checkbox", { name: "Bold" })).not.toBeChecked();
|
||||
});
|
||||
});
|
||||
|
||||
describe("scheme attribute state", () => {
|
||||
beforeEach(() => schemePage("editor.colorScheme.language-defaults"));
|
||||
it("shows checked attributes and inherited colours from the selected scheme", () => {
|
||||
|
||||
@@ -29,7 +29,7 @@ import { executeAction, registerActions } from "@/platform/actions";
|
||||
import { call, commands } from "@/platform/ipc";
|
||||
import { ask, confirm, showError } from "@/workbench/messages";
|
||||
import { parseIcls, importScheme, deleteScheme, exportIcls } from "@/platform/icls";
|
||||
import { tx } from "@/platform/i18n";
|
||||
import { tx, useTx } from "@/platform/i18n";
|
||||
import { selectPage } from "../../model/staging";
|
||||
|
||||
type Overrides = Record<string, Record<string, TextAttributesOverride>>;
|
||||
@@ -689,6 +689,74 @@ const SAMPLES: Record<string, CodeSample> = {
|
||||
[["}", "java.operator"]],
|
||||
],
|
||||
},
|
||||
Go: {
|
||||
code: [
|
||||
[["package ", "go.keyword"], ["palette"]],
|
||||
[
|
||||
["import ", "go.keyword"],
|
||||
['"fmt"', "go.string"],
|
||||
],
|
||||
[["// Retry a greeting", "go.lineComment"]],
|
||||
[
|
||||
["const ", "go.keyword"],
|
||||
["MaxRetries", "go.constant"],
|
||||
[" = ", "go.operator"],
|
||||
["3", "go.number"],
|
||||
],
|
||||
[
|
||||
["var ", "go.keyword"],
|
||||
["DefaultName", "go.globalVariable"],
|
||||
[" = ", "go.operator"],
|
||||
['"Go"', "go.string"],
|
||||
],
|
||||
[
|
||||
["type ", "go.keyword"],
|
||||
["Greeter", "go.className"],
|
||||
[" struct ", "go.keyword"],
|
||||
["{", "go.operator"],
|
||||
],
|
||||
[
|
||||
[" Name", "go.field"],
|
||||
[" string", "go.predefined"],
|
||||
],
|
||||
[["}", "go.operator"]],
|
||||
[
|
||||
["func ", "go.keyword"],
|
||||
["(", "go.operator"],
|
||||
["g", "go.parameter"],
|
||||
[" Greeter", "go.className"],
|
||||
[") ", "go.operator"],
|
||||
["Greet", "go.functionDeclaration"],
|
||||
["(", "go.operator"],
|
||||
["count", "go.parameter"],
|
||||
[" int", "go.predefined"],
|
||||
[") ", "go.operator"],
|
||||
["string", "go.predefined"],
|
||||
[" {", "go.operator"],
|
||||
],
|
||||
[
|
||||
[" message", "go.identifier"],
|
||||
[" := ", "go.operator"],
|
||||
["fmt", "go.packageReference"],
|
||||
[".", "go.operator"],
|
||||
["Sprintf", "go.functionCall"],
|
||||
["(", "go.operator"],
|
||||
['"Hello, %s', "go.string"],
|
||||
["\\n", "go.escape"],
|
||||
['"', "go.string"],
|
||||
[", ", "go.operator"],
|
||||
["g", "go.parameter"],
|
||||
[".", "go.operator"],
|
||||
["Name", "go.field"],
|
||||
[")", "go.operator"],
|
||||
],
|
||||
[
|
||||
[" return ", "go.keyword"],
|
||||
["message", "go.identifier"],
|
||||
],
|
||||
[["}", "go.operator"]],
|
||||
],
|
||||
},
|
||||
Kotlin: {
|
||||
code: [
|
||||
[["// Kotlin", "kotlin.lineComment"]],
|
||||
@@ -979,6 +1047,7 @@ function ColorRow({
|
||||
}
|
||||
|
||||
function ColorSchemePage({ scopes, landing }: { scopes: readonly string[]; landing?: boolean }) {
|
||||
const translate = useTx();
|
||||
const [scheme, setScheme] = useSetting<string>("editor.colorScheme", "global");
|
||||
const [overrides, setOverrides] = useSetting<Overrides>("editor.colorOverrides", "global");
|
||||
const [weight] = useSetting<number>("editor.fontWeight");
|
||||
@@ -1219,7 +1288,7 @@ function ColorSchemePage({ scopes, landing }: { scopes: readonly string[]; landi
|
||||
aria-label="Color scheme attributes"
|
||||
roots={roots}
|
||||
getKey={(n) => n.key}
|
||||
getLabel={(n) => n.label}
|
||||
getLabel={(n) => translate(n.label)}
|
||||
getChildren={(n) => n.children}
|
||||
isExpandable={(n) => !!n.children?.length}
|
||||
expanded={expanded}
|
||||
@@ -1232,7 +1301,7 @@ function ColorSchemePage({ scopes, landing }: { scopes: readonly string[]; landi
|
||||
<span
|
||||
className={`${styles.treeLabel} ${(n.attr ? mine?.[n.attr.id] : modifiedKeys.has(n.key)) ? styles.attrModified : ""}`}
|
||||
>
|
||||
{n.label}
|
||||
{translate(n.label)}
|
||||
</span>
|
||||
)}
|
||||
speedSearch
|
||||
|
||||
Reference in new issue
Заблокувати користувача