@theia/core
Version:
Theia is a cloud & desktop IDE framework implemented in TypeScript.
60 lines (52 loc) • 2.54 kB
text/typescript
// *****************************************************************************
// Copyright (C) 2021 Ericsson and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
import { inject, injectable } from 'inversify';
import { isObject } from '../types.js';
import { IndexedAccess, PreferenceSchemaService } from './preference-schema.js';
import { JSONValue } from '@lumino/coreutils';
export interface OverridePreferenceName {
preferenceName: string
overrideIdentifier: string
}
export namespace OverridePreferenceName {
export function is(arg: unknown): arg is OverridePreferenceName {
return isObject(arg) && 'preferenceName' in arg && 'overrideIdentifier' in arg;
}
}
const OVERRIDE_PROPERTY = '\\[(.*)\\]$';
export const OVERRIDE_PROPERTY_PATTERN = new RegExp(OVERRIDE_PROPERTY);
export const getOverridePattern = (identifier: string) => `\\[(${identifier})\\]$`;
()
export class PreferenceLanguageOverrideService {
(PreferenceSchemaService)
protected readonly preferenceSchemaService: PreferenceSchemaService;
static testOverrideValue(name: string, value: unknown): value is IndexedAccess<JSONValue> {
return isObject(value) && OVERRIDE_PROPERTY_PATTERN.test(name);
}
/**
* @param overrideIdentifier the language id associated for a language override, e.g. `typescript`
* @returns the form used to mark language overrides in preference files, e.g. `[typescript]`
*/
markLanguageOverride(overrideIdentifier: string): string {
return `[${overrideIdentifier}]`;
}
/**
* @returns the flat JSON path to an overridden preference, e.g. [typescript].editor.tabSize.
*/
overridePreferenceName({ preferenceName, overrideIdentifier }: OverridePreferenceName): string {
return `${this.markLanguageOverride(overrideIdentifier)}.${preferenceName}`;
}
}