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

Provide a way to refresh a grammar or theme without restarting Eclipse #839

Open
cabintech opened this issue Dec 4, 2024 · 1 comment
Open

Comments

@cabintech
Copy link

cabintech commented Dec 4, 2024

It is wildly tedious to test incremental changes to grammars and themes loaded from files (e.g. not plugins). The TextMate preferences has no 'reload' option for grammar or theme files. So one approach is to delete the grammar/theme, then re-load it. But if you don't close and reopen the Preferences dialog that does not work (it is not enough to delete, "apply", and reload). Then close and reopen the generic editor to see the changes... but this works only for themes, grammars still do not update. For that you have to exist and restart Eclipse.

[Correction, with the latest release themes (very nicely) update live from the file system the next time the editor gets focus, but grammars do not.]

@sebthom
Copy link
Member

sebthom commented Dec 8, 2024

FYI: For themes reload is implemented in the UI plugin like this:

private ITokenProvider getTokenProvider() {
if (tokenProvider == null || isModified()) {
try (InputStream in = getInputStream()) {
final var path = getPath();
final String extension = path.substring(path.lastIndexOf('.') + 1).trim().toLowerCase();
tokenProvider = switch (extension) {
case "css" -> new CSSTokenProvider(in);
case "json" -> new TMThemeTokenProvider(ContentType.JSON, in);
case "yaml", "yaml-tmtheme", "yml" -> new TMThemeTokenProvider(ContentType.YAML, in);
case "plist", "tmtheme", "xml" -> new TMThemeTokenProvider(ContentType.XML, in);
default -> throw new IllegalArgumentException("Unsupported file type: " + path);
};
} catch (final Exception ex) {
TMUIPlugin.logError(ex);
return null;
}
}
return tokenProvider;
}
private long lastModified = -1;
private long lastModifiedRecheck = -1;
private boolean isModified() {
final long now = System.currentTimeMillis();
if (now > lastModifiedRecheck) {
lastModifiedRecheck = now + 5_000;
final long oldModified = lastModified;
lastModified = getLastModified();
return lastModified != oldModified;
}
return false;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants