Skip to content

Commit

Permalink
Add editor.renderValidationDecorations (#89057)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Jan 24, 2020
1 parent a9a5fd0 commit c7cc30c
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 78 deletions.
4 changes: 2 additions & 2 deletions src/vs/editor/browser/widget/codeEditorWidget.ts
Expand Up @@ -22,7 +22,7 @@ import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService
import { ICommandDelegate } from 'vs/editor/browser/view/viewController';
import { IContentWidgetData, IOverlayWidgetData, View } from 'vs/editor/browser/view/viewImpl';
import { ViewOutgoingEvents } from 'vs/editor/browser/view/viewOutgoingEvents';
import { ConfigurationChangedEvent, EditorLayoutInfo, IEditorOptions, EditorOption, IComputedEditorOptions, FindComputedEditorOptionValueById, IEditorConstructionOptions } from 'vs/editor/common/config/editorOptions';
import { ConfigurationChangedEvent, EditorLayoutInfo, IEditorOptions, EditorOption, IComputedEditorOptions, FindComputedEditorOptionValueById, IEditorConstructionOptions, shouldRenderValidationDecorations } from 'vs/editor/common/config/editorOptions';
import { Cursor, CursorStateChangedEvent } from 'vs/editor/common/controller/cursor';
import { CursorColumns, ICursors } from 'vs/editor/common/controller/cursorCommon';
import { ICursorPositionChangedEvent, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
Expand Down Expand Up @@ -1064,7 +1064,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
if (!this._modelData) {
return null;
}
return this._modelData.model.getLineDecorations(lineNumber, this._id, this._configuration.options.get(EditorOption.readOnly));
return this._modelData.model.getLineDecorations(lineNumber, this._id, shouldRenderValidationDecorations(this._configuration.options));
}

public deltaDecorations(oldDecorations: string[], newDecorations: IModelDeltaDecoration[]): string[] {
Expand Down
26 changes: 26 additions & 0 deletions src/vs/editor/common/config/editorOptions.ts
Expand Up @@ -135,6 +135,11 @@ export interface IEditorOptions {
* Defaults to false.
*/
readOnly?: boolean;
/**
* Should the editor render validation decorations.
* Defaults to editable.
*/
renderValidationDecorations?: 'editable' | 'on' | 'off';
/**
* Control the behavior and rendering of the scrollbars.
*/
Expand Down Expand Up @@ -2334,6 +2339,21 @@ class EditorRenderLineNumbersOption extends BaseEditorOption<EditorOption.lineNu

//#endregion

//#region renderValidationDecorations

/**
* @internal
*/
export function shouldRenderValidationDecorations(options: IComputedEditorOptions): boolean {
const renderValidationDecorations = options.get(EditorOption.renderValidationDecorations);
if (renderValidationDecorations === 'editable') {
return !options.get(EditorOption.readOnly);
}
return renderValidationDecorations === 'on' ? true : false;
}

//#endregion

//#region rulers

class EditorRulers extends SimpleEditorOption<EditorOption.rulers, number[]> {
Expand Down Expand Up @@ -3168,6 +3188,7 @@ export const enum EditorOption {
renderIndentGuides,
renderFinalNewline,
renderLineHighlight,
renderValidationDecorations,
renderWhitespace,
revealHorizontalRightPadding,
roundedSelection,
Expand Down Expand Up @@ -3586,6 +3607,11 @@ export const EditorOptions = {
description: nls.localize('renderLineHighlight', "Controls how the editor should render the current line highlight.")
}
)),
renderValidationDecorations: register(new EditorStringEnumOption(
EditorOption.renderValidationDecorations, 'renderValidationDecorations',
'editable' as 'editable' | 'on' | 'off',
['editable', 'on', 'off'] as const
)),
renderWhitespace: register(new EditorStringEnumOption(
EditorOption.renderWhitespace, 'renderWhitespace',
'none' as 'none' | 'boundary' | 'selection' | 'all',
Expand Down
73 changes: 37 additions & 36 deletions src/vs/editor/common/standalone/standaloneEnums.ts
Expand Up @@ -238,42 +238,43 @@ export enum EditorOption {
renderIndentGuides = 70,
renderFinalNewline = 71,
renderLineHighlight = 72,
renderWhitespace = 73,
revealHorizontalRightPadding = 74,
roundedSelection = 75,
rulers = 76,
scrollbar = 77,
scrollBeyondLastColumn = 78,
scrollBeyondLastLine = 79,
selectionClipboard = 80,
selectionHighlight = 81,
selectOnLineNumbers = 82,
semanticHighlighting = 83,
showFoldingControls = 84,
showUnused = 85,
snippetSuggestions = 86,
smoothScrolling = 87,
stopRenderingLineAfter = 88,
suggest = 89,
suggestFontSize = 90,
suggestLineHeight = 91,
suggestOnTriggerCharacters = 92,
suggestSelection = 93,
tabCompletion = 94,
useTabStops = 95,
wordSeparators = 96,
wordWrap = 97,
wordWrapBreakAfterCharacters = 98,
wordWrapBreakBeforeCharacters = 99,
wordWrapColumn = 100,
wordWrapMinified = 101,
wrappingIndent = 102,
wrappingAlgorithm = 103,
editorClassName = 104,
pixelRatio = 105,
tabFocusMode = 106,
layoutInfo = 107,
wrappingInfo = 108
renderValidationDecorations = 73,
renderWhitespace = 74,
revealHorizontalRightPadding = 75,
roundedSelection = 76,
rulers = 77,
scrollbar = 78,
scrollBeyondLastColumn = 79,
scrollBeyondLastLine = 80,
selectionClipboard = 81,
selectionHighlight = 82,
selectOnLineNumbers = 83,
semanticHighlighting = 84,
showFoldingControls = 85,
showUnused = 86,
snippetSuggestions = 87,
smoothScrolling = 88,
stopRenderingLineAfter = 89,
suggest = 90,
suggestFontSize = 91,
suggestLineHeight = 92,
suggestOnTriggerCharacters = 93,
suggestSelection = 94,
tabCompletion = 95,
useTabStops = 96,
wordSeparators = 97,
wordWrap = 98,
wordWrapBreakAfterCharacters = 99,
wordWrapBreakBeforeCharacters = 100,
wordWrapColumn = 101,
wordWrapMinified = 102,
wrappingIndent = 103,
wrappingAlgorithm = 104,
editorClassName = 105,
pixelRatio = 106,
tabFocusMode = 107,
layoutInfo = 108,
wrappingInfo = 109
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/vs/editor/common/viewModel/viewModelDecorations.ts
Expand Up @@ -10,7 +10,7 @@ import * as editorCommon from 'vs/editor/common/editorCommon';
import { IModelDecoration, ITextModel } from 'vs/editor/common/model';
import { IViewModelLinesCollection } from 'vs/editor/common/viewModel/splitLinesCollection';
import { ICoordinatesConverter, InlineDecoration, InlineDecorationType, ViewModelDecoration } from 'vs/editor/common/viewModel/viewModel';
import { EditorOption } from 'vs/editor/common/config/editorOptions';
import { shouldRenderValidationDecorations } from 'vs/editor/common/config/editorOptions';

export interface IDecorationsViewportData {
/**
Expand Down Expand Up @@ -104,7 +104,7 @@ export class ViewModelDecorations implements IDisposable {
}

private _getDecorationsViewportData(viewportRange: Range): IDecorationsViewportData {
const modelDecorations = this._linesCollection.getDecorationsInRange(viewportRange, this.editorId, this.configuration.options.get(EditorOption.readOnly));
const modelDecorations = this._linesCollection.getDecorationsInRange(viewportRange, this.editorId, shouldRenderValidationDecorations(this.configuration.options));
const startLineNumber = viewportRange.startLineNumber;
const endLineNumber = viewportRange.endLineNumber;

Expand Down
4 changes: 2 additions & 2 deletions src/vs/editor/common/viewModel/viewModelImpl.ts
Expand Up @@ -6,7 +6,7 @@
import { Color } from 'vs/base/common/color';
import { IDisposable } from 'vs/base/common/lifecycle';
import * as strings from 'vs/base/common/strings';
import { ConfigurationChangedEvent, EDITOR_FONT_DEFAULTS, EditorOption } from 'vs/editor/common/config/editorOptions';
import { ConfigurationChangedEvent, EDITOR_FONT_DEFAULTS, EditorOption, shouldRenderValidationDecorations } from 'vs/editor/common/config/editorOptions';
import { IPosition, Position } from 'vs/editor/common/core/position';
import { IRange, Range } from 'vs/editor/common/core/range';
import { IConfiguration, IViewState } from 'vs/editor/common/editorCommon';
Expand Down Expand Up @@ -596,7 +596,7 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel
}

public getAllOverviewRulerDecorations(theme: ITheme): IOverviewRulerDecorations {
return this.lines.getAllOverviewRulerDecorations(this.editorId, this.configuration.options.get(EditorOption.readOnly), theme);
return this.lines.getAllOverviewRulerDecorations(this.editorId, shouldRenderValidationDecorations(this.configuration.options), theme);
}

public invalidateOverviewRulerColorCache(): void {
Expand Down
79 changes: 43 additions & 36 deletions src/vs/monaco.d.ts
Expand Up @@ -2609,6 +2609,11 @@ declare namespace monaco.editor {
* Defaults to false.
*/
readOnly?: boolean;
/**
* Should the editor render validation decorations.
* Defaults to editable.
*/
renderValidationDecorations?: 'editable' | 'on' | 'off';
/**
* Control the behavior and rendering of the scrollbars.
*/
Expand Down Expand Up @@ -3753,42 +3758,43 @@ declare namespace monaco.editor {
renderIndentGuides = 70,
renderFinalNewline = 71,
renderLineHighlight = 72,
renderWhitespace = 73,
revealHorizontalRightPadding = 74,
roundedSelection = 75,
rulers = 76,
scrollbar = 77,
scrollBeyondLastColumn = 78,
scrollBeyondLastLine = 79,
selectionClipboard = 80,
selectionHighlight = 81,
selectOnLineNumbers = 82,
semanticHighlighting = 83,
showFoldingControls = 84,
showUnused = 85,
snippetSuggestions = 86,
smoothScrolling = 87,
stopRenderingLineAfter = 88,
suggest = 89,
suggestFontSize = 90,
suggestLineHeight = 91,
suggestOnTriggerCharacters = 92,
suggestSelection = 93,
tabCompletion = 94,
useTabStops = 95,
wordSeparators = 96,
wordWrap = 97,
wordWrapBreakAfterCharacters = 98,
wordWrapBreakBeforeCharacters = 99,
wordWrapColumn = 100,
wordWrapMinified = 101,
wrappingIndent = 102,
wrappingAlgorithm = 103,
editorClassName = 104,
pixelRatio = 105,
tabFocusMode = 106,
layoutInfo = 107,
wrappingInfo = 108
renderValidationDecorations = 73,
renderWhitespace = 74,
revealHorizontalRightPadding = 75,
roundedSelection = 76,
rulers = 77,
scrollbar = 78,
scrollBeyondLastColumn = 79,
scrollBeyondLastLine = 80,
selectionClipboard = 81,
selectionHighlight = 82,
selectOnLineNumbers = 83,
semanticHighlighting = 84,
showFoldingControls = 85,
showUnused = 86,
snippetSuggestions = 87,
smoothScrolling = 88,
stopRenderingLineAfter = 89,
suggest = 90,
suggestFontSize = 91,
suggestLineHeight = 92,
suggestOnTriggerCharacters = 93,
suggestSelection = 94,
tabCompletion = 95,
useTabStops = 96,
wordSeparators = 97,
wordWrap = 98,
wordWrapBreakAfterCharacters = 99,
wordWrapBreakBeforeCharacters = 100,
wordWrapColumn = 101,
wordWrapMinified = 102,
wrappingIndent = 103,
wrappingAlgorithm = 104,
editorClassName = 105,
pixelRatio = 106,
tabFocusMode = 107,
layoutInfo = 108,
wrappingInfo = 109
}
export const EditorOptions: {
acceptSuggestionOnCommitCharacter: IEditorOption<EditorOption.acceptSuggestionOnCommitCharacter, boolean>;
Expand Down Expand Up @@ -3864,6 +3870,7 @@ declare namespace monaco.editor {
renderIndentGuides: IEditorOption<EditorOption.renderIndentGuides, boolean>;
renderFinalNewline: IEditorOption<EditorOption.renderFinalNewline, boolean>;
renderLineHighlight: IEditorOption<EditorOption.renderLineHighlight, 'all' | 'line' | 'none' | 'gutter'>;
renderValidationDecorations: IEditorOption<EditorOption.renderValidationDecorations, 'on' | 'off' | 'editable'>;
renderWhitespace: IEditorOption<EditorOption.renderWhitespace, 'all' | 'none' | 'boundary' | 'selection'>;
revealHorizontalRightPadding: IEditorOption<EditorOption.revealHorizontalRightPadding, number>;
roundedSelection: IEditorOption<EditorOption.roundedSelection, boolean>;
Expand Down

0 comments on commit c7cc30c

Please sign in to comment.