Merge x-doc and occurrence setting, merge word based suggestion settings (#197690)

* change x-doc setting for readability

* Update editor configuration options for word-based
suggestions and occurrence highlighting + settings migration

* cleanup
This commit is contained in:
Michael Lively 2023-11-10 13:17:10 -08:00 committed by GitHub
parent 5d0263b099
commit 6f2f46ec25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 183 additions and 196 deletions

View file

@ -91,6 +91,8 @@ registerSimpleEditorSettingMigration('autoIndent', [[false, 'advanced'], [true,
registerSimpleEditorSettingMigration('matchBrackets', [[true, 'always'], [false, 'never']]);
registerSimpleEditorSettingMigration('renderFinalNewline', [[true, 'on'], [false, 'off']]);
registerSimpleEditorSettingMigration('cursorSmoothCaretAnimation', [[true, 'on'], [false, 'off']]);
registerSimpleEditorSettingMigration('occurrencesHighlight', [[true, 'singleFile'], [false, 'off']]);
registerSimpleEditorSettingMigration('wordBasedSuggestions', [[true, 'matchingDocuments'], [false, 'off']]);
registerEditorSettingMigration('autoClosingBrackets', (value, read, write) => {
if (value === false) {

View file

@ -213,16 +213,15 @@ class WordBasedCompletionItemProvider implements languages.CompletionItemProvide
async provideCompletionItems(model: ITextModel, position: Position): Promise<languages.CompletionList | undefined> {
type WordBasedSuggestionsConfig = {
wordBasedSuggestions?: boolean;
wordBasedSuggestionsMode?: 'currentDocument' | 'matchingDocuments' | 'allDocuments';
wordBasedSuggestions?: 'off' | 'currentDocument' | 'matchingDocuments' | 'allDocuments';
};
const config = this._configurationService.getValue<WordBasedSuggestionsConfig>(model.uri, position, 'editor');
if (!config.wordBasedSuggestions) {
if (config.wordBasedSuggestions === 'off') {
return undefined;
}
const models: URI[] = [];
if (config.wordBasedSuggestionsMode === 'currentDocument') {
if (config.wordBasedSuggestions === 'currentDocument') {
// only current file and only if not too large
if (canSyncModel(this._modelService, model.uri)) {
models.push(model.uri);
@ -236,7 +235,7 @@ class WordBasedCompletionItemProvider implements languages.CompletionItemProvide
if (candidate === model) {
models.unshift(candidate.uri);
} else if (config.wordBasedSuggestionsMode === 'allDocuments' || candidate.getLanguageId() === model.getLanguageId()) {
} else if (config.wordBasedSuggestions === 'allDocuments' || candidate.getLanguageId() === model.getLanguageId()) {
models.push(candidate.uri);
}
}

View file

@ -62,19 +62,15 @@ const editorConfiguration: IConfigurationNode = {
description: nls.localize('largeFileOptimizations', "Special handling for large files to disable certain memory intensive features.")
},
'editor.wordBasedSuggestions': {
type: 'boolean',
default: true,
description: nls.localize('wordBasedSuggestions', "Controls whether completions should be computed based on words in the document.")
},
'editor.wordBasedSuggestionsMode': {
enum: ['currentDocument', 'matchingDocuments', 'allDocuments'],
enum: ['off', 'currentDocument', 'matchingDocuments', 'allDocuments'],
default: 'matchingDocuments',
enumDescriptions: [
nls.localize('wordBasedSuggestionsMode.currentDocument', 'Only suggest words from the active document.'),
nls.localize('wordBasedSuggestionsMode.matchingDocuments', 'Suggest words from all open documents of the same language.'),
nls.localize('wordBasedSuggestionsMode.allDocuments', 'Suggest words from all open documents.')
nls.localize('wordBasedSuggestions.off', 'Turn off Word Based Suggestions.'),
nls.localize('wordBasedSuggestions.currentDocument', 'Only suggest words from the active document.'),
nls.localize('wordBasedSuggestions.matchingDocuments', 'Suggest words from all open documents of the same language.'),
nls.localize('wordBasedSuggestions.allDocuments', 'Suggest words from all open documents.')
],
description: nls.localize('wordBasedSuggestionsMode', "Controls from which documents word based completions are computed.")
description: nls.localize('wordBasedSuggestions', "Controls whether completions should be computed based on words in the document and from which documents they are computed.")
},
'editor.semanticHighlighting.enabled': {
enum: [true, false, 'configuredByTheme'],

View file

@ -559,14 +559,12 @@ export interface IEditorOptions {
selectionHighlight?: boolean;
/**
* Enable semantic occurrences highlight.
* Defaults to true.
* Defaults to 'singleFile'.
* 'off' disables occurrence highlighting
* 'singleFile' triggers occurrence highlighting in the current document
* 'multiFile' triggers occurrence highlighting across valid open documents
*/
occurrencesHighlight?: boolean;
/**
* Enable semantic occurrences highlight.
* Defaults to true.
*/
multiDocumentOccurrencesHighlight?: boolean;
occurrencesHighlight?: 'off' | 'singleFile' | 'multiFile';
/**
* Show code lens
* Defaults to true.
@ -5121,7 +5119,6 @@ export const enum EditorOption {
multiCursorModifier,
multiCursorPaste,
multiCursorLimit,
multiDocumentOccurrencesHighlight,
occurrencesHighlight,
overviewRulerBorder,
overviewRulerLanes,
@ -5618,13 +5615,18 @@ export const EditorOptions = {
markdownDescription: nls.localize('multiCursorLimit', "Controls the max number of cursors that can be in an active editor at once.")
}
)),
occurrencesHighlight: register(new EditorBooleanOption(
EditorOption.occurrencesHighlight, 'occurrencesHighlight', true,
{ description: nls.localize('occurrencesHighlight', "Controls whether the editor should highlight semantic symbol occurrences.") }
)),
multiDocumentOccurrencesHighlight: register(new EditorBooleanOption(
EditorOption.multiDocumentOccurrencesHighlight, 'multiDocumentOccurrencesHighlight', false,
{ description: nls.localize('multiDocumentOccurrencesHighlight', "Experimental: Controls whether the editor should highlight word occurrences accross multiple open editors.") }
occurrencesHighlight: register(new EditorStringEnumOption(
EditorOption.occurrencesHighlight, 'occurrencesHighlight',
'singleFile' as 'off' | 'singleFile' | 'multiFile',
['off', 'singleFile', 'multiFile'] as const,
{
markdownEnumDescriptions: [
nls.localize('occurrencesHighlight.off', "Does not highlight occurrences."),
nls.localize('occurrencesHighlight.singleFile', "Highlights occurrences only in the current file."),
nls.localize('occurrencesHighlight.multiFile', "Experimental: Highlights occurrences across all valid open files.")
],
markdownDescription: nls.localize('occurrencesHighlight', "Controls whether occurrences should be highlighted across open files.")
}
)),
overviewRulerBorder: register(new EditorBooleanOption(
EditorOption.overviewRulerBorder, 'overviewRulerBorder', true,

View file

@ -253,75 +253,74 @@ export enum EditorOption {
multiCursorModifier = 77,
multiCursorPaste = 78,
multiCursorLimit = 79,
multiDocumentOccurrencesHighlight = 80,
occurrencesHighlight = 81,
overviewRulerBorder = 82,
overviewRulerLanes = 83,
padding = 84,
pasteAs = 85,
parameterHints = 86,
peekWidgetDefaultFocus = 87,
definitionLinkOpensInPeek = 88,
quickSuggestions = 89,
quickSuggestionsDelay = 90,
readOnly = 91,
readOnlyMessage = 92,
renameOnType = 93,
renderControlCharacters = 94,
renderFinalNewline = 95,
renderLineHighlight = 96,
renderLineHighlightOnlyWhenFocus = 97,
renderValidationDecorations = 98,
renderWhitespace = 99,
revealHorizontalRightPadding = 100,
roundedSelection = 101,
rulers = 102,
scrollbar = 103,
scrollBeyondLastColumn = 104,
scrollBeyondLastLine = 105,
scrollPredominantAxis = 106,
selectionClipboard = 107,
selectionHighlight = 108,
selectOnLineNumbers = 109,
showFoldingControls = 110,
showUnused = 111,
snippetSuggestions = 112,
smartSelect = 113,
smoothScrolling = 114,
stickyScroll = 115,
stickyTabStops = 116,
stopRenderingLineAfter = 117,
suggest = 118,
suggestFontSize = 119,
suggestLineHeight = 120,
suggestOnTriggerCharacters = 121,
suggestSelection = 122,
tabCompletion = 123,
tabIndex = 124,
unicodeHighlighting = 125,
unusualLineTerminators = 126,
useShadowDOM = 127,
useTabStops = 128,
wordBreak = 129,
wordSeparators = 130,
wordWrap = 131,
wordWrapBreakAfterCharacters = 132,
wordWrapBreakBeforeCharacters = 133,
wordWrapColumn = 134,
wordWrapOverride1 = 135,
wordWrapOverride2 = 136,
wrappingIndent = 137,
wrappingStrategy = 138,
showDeprecated = 139,
inlayHints = 140,
editorClassName = 141,
pixelRatio = 142,
tabFocusMode = 143,
layoutInfo = 144,
wrappingInfo = 145,
defaultColorDecorators = 146,
colorDecoratorsActivatedOn = 147,
inlineCompletionsAccessibilityVerbose = 148
occurrencesHighlight = 80,
overviewRulerBorder = 81,
overviewRulerLanes = 82,
padding = 83,
pasteAs = 84,
parameterHints = 85,
peekWidgetDefaultFocus = 86,
definitionLinkOpensInPeek = 87,
quickSuggestions = 88,
quickSuggestionsDelay = 89,
readOnly = 90,
readOnlyMessage = 91,
renameOnType = 92,
renderControlCharacters = 93,
renderFinalNewline = 94,
renderLineHighlight = 95,
renderLineHighlightOnlyWhenFocus = 96,
renderValidationDecorations = 97,
renderWhitespace = 98,
revealHorizontalRightPadding = 99,
roundedSelection = 100,
rulers = 101,
scrollbar = 102,
scrollBeyondLastColumn = 103,
scrollBeyondLastLine = 104,
scrollPredominantAxis = 105,
selectionClipboard = 106,
selectionHighlight = 107,
selectOnLineNumbers = 108,
showFoldingControls = 109,
showUnused = 110,
snippetSuggestions = 111,
smartSelect = 112,
smoothScrolling = 113,
stickyScroll = 114,
stickyTabStops = 115,
stopRenderingLineAfter = 116,
suggest = 117,
suggestFontSize = 118,
suggestLineHeight = 119,
suggestOnTriggerCharacters = 120,
suggestSelection = 121,
tabCompletion = 122,
tabIndex = 123,
unicodeHighlighting = 124,
unusualLineTerminators = 125,
useShadowDOM = 126,
useTabStops = 127,
wordBreak = 128,
wordSeparators = 129,
wordWrap = 130,
wordWrapBreakAfterCharacters = 131,
wordWrapBreakBeforeCharacters = 132,
wordWrapColumn = 133,
wordWrapOverride1 = 134,
wordWrapOverride2 = 135,
wrappingIndent = 136,
wrappingStrategy = 137,
showDeprecated = 138,
inlayHints = 139,
editorClassName = 140,
pixelRatio = 141,
tabFocusMode = 142,
layoutInfo = 143,
wrappingInfo = 144,
defaultColorDecorators = 145,
colorDecoratorsActivatedOn = 146,
inlineCompletionsAccessibilityVerbose = 147
}
/**

View file

@ -1037,7 +1037,8 @@ export class SelectionHighlighter extends Disposable implements IEditorContribut
}
}
const hasSemanticHighlights = this._languageFeaturesService.documentHighlightProvider.has(model) && this.editor.getOption(EditorOption.occurrencesHighlight);
const occurrenceHighlighting: boolean = this.editor.getOption(EditorOption.occurrencesHighlight) !== 'off';
const hasSemanticHighlights = this._languageFeaturesService.documentHighlightProvider.has(model) && occurrenceHighlighting;
const decorations = matches.map(r => {
return {
range: r,

View file

@ -256,8 +256,7 @@ class WordHighlighter {
private readonly editor: IActiveCodeEditor;
private readonly providers: LanguageFeatureRegistry<DocumentHighlightProvider>;
private readonly multiDocumentProviders: LanguageFeatureRegistry<MultiDocumentHighlightProvider>;
private occurrencesHighlight: boolean;
private multiDocumentOccurrencesHighlight: boolean;
private occurrencesHighlight: string;
private readonly model: ITextModel;
private readonly decorations: IEditorDecorationsCollection;
private readonly toUnhook = new DisposableStore();
@ -285,7 +284,6 @@ class WordHighlighter {
this._hasWordHighlights = ctxHasWordHighlights.bindTo(contextKeyService);
this._ignorePositionChangeEvent = false;
this.occurrencesHighlight = this.editor.getOption(EditorOption.occurrencesHighlight);
this.multiDocumentOccurrencesHighlight = this.editor.getOption(EditorOption.multiDocumentOccurrencesHighlight);
this.model = this.editor.getModel();
this.toUnhook.add(editor.onDidChangeCursorPosition((e: ICursorPositionChangedEvent) => {
if (this._ignorePositionChangeEvent) {
@ -293,7 +291,7 @@ class WordHighlighter {
return;
}
if (!this.occurrencesHighlight) {
if (this.occurrencesHighlight === 'off') {
// Early exit if nothing needs to be done!
// Leave some form of early exit check here if you wish to continue being a cursor position change listener ;)
return;
@ -319,12 +317,6 @@ class WordHighlighter {
this.occurrencesHighlight = newValue;
this._stopAll();
}
const newMultiDocumentValue = this.editor.getOption(EditorOption.multiDocumentOccurrencesHighlight);
if (this.multiDocumentOccurrencesHighlight !== newMultiDocumentValue) {
this.multiDocumentOccurrencesHighlight = newMultiDocumentValue;
this._stopAll();
}
}));
this.decorations = this.editor.createDecorationsCollection();
@ -346,14 +338,14 @@ class WordHighlighter {
}
public restore(): void {
if (!this.occurrencesHighlight) {
if (this.occurrencesHighlight === 'off') {
return;
}
this._run();
}
public stop(): void {
if (!this.occurrencesHighlight) {
if (this.occurrencesHighlight === 'off') {
return;
}
@ -513,7 +505,7 @@ class WordHighlighter {
private _onPositionChanged(e: ICursorPositionChangedEvent): void {
// disabled
if (!this.occurrencesHighlight) {
if (this.occurrencesHighlight === 'off') {
this._stopAll();
return;
}
@ -586,7 +578,7 @@ class WordHighlighter {
}
// multi-doc OFF
if (!this.multiDocumentOccurrencesHighlight) {
if (this.occurrencesHighlight === 'singleFile') {
return [];
}

View file

@ -120,7 +120,7 @@ export interface IGlobalEditorOptions {
* Controls whether completions should be computed based on words in the document.
* Defaults to true.
*/
wordBasedSuggestions?: boolean;
wordBasedSuggestions?: 'off' | 'currentDocument' | 'matchingDocuments' | 'allDocuments';
/**
* Controls whether word based completions should be included from opened documents of the same language or any language.
*/

154
src/vs/monaco.d.ts vendored
View file

@ -1317,7 +1317,7 @@ declare namespace monaco.editor {
* Controls whether completions should be computed based on words in the document.
* Defaults to true.
*/
wordBasedSuggestions?: boolean;
wordBasedSuggestions?: 'off' | 'currentDocument' | 'matchingDocuments' | 'allDocuments';
/**
* Controls whether word based completions should be included from opened documents of the same language or any language.
*/
@ -3538,14 +3538,12 @@ declare namespace monaco.editor {
selectionHighlight?: boolean;
/**
* Enable semantic occurrences highlight.
* Defaults to true.
* Defaults to 'singleFile'.
* 'off' disables occurrence highlighting
* 'singleFile' triggers occurrence highlighting in the current document
* 'multiFile' triggers occurrence highlighting across valid open documents
*/
occurrencesHighlight?: boolean;
/**
* Enable semantic occurrences highlight.
* Defaults to true.
*/
multiDocumentOccurrencesHighlight?: boolean;
occurrencesHighlight?: 'off' | 'singleFile' | 'multiFile';
/**
* Show code lens
* Defaults to true.
@ -4801,75 +4799,74 @@ declare namespace monaco.editor {
multiCursorModifier = 77,
multiCursorPaste = 78,
multiCursorLimit = 79,
multiDocumentOccurrencesHighlight = 80,
occurrencesHighlight = 81,
overviewRulerBorder = 82,
overviewRulerLanes = 83,
padding = 84,
pasteAs = 85,
parameterHints = 86,
peekWidgetDefaultFocus = 87,
definitionLinkOpensInPeek = 88,
quickSuggestions = 89,
quickSuggestionsDelay = 90,
readOnly = 91,
readOnlyMessage = 92,
renameOnType = 93,
renderControlCharacters = 94,
renderFinalNewline = 95,
renderLineHighlight = 96,
renderLineHighlightOnlyWhenFocus = 97,
renderValidationDecorations = 98,
renderWhitespace = 99,
revealHorizontalRightPadding = 100,
roundedSelection = 101,
rulers = 102,
scrollbar = 103,
scrollBeyondLastColumn = 104,
scrollBeyondLastLine = 105,
scrollPredominantAxis = 106,
selectionClipboard = 107,
selectionHighlight = 108,
selectOnLineNumbers = 109,
showFoldingControls = 110,
showUnused = 111,
snippetSuggestions = 112,
smartSelect = 113,
smoothScrolling = 114,
stickyScroll = 115,
stickyTabStops = 116,
stopRenderingLineAfter = 117,
suggest = 118,
suggestFontSize = 119,
suggestLineHeight = 120,
suggestOnTriggerCharacters = 121,
suggestSelection = 122,
tabCompletion = 123,
tabIndex = 124,
unicodeHighlighting = 125,
unusualLineTerminators = 126,
useShadowDOM = 127,
useTabStops = 128,
wordBreak = 129,
wordSeparators = 130,
wordWrap = 131,
wordWrapBreakAfterCharacters = 132,
wordWrapBreakBeforeCharacters = 133,
wordWrapColumn = 134,
wordWrapOverride1 = 135,
wordWrapOverride2 = 136,
wrappingIndent = 137,
wrappingStrategy = 138,
showDeprecated = 139,
inlayHints = 140,
editorClassName = 141,
pixelRatio = 142,
tabFocusMode = 143,
layoutInfo = 144,
wrappingInfo = 145,
defaultColorDecorators = 146,
colorDecoratorsActivatedOn = 147,
inlineCompletionsAccessibilityVerbose = 148
occurrencesHighlight = 80,
overviewRulerBorder = 81,
overviewRulerLanes = 82,
padding = 83,
pasteAs = 84,
parameterHints = 85,
peekWidgetDefaultFocus = 86,
definitionLinkOpensInPeek = 87,
quickSuggestions = 88,
quickSuggestionsDelay = 89,
readOnly = 90,
readOnlyMessage = 91,
renameOnType = 92,
renderControlCharacters = 93,
renderFinalNewline = 94,
renderLineHighlight = 95,
renderLineHighlightOnlyWhenFocus = 96,
renderValidationDecorations = 97,
renderWhitespace = 98,
revealHorizontalRightPadding = 99,
roundedSelection = 100,
rulers = 101,
scrollbar = 102,
scrollBeyondLastColumn = 103,
scrollBeyondLastLine = 104,
scrollPredominantAxis = 105,
selectionClipboard = 106,
selectionHighlight = 107,
selectOnLineNumbers = 108,
showFoldingControls = 109,
showUnused = 110,
snippetSuggestions = 111,
smartSelect = 112,
smoothScrolling = 113,
stickyScroll = 114,
stickyTabStops = 115,
stopRenderingLineAfter = 116,
suggest = 117,
suggestFontSize = 118,
suggestLineHeight = 119,
suggestOnTriggerCharacters = 120,
suggestSelection = 121,
tabCompletion = 122,
tabIndex = 123,
unicodeHighlighting = 124,
unusualLineTerminators = 125,
useShadowDOM = 126,
useTabStops = 127,
wordBreak = 128,
wordSeparators = 129,
wordWrap = 130,
wordWrapBreakAfterCharacters = 131,
wordWrapBreakBeforeCharacters = 132,
wordWrapColumn = 133,
wordWrapOverride1 = 134,
wordWrapOverride2 = 135,
wrappingIndent = 136,
wrappingStrategy = 137,
showDeprecated = 138,
inlayHints = 139,
editorClassName = 140,
pixelRatio = 141,
tabFocusMode = 142,
layoutInfo = 143,
wrappingInfo = 144,
defaultColorDecorators = 145,
colorDecoratorsActivatedOn = 146,
inlineCompletionsAccessibilityVerbose = 147
}
export const EditorOptions: {
@ -4955,8 +4952,7 @@ declare namespace monaco.editor {
multiCursorModifier: IEditorOption<EditorOption.multiCursorModifier, 'altKey' | 'metaKey' | 'ctrlKey'>;
multiCursorPaste: IEditorOption<EditorOption.multiCursorPaste, 'spread' | 'full'>;
multiCursorLimit: IEditorOption<EditorOption.multiCursorLimit, number>;
occurrencesHighlight: IEditorOption<EditorOption.occurrencesHighlight, boolean>;
multiDocumentOccurrencesHighlight: IEditorOption<EditorOption.multiDocumentOccurrencesHighlight, boolean>;
occurrencesHighlight: IEditorOption<EditorOption.occurrencesHighlight, 'off' | 'singleFile' | 'multiFile'>;
overviewRulerBorder: IEditorOption<EditorOption.overviewRulerBorder, boolean>;
overviewRulerLanes: IEditorOption<EditorOption.overviewRulerLanes, number>;
padding: IEditorOption<EditorOption.padding, Readonly<Required<IEditorPaddingOptions>>>;

View file

@ -1759,8 +1759,8 @@ class SCMInputWidget {
}
const uri = input.repository.provider.inputBoxDocumentUri;
if (this.configurationService.getValue('editor.wordBasedSuggestions', { resource: uri }) !== false) {
this.configurationService.updateValue('editor.wordBasedSuggestions', false, { resource: uri }, ConfigurationTarget.MEMORY);
if (this.configurationService.getValue('editor.wordBasedSuggestions', { resource: uri }) !== 'off') {
this.configurationService.updateValue('editor.wordBasedSuggestions', 'off', { resource: uri }, ConfigurationTarget.MEMORY);
}
const modelValue: typeof this.model = { input, textModelRef: undefined };