Skip to content
This repository has been archived by the owner on Jun 22, 2023. It is now read-only.

Code highlighting #26

Merged
merged 14 commits into from
Mar 3, 2022
Merged

Code highlighting #26

merged 14 commits into from
Mar 3, 2022

Conversation

CollinJoseph
Copy link
Contributor

Completed code highlighting for python and rust for now. I haven't added language option to the schema. Current the highlighting is hard-coded to rust should be able to change that when all the loggers start to sent the language.

Copy link
Member

@STBoyden STBoyden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you for adding this :)

@STBoyden
Copy link
Member

One issue I have encountered is that it needs to be made compatible with the new WASM-based client as well as the desktop client. Could you look into whether you could adapt it to use this?

Copy link
Member

@STBoyden STBoyden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above comment.

@CollinJoseph CollinJoseph requested a review from STBoyden March 1, 2022 20:49
Increased perfomance by storing layout job so it is recreated every frame. It is only recreated when code is change which is checked by comparing hashes
codectrl-gui/Cargo.toml Outdated Show resolved Hide resolved

let ps = SyntaxSet::load_defaults_newlines();
let ts = ThemeSet::load_defaults();
let syntax = ps.find_syntax_by_extension("py").unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you instead get the extension of the log file name?

Copy link
Member

@STBoyden STBoyden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one more thing and it should be fine to merge, after I test it.

pub fn code_highlighter(code: &str, lang: &str) -> egui::text::LayoutJob {
let ps = SyntaxSet::load_defaults_newlines();
let ts = ThemeSet::load_defaults();
let syntax = ps.find_syntax_by_extension("py").unwrap();
let syntax = ps.find_syntax_by_extension(lang_to_short(lang)).unwrap();
Copy link
Member

@STBoyden STBoyden Mar 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://docs.rs/syntect/4.6.0/syntect/parsing/struct.SyntaxSet.html#method.find_syntax_by_name

You should be able to use that and just pass lang into it, rather than creating a new function for it.

Something like this:

let syntax =  ps.find_syntax_by_name(lang).unwrap();

Comment on lines 9 to 17
fn lang_to_short(lang: &str) -> &str {
// Add more language here
match lang {
"rust" => "rs",
"python" => "py",
_ => "",
}
}

Copy link
Member

@STBoyden STBoyden Mar 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at previous comment to see why possibly unnecessary.

Syntax definition search goes from language specified by the logger -> the extension of the file -> plaintext.
@STBoyden STBoyden merged commit 0d738f8 into main Mar 3, 2022
@STBoyden STBoyden deleted the code-highlighting branch July 11, 2022 14:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants