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

vscode: support icons contribution point #12912

Merged
merged 13 commits into from
Oct 26, 2023
9 changes: 9 additions & 0 deletions packages/monaco/src/browser/monaco-frontend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ import { MimeService } from '@theia/core/lib/browser/mime-service';
import { MonacoEditorServices } from './monaco-editor';
import { MonacoColorRegistry } from './monaco-color-registry';
import { ColorRegistry } from '@theia/core/lib/browser/color-registry';
import { IconRegistry, IconStyleSheetService } from './monaco-icon-registry-types';
import { MonacoIconRegistry } from './monaco-icon-registry';
import { MonacoIconStyleSheetService } from './monaco-icon-style-sheet';
import { MonacoThemingService } from './monaco-theming-service';
import { bindContributionProvider } from '@theia/core';
import { WorkspaceSymbolCommand } from './workspace-symbol-command';
Expand Down Expand Up @@ -187,6 +190,12 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {

bind(ThemeServiceWithDB).toSelf().inSingletonScope();
rebind(ThemeService).toService(ThemeServiceWithDB);

bind(MonacoIconRegistry).toSelf().inSingletonScope();
bind(IconRegistry).toService(MonacoIconRegistry);

bind(MonacoIconStyleSheetService).toSelf().inSingletonScope();
bind(IconStyleSheetService).toService(MonacoIconStyleSheetService);
});

export const MonacoConfigurationService = Symbol('MonacoConfigurationService');
Expand Down
127 changes: 127 additions & 0 deletions packages/monaco/src/browser/monaco-icon-registry-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// *****************************************************************************
// Copyright (C) 2023 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-only WITH Classpath-exception-2.0
// *****************************************************************************

import { Event } from '@theia/core';
vladarama marked this conversation as resolved.
Show resolved Hide resolved
import { IJSONSchema } from '@theia/core/lib/common/json-schema';
import { ThemeIcon } from '@theia/monaco-editor-core/esm/vs/platform/theme/common/themeService';
import { URI } from '@theia/core/shared/vscode-uri';

// ------ API types

export type IconIdentifier = string;
vladarama marked this conversation as resolved.
Show resolved Hide resolved

// icon registry
export const Extensions = {
vladarama marked this conversation as resolved.
Show resolved Hide resolved
IconContribution: 'base.contributions.icons'
};

export type IconDefaults = ThemeIcon | IconDefinition;
vladarama marked this conversation as resolved.
Show resolved Hide resolved

export interface IconDefinition {
font?: IconFontContribution; // undefined for the default font (codicon)
fontCharacter: string;
}

export interface IconContribution {
readonly id: string;
description: string | undefined;
deprecationMessage?: string;
readonly defaults: IconDefaults;
}

export interface IconFontContribution {
readonly id: string;
readonly definition: IconFontDefinition;
}

export interface IconFontDefinition {
readonly weight?: string;
readonly style?: string;
readonly src: IconFontSource[];
}

export interface IconFontSource {
readonly location: URI;
readonly format: string;
}

export const IconRegistry = Symbol('IconRegistry');
export interface IconRegistry {
vladarama marked this conversation as resolved.
Show resolved Hide resolved

readonly onDidChange: Event<void>;

/**
* Register a icon to the registry.
* @param id The icon id
* @param defaults The default values
* @param description The description
*/
registerIcon(id: IconIdentifier, defaults: IconDefaults, description?: string): ThemeIcon;

/**
* Deregister a icon from the registry.
*/
deregisterIcon(id: IconIdentifier): void;

/**
* Get all icon contributions
*/
getIcons(): IconContribution[];
vladarama marked this conversation as resolved.
Show resolved Hide resolved

/**
* Get the icon for the given id
*/
getIcon(id: IconIdentifier): IconContribution | undefined;
vladarama marked this conversation as resolved.
Show resolved Hide resolved

/**
* JSON schema for an object to assign icon values to one of the icon contributions.
*/
getIconSchema(): IJSONSchema;
vladarama marked this conversation as resolved.
Show resolved Hide resolved

/**
* JSON schema to for a reference to a icon contribution.
*/
getIconReferenceSchema(): IJSONSchema;
vladarama marked this conversation as resolved.
Show resolved Hide resolved

/**
* Register a icon font to the registry.
* @param id The icon font id
* @param definition The icon font definition
*/
registerIconFont(id: string, definition: IconFontDefinition): IconFontDefinition;

/**
* Deregister an icon font to the registry.
*/
deregisterIconFont(id: string): void;

/**
* Get the icon font for the given id
*/
getIconFont(id: string): IconFontDefinition | undefined;
}

export const IconsStyleSheet = Symbol('IconsStyleSheet');
vladarama marked this conversation as resolved.
Show resolved Hide resolved
export interface IconsStyleSheet {
getCSS(): string;
readonly onDidChange: Event<void>;
}

export const IconStyleSheetService = Symbol('IconStyleSheetService');
export interface IconStyleSheetService {
getIconsStyleSheet(): IconsStyleSheet;
}

58 changes: 58 additions & 0 deletions packages/monaco/src/browser/monaco-icon-registry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// *****************************************************************************
// Copyright (C) 2023 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-only WITH Classpath-exception-2.0
// *****************************************************************************

import { injectable } from '@theia/core/shared/inversify';
import * as monaco from '@theia/monaco-editor-core/esm/vs/platform/theme/common/iconRegistry';
vladarama marked this conversation as resolved.
Show resolved Hide resolved
import { IconContribution, IconDefaults, IconFontDefinition, IconRegistry } from './monaco-icon-registry-types';
import { Event } from '@theia/core';
import { IJSONSchema } from '@theia/core/lib/common/json-schema';
import { ThemeIcon } from '@theia/monaco-editor-core/esm/vs/platform/theme/common/themeService';

@injectable()
export class MonacoIconRegistry implements IconRegistry {
vladarama marked this conversation as resolved.
Show resolved Hide resolved
protected readonly iconRegistry = monaco.getIconRegistry();

onDidChange: Event<void> = this.iconRegistry.onDidChange;

registerIcon(id: string, defaults: IconDefaults, description?: string | undefined): ThemeIcon {
return this.iconRegistry.registerIcon(id, defaults, description);
}
deregisterIcon(id: string): void {
return this.iconRegistry.deregisterIcon(id);
}
getIcons(): IconContribution[] {
return this.iconRegistry.getIcons();
}
getIcon(id: string): IconContribution | undefined {
return this.iconRegistry.getIcon(id);
}
getIconSchema(): IJSONSchema {
return this.iconRegistry.getIconSchema();
}
getIconReferenceSchema(): IJSONSchema {
return this.iconRegistry.getIconReferenceSchema();
}
registerIconFont(id: string, definition: IconFontDefinition): IconFontDefinition {
return this.iconRegistry.registerIconFont(id, definition);
}
deregisterIconFont(id: string): void {
return this.iconRegistry.deregisterIconFont(id);
}
getIconFont(id: string): IconFontDefinition | undefined {
return this.iconRegistry.getIconFont(id);
}

}
27 changes: 27 additions & 0 deletions packages/monaco/src/browser/monaco-icon-style-sheet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// *****************************************************************************
// Copyright (C) 2023 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-only WITH Classpath-exception-2.0
// *****************************************************************************

import { injectable } from '@theia/core/shared/inversify';
import { getIconsStyleSheet } from '@theia/monaco-editor-core/esm/vs/platform/theme/browser/iconsStyleSheet';
import { IconsStyleSheet } from './monaco-icon-registry-types';

@injectable()
export class MonacoIconStyleSheetService {
vladarama marked this conversation as resolved.
Show resolved Hide resolved
protected getIconsStyleSheet(): IconsStyleSheet {
return getIconsStyleSheet(undefined);
}

}
31 changes: 30 additions & 1 deletion packages/plugin-ext/src/common/plugin-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { RpcServer } from '@theia/core/lib/common/messaging/proxy-factory';
import { RPCProtocol } from './rpc-protocol';
import { Disposable } from '@theia/core/lib/common/disposable';
import { LogPart, KeysToAnyValues, KeysToKeysToAnyValue } from './types';
import { CharacterPair, CommentRule, PluginAPIFactory, Plugin } from './plugin-api-rpc';
import { CharacterPair, CommentRule, PluginAPIFactory, Plugin, ThemeIcon } from './plugin-api-rpc';
import { ExtPluginApi } from './plugin-ext-api-contribution';
import { IJSONSchema, IJSONSchemaSnippet } from '@theia/core/lib/common/json-schema';
import { RecursivePartial } from '@theia/core/lib/common/types';
Expand Down Expand Up @@ -90,6 +90,7 @@ export interface PluginPackageContribution {
snippets?: PluginPackageSnippetsContribution[];
themes?: PluginThemeContribution[];
iconThemes?: PluginIconThemeContribution[];
icons?: PluginIconContribution[];
colors?: PluginColorContribution[];
taskDefinitions?: PluginTaskDefinitionContribution[];
problemMatchers?: PluginProblemMatcherContribution[];
Expand Down Expand Up @@ -262,6 +263,13 @@ export interface PluginIconThemeContribution {
uiTheme?: PluginUiTheme;
}

export interface PluginIconContribution {
[id: string]: {
description: string;
default: { fontPath: string; fontCharacter: string } | string;
};
}

export interface PlatformSpecificAdapterContribution {
program?: string;
args?: string[];
Expand Down Expand Up @@ -586,6 +594,7 @@ export interface PluginContribution {
snippets?: SnippetContribution[];
themes?: ThemeContribution[];
iconThemes?: IconThemeContribution[];
icons?: IconContribution[];
colors?: ColorDefinition[];
taskDefinitions?: TaskDefinition[];
problemMatchers?: ProblemMatcherContribution[];
Expand Down Expand Up @@ -662,6 +671,26 @@ export interface IconThemeContribution {
uiTheme?: UiTheme;
}

export interface IconDefinition {
fontCharacter: string;
location: string;
}

export type IconDefaults = ThemeIcon | IconDefinition;

export interface IconContribution {
id: string;
extensionId: string;
description: string | undefined;
defaults: IconDefaults;
}

export namespace IconContribution {
export function isIconDefinition(defaults: IconDefaults): defaults is IconDefinition {
return 'fontCharacter' in defaults;
}
}

export interface GrammarsContribution {
format: 'json' | 'plist';
language?: string;
Expand Down
Loading
Loading