diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2022-05-20 16:40:55 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-20 16:40:55 -0400 |
commit | 1fcecb6789c3f111bc1554766ba9347afcfd02dc (patch) | |
tree | 19cd1b121412b992994b2fe4bea0463793d3986e /cli/tools/repl/editor.rs | |
parent | e7c894e8f54ebd2d9fd61c97a265906ac54e2068 (diff) |
refactor: upgrade to deno_ast 0.15 (#14680)
Diffstat (limited to 'cli/tools/repl/editor.rs')
-rw-r--r-- | cli/tools/repl/editor.rs | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/cli/tools/repl/editor.rs b/cli/tools/repl/editor.rs index 43047e585..82719f27a 100644 --- a/cli/tools/repl/editor.rs +++ b/cli/tools/repl/editor.rs @@ -179,7 +179,7 @@ impl Completer for EditorHelper { if !lsp_completions.is_empty() { // assumes all lsp completions have the same start position return Ok(( - lsp_completions[0].span.lo.0 as usize, + lsp_completions[0].range.start, lsp_completions.into_iter().map(|c| c.new_text).collect(), )); } @@ -302,43 +302,40 @@ impl Highlighter for EditorHelper { // 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(); - let span = std::ops::Range { - start: item.span.lo.0 as usize, - end: item.span.hi.0 as usize, - }; + let range = item.range; out_line.replace_range( - span.start + offset..span.end + offset, + range.start + offset..range.end + offset, &match item.inner { deno_ast::TokenOrComment::Token(token) => match token { Token::Str { .. } | Token::Template { .. } | Token::BackQuote => { - colors::green(&line[span]).to_string() + colors::green(&line[range]).to_string() } - Token::Regex(_, _) => colors::red(&line[span]).to_string(), + Token::Regex(_, _) => colors::red(&line[range]).to_string(), Token::Num { .. } | Token::BigInt { .. } => { - colors::yellow(&line[span]).to_string() + colors::yellow(&line[range]).to_string() } Token::Word(word) => match word { Word::True | Word::False | Word::Null => { - colors::yellow(&line[span]).to_string() + colors::yellow(&line[range]).to_string() } - Word::Keyword(_) => colors::cyan(&line[span]).to_string(), + Word::Keyword(_) => colors::cyan(&line[range]).to_string(), Word::Ident(ident) => { if ident == *"undefined" { - colors::gray(&line[span]).to_string() + colors::gray(&line[range]).to_string() } else if ident == *"Infinity" || ident == *"NaN" { - colors::yellow(&line[span]).to_string() + colors::yellow(&line[range]).to_string() } else if ident == *"async" || ident == *"of" { - colors::cyan(&line[span]).to_string() + colors::cyan(&line[range]).to_string() } else { - line[span].to_string() + line[range].to_string() } } }, - _ => line[span].to_string(), + _ => line[range].to_string(), }, deno_ast::TokenOrComment::Comment { .. } => { - colors::gray(&line[span]).to_string() + colors::gray(&line[range]).to_string() } }, ); |