Skip to content
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
c937e9e
wip icon picker main area widget
bollwyvl Aug 28, 2020
2f687f7
merge upstream
bollwyvl Aug 28, 2020
5887eeb
linting
bollwyvl Aug 28, 2020
07062bb
get round-tripping icon theme working
bollwyvl Aug 29, 2020
df45ac5
re-home completion configurer, style
bollwyvl Aug 29, 2020
ab1f8e5
work on license url
bollwyvl Aug 29, 2020
ba2ddfc
flesh out rest of settings
bollwyvl Aug 30, 2020
6981307
wire up simple booleans
bollwyvl Aug 30, 2020
ddd314c
start branded icons
bollwyvl Aug 30, 2020
2db7d46
lazy load icons by theme
bollwyvl Aug 30, 2020
8341192
rename to settingseditor
bollwyvl Aug 30, 2020
91b35f6
rework some type aliases
bollwyvl Aug 30, 2020
4c984d7
remove duplicate ui-components with yarn solve
bollwyvl Aug 30, 2020
773f301
add treatment for suppressIn
bollwyvl Aug 30, 2020
e24392d
give up on the comparison table
bollwyvl Aug 30, 2020
96c35b7
clean up some copy
bollwyvl Aug 30, 2020
6ef20ca
Add link to SPDX list
bollwyvl Aug 30, 2020
49f1df5
fix spdx typo
bollwyvl Aug 30, 2020
265ccd6
Merge remote-tracking branch 'upstream/master' into add-completion-co…
bollwyvl Sep 1, 2020
a5296e9
some style tweaks, add refresh button, linting
bollwyvl Sep 1, 2020
fee7e84
rework color schemes, add modifications per license
bollwyvl Sep 1, 2020
7156739
rework style
bollwyvl Sep 1, 2020
199816d
Merge remote-tracking branch 'origin/add-completion-configurer' into …
bollwyvl Sep 1, 2020
34cc443
move default color schemes to core, palette work
bollwyvl Sep 1, 2020
051d355
register null theme
bollwyvl Sep 1, 2020
7149a21
Merge remote-tracking branch 'upstream/master' into add-completion-co…
bollwyvl Sep 4, 2020
677436a
python linter, i guess
bollwyvl Sep 4, 2020
7a7c85d
unwrap map in merge
bollwyvl Sep 4, 2020
5a7a81d
default to null theme (if available)
bollwyvl Sep 4, 2020
4953232
fix existing robot tests for theme stuff
bollwyvl Sep 4, 2020
12fe40d
add bs4 to attempt windows utf-8 reading
bollwyvl Sep 5, 2020
70efe7e
fix typo
bollwyvl Sep 8, 2020
e7fa8e4
linting
bollwyvl Sep 8, 2020
affb602
start reworking plugin settings file cleaning, etc.
bollwyvl Sep 8, 2020
5c6b31c
screenshot filename typo
bollwyvl Sep 8, 2020
3512061
rework menu item labels
bollwyvl Sep 8, 2020
aa7b014
Merge remote-tracking branch 'upstream/master' into add-completion-co…
bollwyvl Sep 8, 2020
636bbc3
reorganize atest keywords, libraries
bollwyvl Sep 8, 2020
74ca304
start theme/scheme robot test, add some more dom markers
bollwyvl Sep 8, 2020
f448535
wuks the command palette selector, some thoughts on parsing images
bollwyvl Sep 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,6 @@ atest/output/
junit.xml
coverage/
.vscode/
_schema.d.ts
_*.d.ts
_build
.virtual_documents/
7 changes: 4 additions & 3 deletions packages/completion-theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
"lab:link": "jupyter labextension link . --no-build"
},
"devDependencies": {
"react": "*",
"@jupyterlab/ui-components": "~2.2.0"
"react": "*"
},
"peerDependencies": {
"react": "*"
},
"peerDependencies": {},
"jupyterlab": {
"extension": true,
"schemaDir": "schema"
Expand Down
71 changes: 0 additions & 71 deletions packages/completion-theme/src/about.tsx

This file was deleted.

139 changes: 55 additions & 84 deletions packages/completion-theme/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,75 +1,83 @@
import { kernelIcon, LabIcon } from '@jupyterlab/ui-components';
import {
Dialog,
ICommandPalette,
IThemeManager,
showDialog
} from '@jupyterlab/apputils';
import { JupyterFrontEndPlugin } from '@jupyterlab/application';

import {
ICompletionIconSet,
ICompletionTheme,
ILSPCompletionThemeManager,
PLUGIN_ID,
COMPLETER_THEME_PREFIX,
KernelKind
KernelKind,
TCompletionLabIcons
} from './types';
import { render_themes_list } from './about';
import '../style/index.css';

const RE_ICON_THEME_CLASS = /jp-icon[^" ]+/g;
const GREYSCALE_CLASS = 'jp-icon4';

export class CompletionThemeManager implements ILSPCompletionThemeManager {
protected current_icons: Map<string, LabIcon>;
protected current_icons: TCompletionLabIcons;
protected themes: Map<string, ICompletionTheme>;
private current_theme_id: string;
private icons_cache: Map<string, LabIcon>;
private color_scheme: string;

constructor(protected themeManager: IThemeManager) {
constructor() {
this.themes = new Map();
this.icons_cache = new Map();
themeManager.themeChanged.connect(this.update_icons_set, this);
}

protected is_theme_light() {
const current = this.themeManager.theme;
if (!current) {
// assume true by default
return true;
}
return this.themeManager.isLight(current);
theme_ids() {
return [...this.themes.keys()];
}

get_iconset(theme: ICompletionTheme): Map<keyof ICompletionIconSet, LabIcon> {
const icons_sets = theme.icons;
const dark_mode_and_dark_supported =
!this.is_theme_light() && typeof icons_sets.dark !== 'undefined';
const set: ICompletionIconSet = dark_mode_and_dark_supported
? icons_sets.dark
: icons_sets.light;
const icons: Map<keyof ICompletionIconSet, LabIcon> = new Map();
const mode = this.is_theme_light() ? 'light' : 'dark';
for (let [completion_kind, svg] of Object.entries(set)) {
let name =
'lsp:' + theme.id + '-' + completion_kind.toLowerCase() + '-' + mode;
let icon: LabIcon;
if (this.icons_cache.has(name)) {
icon = this.icons_cache.get(name);
} else {
icon = new LabIcon({
name: name,
svgstr: svg
});
get_current_theme_id() {
return this.current_theme_id;
}

get_theme(id: string) {
return this.themes.get(id);
}

async get_icons(
theme: ICompletionTheme,
color_scheme: string
): Promise<TCompletionLabIcons> {
const icons: TCompletionLabIcons = new Map();

for (const [completion_kind, raw] of Object.entries(
await theme.icons.svg()
)) {
const name = `lsp:${theme.id}-${completion_kind}-${color_scheme}`.toLowerCase();
let icon = this.icons_cache.get(name);
let svgstr = raw;
if (color_scheme === 'greyscale') {
svgstr = svgstr.replace(RE_ICON_THEME_CLASS, GREYSCALE_CLASS);
}
if (icon == null) {
icon = new LabIcon({ name, svgstr });
this.icons_cache.set(name, icon);
}
icons.set(completion_kind as keyof ICompletionIconSet, icon);
}
return icons;
}

protected update_icons_set() {
get_color_scheme() {
return this.color_scheme;
}

set_color_scheme(color_scheme: string) {
this.color_scheme = color_scheme;
}

protected async update_icons_set() {
if (this.current_theme === null) {
return;
}
this.current_icons = this.get_iconset(this.current_theme);
this.current_icons = await this.get_icons(
this.current_theme,
this.color_scheme
);
}

get_icon(type: string): LabIcon {
Expand All @@ -81,8 +89,8 @@ export class CompletionThemeManager implements ILSPCompletionThemeManager {
type =
type.substring(0, 1).toUpperCase() + type.substring(1).toLowerCase();
}
if (this.current_icons.has(type)) {
return this.current_icons.get(type).bindprops(options);
if (this.current_icons.has(type as any)) {
return this.current_icons.get(type as any).bindprops(options);
}
if (type === KernelKind) {
return kernelIcon;
Expand All @@ -94,7 +102,7 @@ export class CompletionThemeManager implements ILSPCompletionThemeManager {
return COMPLETER_THEME_PREFIX + this.current_theme_id;
}

set_theme(id: string | null) {
async set_theme(id: string | null) {
if (this.current_theme_id) {
document.body.classList.remove(this.current_theme_class);
}
Expand All @@ -105,7 +113,7 @@ export class CompletionThemeManager implements ILSPCompletionThemeManager {
}
this.current_theme_id = id;
document.body.classList.add(this.current_theme_class);
this.update_icons_set();
await this.update_icons_set();
}

protected get current_theme(): ICompletionTheme | null {
Expand All @@ -124,50 +132,13 @@ export class CompletionThemeManager implements ILSPCompletionThemeManager {
);
}
this.themes.set(theme.id, theme);
this.update_icons_set();
}

/**
* Display the registered themes in a dialog,
* both for the user to know what they can choose from,
* and for the developer to quickly check how the icons
* from each theme would look rendered.
*/
display_themes() {
showDialog({
title: 'LSP Completer Themes',
body: render_themes_list({
themes: [...this.themes.values()],
current: this.current_theme,
get_set: this.get_iconset.bind(this)
}),
buttons: [Dialog.okButton()]
}).catch(console.warn);
}
}

const LSP_CATEGORY = 'Language server protocol';

export const COMPLETION_THEME_MANAGER: JupyterFrontEndPlugin<ILSPCompletionThemeManager> = {
id: PLUGIN_ID,
requires: [IThemeManager, ICommandPalette],
activate: (
app,
themeManager: IThemeManager,
commandPalette: ICommandPalette
) => {
let manager = new CompletionThemeManager(themeManager);
const command_id = 'lsp:completer-about-themes';
app.commands.addCommand(command_id, {
label: 'Display the completer themes',
execute: () => {
manager.display_themes();
}
});
commandPalette.addItem({
category: LSP_CATEGORY,
command: command_id
});
activate: app => {
let manager = new CompletionThemeManager();
return manager;
},
provides: ILSPCompletionThemeManager,
Expand Down
41 changes: 25 additions & 16 deletions packages/completion-theme/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ export interface ICompletionIconSet extends requiredIcons {

export interface ILicenseInfo {
/**
* Licence name.
* License name.
*/
name: string;
/**
* Abbreviation of the licence name;
* SDPX identifer of the license.
*/
abbreviation: string;
spdx: string;
/**
* The copyright holder/owner name.
*/
licensor: string;
/**
* Link to the full licence text.
* URL of the full license text.
*/
link: string;
url: string;
}

export interface ICompletionTheme {
Expand All @@ -85,15 +85,11 @@ export interface ICompletionTheme {
/**
* Short name of the license of the icons included.
*/
licence: ILicenseInfo;
license: ILicenseInfo;
/**
* The version to be used in the light mode.
* The icons as SVG strings, keyed by completion kind.
*/
light: ICompletionIconSet;
/**
* The version to be used in the dark mode.
*/
dark?: ICompletionIconSet;
svg(): Promise<ICompletionIconSet>;
/**
* Icon properties to be set on each of the icons.
* NOTE: setting className here will not work, as
Expand All @@ -106,16 +102,29 @@ export interface ICompletionTheme {
};
}

export type TCompletionLabIcons = Map<keyof ICompletionIconSet, LabIcon>;

export interface ILSPCompletionThemeManager {
get_icon(type: string): LabIcon.ILabIcon | null;
get_icon(type: string): LabIcon | null;

set_theme(theme_id: string | null): void;

get_theme(theme_id: string): ICompletionTheme;

get_current_theme_id(): string;

set_color_scheme(scheme_id: string): void;

get_color_scheme(): string;

register_theme(theme: ICompletionTheme): void;

get_iconset(
theme: ICompletionTheme
): Map<keyof ICompletionIconSet, LabIcon.ILabIcon>;
get_icons(
theme: ICompletionTheme,
color_scheme: string
): Promise<TCompletionLabIcons>;

theme_ids(): string[];
}

export const ILSPCompletionThemeManager = new Token<ILSPCompletionThemeManager>(
Expand Down
Loading