summaryrefslogtreecommitdiff
path: root/cli/tools/repl/editor.rs
diff options
context:
space:
mode:
authorsigmaSd <bedisnbiba@gmail.com>2022-08-10 17:39:16 +0100
committerGitHub <noreply@github.com>2022-08-10 12:39:16 -0400
commit5b2ae25f13bc089f2173c6693fe3f731981525b4 (patch)
treed731fcfb52884f58c61005d454c739aaf3eab240 /cli/tools/repl/editor.rs
parentafc29c28aedcba016a5c4205080c5907fd7bde0b (diff)
feat(repl): add color to functions for syntax highlighting (#15434)
Diffstat (limited to 'cli/tools/repl/editor.rs')
-rw-r--r--cli/tools/repl/editor.rs17
1 files changed, 15 insertions, 2 deletions
diff --git a/cli/tools/repl/editor.rs b/cli/tools/repl/editor.rs
index c6549f61d..69fec9df0 100644
--- a/cli/tools/repl/editor.rs
+++ b/cli/tools/repl/editor.rs
@@ -304,7 +304,10 @@ impl Highlighter for EditorHelper {
fn highlight<'l>(&self, line: &'l str, _: usize) -> Cow<'l, str> {
let mut out_line = String::from(line);
- for item in deno_ast::lex(line, deno_ast::MediaType::TypeScript) {
+ let mut lexed_items = deno_ast::lex(line, deno_ast::MediaType::TypeScript)
+ .into_iter()
+ .peekable();
+ while let Some(item) = lexed_items.next() {
// Adding color adds more bytes to the string,
// so an offset is needed to stop spans falling out of sync.
let offset = out_line.len() - line.len();
@@ -334,7 +337,17 @@ impl Highlighter for EditorHelper {
} else if ident == *"async" || ident == *"of" {
colors::cyan(&line[range]).to_string()
} else {
- line[range].to_string()
+ let next = lexed_items.peek().map(|item| &item.inner);
+ if matches!(
+ next,
+ Some(deno_ast::TokenOrComment::Token(Token::LParen))
+ ) {
+ // We're looking for something that looks like a function
+ // We use a simple heuristic: 'ident' followed by 'LParen'
+ colors::intense_blue(&line[range]).to_string()
+ } else {
+ line[range].to_string()
+ }
}
}
},