Файли
openidea/src/editor/core/cm/properties.ts
T
lleviathe 732e92f756 fix(editor): colour .env and properties keys like other key-value files (#3979)
Adds a properties/.env stream language wrapper so keys use the keyword colour, the first separator the operator colour and values the string colour.

Co-authored-by: lleviathe <[email protected]>
2026-11-17 21:23:53 +08:00

39 рядки
1.4 KiB
TypeScript

/**
* `.properties`, `.ini`, `.env` and Godot resources, coloured like IntelliJ's Properties and
* DotEnv highlighters: the key is KEYWORD, the first `=` or `:` is OPERATION_SIGN and the rest
* of the line (with its continuation lines) is STRING. The legacy mode finds the parts; its
* own `def` and `quote` styles would read as a variable and plain text.
*/
import { StreamLanguage, type StreamParser } from "@codemirror/language";
import { properties } from "@codemirror/legacy-modes/mode/properties";
/** The legacy state with the one field read here, plus the line's separator. */
interface State {
nextMultiline: boolean;
separated: boolean;
}
const parser: StreamParser<State> = {
name: properties.name,
startState: (indentUnit) => ({ ...(properties.startState!(indentUnit) as State), separated: false }),
// CodeMirror skips `token` on empty lines; a blank line ends a continued value.
blankLine(state) {
state.nextMultiline = false;
},
token(stream, state) {
if (stream.sol() && !state.nextMultiline) state.separated = false;
const style = properties.token(stream, state);
if (style === "def") return "keyword";
if (style === "quote") return "string";
// The legacy mode returns null only for `=` and `:`.
if (style === null) {
if (state.separated) return "string";
state.separated = true;
return "operator";
}
return style;
},
};
export const propertiesLanguage = StreamLanguage.define(parser);