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 | |
parent | e7c894e8f54ebd2d9fd61c97a265906ac54e2068 (diff) |
refactor: upgrade to deno_ast 0.15 (#14680)
Diffstat (limited to 'cli/tools/repl')
-rw-r--r-- | cli/tools/repl/editor.rs | 31 | ||||
-rw-r--r-- | cli/tools/repl/mod.rs | 2 | ||||
-rw-r--r-- | cli/tools/repl/session.rs | 2 |
3 files changed, 16 insertions, 19 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() } }, ); diff --git a/cli/tools/repl/mod.rs b/cli/tools/repl/mod.rs index 7ca229ab3..110a89f14 100644 --- a/cli/tools/repl/mod.rs +++ b/cli/tools/repl/mod.rs @@ -70,7 +70,7 @@ async fn read_eval_file( .fetch(&specifier, &mut Permissions::allow_all()) .await?; - Ok((*file.source).clone()) + Ok((*file.source).to_string()) } pub async fn run( diff --git a/cli/tools/repl/session.rs b/cli/tools/repl/session.rs index c256172e4..d5058ab72 100644 --- a/cli/tools/repl/session.rs +++ b/cli/tools/repl/session.rs @@ -332,7 +332,7 @@ impl ReplSession { ) -> Result<TsEvaluateResponse, AnyError> { let parsed_module = deno_ast::parse_module(deno_ast::ParseParams { specifier: "repl.ts".to_string(), - source: deno_ast::SourceTextInfo::from_string(expression.to_string()), + text_info: deno_ast::SourceTextInfo::from_string(expression.to_string()), media_type: deno_ast::MediaType::TypeScript, capture_tokens: false, maybe_syntax: None, |