-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Colin Grant <[email protected]>
- Loading branch information
Colin Grant
committed
Jun 8, 2021
1 parent
2880525
commit 945fa1e
Showing
16 changed files
with
523 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
packages/vsx-registry/src/browser/recommended-extensions/preference-provider-overrides.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2021 Ericsson and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { | ||
FolderPreferenceProvider, | ||
FolderPreferenceProviderFactory, | ||
FolderPreferenceProviderFolder, | ||
UserPreferenceProvider, | ||
UserPreferenceProviderFactory | ||
} from '@theia/preferences/lib/browser'; | ||
import { Container, injectable, interfaces } from '@theia/core/shared/inversify'; | ||
import { extensionsConfigurationSchema } from './recommended-extensions-json-schema'; | ||
import { | ||
WorkspaceFilePreferenceProvider, | ||
WorkspaceFilePreferenceProviderFactory, | ||
WorkspaceFilePreferenceProviderOptions | ||
} from '@theia/preferences/lib/browser/workspace-file-preference-provider'; | ||
import { bindFactory } from '@theia/preferences/lib/browser/preference-bindings'; | ||
import { SectionPreferenceProviderSection, SectionPreferenceProviderUri } from '@theia/preferences/lib/browser/section-preference-provider'; | ||
|
||
/** | ||
* The overrides in this file are required because the base preference providers assume that a | ||
* section name (extensions) will not be used as a prefix (extensions.ignoreRecommendations). | ||
*/ | ||
|
||
@injectable() | ||
export class FolderPreferenceProviderWithExtensions extends FolderPreferenceProvider { | ||
protected getPath(preferenceName: string): string[] | undefined { | ||
const path = super.getPath(preferenceName); | ||
if (this.section !== 'extensions' || !path?.length) { | ||
return path; | ||
} | ||
const isExtensionsField = path[0] in extensionsConfigurationSchema.properties!; | ||
if (isExtensionsField) { | ||
return path; | ||
} | ||
return undefined; | ||
} | ||
} | ||
|
||
@injectable() | ||
export class UserPreferenceProviderWithExtensions extends UserPreferenceProvider { | ||
protected getPath(preferenceName: string): string[] | undefined { | ||
const path = super.getPath(preferenceName); | ||
if (this.section !== 'extensions' || !path?.length) { | ||
return path; | ||
} | ||
const isExtensionsField = path[0] in extensionsConfigurationSchema.properties!; | ||
if (isExtensionsField) { | ||
return path; | ||
} | ||
return undefined; | ||
} | ||
} | ||
|
||
@injectable() | ||
export class WorkspaceFilePreferenceProviderWithExtensions extends WorkspaceFilePreferenceProvider { | ||
protected belongsInSection(firstSegment: string, remainder: string): boolean { | ||
if (firstSegment === 'extensions') { | ||
return remainder in extensionsConfigurationSchema.properties!; | ||
} | ||
return this.configurations.isSectionName(firstSegment); | ||
} | ||
} | ||
|
||
export function bindPreferenceProviderOverrides(bind: interfaces.Bind, unbind: interfaces.Unbind): void { | ||
unbind(UserPreferenceProviderFactory); | ||
unbind(FolderPreferenceProviderFactory); | ||
unbind(WorkspaceFilePreferenceProviderFactory); | ||
bindFactory(bind, UserPreferenceProviderFactory, UserPreferenceProviderWithExtensions, SectionPreferenceProviderUri, SectionPreferenceProviderSection); | ||
bindFactory( | ||
bind, | ||
FolderPreferenceProviderFactory, | ||
FolderPreferenceProviderWithExtensions, | ||
SectionPreferenceProviderUri, | ||
SectionPreferenceProviderSection, | ||
FolderPreferenceProviderFolder, | ||
); | ||
bind(WorkspaceFilePreferenceProviderFactory).toFactory(ctx => (options: WorkspaceFilePreferenceProviderOptions) => { | ||
const child = new Container({ defaultScope: 'Singleton' }); | ||
child.parent = ctx.container; | ||
child.bind(WorkspaceFilePreferenceProvider).to(WorkspaceFilePreferenceProviderWithExtensions); | ||
child.bind(WorkspaceFilePreferenceProviderOptions).toConstantValue(options); | ||
return child.get(WorkspaceFilePreferenceProvider); | ||
}); | ||
} |
72 changes: 72 additions & 0 deletions
72
...ges/vsx-registry/src/browser/recommended-extensions/recommended-extensions-json-schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2021 Ericsson and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify'; | ||
import { InMemoryResources } from '@theia/core'; | ||
import { JsonSchemaContribution, JsonSchemaRegisterContext } from '@theia/core/lib/browser/json-schema-store'; | ||
import { IJSONSchema } from '@theia/core/lib/common/json-schema'; | ||
import URI from '@theia/core/lib/common/uri'; | ||
import { WorkspaceService } from '@theia/workspace/lib/browser'; | ||
|
||
export const extensionsSchemaID = 'vscode://schemas/extensions'; | ||
export const extensionsConfigurationSchema: IJSONSchema = { | ||
$id: extensionsSchemaID, | ||
default: { recommendations: [] }, | ||
type: 'object', | ||
|
||
properties: { | ||
recommendations: { | ||
title: 'A list of extensions recommended for users of this workspace. Should use the form "<publisher>.<extension name>"', | ||
type: 'array', | ||
items: { | ||
type: 'string', | ||
pattern: '^\\w[\\w-]+\\.\\w[\\w-]+$', | ||
patternErrorMessage: "Expected format '${publisher}.${name}'. Example: 'eclipse.theia'." | ||
}, | ||
default: [], | ||
}, | ||
unwantedRecommendations: { | ||
title: 'A list of extensions recommended by default that should not be recommended to users of this workspace. Should use the form "<publisher>.<extension name>"', | ||
type: 'array', | ||
items: { | ||
type: 'string', | ||
pattern: '^\\w[\\w-]+\\.\\w[\\w-]+$', | ||
patternErrorMessage: "Expected format '${publisher}.${name}'. Example: 'eclipse.theia'." | ||
}, | ||
default: [], | ||
} | ||
} | ||
}; | ||
|
||
@injectable() | ||
export class ExtensionSchemaContribution implements JsonSchemaContribution { | ||
protected readonly uri = new URI(extensionsSchemaID); | ||
@inject(InMemoryResources) protected readonly inmemoryResources: InMemoryResources; | ||
@inject(WorkspaceService) protected readonly workspaceService: WorkspaceService; | ||
|
||
@postConstruct() | ||
protected init(): void { | ||
this.inmemoryResources.add(this.uri, JSON.stringify(extensionsConfigurationSchema)); | ||
} | ||
|
||
registerSchemas(context: JsonSchemaRegisterContext): void { | ||
context.registerSchema({ | ||
fileMatch: ['extensions.json'], | ||
url: this.uri.toString(), | ||
}); | ||
this.workspaceService.updateSchema('extensions', { $ref: this.uri.toString() }); | ||
} | ||
} |
Oops, something went wrong.