mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Merge pull request #16797 from atom/mb-legacy-scope-alias-renames
Tweak config APIs for dealing w/ legacy scope aliases
This commit is contained in:
@@ -115,7 +115,7 @@ describe('Config', () => {
|
||||
|
||||
describe('when the first component of the scope descriptor matches a legacy scope alias', () =>
|
||||
it('falls back to properties defined for the legacy scope if no value is found for the original scope descriptor', () => {
|
||||
atom.config.addLegacyScopeAlias('javascript', '.source.js')
|
||||
atom.config.setLegacyScopeAliasForNewScope('javascript', '.source.js')
|
||||
atom.config.set('foo', 100, {scopeSelector: '.source.js'})
|
||||
atom.config.set('foo', 200, {scopeSelector: 'javascript for_statement'})
|
||||
|
||||
@@ -154,7 +154,7 @@ describe('Config', () => {
|
||||
|
||||
describe('when the first component of the scope descriptor matches a legacy scope alias', () =>
|
||||
it('includes the values defined for the legacy scope', () => {
|
||||
atom.config.addLegacyScopeAlias('javascript', '.source.js')
|
||||
atom.config.setLegacyScopeAliasForNewScope('javascript', '.source.js')
|
||||
|
||||
expect(atom.config.set('foo', 41)).toBe(true)
|
||||
expect(atom.config.set('foo', 42, {scopeSelector: 'javascript'})).toBe(true)
|
||||
|
||||
@@ -429,7 +429,7 @@ class Config {
|
||||
this.settingsLoaded = false
|
||||
this.transactDepth = 0
|
||||
this.pendingOperations = []
|
||||
this.legacyScopeAliases = {}
|
||||
this.legacyScopeAliases = new Map()
|
||||
this.requestSave = _.debounce(() => this.save(), 1)
|
||||
}
|
||||
|
||||
@@ -618,7 +618,7 @@ class Config {
|
||||
keyPath,
|
||||
options
|
||||
)
|
||||
legacyScopeDescriptor = this.getLegacyScopeDescriptor(scopeDescriptor)
|
||||
legacyScopeDescriptor = this.getLegacyScopeDescriptorForNewScopeDescriptor(scopeDescriptor)
|
||||
if (legacyScopeDescriptor) {
|
||||
result.push(...Array.from(this.scopedSettingsStore.getAll(
|
||||
legacyScopeDescriptor.getScopeChain(),
|
||||
@@ -818,12 +818,22 @@ class Config {
|
||||
}
|
||||
}
|
||||
|
||||
addLegacyScopeAlias (languageId, legacyScopeName) {
|
||||
this.legacyScopeAliases[languageId] = legacyScopeName
|
||||
getLegacyScopeDescriptorForNewScopeDescriptor (scopeDescriptor) {
|
||||
scopeDescriptor = ScopeDescriptor.fromObject(scopeDescriptor)
|
||||
const legacyAlias = this.legacyScopeAliases.get(scopeDescriptor.scopes[0])
|
||||
if (legacyAlias) {
|
||||
const scopes = scopeDescriptor.scopes.slice()
|
||||
scopes[0] = legacyAlias
|
||||
return new ScopeDescriptor({scopes})
|
||||
}
|
||||
}
|
||||
|
||||
removeLegacyScopeAlias (languageId) {
|
||||
delete this.legacyScopeAliases[languageId]
|
||||
setLegacyScopeAliasForNewScope (languageId, legacyScopeName) {
|
||||
this.legacyScopeAliases.set(languageId, legacyScopeName)
|
||||
}
|
||||
|
||||
removeLegacyScopeAliasForNewScope (languageId) {
|
||||
this.legacyScopeAliases.delete(languageId)
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1202,7 +1212,7 @@ class Config {
|
||||
options
|
||||
)
|
||||
|
||||
const legacyScopeDescriptor = this.getLegacyScopeDescriptor(scopeDescriptor)
|
||||
const legacyScopeDescriptor = this.getLegacyScopeDescriptorForNewScopeDescriptor(scopeDescriptor)
|
||||
if (result != null) {
|
||||
return result
|
||||
} else if (legacyScopeDescriptor) {
|
||||
@@ -1230,15 +1240,6 @@ class Config {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
getLegacyScopeDescriptor (scopeDescriptor) {
|
||||
const legacyAlias = this.legacyScopeAliases[scopeDescriptor.scopes[0]]
|
||||
if (legacyAlias) {
|
||||
const scopes = scopeDescriptor.scopes.slice()
|
||||
scopes[0] = legacyAlias
|
||||
return new ScopeDescriptor({scopes})
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Base schema enforcers. These will coerce raw input into the specified type,
|
||||
|
||||
@@ -399,7 +399,7 @@ class GrammarRegistry {
|
||||
if (grammar instanceof TreeSitterGrammar) {
|
||||
this.treeSitterGrammarsById[grammar.id] = grammar
|
||||
if (grammar.legacyScopeName) {
|
||||
this.config.addLegacyScopeAlias(grammar.id, grammar.legacyScopeName)
|
||||
this.config.setLegacyScopeAliasForNewScope(grammar.id, grammar.legacyScopeName)
|
||||
this.textMateScopeNamesByTreeSitterLanguageId.set(grammar.id, grammar.legacyScopeName)
|
||||
this.treeSitterLanguageIdsByTextMateScopeName.set(grammar.legacyScopeName, grammar.id)
|
||||
}
|
||||
@@ -414,7 +414,7 @@ class GrammarRegistry {
|
||||
if (grammar instanceof TreeSitterGrammar) {
|
||||
delete this.treeSitterGrammarsById[grammar.id]
|
||||
if (grammar.legacyScopeName) {
|
||||
this.config.removeLegacyScopeAlias(grammar.id)
|
||||
this.config.removeLegacyScopeAliasForNewScope(grammar.id)
|
||||
this.textMateScopeNamesByTreeSitterLanguageId.delete(grammar.id)
|
||||
this.treeSitterLanguageIdsByTextMateScopeName.delete(grammar.legacyScopeName)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user