Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from Oct 12, 2021

Conversation

hediet
Copy link
Member

@hediet hediet commented Oct 6, 2021

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
Copy link
Member

alexdima commented Oct 7, 2021

@hediet Could you please fix the tests.

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

@alexdima alexdima left a comment

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.


const closingBrackets = new Map</* closingText */ string, { openingBrackets: SmallImmutableSet<OpeningBracketId>, first: OpeningBracketId }>();
const openingBrackets = new Set</* openingText */ string>();

for (const [openingText, closingText] of brackets) {
if (openingText === '' || closingText === '') {
Copy link
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.

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
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 = {

this.config = computeConfig(this.languageId, this.resource, this.configurationService, this.modeService);

this._register(this.configurationService.onDidChangeConfiguration((e) => {
this.update();
Copy link
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
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
Copy link
Member

@alexdima alexdima left a comment

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.

@@ -27,6 +27,7 @@ import { URI } from 'vs/base/common/uri';
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
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
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