Skip to content

Allows settings to override language contributed bracket pair configurations.#134503

Merged
hediet merged 6 commits into
mainfrom
hediet/configurable-bracket-pairs
Oct 12, 2021
Merged

Allows settings to override language contributed bracket pair configurations.#134503
hediet merged 6 commits into
mainfrom
hediet/configurable-bracket-pairs

Conversation

@hediet

@hediet hediet commented Oct 6, 2021

Copy link
Copy Markdown
Member

This PR fixes #131412

TODOs:

  • The new settings must be added to the JSON Schema

@hediet hediet requested a review from alexdima October 6, 2021 14:09
@hediet hediet self-assigned this Oct 6, 2021
@alexdima

alexdima commented Oct 7, 2021

Copy link
Copy Markdown
Member

@hediet Could you please fix the tests.

@alexdima alexdima added this to the October 2021 milestone Oct 7, 2021

@alexdima alexdima left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left notes, we can also discuss.

Comment thread src/vs/editor/common/modes/languageConfigurationRegistry.ts Outdated
Comment thread src/vs/editor/common/model/bracketPairColorizer/bracketPairColorizer.ts Outdated
const openingBrackets = new Set</* openingText */ string>();

for (const [openingText, closingText] of brackets) {
if (openingText === '' || closingText === '') {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to move the validation of brackets (i.e. that empty brackets are not allowed to ResolvedLanguageConfiguration). Otherwise, we would need to check for empty strings in all consumers of ResolvedLanguageConfiguration.

Comment thread src/vs/workbench/contrib/codeEditor/browser/workbenchReferenceSearch.ts Outdated
Comment thread src/vs/editor/contrib/gotoSymbol/peek/referencesController.ts Outdated
Comment thread src/vs/editor/standalone/browser/referenceSearch/standaloneReferenceSearch.ts Outdated
return this._brackets;
}
function getCustomizedLanguageConfig(languageIdentifier: LanguageIdentifier, resource: URI | undefined, configurationService: IConfigurationService): LanguageConfiguration {
// TODO how should these keys be registered to the JSON schema?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can define them together with the other non-editor options yet still editor.* settings at

const editorConfiguration: IConfigurationNode = {

Comment thread src/vs/editor/common/modes/languageConfigurationRegistry.ts Outdated
Comment thread src/vs/editor/common/modes/languageConfigurationRegistry.ts Outdated
Comment thread src/vs/editor/common/modes/languageConfigurationRegistry.ts Outdated
this.config = computeConfig(this.languageId, this.resource, this.configurationService, this.modeService);

this._register(this.configurationService.onDidChangeConfiguration((e) => {
this.update();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!e.affectsConfiguration('editor')) {
  return;
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do it like this now:

const customizedLanguageConfigKeys = {
	brackets: 'editor.language.brackets',
	colorizedBracketPairs: 'editor.language.colorizedBracketPairs'
};

// ...

const languageConfigKeys = new Set(Object.values(customizedLanguageConfigKeys));

const globalConfigChanged = e.change.keys.some((k) =>
				languageConfigKeys.has(k)
			);
const localConfigChanged = e.change.overrides
    .filter(([overrideLangName, keys]) =>
        keys.some((k) => languageConfigKeys.has(k))
    )
    .map(([overrideLangName]) => this.modeService.getLanguageIdentifier(overrideLangName));

if (globalConfigChanged) {
    this.configurations.clear();
    this.onDidChangeEmitter.fire(new LanguageConfigurationServiceChangeEvent(undefined));
} else {
    for (const languageIdentifier of localConfigChanged) {
        if (languageIdentifier) {
            this.configurations.delete(languageIdentifier.id);
            this.onDidChangeEmitter.fire(new LanguageConfigurationServiceChangeEvent(languageIdentifier));
        }
    }
}

@hediet hediet force-pushed the hediet/configurable-bracket-pairs branch from eeaa845 to c3e8f38 Compare October 11, 2021 13:52
@hediet hediet force-pushed the hediet/configurable-bracket-pairs branch from 10aef2b to 6650201 Compare October 11, 2021 14:35
# Conflicts:
#	src/vs/editor/common/modes/languageConfigurationRegistry.ts
@hediet hediet requested a review from alexdima October 12, 2021 08:46

@alexdima alexdima left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good! Just one last problem I just noticed.

import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo';
import { Iterable } from 'vs/base/common/iterator';
import { ResourceFileEdit } from 'vs/editor/browser/services/bulkEditService';
import { TestLanguageConfigurationService } from 'vs/editor/test/common/modes/testLanguageConfigurationService';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a test, we should not use the TestLanguageConfigurationService here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@hediet hediet merged commit 3b1df93 into main Oct 12, 2021
@hediet hediet deleted the hediet/configurable-bracket-pairs branch October 12, 2021 09:50
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow customizing bracket pairs

2 participants