From f3666b8d5c16b990571fa19327265251d16c9270 Mon Sep 17 00:00:00 2001 From: Robin van der Linde Date: Sat, 4 Jan 2025 22:00:31 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Handle=20override=20and=20?= =?UTF-8?q?overrideAll=20better?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/generic.ts | 26 ++++++++++++++------------ src/layers.ts | 26 ++++++++++++++++++++------ 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/generic.ts b/src/generic.ts index 69f2650..8566f8a 100644 --- a/src/generic.ts +++ b/src/generic.ts @@ -89,15 +89,17 @@ export const iconDefinitionProvider = * - As a color name, like red * * JSON paths: - * - (layers.{index}.)lineRendering.{index}.color - * - (layers.{index}.)lineRendering.{index}.color.render - * - (layers.{index}.)lineRendering.{index}.color.mappings.{index}.then - * - (layers.{index}.)lineRendering.{index}.fillColor - * - (layers.{index}.)lineRendering.{index}.fillColor.render - * - (layers.{index}.)lineRendering.{index}.fillColor.mappings.{index}.then - * - (layers.{index}.)pointRendering.{index}.marker.{index}.color - * - (layers.{index}.)pointRendering.{index}.marker.{index}.color.render - * - (layers.{index}.)pointRendering.{index}.marker.{index}.color.mappings.{index}.then + * - (layers.{index}(.override).)lineRendering.{index}.color + * - (layers.{index}(.override).)lineRendering.{index}.color.render + * - (layers.{index}(.override).)lineRendering.{index}.color.mappings.{index}.then + * - (layers.{index}(.override).)lineRendering.{index}.fillColor + * - (layers.{index}(.override).)lineRendering.{index}.fillColor.render + * - (layers.{index}(.override).)lineRendering.{index}.fillColor.mappings.{index}.then + * - (layers.{index}(.override).)pointRendering.{index}.marker.{index}.color + * - (layers.{index}(.override).)pointRendering.{index}.marker.{index}.color.render + * - (layers.{index}(.override).)pointRendering.{index}.marker.{index}.color.mappings.{index}.then + * + * In all cases (layers.{index}.) can also be replaced by overrideAll * */ export const colorProvider = vscode.languages.registerColorProvider( @@ -164,9 +166,9 @@ export const colorProvider = vscode.languages.registerColorProvider( findPaths(jsonParsed); const regexes = [ - /^(layers.\d+.)?lineRendering.\d+.color((.render)|(.mappings.\d+.then))?$/, - /^(layers.\d+.)?lineRendering.\d+.fillColor((.render)|(.mappings.\d+.then))?$/, - /^(layers.\d+.)?pointRendering.\d+.marker.\d+.color((.render)|(.mappings.\d+.then))?$/, + /^((layers\.\d+\.(override\.([+=])?)?)|(overrideAll\.))?lineRendering\.\d+\.color((\.render)|(\.mappings\.\d+\.then))?$/, + /^((layers\.\d+\.(override\.([+=])?)?)|(overrideAll\.))?lineRendering.\d+.fillColor((.render)|(.mappings.\d+.then))?$/, + /^((layers\.\d+\.(override\.([+=])?)?)|(overrideAll\.))?pointRendering.\d+.marker.\d+.color((.render)|(.mappings.\d+.then))?$/, ]; regexes.forEach((regex) => { diff --git a/src/layers.ts b/src/layers.ts index 57867f7..137c4b8 100644 --- a/src/layers.ts +++ b/src/layers.ts @@ -20,7 +20,9 @@ import { JSONPath } from "jsonc-parser"; * This provider will provide a list of existing tagRenderings for autocompletion * * JSON path: - * - (layers.{index}.)tagRenderings.{index}(.builtin) + * - (layers.{index}.(override).)tagRenderings.{index}(.builtin) + * - overrideAll.tagRenderings.{index}(.builtin) + * Also +/= characters around tagRenderings are supported */ export const tagRenderingCompletionProvider = vscode.languages.registerCompletionItemProvider( @@ -43,7 +45,9 @@ export const tagRenderingCompletionProvider = const text = document.getText(); const jsonPath = getCursorPath(text, position); - const regex = /^(layers.\d+.)?tagRenderings\.\d+(.builtin)?$/; + // This technically also matches layers.1.tagRenderings+, and similar, but that's fine + const regex = + /^((layers\.\d+\.(override\.([+=])?)?)|(overrideAll\.))?tagRenderings(\+)?\.\d+(.builtin)?$/; if (regex.exec(jsonPath)) { const tagRenderings = await getTagRenderings(); console.log(`Got ${tagRenderings.length} tagRenderings`); @@ -63,7 +67,9 @@ export const tagRenderingCompletionProvider = * This provider will provide a definition for tagRenderings, allowing users to jump to the tagRendering definition * * JSON path: - * - (layers.{index}.)tagRenderings.{index}(.builtin) + * - (layers.{index}.(override).)tagRenderings.{index}(.builtin) + * - overrideAll.tagRenderings.{index}(.builtin) + * Also +/= characters around tagRenderings are supported */ export const tagRenderingDefinitionProvider = vscode.languages.registerDefinitionProvider( @@ -82,7 +88,9 @@ export const tagRenderingDefinitionProvider = const jsonPath = getCursorPath(text, position); const rawJsonPath = getRawCursorPath(text, position); - const regex = /^(layers.\d.)?tagRenderings.\d*(.builtin)?$/; + // This technically also matches layers.1.tagRenderings+, and similar, but that's fine + const regex = + /^((layers\.\d+\.(override\.([+=])?)?)|(overrideAll\.))?tagRenderings(\+)?\.\d+(.builtin)?$/; if (regex.exec(jsonPath)) { const tagRendering = getValueFromPath(text, rawJsonPath); @@ -171,6 +179,8 @@ export const tagRenderingDefinitionProvider = * * JSON path: * - (layers.{index}.)filter.{index} + * - overrideAll.filter.{index} + * Also +/= characters around filter are supported */ export const filterCompletionProvider = vscode.languages.registerCompletionItemProvider( @@ -195,7 +205,8 @@ export const filterCompletionProvider = console.log(jsonPath); - const regex = /^(layers.\d+.)?filter\.\d+$/; + const regex = + /^((layers\.\d+\.(override\.([+=])?)?)|(overrideAll\.))?filter(\+)?\.\d+$/; if (regex.exec(jsonPath)) { const filters = await getFilters(); console.log(`Got ${filters.length} filters`); @@ -216,6 +227,8 @@ export const filterCompletionProvider = * * JSON path: * - (layers.{index}.)filter.{index} + * - overrideAll.filter.{index} + * Also +/= characters around filter are supported */ export const filterDefinitionProvider = vscode.languages.registerDefinitionProvider( @@ -234,7 +247,8 @@ export const filterDefinitionProvider = const jsonPath = getCursorPath(text, position); const rawJsonPath = getRawCursorPath(text, position); - const regex = /^(layers.\d.)?filter.\d*$/; + const regex = + /^((layers\.\d+\.(override\.([+=])?)?)|(overrideAll\.))?filter(\+)?\.\d+$/; if (regex.exec(jsonPath)) { const filter = getValueFromPath(text, rawJsonPath);