summaryrefslogtreecommitdiff
path: root/cli/lsp/analysis.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2022-01-19 17:10:14 -0500
committerGitHub <noreply@github.com>2022-01-19 17:10:14 -0500
commitf73a5fbc89c1e1255ae886b1dfe23329d7ad8713 (patch)
tree9e5054ef3ff6ef2ba3d55283ca8b6ec6cdb764de /cli/lsp/analysis.rs
parent6cf05220e3370365a2c6ce8116d1c5624004ca59 (diff)
refactor(lsp): reduce data stored in `StateSnapshot` (#13426)
Diffstat (limited to 'cli/lsp/analysis.rs')
-rw-r--r--cli/lsp/analysis.rs21
1 files changed, 9 insertions, 12 deletions
diff --git a/cli/lsp/analysis.rs b/cli/lsp/analysis.rs
index bbc30043d..03329a8b9 100644
--- a/cli/lsp/analysis.rs
+++ b/cli/lsp/analysis.rs
@@ -1,5 +1,6 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
+use super::documents::Documents;
use super::language_server;
use super::tsc;
@@ -171,14 +172,11 @@ fn code_as_string(code: &Option<lsp::NumberOrString>) -> String {
fn check_specifier(
specifier: &str,
referrer: &ModuleSpecifier,
- snapshot: &language_server::StateSnapshot,
+ documents: &Documents,
) -> Option<String> {
for ext in SUPPORTED_EXTENSIONS {
let specifier_with_ext = format!("{}{}", specifier, ext);
- if snapshot
- .documents
- .contains_import(&specifier_with_ext, referrer)
- {
+ if documents.contains_import(&specifier_with_ext, referrer) {
return Some(specifier_with_ext);
}
}
@@ -190,10 +188,9 @@ fn check_specifier(
pub(crate) fn fix_ts_import_changes(
referrer: &ModuleSpecifier,
changes: &[tsc::FileTextChanges],
- language_server: &language_server::Inner,
+ documents: &Documents,
) -> Result<Vec<tsc::FileTextChanges>, AnyError> {
let mut r = Vec::new();
- let snapshot = language_server.snapshot()?;
for change in changes {
let mut text_changes = Vec::new();
for text_change in &change.text_changes {
@@ -205,7 +202,7 @@ pub(crate) fn fix_ts_import_changes(
.ok_or_else(|| anyhow!("Missing capture."))?
.as_str();
if let Some(new_specifier) =
- check_specifier(specifier, referrer, &snapshot)
+ check_specifier(specifier, referrer, documents)
{
let new_text =
text_change.new_text.replace(specifier, &new_specifier);
@@ -234,7 +231,7 @@ pub(crate) fn fix_ts_import_changes(
fn fix_ts_import_action(
referrer: &ModuleSpecifier,
action: &tsc::CodeFixAction,
- language_server: &language_server::Inner,
+ documents: &Documents,
) -> Result<tsc::CodeFixAction, AnyError> {
if action.fix_name == "import" {
let change = action
@@ -251,9 +248,8 @@ fn fix_ts_import_action(
.get(1)
.ok_or_else(|| anyhow!("Missing capture."))?
.as_str();
- let snapshot = language_server.snapshot()?;
if let Some(new_specifier) =
- check_specifier(specifier, referrer, &snapshot)
+ check_specifier(specifier, referrer, documents)
{
let description = action.description.replace(specifier, &new_specifier);
let changes = action
@@ -622,7 +618,8 @@ impl CodeActionCollection {
"The action returned from TypeScript is unsupported.",
));
}
- let action = fix_ts_import_action(specifier, action, language_server)?;
+ let action =
+ fix_ts_import_action(specifier, action, &language_server.documents)?;
let edit = ts_changes_to_edit(&action.changes, language_server).await?;
let code_action = lsp::CodeAction {
title: action.description.clone(),