️ Handle override and overrideAll better
Some checks failed
Build extension / build (push) Failing after 30s
Linter / lint (push) Has been cancelled

This commit is contained in:
Robin van der Linde 2025-01-04 22:00:31 +01:00
parent 25f4b44e57
commit f3666b8d5c
Signed by: Robin-van-der-Linde
GPG key ID: 53956B3252478F0D
2 changed files with 34 additions and 18 deletions

View file

@ -89,15 +89,17 @@ export const iconDefinitionProvider =
* - As a color name, like red * - As a color name, like red
* *
* JSON paths: * JSON paths:
* - (layers.{index}.)lineRendering.{index}.color * - (layers.{index}(.override).)lineRendering.{index}.color
* - (layers.{index}.)lineRendering.{index}.color.render * - (layers.{index}(.override).)lineRendering.{index}.color.render
* - (layers.{index}.)lineRendering.{index}.color.mappings.{index}.then * - (layers.{index}(.override).)lineRendering.{index}.color.mappings.{index}.then
* - (layers.{index}.)lineRendering.{index}.fillColor * - (layers.{index}(.override).)lineRendering.{index}.fillColor
* - (layers.{index}.)lineRendering.{index}.fillColor.render * - (layers.{index}(.override).)lineRendering.{index}.fillColor.render
* - (layers.{index}.)lineRendering.{index}.fillColor.mappings.{index}.then * - (layers.{index}(.override).)lineRendering.{index}.fillColor.mappings.{index}.then
* - (layers.{index}.)pointRendering.{index}.marker.{index}.color * - (layers.{index}(.override).)pointRendering.{index}.marker.{index}.color
* - (layers.{index}.)pointRendering.{index}.marker.{index}.color.render * - (layers.{index}(.override).)pointRendering.{index}.marker.{index}.color.render
* - (layers.{index}.)pointRendering.{index}.marker.{index}.color.mappings.{index}.then * - (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( export const colorProvider = vscode.languages.registerColorProvider(
@ -164,9 +166,9 @@ export const colorProvider = vscode.languages.registerColorProvider(
findPaths(jsonParsed); findPaths(jsonParsed);
const regexes = [ const regexes = [
/^(layers.\d+.)?lineRendering.\d+.color((.render)|(.mappings.\d+.then))?$/, /^((layers\.\d+\.(override\.([+=])?)?)|(overrideAll\.))?lineRendering\.\d+\.color((\.render)|(\.mappings\.\d+\.then))?$/,
/^(layers.\d+.)?lineRendering.\d+.fillColor((.render)|(.mappings.\d+.then))?$/, /^((layers\.\d+\.(override\.([+=])?)?)|(overrideAll\.))?lineRendering.\d+.fillColor((.render)|(.mappings.\d+.then))?$/,
/^(layers.\d+.)?pointRendering.\d+.marker.\d+.color((.render)|(.mappings.\d+.then))?$/, /^((layers\.\d+\.(override\.([+=])?)?)|(overrideAll\.))?pointRendering.\d+.marker.\d+.color((.render)|(.mappings.\d+.then))?$/,
]; ];
regexes.forEach((regex) => { regexes.forEach((regex) => {

View file

@ -20,7 +20,9 @@ import { JSONPath } from "jsonc-parser";
* This provider will provide a list of existing tagRenderings for autocompletion * This provider will provide a list of existing tagRenderings for autocompletion
* *
* JSON path: * 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 = export const tagRenderingCompletionProvider =
vscode.languages.registerCompletionItemProvider( vscode.languages.registerCompletionItemProvider(
@ -43,7 +45,9 @@ export const tagRenderingCompletionProvider =
const text = document.getText(); const text = document.getText();
const jsonPath = getCursorPath(text, position); 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)) { if (regex.exec(jsonPath)) {
const tagRenderings = await getTagRenderings(); const tagRenderings = await getTagRenderings();
console.log(`Got ${tagRenderings.length} tagRenderings`); 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 * This provider will provide a definition for tagRenderings, allowing users to jump to the tagRendering definition
* *
* JSON path: * 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 = export const tagRenderingDefinitionProvider =
vscode.languages.registerDefinitionProvider( vscode.languages.registerDefinitionProvider(
@ -82,7 +88,9 @@ export const tagRenderingDefinitionProvider =
const jsonPath = getCursorPath(text, position); const jsonPath = getCursorPath(text, position);
const rawJsonPath = getRawCursorPath(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)) { if (regex.exec(jsonPath)) {
const tagRendering = getValueFromPath(text, rawJsonPath); const tagRendering = getValueFromPath(text, rawJsonPath);
@ -171,6 +179,8 @@ export const tagRenderingDefinitionProvider =
* *
* JSON path: * JSON path:
* - (layers.{index}.)filter.{index} * - (layers.{index}.)filter.{index}
* - overrideAll.filter.{index}
* Also +/= characters around filter are supported
*/ */
export const filterCompletionProvider = export const filterCompletionProvider =
vscode.languages.registerCompletionItemProvider( vscode.languages.registerCompletionItemProvider(
@ -195,7 +205,8 @@ export const filterCompletionProvider =
console.log(jsonPath); console.log(jsonPath);
const regex = /^(layers.\d+.)?filter\.\d+$/; const regex =
/^((layers\.\d+\.(override\.([+=])?)?)|(overrideAll\.))?filter(\+)?\.\d+$/;
if (regex.exec(jsonPath)) { if (regex.exec(jsonPath)) {
const filters = await getFilters(); const filters = await getFilters();
console.log(`Got ${filters.length} filters`); console.log(`Got ${filters.length} filters`);
@ -216,6 +227,8 @@ export const filterCompletionProvider =
* *
* JSON path: * JSON path:
* - (layers.{index}.)filter.{index} * - (layers.{index}.)filter.{index}
* - overrideAll.filter.{index}
* Also +/= characters around filter are supported
*/ */
export const filterDefinitionProvider = export const filterDefinitionProvider =
vscode.languages.registerDefinitionProvider( vscode.languages.registerDefinitionProvider(
@ -234,7 +247,8 @@ export const filterDefinitionProvider =
const jsonPath = getCursorPath(text, position); const jsonPath = getCursorPath(text, position);
const rawJsonPath = getRawCursorPath(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)) { if (regex.exec(jsonPath)) {
const filter = getValueFromPath(text, rawJsonPath); const filter = getValueFromPath(text, rawJsonPath);