* boolean -> boolean|DeriveFromWorkspaceTrust (with DeriveFromWorkspaceTrust being the default)
* allowedCharacters: string[] -> allowedCharacters: string and allowedCodePoints: number[]
This commit is contained in:
parent
5349b091c3
commit
7dabffd889
|
@ -900,20 +900,6 @@ export function boolean(value: any, defaultValue: boolean): boolean {
|
|||
return Boolean(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function booleanOrUndefined(value: any): boolean | undefined {
|
||||
if (typeof value === 'undefined') {
|
||||
return undefined;
|
||||
}
|
||||
if (value === 'false') {
|
||||
// treat the string 'false' as false
|
||||
return false;
|
||||
}
|
||||
return Boolean(value);
|
||||
}
|
||||
|
||||
class EditorBooleanOption<K1 extends EditorOption> extends SimpleEditorOption<K1, boolean> {
|
||||
|
||||
constructor(id: K1, name: PossibleKeyName<boolean>, defaultValue: boolean, schema: IConfigurationPropertySchema | undefined = undefined) {
|
||||
|
@ -3263,21 +3249,31 @@ class EditorScrollbar extends BaseEditorOption<EditorOption.scrollbar, InternalE
|
|||
|
||||
//#region UnicodeHighlight
|
||||
|
||||
export type DeriveFromWorkspaceTrust = 'deriveFromWorkspaceTrust';
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export const deriveFromWorkspaceTrust: DeriveFromWorkspaceTrust = 'deriveFromWorkspaceTrust';
|
||||
|
||||
/**
|
||||
* Configuration options for unicode highlighting.
|
||||
*/
|
||||
export interface IUnicodeHighlightOptions {
|
||||
nonBasicASCII?: boolean;
|
||||
invisibleCharacters?: boolean;
|
||||
ambiguousCharacters?: boolean;
|
||||
includeComments?: boolean;
|
||||
allowedCharacters?: string[];
|
||||
nonBasicASCII?: boolean | DeriveFromWorkspaceTrust;
|
||||
invisibleCharacters?: boolean | DeriveFromWorkspaceTrust;
|
||||
ambiguousCharacters?: boolean | DeriveFromWorkspaceTrust;
|
||||
includeComments?: boolean | DeriveFromWorkspaceTrust;
|
||||
/**
|
||||
* A list of allowed code points in a single string.
|
||||
*/
|
||||
allowedCharacters?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type InternalUnicodeHighlightOptions = Readonly<IUnicodeHighlightOptions>;
|
||||
export type InternalUnicodeHighlightOptions = Required<Readonly<IUnicodeHighlightOptions>>;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
|
@ -3293,11 +3289,11 @@ export const unicodeHighlightConfigKeys = {
|
|||
class UnicodeHighlight extends BaseEditorOption<EditorOption.unicodeHighlighting, InternalUnicodeHighlightOptions> {
|
||||
constructor() {
|
||||
const defaults: InternalUnicodeHighlightOptions = {
|
||||
nonBasicASCII: false,
|
||||
invisibleCharacters: true,
|
||||
ambiguousCharacters: false,
|
||||
includeComments: false,
|
||||
allowedCharacters: [],
|
||||
nonBasicASCII: deriveFromWorkspaceTrust,
|
||||
invisibleCharacters: deriveFromWorkspaceTrust,
|
||||
ambiguousCharacters: deriveFromWorkspaceTrust,
|
||||
includeComments: deriveFromWorkspaceTrust,
|
||||
allowedCharacters: '',
|
||||
};
|
||||
|
||||
super(
|
||||
|
@ -3305,25 +3301,29 @@ class UnicodeHighlight extends BaseEditorOption<EditorOption.unicodeHighlighting
|
|||
{
|
||||
[unicodeHighlightConfigKeys.nonBasicASCII]: {
|
||||
restricted: true,
|
||||
type: 'boolean',
|
||||
type: ['boolean', 'string'],
|
||||
enum: [true, false, deriveFromWorkspaceTrust],
|
||||
default: defaults.nonBasicASCII,
|
||||
description: nls.localize('unicodeHighlight.nonBasicASCII', "Controls whether all non-basic ASCII characters are highlighted. Only characters between U+0020 and U+007E, tab, line-feed and carriage-return are considered basic ASCII.")
|
||||
},
|
||||
[unicodeHighlightConfigKeys.invisibleCharacters]: {
|
||||
restricted: true,
|
||||
type: 'boolean',
|
||||
type: ['boolean', 'string'],
|
||||
enum: [true, false, deriveFromWorkspaceTrust],
|
||||
default: defaults.invisibleCharacters,
|
||||
description: nls.localize('unicodeHighlight.invisibleCharacters', "Controls whether characters that just reserve space or have no width at all are highlighted.")
|
||||
},
|
||||
[unicodeHighlightConfigKeys.ambiguousCharacters]: {
|
||||
restricted: true,
|
||||
type: 'boolean',
|
||||
type: ['boolean', 'string'],
|
||||
enum: [true, false, deriveFromWorkspaceTrust],
|
||||
default: defaults.ambiguousCharacters,
|
||||
description: nls.localize('unicodeHighlight.ambiguousCharacters', "Controls whether characters are highlighted that can be confused with basic ASCII characters, except those that are common in the current user locale.")
|
||||
},
|
||||
[unicodeHighlightConfigKeys.includeComments]: {
|
||||
restricted: true,
|
||||
type: 'boolean',
|
||||
type: ['boolean', 'string'],
|
||||
enum: [true, false, deriveFromWorkspaceTrust],
|
||||
default: defaults.includeComments,
|
||||
description: nls.localize('unicodeHighlight.includeComments', "Controls whether characters in comments should also be subject to unicode highlighting.")
|
||||
},
|
||||
|
@ -3343,27 +3343,20 @@ class UnicodeHighlight extends BaseEditorOption<EditorOption.unicodeHighlighting
|
|||
}
|
||||
const input = _input as IUnicodeHighlightOptions;
|
||||
return {
|
||||
nonBasicASCII: booleanOrUndefined(input.nonBasicASCII),
|
||||
invisibleCharacters: booleanOrUndefined(input.invisibleCharacters),
|
||||
ambiguousCharacters: booleanOrUndefined(input.ambiguousCharacters),
|
||||
includeComments: booleanOrUndefined(input.includeComments),
|
||||
allowedCharacters: validateStringArray(input.allowedCharacters),
|
||||
nonBasicASCII: primitiveSet<boolean | DeriveFromWorkspaceTrust>(input.nonBasicASCII, deriveFromWorkspaceTrust, [true, false, deriveFromWorkspaceTrust]),
|
||||
invisibleCharacters: primitiveSet<boolean | DeriveFromWorkspaceTrust>(input.invisibleCharacters, deriveFromWorkspaceTrust, [true, false, deriveFromWorkspaceTrust]),
|
||||
ambiguousCharacters: primitiveSet<boolean | DeriveFromWorkspaceTrust>(input.ambiguousCharacters, deriveFromWorkspaceTrust, [true, false, deriveFromWorkspaceTrust]),
|
||||
includeComments: primitiveSet<boolean | DeriveFromWorkspaceTrust>(input.includeComments, deriveFromWorkspaceTrust, [true, false, deriveFromWorkspaceTrust]),
|
||||
allowedCharacters: string(input.allowedCharacters, ''),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function validateStringArray(value: any): string[] {
|
||||
if (!Array.isArray(value)) {
|
||||
return [];
|
||||
function string(value: unknown, defaultValue: string): string {
|
||||
if (typeof value !== 'string') {
|
||||
return defaultValue;
|
||||
}
|
||||
const result = new Array();
|
||||
|
||||
for (const item of value) {
|
||||
if (typeof item === 'string') {
|
||||
result.push(item);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return value;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
|
|
@ -90,13 +90,15 @@ export type UnicodeHighlighterReason = {
|
|||
};
|
||||
|
||||
class CodePointHighlighter {
|
||||
private readonly excludedCharacters: Set<string>;
|
||||
private readonly allowedCodePoints: Set<number>;
|
||||
constructor(private readonly options: UnicodeHighlighterOptions) {
|
||||
this.excludedCharacters = new Set(options.excludedCharacters);
|
||||
this.allowedCodePoints = new Set(options.allowedCodePoints);
|
||||
}
|
||||
|
||||
public shouldHighlightNonBasicASCII(character: string): SimpleHighlightReason {
|
||||
if (this.excludedCharacters.has(character)) {
|
||||
const codePoint = character.codePointAt(0)!;
|
||||
|
||||
if (this.allowedCodePoints.has(codePoint)) {
|
||||
return SimpleHighlightReason.None;
|
||||
}
|
||||
|
||||
|
@ -104,8 +106,6 @@ class CodePointHighlighter {
|
|||
return SimpleHighlightReason.NonBasicASCII;
|
||||
}
|
||||
|
||||
const codePoint = character.codePointAt(0)!;
|
||||
|
||||
if (this.options.invisibleCharacters) {
|
||||
const isAllowedInvisibleCharacter = character === ' ' || character === '\n' || character === '\t';
|
||||
// TODO check for emojis
|
||||
|
@ -141,5 +141,5 @@ export interface UnicodeHighlighterOptions {
|
|||
ambiguousCharacters: boolean;
|
||||
invisibleCharacters: boolean;
|
||||
includeComments: boolean;
|
||||
excludedCharacters: string[];
|
||||
allowedCodePoints: number[];
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import { InvisibleCharacters } from 'vs/base/common/strings';
|
|||
import 'vs/css!./unicodeHighlighter';
|
||||
import { IActiveCodeEditor, ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
import { EditorAction, registerEditorAction, registerEditorContribution, ServicesAccessor } from 'vs/editor/browser/editorExtensions';
|
||||
import { EditorOption, InternalUnicodeHighlightOptions, IUnicodeHighlightOptions, unicodeHighlightConfigKeys } from 'vs/editor/common/config/editorOptions';
|
||||
import { DeriveFromWorkspaceTrust, deriveFromWorkspaceTrust, EditorOption, InternalUnicodeHighlightOptions, unicodeHighlightConfigKeys } from 'vs/editor/common/config/editorOptions';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { IEditorContribution } from 'vs/editor/common/editorCommon';
|
||||
import { IModelDecoration, IModelDeltaDecoration, ITextModel, MinimapPosition, OverviewRulerLane, TrackedRangeStickiness } from 'vs/editor/common/model';
|
||||
|
@ -96,7 +96,7 @@ export class UnicodeHighlighter extends Disposable implements IEditorContributio
|
|||
ambiguousCharacters: options.ambiguousCharacters,
|
||||
invisibleCharacters: options.invisibleCharacters,
|
||||
includeComments: options.includeComments,
|
||||
excludedCharacters: options.allowedCharacters,
|
||||
allowedCodePoints: Array.from(options.allowedCharacters).map(c => c.codePointAt(0)!),
|
||||
};
|
||||
|
||||
if (this._editorWorkerService.canComputeUnicodeHighlights(this._editor.getModel().uri)) {
|
||||
|
@ -118,24 +118,27 @@ export interface UnicodeHighlighterDecorationInfo {
|
|||
reason: UnicodeHighlighterReason;
|
||||
}
|
||||
|
||||
function resolveOptions(_trusted: boolean, options: Readonly<IUnicodeHighlightOptions>): Required<Readonly<IUnicodeHighlightOptions>> {
|
||||
type RemoveDeriveFromWorkspaceTrust<T> = T extends DeriveFromWorkspaceTrust ? never : T;
|
||||
|
||||
function resolveOptions(_trusted: boolean, options: InternalUnicodeHighlightOptions): { [TKey in keyof InternalUnicodeHighlightOptions]: RemoveDeriveFromWorkspaceTrust<InternalUnicodeHighlightOptions[TKey]> } {
|
||||
/*
|
||||
// TODO@hediet enable some settings by default (depending on trust).
|
||||
// For now, make it opt in, so there is some time to test it without breaking anyone.
|
||||
|
||||
return {
|
||||
nonBasicASCII: options.nonBasicASCII ?? (trusted ? false : true),
|
||||
ambiguousCharacters: options.ambiguousCharacters ?? (trusted ? false : true),
|
||||
invisibleCharacters: options.invisibleCharacters ?? (trusted ? true : true),
|
||||
excludeComments: options.excludeComments ?? (trusted ? true : false),
|
||||
nonBasicASCII: options.nonBasicASCII !== deriveFromWorkspaceTrust ? options.nonBasicASCII : (trusted ? false : true),
|
||||
ambiguousCharacters: options.ambiguousCharacters !== deriveFromWorkspaceTrust ? options.ambiguousCharacters : (trusted ? false : true),
|
||||
invisibleCharacters: options.invisibleCharacters !== deriveFromWorkspaceTrust ? options.invisibleCharacters : (trusted ? true : true),
|
||||
includeComments: options.includeComments !== deriveFromWorkspaceTrust ? options.includeComments : (trusted ? true : false),
|
||||
allowedCharacters: options.allowedCharacters ?? [],
|
||||
};
|
||||
*/
|
||||
|
||||
return {
|
||||
nonBasicASCII: options.nonBasicASCII ?? false,
|
||||
ambiguousCharacters: options.ambiguousCharacters ?? false,
|
||||
invisibleCharacters: options.invisibleCharacters ?? false,
|
||||
includeComments: options.includeComments ?? true,
|
||||
nonBasicASCII: options.nonBasicASCII !== deriveFromWorkspaceTrust ? options.nonBasicASCII : false,
|
||||
ambiguousCharacters: options.ambiguousCharacters !== deriveFromWorkspaceTrust ? options.ambiguousCharacters : false,
|
||||
invisibleCharacters: options.invisibleCharacters !== deriveFromWorkspaceTrust ? options.invisibleCharacters : false,
|
||||
includeComments: options.includeComments !== deriveFromWorkspaceTrust ? options.includeComments : true,
|
||||
allowedCharacters: options.allowedCharacters ?? [],
|
||||
};
|
||||
}
|
||||
|
|
17
src/vs/monaco.d.ts
vendored
17
src/vs/monaco.d.ts
vendored
|
@ -3863,15 +3863,20 @@ declare namespace monaco.editor {
|
|||
readonly scrollByPage: boolean;
|
||||
}
|
||||
|
||||
export type DeriveFromWorkspaceTrust = 'deriveFromWorkspaceTrust';
|
||||
|
||||
/**
|
||||
* Configuration options for unicode highlighting.
|
||||
*/
|
||||
export interface IUnicodeHighlightOptions {
|
||||
nonBasicASCII?: boolean;
|
||||
invisibleCharacters?: boolean;
|
||||
ambiguousCharacters?: boolean;
|
||||
includeComments?: boolean;
|
||||
allowedCharacters?: string[];
|
||||
nonBasicASCII?: boolean | DeriveFromWorkspaceTrust;
|
||||
invisibleCharacters?: boolean | DeriveFromWorkspaceTrust;
|
||||
ambiguousCharacters?: boolean | DeriveFromWorkspaceTrust;
|
||||
includeComments?: boolean | DeriveFromWorkspaceTrust;
|
||||
/**
|
||||
* A list of allowed code points in a single string.
|
||||
*/
|
||||
allowedCharacters?: string;
|
||||
}
|
||||
|
||||
export interface IInlineSuggestOptions {
|
||||
|
@ -4365,7 +4370,7 @@ declare namespace monaco.editor {
|
|||
suggestSelection: IEditorOption<EditorOption.suggestSelection, 'first' | 'recentlyUsed' | 'recentlyUsedByPrefix'>;
|
||||
tabCompletion: IEditorOption<EditorOption.tabCompletion, 'on' | 'off' | 'onlySnippets'>;
|
||||
tabIndex: IEditorOption<EditorOption.tabIndex, number>;
|
||||
unicodeHighlight: IEditorOption<EditorOption.unicodeHighlighting, Readonly<IUnicodeHighlightOptions>>;
|
||||
unicodeHighlight: IEditorOption<EditorOption.unicodeHighlighting, Required<Readonly<IUnicodeHighlightOptions>>>;
|
||||
unusualLineTerminators: IEditorOption<EditorOption.unusualLineTerminators, 'auto' | 'off' | 'prompt'>;
|
||||
useShadowDOM: IEditorOption<EditorOption.useShadowDOM, boolean>;
|
||||
useTabStops: IEditorOption<EditorOption.useTabStops, boolean>;
|
||||
|
|
Loading…
Reference in a new issue