Skip to content

Commit

Permalink
refactor: remove dead code from lsp (denoland#13743)
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Feb 23, 2022
1 parent 7122187 commit 973fe6d
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 134 deletions.
13 changes: 0 additions & 13 deletions cli/lsp/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use deno_core::anyhow::anyhow;
use deno_core::error::custom_error;
use deno_core::error::AnyError;
use deno_core::serde::Deserialize;
use deno_core::serde_json;
use deno_core::serde_json::json;
use deno_core::ModuleSpecifier;
use lspower::lsp;
Expand Down Expand Up @@ -61,18 +60,6 @@ static PREFERRED_FIXES: Lazy<HashMap<&'static str, (u32, bool)>> =
static IMPORT_SPECIFIER_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r#"\sfrom\s+["']([^"']*)["']"#).unwrap());

static DENO_TYPES_RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(r#"(?i)^\s*@deno-types\s*=\s*(?:["']([^"']+)["']|(\S+))"#).unwrap()
});

static TRIPLE_SLASH_REFERENCE_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"(?i)^/\s*<reference\s.*?/>").unwrap());

static PATH_REFERENCE_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r#"(?i)\spath\s*=\s*["']([^"']*)["']"#).unwrap());
static TYPES_REFERENCE_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r#"(?i)\stypes\s*=\s*["']([^"']*)["']"#).unwrap());

const SUPPORTED_EXTENSIONS: &[&str] = &[".ts", ".tsx", ".js", ".jsx", ".mjs"];

/// Category of self-generated diagnostic messages (those not coming from)
Expand Down
1 change: 0 additions & 1 deletion cli/lsp/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use deno_core::anyhow::bail;
use deno_core::error::AnyError;
use deno_core::futures::future;
use deno_core::serde_json;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use lspower::lsp;
use lspower::lsp::ConfigurationItem;
Expand Down
4 changes: 1 addition & 3 deletions cli/lsp/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
use super::client::Client;
use super::config::ConfigSnapshot;
use super::documents::Documents;
use super::language_server;
use super::lsp_custom;
use super::registries::ModuleRegistry;
use super::tsc;

use crate::fs_util::is_supported_ext;
use crate::fs_util::specifier_to_file_path;

use deno_ast::swc::common::BytePos;
use deno_ast::LineAndColumnIndex;
use deno_ast::SourceTextInfo;
use deno_core::normalize_path;
Expand Down Expand Up @@ -105,7 +103,7 @@ fn to_narrow_lsp_range(
});
let text_bytes = text_info.text_str().as_bytes();
let has_trailing_quote =
matches!(text_bytes[end_byte_index.0 as usize - 1], (b'"' | b'\''));
matches!(text_bytes[end_byte_index.0 as usize - 1], b'"' | b'\'');
lsp::Range {
start: lsp::Position {
line: range.start.line as u32,
Expand Down
14 changes: 0 additions & 14 deletions cli/lsp/config.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.

use deno_core::anyhow::anyhow;
use deno_core::error::AnyError;
use deno_core::parking_lot::RwLock;
use deno_core::serde::Deserialize;
use deno_core::serde::Serialize;
use deno_core::serde_json;
use deno_core::serde_json::Value;
use deno_core::url::Url;
use deno_core::ModuleSpecifier;
use deno_runtime::tokio_util::create_basic_runtime;
use log::error;
use lsp::WorkspaceFolder;
use lspower::lsp;
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::sync::Arc;
use std::thread;
use tokio::sync::mpsc;

use super::client::Client;

pub const SETTINGS_SECTION: &str = "deno";

Expand Down Expand Up @@ -221,11 +212,6 @@ impl ConfigSnapshot {
}
}

enum ConfigRequest {
All,
Specifier(ModuleSpecifier, ModuleSpecifier),
}

#[derive(Debug, Clone)]
pub struct SpecifierWithClientUri {
pub specifier: ModuleSpecifier,
Expand Down
9 changes: 2 additions & 7 deletions cli/lsp/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,11 @@ use deno_runtime::tokio_util::create_basic_runtime;
use log::error;
use lspower::lsp;
use std::collections::HashMap;
use std::collections::HashSet;
use std::mem;
use std::sync::Arc;
use std::thread;
use tokio::sync::mpsc;
use tokio::sync::Mutex;
use tokio::time::sleep;
use tokio::time::Duration;
use tokio::time::Instant;
use tokio_util::sync::CancellationToken;

pub(crate) type SnapshotForDiagnostics =
Expand Down Expand Up @@ -80,7 +76,7 @@ impl DiagnosticsPublisher {
// in case they're not keep track of that
let diagnostics_by_version =
all_diagnostics.entry(specifier.clone()).or_default();
let mut version_diagnostics =
let version_diagnostics =
diagnostics_by_version.entry(version).or_default();
version_diagnostics.extend(diagnostics);

Expand Down Expand Up @@ -180,6 +176,7 @@ impl DiagnosticsServer {
self.ts_diagnostics.invalidate_all();
}

#[allow(unused_must_use)]
pub(crate) fn start(&mut self) {
let (tx, mut rx) = mpsc::unbounded_channel::<SnapshotForDiagnostics>();
self.channel = Some(tx);
Expand Down Expand Up @@ -574,7 +571,6 @@ struct DiagnosticDataSpecifier {
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
struct DiagnosticDataRedirect {
pub specifier: ModuleSpecifier,
pub redirect: ModuleSpecifier,
}

Expand Down Expand Up @@ -1033,7 +1029,6 @@ let c: number = "a";

#[tokio::test]
async fn test_cancelled_ts_diagnostics_request() {
let specifier = ModuleSpecifier::parse("file:https:///a.ts").unwrap();
let (snapshot, _) = setup(&[(
"file:https:///a.ts",
r#"export let a: string = 5;"#,
Expand Down
28 changes: 0 additions & 28 deletions cli/lsp/documents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use deno_core::error::AnyError;
use deno_core::parking_lot::Mutex;
use deno_core::url;
use deno_core::ModuleSpecifier;
use deno_graph::source::ResolveResponse;
use deno_graph::Module;
use deno_graph::Resolved;
use lspower::lsp;
Expand All @@ -37,7 +36,6 @@ use std::path::Path;
use std::path::PathBuf;
use std::str::FromStr;
use std::sync::Arc;
use std::time::SystemTime;

static JS_HEADERS: Lazy<HashMap<String, String>> = Lazy::new(|| {
([(
Expand Down Expand Up @@ -550,32 +548,6 @@ pub(crate) fn to_lsp_range(range: &deno_graph::Range) -> lsp::Range {
}
}

fn to_deno_graph_range(
specifier: &ModuleSpecifier,
maybe_range: Option<&lsp::Range>,
) -> deno_graph::Range {
let specifier = specifier.clone();
if let Some(range) = maybe_range {
deno_graph::Range {
specifier,
start: deno_graph::Position {
line: range.start.line as usize,
character: range.start.character as usize,
},
end: deno_graph::Position {
line: range.end.line as usize,
character: range.end.character as usize,
},
}
} else {
deno_graph::Range {
specifier,
start: deno_graph::Position::zeroed(),
end: deno_graph::Position::zeroed(),
}
}
}

/// Recurse and collect specifiers that appear in the dependent map.
fn recurse_dependents(
specifier: &ModuleSpecifier,
Expand Down
8 changes: 1 addition & 7 deletions cli/lsp/language_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ use deno_core::serde_json;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use deno_core::ModuleSpecifier;
use deno_graph::Resolved;
use import_map::ImportMap;
use log::error;
use log::info;
use log::warn;
use lspower::jsonrpc::Error as LspError;
use lspower::jsonrpc::Result as LspResult;
Expand All @@ -20,7 +18,6 @@ use lspower::lsp::*;
use serde_json::from_value;
use std::env;
use std::path::PathBuf;
use std::sync::atomic::Ordering;
use std::sync::Arc;
use tokio::fs;

Expand All @@ -34,7 +31,6 @@ use super::client::Client;
use super::code_lens;
use super::completions;
use super::config::Config;
use super::config::ConfigSnapshot;
use super::config::SETTINGS_SECTION;
use super::diagnostics;
use super::diagnostics::DiagnosticsServer;
Expand All @@ -53,7 +49,6 @@ use super::registries::ModuleRegistry;
use super::registries::ModuleRegistryOptions;
use super::text;
use super::tsc;
use super::tsc::AssetDocument;
use super::tsc::Assets;
use super::tsc::AssetsSnapshot;
use super::tsc::TsServer;
Expand All @@ -65,7 +60,6 @@ use crate::config_file::TsConfig;
use crate::deno_dir;
use crate::file_fetcher::get_source_from_data_url;
use crate::fs_util;
use crate::logger;
use crate::proc_state::import_map_from_text;
use crate::tools::fmt::format_file;
use crate::tools::fmt::format_parsed_source;
Expand Down Expand Up @@ -2484,7 +2478,7 @@ impl lspower::LanguageServer for LanguageServer {
tokio::spawn(async move {
if let Ok(configs) = client
.specifier_configurations(
specifiers.iter().map(|(s)| s.client_uri.clone()).collect(),
specifiers.iter().map(|s| s.client_uri.clone()).collect(),
)
.await
{
Expand Down
3 changes: 0 additions & 3 deletions cli/lsp/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.

// FIXME(bartlomieju): remove this attribute
#![allow(unused)]

use deno_core::error::AnyError;
use lspower::LspService;
use lspower::Server;
Expand Down
1 change: 0 additions & 1 deletion cli/lsp/performance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::cmp;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::fmt;
use std::sync::Arc;
use std::time::Duration;
use std::time::Instant;

Expand Down
5 changes: 1 addition & 4 deletions cli/lsp/registries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ use crate::file_fetcher::FileFetcher;
use crate::http_cache::HttpCache;

use deno_core::anyhow::anyhow;
use deno_core::anyhow::Context;
use deno_core::error::AnyError;
use deno_core::resolve_url;
use deno_core::serde::Deserialize;
use deno_core::serde_json;
use deno_core::serde_json::json;
Expand Down Expand Up @@ -640,7 +638,6 @@ impl ModuleRegistry {
value,
..
}) => Some(value),
_ => None,
};
}
}
Expand Down Expand Up @@ -867,7 +864,7 @@ impl ModuleRegistry {
(items, None, false)
}
};
if (incomplete) {
if incomplete {
is_incomplete = true;
}
for (idx, item) in items.into_iter().enumerate() {
Expand Down
3 changes: 0 additions & 3 deletions cli/lsp/repl.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.

use std::collections::HashMap;
use std::future::Future;

use deno_ast::swc::common::BytePos;
use deno_ast::swc::common::Span;
Expand Down Expand Up @@ -34,8 +33,6 @@ use lspower::lsp::VersionedTextDocumentIdentifier;
use lspower::lsp::WorkDoneProgressParams;
use lspower::LanguageServer;

use crate::logger;

use super::client::Client;
use super::config::CompletionSettings;
use super::config::ImportCompletionSettings;
Expand Down
Loading

0 comments on commit 973fe6d

Please sign in to comment.